From 4038cf95c7ef0eb623782bd1e911ed5b9a04739f Mon Sep 17 00:00:00 2001 From: pbca26 Date: Mon, 22 Mar 2021 18:05:16 +0300 Subject: [PATCH 1/9] move chain params to a separate file --- api/chains.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 api/chains.js diff --git a/api/chains.js b/api/chains.js new file mode 100644 index 0000000..86b2159 --- /dev/null +++ b/api/chains.js @@ -0,0 +1,16 @@ +var chains = { + 'RICK': { + isV2: false, + params: '-ac_supply=90000000000 -ac_reward=100000000 -ac_cc=3 -ac_staked=10 -addnode=138.201.136.145 -addnode=95.217.44.58', + }, + 'WSB': { + isV2: false, + params: '-ac_supply=90000000000 -ac_cc=3 -ac_reward=100000000 -addnode=94.130.38.173 -addnode=178.63.47.105', + }, + 'TOKENSV2': { + isV2: true, + params: '-ac_supply=10000000 -ac_reward=1000000000 -ac_decay=77700000 -ac_halving=43800 -ac_cc=1 -ac_ccenable=227,224,245,243,228,242,123,247 -addnode=159.69.53.25', + }, +}; + +module.exports = chains; \ No newline at end of file From 904d7b6b9f998c6099947445cf7b75b4c216adbd Mon Sep 17 00:00:00 2001 From: pbca26 Date: Mon, 22 Mar 2021 18:08:38 +0300 Subject: [PATCH 2/9] api add set chain helpers --- api/daemon.js | 90 +++++++++++++++++++++++++++++++++------------------ 1 file changed, 59 insertions(+), 31 deletions(-) diff --git a/api/daemon.js b/api/daemon.js index 99237ef..c32606a 100644 --- a/api/daemon.js +++ b/api/daemon.js @@ -9,6 +9,8 @@ const platform = os.platform() const path = require('path'); const fixPath = require('fix-path'); +const chains = require('./chains'); + let default_config; if (process.argv.indexOf('chain=rick') > -1) { @@ -16,17 +18,31 @@ if (process.argv.indexOf('chain=rick') > -1) { bin_folder: getBinsFolder(), chain_name: 'RICK', coin_name: 'RICK', - chain_launch_params: '-ac_supply=90000000000 -ac_reward=100000000 -ac_cc=3 -ac_staked=10 -addnode=138.201.136.145 -addnode=95.217.44.58 -printtoconsole' + chain_launch_params: chains.RICK + ' -printtoconsole' } } else { default_config = { bin_folder: getBinsFolder(), chain_name: 'WSB', coin_name: 'WSB', - chain_launch_params: '-ac_supply=90000000000 -ac_cc=3 -ac_reward=100000000 -addnode=94.130.38.173 -addnode=178.63.47.105 -printtoconsole' + chain_launch_params: chains.WSB + ' -printtoconsole' } } +function setChain(chain) { + default_config = { + bin_folder: getBinsFolder(), + chain_name: chain, + coin_name: chain, + chain_launch_params: chains[chain].params + ' -printtoconsole' + }; + + config.coin_name = chain; + + console.warn('setChain config', default_config); + readConfig(); +} + // Data let komodod_path = undefined let cli_path = undefined @@ -43,7 +59,7 @@ function to_cli_args(command) { function readConfig() { // Set default config = { ...default_config } - + // FIXME const config_path = getKomodoFolder() + 'gui_config.json' try { let data = JSON.parse(fs.readFileSync(config_path)) @@ -86,6 +102,7 @@ function forceImportKey(keypair) { getAddressFromPubkey(keypair.pubkey).then(addr_info => { keypair.address = addr_info.address keypair.CCaddress = addr_info.CCaddress + keypair.pubkey = keypair.pubkey resolve({ generated: false, @@ -105,6 +122,7 @@ function prepareDaemon(needs_keygen) { getAddressFromPubkey(keypair.pubkey).then(addr_info => { keypair.address = addr_info.address keypair.CCaddress = addr_info.CCaddress + keypair.pubkey = keypair.pubkey resolve({ generated: needs_keygen, @@ -180,6 +198,7 @@ function launchDaemon(pubkey) { getAddressFromPubkey(keypair.pubkey).then(addr_info => { keypair.address = addr_info.address keypair.CCaddress = addr_info.CCaddress + keypair.pubkey = keypair.pubkey resolve({ generated: false, @@ -213,12 +232,18 @@ function stopDaemon() { // Wait a bit and tell that it's done, not being sure let timeout = setTimeout(() => { resolve() }, 20000) - // If we get a close signal, that's it - komodod.on('close', code => { - clearTimeout(timeout) - - resolve() - }) + if (komodod) { + // If we get a close signal, that's it + komodod.on('close', code => { + clearTimeout(timeout) + + resolve() + }) + } else { + clearTimeout(timeout) + + resolve() + } }) }) @@ -411,7 +436,7 @@ function getAddressFromPubkey(pubkey) { if(stdout) { let json = JSON.parse(stdout) // console.log('getAddressFromPubkey success: ', json) - resolve({ address: json.myaddress, CCaddress: json['PubkeyCCaddress(Tokens)'], } ) + resolve({ address: json.myaddress, CCaddress: json['mypk Tokens CC Address'], } ) } }) @@ -470,6 +495,8 @@ function sendTokenToAddress(token_id, address, amount) { reject(stderr) } + console.warn('tokentransfer hex', stdout); + if(stdout) { console.log('tokentransfer ' + address + ' ' + amount) @@ -488,30 +515,30 @@ function sendTokenToAddress(token_id, address, amount) { function createToken(name, supply, description) { - return new Promise((resolve, reject) => { - console.log('Creating token ' + name + ', supply: ' + supply + ' (' + (supply * 0.00000001) + ') ' + ' description: ' + description) - - let args = to_cli_args('tokencreate ' + name + ' ' + supply * 0.00000001) - if(description !== '') args.push('"' + description + '"') + return new Promise((resolve, reject) => { + console.log('Creating token ' + name + ', supply: ' + supply + ' (' + (supply * 0.00000001) + ') ' + ' description: ' + description) + + let args = to_cli_args('tokencreate ' + name + ' ' + supply * 0.00000001) + if(description !== '') args.push('"' + description + '"') - child_process.execFile(cli_path, args, (error, stdout, stderr) => { + child_process.execFile(cli_path, args, (error, stdout, stderr) => { - if(stderr) { - console.log('createToken failed: ', stderr) - reject(stderr) - } + if(stderr) { + console.log('createToken failed: ', stderr) + reject(stderr) + } - if(stdout) { - console.log('Broadcasting tokencreate...') - broadcastTX(JSON.parse(stdout).hex).then(txid => { - resolve(txid) - }).catch(e => { - reject(e) - }) - } + if(stdout) { + console.log('Broadcasting tokencreate...') + broadcastTX(JSON.parse(stdout).hex).then(txid => { + resolve(txid) + }).catch(e => { + reject(e) + }) + } - }) - }) + }) + }) } @@ -651,5 +678,6 @@ module.exports = { cancelTokenOrder, readConfig, forceImportKey, - chainName: default_config.chain_name, + chains, + setChain, } \ No newline at end of file From a2a596c653fbc161ba6d986317735c27fb524e75 Mon Sep 17 00:00:00 2001 From: pbca26 Date: Mon, 29 Mar 2021 18:03:42 +0300 Subject: [PATCH 3/9] add chain selector modal html --- index.html | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/index.html b/index.html index 83ba84a..b20a9e4 100644 --- a/index.html +++ b/index.html @@ -138,7 +138,7 @@
- My tokens address + My tokens address | pubkey @@ -612,7 +612,21 @@ - + + From 631a5bba22db78c47c8144a73f612c766e7a560e Mon Sep 17 00:00:00 2001 From: pbca26 Date: Mon, 29 Mar 2021 20:53:24 +0300 Subject: [PATCH 4/9] add chain selector logic --- renderer.js | 108 ++++++++++++++++++++++++++++++++-------------------- 1 file changed, 66 insertions(+), 42 deletions(-) diff --git a/renderer.js b/renderer.js index c042bed..a032a89 100644 --- a/renderer.js +++ b/renderer.js @@ -309,45 +309,69 @@ $('#form-submit-password').submit(event => { function init(pubkey) { return new Promise((resolve, reject) => { - inputLock(true, 'Preparing the daemon.') - - // Launch daemon - daemon.startUp(pubkey).then(wallet => { - // Store the key - store.set('pubkey', wallet.pubkey) - - // Save the new pubkey if generated for first time - if(wallet.generated) { - store.set('generated_privkey', wallet.privkey) - store.set('generated_pubkey', wallet.pubkey) - - console.log('Firstprivkey : ', store.get('first_privkey')) - if(store.get('first_privkey') === '') { - store.set('first_privkey', wallet.privkey) - store.set('first_pubkey', wallet.pubkey) - } - } - - // // Add block for test - // let transactions = [] - // for(let i = 0; i < 500; ++i) - // transactions.push(daemon.sendToAddress('RKSXk8CSb1tR1WBfx4z4xdedYLHPcPTFTx', 0.01)) - // Promise.all(transactions, () => { console.log('Sent all') }) - - // Set UI Values - updateNewAddress(wallet.address) - $('#myccaddress').val(daemon.getKeyPair().CCaddress); - Promise.all([ - updateBalance(), - updateTokenLists(), - updateTokenOrders() - ]).then(() => { - // Unlock input - inputLock(false) - - resolve() - }) - }) + console.warn('init'); + + $("#chain-selector").modal({ + backdrop: "static", // Remove ability to close modal with click + keyboard: false, // Remove option to close with keyboard + show: true // Display loader! + }) + + var $secondChoice = $("#chain-selector-dropdown"); + $secondChoice.empty(); + $secondChoice.append(""); + $.each(Object.keys(daemon.chains), function(index, value) { + $secondChoice.append(""); + }); + + $('#chain-selector-dropdown').on('change', function() { + console.warn(this.value); + + if (this.value !== 'None') { + daemon.setChain(this.value); + $("#chain-selector").modal('hide'); + + inputLock(true, 'Preparing the daemon.') + + // Launch daemon + daemon.startUp(pubkey).then(wallet => { + // Store the key + store.set('pubkey', wallet.pubkey) + + // Save the new pubkey if generated for first time + if(wallet.generated) { + store.set('generated_privkey', wallet.privkey) + store.set('generated_pubkey', wallet.pubkey) + + console.log('Firstprivkey : ', store.get('first_privkey')) + if(store.get('first_privkey') === '') { + store.set('first_privkey', wallet.privkey) + store.set('first_pubkey', wallet.pubkey) + } + } + + // // Add block for test + // let transactions = [] + // for(let i = 0; i < 500; ++i) + // transactions.push(daemon.sendToAddress('RKSXk8CSb1tR1WBfx4z4xdedYLHPcPTFTx', 0.01)) + // Promise.all(transactions, () => { console.log('Sent all') }) + + // Set UI Values + updateNewAddress(wallet.address) + $('#myccaddress').val(daemon.getKeyPair().CCaddress + ' | ' + daemon.getKeyPair().pubkey); + Promise.all([ + updateBalance(), + updateTokenLists(), + updateTokenOrders() + ]).then(() => { + // Unlock input + inputLock(false) + + resolve() + }) + }) + } + }); }) } @@ -574,7 +598,7 @@ $('#form-create-token-submit').submit(event => { (description !== '' ? ('(' + description + ')') : '') + ' with ' + supply + ' ' + daemon.getCoinName() + '\nTransaction ID: ' + createTokenTxid + '') $('#txid-link').on('click', function(e) { - openExtLink('http://www.atomicexplorer.com:10026/#/tokens/contract/' + daemon.chainName + '/' + createTokenTxid); + openExtLink('http://www.atomicexplorer.com:10026/#/tokens/contract/' + daemon.getCoinName() + '/' + createTokenTxid); }) addToHistory('Created token ' + name + (description !== '' ? ('(' + description + ')') : '') @@ -631,7 +655,7 @@ actions.forEach(action => { addToHistory('Created token order, ' + action + 'ing ' + supply + ' ' + name + ' for ' + stripZeros(price) + ' ' + daemon.getCoinName() + ' each. \nTransaction ID: ' + sellTokenOrderTxid) $('#txid-link').on('click', function(e) { - openExtLink('http://www.atomicexplorer.com:10026/#/tokens/transaction/' + daemon.chainName + '/' + tokenid + '/' + sellTokenOrderTxid); + openExtLink('http://www.atomicexplorer.com:10026/#/tokens/transaction/' + daemon.getCoinName() + '/' + tokenid + '/' + sellTokenOrderTxid); }) }).catch(e => { statusAlert(false, 'Could not create token trade order: ' + e) @@ -875,7 +899,7 @@ $('#form-token-fill-order-submit').submit(event => { '\nOrder ID: ' + txid + '\nFill Order ID: ' + fill_order_id) $('#txid-link').on('click', function(e) { - openExtLink('http://www.atomicexplorer.com:10026/#/tokens/transactions/' + daemon.chainName + '/' + tokenid); + openExtLink('http://www.atomicexplorer.com:10026/#/tokens/transactions/' + daemon.getCoinName() + '/' + tokenid); }) }).catch(e => { statusAlert(false, e) From 66d5afdd4bd8fd24d4765f475385637cbc39b82c Mon Sep 17 00:00:00 2001 From: pbca26 Date: Thu, 1 Apr 2021 16:39:00 +0300 Subject: [PATCH 5/9] #18 add nft creator form --- api/daemon.js | 65 ++++++++++++++++++++++++++++++++------------------- index.html | 40 +++++++++++++++++++++++++++++++ renderer.js | 44 ++++++++++++++++++++++++++++++---- style.css | 3 +++ 4 files changed, 124 insertions(+), 28 deletions(-) diff --git a/api/daemon.js b/api/daemon.js index c32606a..f1b297a 100644 --- a/api/daemon.js +++ b/api/daemon.js @@ -514,31 +514,48 @@ function sendTokenToAddress(token_id, address, amount) { -function createToken(name, supply, description) { - return new Promise((resolve, reject) => { - console.log('Creating token ' + name + ', supply: ' + supply + ' (' + (supply * 0.00000001) + ') ' + ' description: ' + description) - - let args = to_cli_args('tokencreate ' + name + ' ' + supply * 0.00000001) - if(description !== '') args.push('"' + description + '"') - - child_process.execFile(cli_path, args, (error, stdout, stderr) => { - - if(stderr) { - console.log('createToken failed: ', stderr) - reject(stderr) - } - - if(stdout) { - console.log('Broadcasting tokencreate...') - broadcastTX(JSON.parse(stdout).hex).then(txid => { - resolve(txid) - }).catch(e => { - reject(e) - }) - } +function createToken(name, supply, description, opreturn) { + return new Promise((resolve, reject) => { + console.log('Creating token ' + name + ', supply: ' + supply + ' (' + (supply * 0.00000001) + ') ' + ' description: ' + description) + + if (opreturn && opreturn !== null) { + console.warn('Create token NFT', opreturn) + opreturn = Buffer.from(JSON.stringify(opreturn)).toString('hex') + console.warn('NTF opreturn hex', opreturn) + } - }) - }) + let args = to_cli_args('tokencreate ' + name + ' ' + supply * 0.00000001) + if(description !== '') args.push('"' + description + '"') + if(opreturn && opreturn !== null) args.push('f7' + opreturn) + + console.warn('token create cliarg', args) + console.warn(args.join(' ')) + + child_process.execFile(cli_path, args, (error, stdout, stderr) => { + + if(stderr) { + console.log('createToken failed: ', stderr) + reject(stderr) + } + + if (JSON.stringify(stdout).indexOf('Non-fungible data incorrect') > -1) { + console.log('createToken failed: ', stdout) + reject(stdout) + } + + console.warn('daemon token create stdout', stdout) + + if(stdout) { + console.log('Broadcasting tokencreate...') + broadcastTX(JSON.parse(stdout).hex).then(txid => { + resolve(txid) + }).catch(e => { + reject(e) + }) + } + + }) + }) } diff --git a/index.html b/index.html index b20a9e4..27c1117 100644 --- a/index.html +++ b/index.html @@ -426,6 +426,16 @@