Improving broadcast functionality
This commit is contained in:
Vivek Teega 2020-11-09 16:39:39 +05:30
parent a4ad1bc9c6
commit 39d01a91b5

View File

@ -70,7 +70,8 @@
<h3>Welcome back</h3> <h3>Welcome back</h3>
<p>Just enter your FLO private key to continue.</p> <p>Just enter your FLO private key to continue.</p>
<form action="" onsubmit="return false"> <form action="" onsubmit="return false">
<sm-input id="get_priv_key_field" privateKey placeholder="FLO Private Key" type="password" required animate> <sm-input id="get_priv_key_field" privateKey placeholder="FLO Private Key" type="password"
required animate>
</sm-input> </sm-input>
<button id="sign_in_btn" class="primary-btn expand" type="submit" disabled> <button id="sign_in_btn" class="primary-btn expand" type="submit" disabled>
Sign In Sign In
@ -79,8 +80,10 @@
</sm-panel> </sm-panel>
<sm-panel> <sm-panel>
<h3>Get started</h3> <h3>Get started</h3>
<p>Create your FLO public and private key pair. <Strong>Don't forget to store them securely!</Strong></p> <p>Create your FLO public and private key pair. <Strong>Don't forget to store them
<sm-button id="generate_flo_id" onclick="generateId()" variant="primary">Get FLO credentials</sm-button> securely!</Strong></p>
<sm-button id="generate_flo_id" onclick="generateId()" variant="primary">Get FLO credentials
</sm-button>
<section id="credentials_section" class="hide-completely"> <section id="credentials_section" class="hide-completely">
<h5>FLO ID</h5> <h5>FLO ID</h5>
<div class="copy-row"> <div class="copy-row">
@ -127,7 +130,9 @@
<sm-panel> <sm-panel>
<div id="my_qr_code"></div> <div id="my_qr_code"></div>
<p>Show this QR Code to receive money using RanchiMall Pay</p> <p>Show this QR Code to receive money using RanchiMall Pay</p>
<a href="" id="download_qr"><sm-button>Download my QR code</sm-button></a> <a href="" id="download_qr">
<sm-button>Download my QR code</sm-button>
</a>
</sm-panel> </sm-panel>
</sm-tab-panels> </sm-tab-panels>
</sm-popup> </sm-popup>
@ -225,8 +230,8 @@
d="M51.65,8H42.07A18.44,18.44,0,0,1,45,15.78h8.88l-2.2,8H45q-1,7.26-5.8,11.1T25.54,39.47L46,63.43V64H33.41L11,37.93l0-6.72H22.11a13.19,13.19,0,0,0,7.8-2.05,9.77,9.77,0,0,0,3.85-5.38H10.11l2.24-8H33.58Q31.44,9,21.93,9H10.11l2.37-9H53.89Z" /> d="M51.65,8H42.07A18.44,18.44,0,0,1,45,15.78h8.88l-2.2,8H45q-1,7.26-5.8,11.1T25.54,39.47L46,63.43V64H33.41L11,37.93l0-6.72H22.11a13.19,13.19,0,0,0,7.8-2.05,9.77,9.77,0,0,0,3.85-5.38H10.11l2.24-8H33.58Q31.44,9,21.93,9H10.11l2.37-9H53.89Z" />
</svg> </svg>
</sm-input> </sm-input>
<sm-input id="deposited_rupee_txid" placeholder="UPI Transaction ID" minlength="12" <sm-input id="deposited_rupee_txid" placeholder="UPI Transaction ID" minlength="12" maxlength="12" required
maxlength="12" required animate></sm-input> animate></sm-input>
</sm-popup> </sm-popup>
<sm-popup id="withdraw_rupee"> <sm-popup id="withdraw_rupee">
<header class="popup-header" slot="header"> <header class="popup-header" slot="header">
@ -336,7 +341,8 @@
What is this? What is this?
</summary> </summary>
<p> <p>
Don't have enough wallet balance? Pay to our cashier through UPI and our cashier will complete that transaction on your behalf. Don't have enough wallet balance? Pay to our cashier through UPI and our cashier will complete that
transaction on your behalf.
</p> </p>
</details> </details>
<details> <details>
@ -390,7 +396,59 @@
</svg> </svg>
</header> </header>
<section id="success_section" class="flex direction-column hide-completely"> <section id="success_section" class="flex direction-column hide-completely">
<svg id="success_art" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 128 128"><defs><style>.a{fill:#d4145a;}.b{fill:#2e3192;}.c{fill:#fff;}.d{fill:#662d91;}.e{fill:#9e005d;}.f{fill:#00a99d;}</style></defs><title>success-art</title><polygon class="a" points="87.96 46.76 59.68 69.04 48.54 54.9 43.83 58.62 54.97 72.75 58.68 77.47 91.67 51.47 87.96 46.76"/><polygon class="b" points="84.33 42.6 61.5 70.43 47.58 59.02 43.78 63.66 57.7 75.07 62.33 78.88 88.97 46.41 84.33 42.6"/><polygon class="c" points="86.09 44.39 60.64 69.85 47.91 57.12 43.66 61.36 56.39 74.09 60.64 78.33 90.33 48.64 86.09 44.39"/><circle class="a" cx="27" cy="33" r="2"/><circle class="a" cx="111.5" cy="93.5" r="5.5"/><circle class="d" cx="47" cy="88" r="2"/><circle class="d" cx="22.5" cy="82.5" r="4.5"/><circle class="d" cx="45.5" cy="114.5" r="3.5"/><circle class="d" cx="82" cy="18" r="5"/><circle class="e" cx="102.5" cy="51.5" r="1.5"/><circle class="e" cx="60.5" cy="37.5" r="2.5"/><circle class="e" cx="103" cy="77" r="3"/><circle class="e" cx="87.5" cy="108.5" r="3.5"/><circle class="f" cx="39" cy="20" r="3"/><circle class="f" cx="85" cy="83" r="2"/><circle class="f" cx="32.5" cy="101.5" r="3.5"/><circle class="f" cx="112" cy="113" r="1"/><circle class="f" cx="115" cy="29" r="2"/><circle class="f" cx="18" cy="53" r="1"/><circle class="f" cx="11" cy="5" r="1"/></svg> <svg id="success_art" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 128 128">
<defs>
<style>
.a {
fill: #d4145a;
}
.b {
fill: #2e3192;
}
.c {
fill: #fff;
}
.d {
fill: #662d91;
}
.e {
fill: #9e005d;
}
.f {
fill: #00a99d;
}
</style>
</defs>
<title>success-art</title>
<polygon class="a"
points="87.96 46.76 59.68 69.04 48.54 54.9 43.83 58.62 54.97 72.75 58.68 77.47 91.67 51.47 87.96 46.76" />
<polygon class="b"
points="84.33 42.6 61.5 70.43 47.58 59.02 43.78 63.66 57.7 75.07 62.33 78.88 88.97 46.41 84.33 42.6" />
<polygon class="c"
points="86.09 44.39 60.64 69.85 47.91 57.12 43.66 61.36 56.39 74.09 60.64 78.33 90.33 48.64 86.09 44.39" />
<circle class="a" cx="27" cy="33" r="2" />
<circle class="a" cx="111.5" cy="93.5" r="5.5" />
<circle class="d" cx="47" cy="88" r="2" />
<circle class="d" cx="22.5" cy="82.5" r="4.5" />
<circle class="d" cx="45.5" cy="114.5" r="3.5" />
<circle class="d" cx="82" cy="18" r="5" />
<circle class="e" cx="102.5" cy="51.5" r="1.5" />
<circle class="e" cx="60.5" cy="37.5" r="2.5" />
<circle class="e" cx="103" cy="77" r="3" />
<circle class="e" cx="87.5" cy="108.5" r="3.5" />
<circle class="f" cx="39" cy="20" r="3" />
<circle class="f" cx="85" cy="83" r="2" />
<circle class="f" cx="32.5" cy="101.5" r="3.5" />
<circle class="f" cx="112" cy="113" r="1" />
<circle class="f" cx="115" cy="29" r="2" />
<circle class="f" cx="18" cy="53" r="1" />
<circle class="f" cx="11" cy="5" r="1" />
</svg>
</section> </section>
<section id="failure_section" class="hide-completely flex direction-column"> <section id="failure_section" class="hide-completely flex direction-column">
<svg id="failure_svg" class="icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64"> <svg id="failure_svg" class="icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64">
@ -559,7 +617,8 @@
</svg> </svg>
<h5>Home</h5> <h5>Home</h5>
</div> </div>
<div title="requests page" id="request_page_btn" class="navbar-item user-option" onclick="showPage('request_page', this)"> <div title="requests page" id="request_page_btn" class="navbar-item user-option"
onclick="showPage('request_page', this)">
<svg class="icon request-icon" viewBox="0 0 64 64"> <svg class="icon request-icon" viewBox="0 0 64 64">
<path <path
d="M47.28,16.8,29.6,34.64a3.3,3.3,0,0,1-3.59.71L2.5,25.42a3.28,3.28,0,0,1,.26-6.13L59.21.87A3.28,3.28,0,0,1,63.32,5l-18.93,56a3.26,3.26,0,0,1-6.12.18l-6.4-15.68" /> d="M47.28,16.8,29.6,34.64a3.3,3.3,0,0,1-3.59.71L2.5,25.42a3.28,3.28,0,0,1,.26-6.13L59.21.87A3.28,3.28,0,0,1,63.32,5l-18.93,56a3.26,3.26,0,0,1-6.12.18l-6.4-15.68" />
@ -577,8 +636,7 @@
</svg> </svg>
<h5>Scan QR</h5> <h5>Scan QR</h5>
</div> </div>
<div title="activity page" id="activity_page_btn" class="navbar-item" <div title="activity page" id="activity_page_btn" class="navbar-item" onclick="showPage('activity_page', this)">
onclick="showPage('activity_page', this)">
<svg class="icon" viewBox="0 0 64 64"> <svg class="icon" viewBox="0 0 64 64">
<path <path
d="M60.38,1,32.8,33.23a1.77,1.77,0,0,0,1.34,2.92h9.63a.79.79,0,0,1,.71,1.13L33,61.36A1.49,1.49,0,0,0,35.49,63l27.58-32.2a1.77,1.77,0,0,0-1.34-2.92H52.1a.79.79,0,0,1-.71-1.13L62.85,2.64A1.49,1.49,0,0,0,60.38,1Z" /> d="M60.38,1,32.8,33.23a1.77,1.77,0,0,0,1.34,2.92h9.63a.79.79,0,0,1,.71,1.13L33,61.36A1.49,1.49,0,0,0,35.49,63l27.58-32.2a1.77,1.77,0,0,0-1.34-2.92H52.1a.79.79,0,0,1-.71-1.13L62.85,2.64A1.49,1.49,0,0,0,60.38,1Z" />
@ -678,8 +736,7 @@
<div class="user-panel"> <div class="user-panel">
<div class="flex align-center space-between"> <div class="flex align-center space-between">
<h4>My Balances</h4> <h4>My Balances</h4>
<button onclick="refreshBalance(this)" class="refresh-balance action expand" <button onclick="refreshBalance(this)" class="refresh-balance action expand" type="submit">
type="submit">
<h4 class="primary-btn expand"> <h4 class="primary-btn expand">
Refresh Balance Refresh Balance
</h4> </h4>
@ -790,13 +847,16 @@
.a { .a {
stroke-width: 9px; stroke-width: 9px;
} }
.b, .b,
.c { .c {
stroke-width: 5px; stroke-width: 5px;
} }
.c { .c {
stroke-dasharray: 11.94 11.94; stroke-dasharray: 11.94 11.94;
} }
.d { .d {
stroke-width: 3px; stroke-width: 3px;
} }
@ -828,7 +888,8 @@
</sm-panel> </sm-panel>
<sm-panel> <sm-panel>
<div class="flex"> <div class="flex">
<sm-button class="justify-right" onclick="showPayThruCashierRequests()">Load pending</sm-button> <sm-button class="justify-right" onclick="showPayThruCashierRequests()">Load pending
</sm-button>
</div> </div>
<div id="pay_requests_container" class="container"></div> <div id="pay_requests_container" class="container"></div>
<div id="pay_illustration" class="empty-state"> <div id="pay_illustration" class="empty-state">
@ -838,13 +899,16 @@
.a { .a {
stroke-width: 9px; stroke-width: 9px;
} }
.b, .b,
.c { .c {
stroke-width: 5px; stroke-width: 5px;
} }
.c { .c {
stroke-dasharray: 11.94 11.94; stroke-dasharray: 11.94 11.94;
} }
.d { .d {
stroke-width: 3px; stroke-width: 3px;
} }
@ -876,7 +940,8 @@
</sm-panel> </sm-panel>
<sm-panel> <sm-panel>
<div class="flex"> <div class="flex">
<sm-button class="justify-right" onclick="showUnconfirmedRequests()">Load pending</sm-button> <sm-button class="justify-right" onclick="showUnconfirmedRequests()">Load pending
</sm-button>
</div> </div>
<div id="unconfirmed_requests_container" class="container"></div> <div id="unconfirmed_requests_container" class="container"></div>
<div class="empty-state"> <div class="empty-state">
@ -886,13 +951,16 @@
.a { .a {
stroke-width: 9px; stroke-width: 9px;
} }
.b, .b,
.c { .c {
stroke-width: 5px; stroke-width: 5px;
} }
.c { .c {
stroke-dasharray: 11.94 11.94; stroke-dasharray: 11.94 11.94;
} }
.d { .d {
stroke-width: 3px; stroke-width: 3px;
} }
@ -927,8 +995,7 @@
<div class="user-panel"> <div class="user-panel">
<div class="flex align-center space-between"> <div class="flex align-center space-between">
<h4>My Balances</h4> <h4>My Balances</h4>
<button onclick="refreshBalance(this)" class="refresh-balance action expand" <button onclick="refreshBalance(this)" class="refresh-balance action expand" type="submit">
type="submit">
<h4 class="primary-btn expand"> <h4 class="primary-btn expand">
Refresh Balance Refresh Balance
</h4> </h4>
@ -10662,52 +10729,100 @@
}) })
}, },
keep_broadcasting: function (raw_transaction_hash, flosight_url, url_index) {
return new Promise(async (resolve, reject) => {
let broadcast_response = await (await fetch(`${flosight_url[url_index]}/api/tx/send`, {
method: 'POST',
// Adding body or contents to send
body: JSON.stringify({
rawtx: raw_transaction_hash
}),
// Adding headers to the request
headers: {
"Content-type": "application/json; charset=UTF-8"
}
}).catch(error => {
console.error('Error:', error);
})).json()
console.log(broadcast_response.txid.result)
await new Promise(r => setTimeout(r, 2000));
// Checking if transaction has been succesfully broadcasted to flosight
let check_txid = await fetch(`${flosight_url[url_index]}/api/tx/${broadcast_response.txid.result}`)
.then((response) => {
if (response.status === 200) {
return response.json()
} else {
console.log('Transaction doesn\'t exist in flosight')
return false
}
})
.catch(error => {
console.error('Error:', error);
})
console.log('tx response')
console.log(check_txid)
if (check_txid !== false) {
resolve(check_txid['txid'].trim())
} else {
resolve(false)
}
})
},
//Broadcast signed Tx in blockchain using API //Broadcast signed Tx in blockchain using API
broadcastTx: function (signedTxHash) { broadcastTx: function (signedTxHash) {
return new Promise((resolve, reject) => { return new Promise(async (resolve, reject) => {
var request = new XMLHttpRequest();
console.log(url)
if (signedTxHash.length < 1)
reject("Empty Signature");
else {
var params = `{"rawtx":"${signedTxHash}"}`;
console.log('TXhash before broadcast')
var url = `https://teegatest.duckdns.org/broadcastTx/${signedTxHash}`;
console.log('TXhash after broadcast', signedTxHash)
request.open('GET', url, true);
//Send the proper header information along with the request
request.setRequestHeader('Content-type', 'application/json');
request.onload = function () {
if (request.readyState == 4 && request.status == 200) {
console.log(request.response);
resolve(JSON.parse(request.response).stdout);
} else {
console.log('error')
reject(JSON.parse(request.response).stderr);
}
}
request.send('');
/*fetch(`https://teegatest.duckdns.org/broadcastTx/${signedTxHash}`) // broadcast to FLO C++ node through RanchiMall FLO api
.then( try {
async function (response) { let broadcast_response = await (await fetch(`https://ranchimallflo.duckdns.org/api/v1.0/broadcastTx/${signedTxHash}`)
response = JSON.parse(response) .catch(error => {
if (response.returncode == 0) { console.log('Error:', error);
console.log('Broadcasted') //broadcast_transaction(raw_transaction_hash)
console.log(response.stdout) }))
resolve(response.stdout) .json().catch(error => {
console.log('Error:', error);
//broadcast_transaction(raw_transaction_hash)
})
if (broadcast_response.returncode == 0) {
console.log('The accepted transaction hash(RMAPI) is : ' + broadcast_response['stdout'].trim())
resolve(broadcast_response['stdout'].trim())
}
}
catch (err) {
console.log('Error:', err);
}
// Since it failed in ranchimallfloAPI, broadcast to multiple flosights
let flosight_url = ['https://flosight.duckdns.org', 'https://explorer.mediciland.com'],
url_index = 0,
broadcast_status = false,
temp_counter = 1
while (!broadcast_status) {
broadcast_status = await this.keep_broadcasting(signedTxHash, flosight_url, url_index)
if (broadcast_status == false) {
console.log(`Transaction not present in ${flosight_url[url_index]}`)
console.log('Going to sleep state for 2 seconds')
await new Promise(r => setTimeout(r, 2000));
if (temp_counter % 3 === 0) {
if (url_index != len(flosight_url) - 1) {
url_index = url_index + 1
} }
else { else {
console.log('Broadcast failed') url_index = 0
console.log(response.stderr)
reject(response.stderr)
} }
} }
) temp_counter += 1
.catch(function (err) {
console.log('Fetch Error :-S', err);
}); */
} }
}
console.log('The accepted transaction hash is : ' + broadcast_status)
resolve(broadcast_status)
}) })
}, },