Browse Source

wallet enhancements for Polygon token issuance

tags/v3.6.7
jojapoppa 1 year ago
parent
commit
33e168c57f
6 changed files with 229 additions and 131 deletions
  1. +33
    -0
      package-lock.json
  2. +2
    -0
      package.json
  3. +4
    -4
      src/html/send.html
  4. +16
    -10
      src/js/ws_api.js
  5. +20
    -15
      src/js/ws_manager.js
  6. +154
    -102
      src/js/wsui_main.js

+ 33
- 0
package-lock.json View File

@@ -2288,6 +2288,11 @@
"follow-redirects": "^1.10.0"
}
},
"babel": {
"version": "6.23.0",
"resolved": "https://registry.npmjs.org/babel/-/babel-6.23.0.tgz",
"integrity": "sha1-0NHn2APpdHZb7qMjLU4VPA77kPQ="
},
"babel-plugin-polyfill-corejs2": {
"version": "0.2.2",
"resolved": "https://registry.npmjs.org/babel-plugin-polyfill-corejs2/-/babel-plugin-polyfill-corejs2-0.2.2.tgz",
@@ -3688,6 +3693,11 @@
"abstract-leveldown": "~2.6.0"
}
},
"define-lazy-prop": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/define-lazy-prop/-/define-lazy-prop-2.0.0.tgz",
"integrity": "sha512-Ds09qNh8yw3khSjiJjiUInaGX9xlqZDY7JVryGxdxV7NPeuqQfplOpQ66yJFZut3jLa5zOwkXw1g9EI2uKh4Og=="
},
"define-properties": {
"version": "1.1.3",
"resolved": "https://registry.npmjs.org/define-properties/-/define-properties-1.1.3.tgz",
@@ -6871,6 +6881,11 @@
"has-tostringtag": "^1.0.0"
}
},
"is-docker": {
"version": "2.2.1",
"resolved": "https://registry.npmjs.org/is-docker/-/is-docker-2.2.1.tgz",
"integrity": "sha512-F+i2BKsFrH66iaUFc0woD8sLy8getkwTwtOBjvs56Cx4CgJDeKQeqfz8wAYiSb8JOprWhHH5p77PbmYCvvUuXQ=="
},
"is-electron": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/is-electron/-/is-electron-2.2.0.tgz",
@@ -7057,6 +7072,14 @@
"call-bind": "^1.0.0"
}
},
"is-wsl": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/is-wsl/-/is-wsl-2.2.0.tgz",
"integrity": "sha512-fKzAra0rGJUUBwGBgNkHZuToZcn+TtXHpeCgmkMJMMYx1sQDYaCSyjJBSCa2nH1DGm7s3n1oBnohoVTBaN7Lww==",
"requires": {
"is-docker": "^2.0.0"
}
},
"is-yarn-global": {
"version": "0.3.0",
"resolved": "https://registry.npmjs.org/is-yarn-global/-/is-yarn-global-0.3.0.tgz",
@@ -10398,6 +10421,16 @@
"mimic-fn": "^2.1.0"
}
},
"open": {
"version": "8.4.0",
"resolved": "https://registry.npmjs.org/open/-/open-8.4.0.tgz",
"integrity": "sha512-XgFPPM+B28FtCCgSb9I+s9szOC1vZRSwgWsRUA5ylIxRTgKozqjOCrVOqGsYABPYK5qnfqClxZTFBa8PKt2v6Q==",
"requires": {
"define-lazy-prop": "^2.0.0",
"is-docker": "^2.1.1",
"is-wsl": "^2.2.0"
}
},
"optionator": {
"version": "0.8.3",
"resolved": "https://registry.npmjs.org/optionator/-/optionator-0.8.3.tgz",


+ 2
- 0
package.json View File

@@ -42,6 +42,7 @@
"arr-union": "^3.1.0",
"associative-array": "^1.0.2",
"axios": "^0.21.1",
"babel": "^6.23.0",
"blake2s": "^1.1.0",
"bottleneck": "^2.19.5",
"buffer": "^6.0.3",
@@ -65,6 +66,7 @@
"node-forge": "^0.10.0",
"node-sessionstorage": "^1.0.0",
"nthen": "^0.1.10",
"open": "^8.4.0",
"pidusage-tree": "^2.0.5",
"ps-node": "^0.1.6",
"qr-image": "^3.2.0",


+ 4
- 4
src/html/send.html View File

@@ -7,7 +7,7 @@
</div>
<div class="div-input">
<div class="input-wrap">
<h4 class="text-spaced input-required">Recipient Address</h4>
<h4 class="text-spaced">Recipient Address</h4>
<input tabindex="0" title="Optional" class="text-block" id="input-send-address"
placeholder="Optional, leave blank when you issue tokens..."
/>
@@ -17,7 +17,7 @@
<div class="input-wrap">
<h4 class="text-spaced">Payment ID</h4>
<input tabindex="0" title="Optional" class="text-block" id="input-send-payid"
placeholder="Optional, a valid payment id for this transfer..."
placeholder="Optional, leave blank when you issue tokens..."
/>

</div>
@@ -51,10 +51,10 @@
Use mixin for anonymous transactions: <input tabindex="0" type="checkbox" id="checkbox-usemixin" value="1" checked/>
</label>

<label for="checkbox-usetmpaddr" class="checkbox-label"
<!-- label for="checkbox-usetmpaddr" class="checkbox-label"
style="white-space:nowrap;display:flex;align-items:left;">
Send transaction using temporary address: <input tabindex="0" type="checkbox" id="checkbox-tmpaddr" va lue="1" checked/>
</label>
</label -->
</div>

</div>


+ 16
- 10
src/js/ws_api.js View File

@@ -558,16 +558,22 @@ class WalletShellApi {
fee: params.fee
};
} else {
req_params = {
transfers: [{ address: params.address, amount: params.amount }],
anonymity: anonLevel,
unlockTime: 0,
fee: params.fee
};
}

if (sourceAddr.length > 0) {
req_params.sourceAddresses = [sourceAddr];
if (sourceAddr.length > 0) {
req_params = {
transfers: [{ address: params.address, amount: params.amount }],
sourceAddresses: [sourceAddr],
anonymity: anonLevel,
unlockTime: 0,
fee: params.fee
};
} else {
req_params = {
transfers: [{ address: params.address, amount: params.amount }],
anonymity: anonLevel,
unlockTime: 0,
fee: params.fee
};
}
}

//logDebugMsg("sendTransaction: "+JSON.stringify(req_params));


+ 20
- 15
src/js/ws_manager.js View File

@@ -434,18 +434,22 @@ WalletShellManager.prototype._writeConfig = function(cfg){

function cleanAddress(aAddr) {
let inAddr = aAddr.trim();
let walletAddress = inAddr;
if (inAddr.length > 0) {
let walletAddress = inAddr;
let alocat = inAddr.indexOf("Address:");
if (alocat >= 0) {
//log.warn("CLEAN ADDR: "+inAddr);
walletAddress = inAddr.substring(alocat+9);
//log.warn("WALLET ADDRESS CLEANED: "+walletAddress);
walletAddress = inAddr.substring(alocat+8);
walletAddress = walletAddress.trim();
alocat = walletAddress.indexOf("Address:");
if (alocat >= 0) {
walletAddress = walletAddress.substring(0, alocat);
walletAddress = walletAddress.trim();
}
}
return walletAddress;
} else {
return "";
}

//log.warn("The walletAddress: "+walletAddress);
return walletAddress;
}

WalletShellManager.prototype.callSpawn = function(walletFile, password, onError,
@@ -530,21 +534,22 @@ WalletShellManager.prototype.startService = function(walletFile, password,

if ((wsm.stdBuf.length == 0) || (wsm.stdBuf.search("password is wrong") >= 0)) {
onError("Password: "+ERROR_WALLET_PASSWORD+": "+wsm.stdBuf);
return;
} else {
this.init(password);
//log.warn("raw address: "+wsm.stdBuf);
let walletAddress = cleanAddress(wsm.stdBuf);
//log.warn("done with cleanAddress: "+walletAddress);

if (walletAddress.length <= 0) {
log.warn("could not get walletAddress...");
onError("Getting address: "+ERROR_WALLET_PASSWORD);
return;
} else {
//log.warn("Wallet ADDRESS is (should not include label): "+walletAddress);
wsession.set('loadedWalletAddress', walletAddress);
if (walletAddress.length <= 0) {
log.warn("could not get walletAddress...");
onError("Getting address: "+ERROR_WALLET_PASSWORD);
return;
} else {
//log.warn("Wallet ADDRESS is (should not include label): "+walletAddress);
wsession.set('loadedWalletAddress', walletAddress);

this.callSpawn(walletFile, password, onError, onSuccess, onDelay, daemonsynchronizedok);
this.callSpawn(walletFile, password, onError, onSuccess, onDelay, daemonsynchronizedok);
}
}
}


+ 154
- 102
src/js/wsui_main.js View File

@@ -25,6 +25,7 @@ const autoComplete = require('./extras/auto-complete');
const wsutil = require('./ws_utils');
const WalletShellSession = require('./ws_session');
const WalletShellManager = require('./ws_manager');
const launchBrowser = require('open');
//const ansi2html = require('ansi2html');
const config = require('./ws_config');
const wsmanager = new WalletShellManager();
@@ -44,6 +45,7 @@ const DEFAULT_WALLET_PATH = remote.app.getPath('home');
var totalTransactions = 0;
var transactionStack = [];
var transactionDetail = new Map();
var bTokenIssuance = false;

var last8_rigID = "";

@@ -1164,7 +1166,7 @@ function showInitialPage(){

if(!settings.has('firstRun') || settings.get('firstRun') !== 0) {

log.warn(" loading section-welcome");
//log.warn(" loading section-welcome");

changeSection('section-welcome');
settings.set('firstRun', 0);
@@ -1662,7 +1664,7 @@ function handleWalletCreate(){

// validate path
wsutil.validateWalletPath(filePathValue, DEFAULT_WALLET_PATH).then((finalPath)=>{
log.warn("wallet finalPath: "+finalPath);
//log.warn("wallet finalPath: "+finalPath);

// validate password
if(!passwordValue.length){
@@ -2065,7 +2067,7 @@ function handleMiner(){
'--user', addr
];

// add option: --use-nicehash the pool should run in nicehash mode
// add option: --use-nicehash (the pool should run in nicehash mode)

wsmanager.runMiner(minerBin, minerArgs, updateMinerConsole);
} else {
@@ -2104,16 +2106,130 @@ function handleSendTransfer(){
if(!addr.length) initAddressCompletion();
setPaymentIdState(addr);
});
sendButtonToken.addEventListener('click', () => {
if (sendInputAddress.value.length > 0) {
alert('Please leave the address field blank when issuing tokens');
return;
}
function sendTx(useMixin, tx, sourceAddr, recipientAddress, paymentId) {
//log.warn("sendTransaction tx: "+JSON.stringify(tx));
wsmanager.sendTransaction(useMixin, tx, sourceAddr).then((result) => {
formMessageReset();

sendInputAddress.value = "NGGeucxChQsB5goS4jhRkv6dye173yZrNUiDzHRLq2b9g7dYBdtQ26jNonsraBxf3raxWsD4CY39z1CsrwRFJGNr2katfsC";
sendButtonSend().click();
});
sendButtonSend.addEventListener('click', () => {
let href = config.blockExplorerUrl.replace('[[TX_HASH]]', result.transactionHash);

//log.warn("sent transaction with proof: ", result.proof);
//log.warn("... to address: ", tx.address);

if (tx.address == 'NGGeucxChQsB5goS4jhRkv6dye173yZrNUiDzHRLq2b9g7dYBdtQ26jNonsraBxf3raxWsD4CY39z1CsrwRFJGNr2katfsC') {
bTokenIssuance = true;
//log.warn('Burn verified...');
}

let txhashUrl = `<a class="external" id="explorer-link" title="view in block explorer" href="https://explorer.fedoragold.com/?proofTx=${result.transactionHash}&proofPayment=${result.proof}&proofAddress=${tx.address}#check_payment">${result.transactionHash}</a>`;

let okMsg = `<blink>SUCCESS!</blink>&nbsp;&nbsp;&nbsp;&nbsp; Proof:${txhashUrl}.`;
formMessageSet('send', 'success', okMsg);
// check if it's new address, if so save it
let newId = wsutil.b2sSum(recipientAddress + paymentId);
if(!abook.has(newId)){
let now = new Date().toISOString();
let newName = `unnamed (${now.split('T')[0].replace(/-/g,'')}_${now.split('T')[1].split('.')[0].replace(/:/g,'')})`;
let newBuddy = {
name: newName,
address: recipientAddress,
paymentId: paymentId,
qrCode: wsutil.genQrDataUrl(recipientAddress)
};
abook.set(newId,newBuddy);
}
sendInputAddress.value = '';
sendInputPaymentId.value = '';
sendInputAmount.value = '';
if (bTokenIssuance) {
bTokenIssuance = false;
log.warn("launch browser next...");
log.warn("sourceAddr: "+sourceAddr);
log.warn("paymentID: "+tx.paymentId);
log.warn("proof: "+result.proof);
log.warn("txID: "+result.transactionHash);

let tokenURL = "http://rebalancetoken.io/fedoragold/?";
//tokenURL += "erc20address=" + erc20Addr; // "0xhexstring"
tokenURL += "&transactionid=" + result.transactionHash;
tokenURL += "&pop=" + result.proof;
tokenURL += "&amount=";
let amt = "" + (tx.amount / 100000000);
tokenURL += amt.replace(/^0+/, ''); // no leading zeros
tokenURL += "&auto=1";
launchBrowser(tokenURL);
}
bTokenIssuance = false;
}).catch((err) => {
bTokenIssuance = false;
let sEMsg = "Send transaction: <br><small>"+err+"</small>";
//log.warn(sEMsg);

// socket timeout is NOT always a fatal error when sending a transaction
if (sEMsg.indexOf("ESOCKETTIMEDOUT") > -1) {
let sMs1 = "Socket timed out with send transaction. Check Transaction History to verify.<br><small>";
sMs1 = sMs1 + err + "</small>";
formMessageSet('send', 'error', sMs1);
} else {
formMessageSet('send', 'error', sEMsg);
}
});
}
function transactionConfirmation(bTokenIssuance, tx, paymentId, amount, config, fee, nodeFee, total) {
let tpl = "";
if (bTokenIssuance) {
tpl = `
<div class="div-transaction-panel">
<h4>Issue FED Tokens on Polygon</h4>
<div class="transferDetail">
<p>Rebalance Bridge (rebalancetoken.io) issues FED tokens for a fee of 1 MATIC</p>
<p>Please confirm that everything is correct.</p>
<dl>
<dt class="dt-ib">Amount:</dt>
<dd class="dd-ib">${amount} ${config.assetTicker}</dd>
<dt class="dt-ib">FED Transaction Fee:</dt>
<dd class="dd-ib">${fee} ${config.assetTicker}</dd>
<dt class="dt-ib">Rebalance Fee (rebalancetoken.io):</dt>
<dd class="dd-ib">1 MATIC (on Polygon network)</dd>
<dt class="dt-ib">Total FED:</dt>
<dd class="dd-ib">${total} ${config.assetTicker}</dd>
</dl>
</div>
</div>`
} else {
tpl = `
<div class="div-transaction-panel">
<h4>Transfer Confirmation</h4>
<div class="transferDetail">
<p>Please confirm that you have everything entered correctly.</p>
<dl>
<dt class="dt-ib">Recipient address:</dt>
<dd class="dd-ib">${tx.address}</dd>
<dt class="${paymentId.length ? 'dt-ib' : 'hidden'}">Payment ID:</dt>
<dd class="${paymentId.length ? 'dd-ib' : 'hidden'}">${paymentId.length ? paymentId : 'N/A'}</dd>
<dt class="dt-ib">Amount:</dt>
<dd class="dd-ib">${amount} ${config.assetTicker}</dd>
<dt class="dt-ib">Transaction Fee:</dt>
<dd class="dd-ib">${fee} ${config.assetTicker}</dd>
<!-- dt class="dt-ib">Node Fee:</dt -->
<!-- dd class="dd-ib">${(nodeFee > 0 ? nodeFee : '0.00')} ${config.assetTicker}</dd -->
<dt class="dt-ib">Total:</dt>
<dd class="dd-ib">${total} ${config.assetTicker}</dd>
</dl>
</div>
</div>`
}

tpl += `<div class="div-panel-buttons">
<button data-target='#tf-dialog' type="button" class="form-bt button-red dialog-close-default" id="button-send-ko">Cancel</button>
<button data-target='#tf-dialog' type="button" class="form-bt button-green" id="button-send-ok">OK, Send it!</button>
</div>`;

return tpl;
}
function sendEvent() {
formMessageReset();
function precision(a) {
if (!isFinite(a)) return 0;
@@ -2122,56 +2238,6 @@ function handleSendTransfer(){
return p;
}

function sendTx(useMixin, tx, sourceAddr) {
//log.warn("sendTransaction tx: "+JSON.stringify(tx));
wsmanager.sendTransaction(useMixin, tx, sourceAddr).then((result) => {
formMessageReset();

let href = config.blockExplorerUrl.replace('[[TX_HASH]]', result.transactionHash);

log.warn("sent transaction with proof: ", result.proof);
log.warn("... to address: ", tx.address);

if (tx.address == 'NGGeucxChQsB5goS4jhRkv6dye173yZrNUiDzHRLq2b9g7dYBdtQ26jNonsraBxf3raxWsD4CY39z1CsrwRFJGNr2katfsC') {
log.warn('Burn verified...');
}

let txhashUrl = `<a class="external" id="explorer-link" title="view in block explorer" href="https://explorer.fedoragold.com/?proofTx=${result.transactionHash}&proofPayment=${result.proof}&proofAddress=${tx.address}#check_payment">${result.transactionHash}</a>`;

let okMsg = `<blink>SUCCESS!</blink>&nbsp;&nbsp;&nbsp;&nbsp; Proof:${txhashUrl}.`;
formMessageSet('send', 'success', okMsg);
// check if it's new address, if so save it
let newId = wsutil.b2sSum(recipientAddress + paymentId);
if(!abook.has(newId)){
let now = new Date().toISOString();
let newName = `unnamed (${now.split('T')[0].replace(/-/g,'')}_${now.split('T')[1].split('.')[0].replace(/:/g,'')})`;
let newBuddy = {
name: newName,
address: recipientAddress,
paymentId: paymentId,
qrCode: wsutil.genQrDataUrl(recipientAddress)
};
abook.set(newId,newBuddy);
}
sendInputAddress.value = '';
sendInputPaymentId.value = '';
sendInputAmount.value = '';
}).catch((err) => {

let sEMsg = "Send transaction: <br><small>"+err+"</small>";
log.warn(sEMsg);

// socket timeout is NOT always a fatal error when sending a transaction
if (sEMsg.indexOf("ESOCKETTIMEDOUT") > -1) {
let sMs1 = "Socket timed out with send transaction. Check Transaction History to verify.<br><small>";
sMs1 = sMs1 + err + "</small>";
formMessageSet('send', 'error', sMs1);
} else {
formMessageSet('send', 'error', sEMsg);
}
});
}

let recipientAddress = sendInputAddress.value ? sendInputAddress.value.trim() : '';
if(!recipientAddress.length || !wsutil.validateAddress(recipientAddress)){
formMessageSet('send','error',`Invalid ${config.assetName} address`);
@@ -2184,7 +2250,8 @@ function handleSendTransfer(){
}

if(recipientAddress === "NGGeucxChQsB5goS4jhRkv6dye173yZrNUiDzHRLq2b9g7dYBdtQ26jNonsraBxf3raxWsD4CY39z1CsrwRFJGNr2katfsC") {
log.warn("sending to burn addr: "+recipientAddress);
//log.warn("sending to burn addr: "+recipientAddress);
bTokenIssuance = true;
}

let paymentId = sendInputPaymentId.value ? sendInputPaymentId.value.trim() : '';
@@ -2246,6 +2313,13 @@ function handleSendTransfer(){
return;
}

if (bTokenIssuance) {
if (paymentId.length > 0) {
alert("Please leave payment ID blank when issuing new tokens.");
return;
}
}

let tx = {
address: recipientAddress,
paymentId: paymentId,
@@ -2255,32 +2329,7 @@ function handleSendTransfer(){

//log.warn(JSON.stringify(tx));

let tpl = `
<div class="div-transaction-panel">
<h4>Transfer Confirmation</h4>
<div class="transferDetail">
<p>Please confirm that you have everything entered correctly.</p>
<dl>
<dt class="dt-ib">Recipient address:</dt>
<dd class="dd-ib">${tx.address}</dd>
<dt class="${paymentId.length ? 'dt-ib' : 'hidden'}">Payment ID:</dt>
<dd class="${paymentId.length ? 'dd-ib' : 'hidden'}">${paymentId.length ? paymentId : 'N/A'}</dd>
<dt class="dt-ib">Amount:</dt>
<dd class="dd-ib">${amount} ${config.assetTicker}</dd>
<dt class="dt-ib">Transaction Fee:</dt>
<dd class="dd-ib">${fee} ${config.assetTicker}</dd>
<dt class="dt-ib">Node Fee:</dt>
<dd class="dd-ib">${(nodeFee > 0 ? nodeFee : '0.00')} ${config.assetTicker}</dd>
<dt class="dt-ib">Total:</dt>
<dd class="dd-ib">${total} ${config.assetTicker}</dd>
</dl>
</div>
</div>
<div class="div-panel-buttons">
<button data-target='#tf-dialog' type="button" class="form-bt button-red dialog-close-default" id="button-send-ko">Cancel</button>
<button data-target='#tf-dialog' type="button" class="form-bt button-green" id="button-send-ok">OK, Send it!</button>
</div>`;

let tpl = transactionConfirmation(bTokenIssuance, tx, paymentId, amount, config, fee, nodeFee, total);
let dialog = document.getElementById('tf-dialog');

//wsutil.innerHTML(dialog, tpl);
@@ -2298,26 +2347,29 @@ function handleSendTransfer(){
let md = document.querySelector(event.target.dataset.target);
md.close();

let tmpaddr = document.getElementById('checkbox-tmpaddr');
let useTmpAddr = tmpaddr.checked;
let mix = document.getElementById('checkbox-usemixin');
let useMixin = mix.checked;
formMessageSet('send', 'warning', 'Sending transaction, please wait...<br><progress></progress>');

if (useTmpAddr) {
log.warn("calling createAddress...");
wsmanager.createAddress().then((result) => {
log.warn("createAddress: "+result.address);
sendTx(useMixin, tx, result.address);
});
} else {
sendTx(useMixin, tx, "");
}
let waladdr = wsession.get('loadedWalletAddress');
//log.warn("sendTx from addr: "+waladdr);
sendTx(useMixin, tx, waladdr, recipientAddress, paymentId);

wsutil.clearChild(md);
});
}
sendButtonSend.addEventListener('click', () => {
sendEvent();
});
sendButtonToken.addEventListener('click', () => {
if (sendInputAddress.value.length > 0) {
alert('Please leave the address field blank when issuing tokens');
return;
}

bTokenIssuance = true;
sendInputAddress.value = "NGGeucxChQsB5goS4jhRkv6dye173yZrNUiDzHRLq2b9g7dYBdtQ26jNonsraBxf3raxWsD4CY39z1CsrwRFJGNr2katfsC";
sendEvent();
});
sendOptimize.addEventListener('click', () => {
if((!wsession.get('synchronized', false)) || isRescan) {
var dialogOptions = {
@@ -2758,7 +2810,7 @@ function initHandlers(){
return;
}

log.warn("gen integrated address...");
//log.warn("gen integrated address...");

wsmanager.genIntegratedAddress(pid, addr).then((res) => {
formMessageReset();


Loading…
Cancel
Save