From c2129f267ab989da21e1d8018a96b5e3e56375fb Mon Sep 17 00:00:00 2001 From: dusmart Date: Thu, 23 Sep 2021 10:12:24 +0800 Subject: [PATCH 1/5] add vote target&&modify unclaimed to undistributed --- index.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index cae6cad..5c5962a 100644 --- a/index.js +++ b/index.js @@ -22,7 +22,8 @@ FETCHSCRIPT(SCRIPTAGENT).then(v => { { const th = document.createElement('th'); th.innerText = 'script hash'; tr.appendChild(th); } { const th = document.createElement('th'); th.innerText = 'neo balance'; tr.appendChild(th); } { const th = document.createElement('th'); th.innerText = 'gas balance*'; tr.appendChild(th); } - { const th = document.createElement('th'); th.innerText = 'unclaimed gas*'; tr.appendChild(th); } + { const th = document.createElement('th'); th.innerText = 'vote target'; tr.appendChild(th); } + { const th = document.createElement('th'); th.innerText = 'undistributed gas*'; tr.appendChild(th); } v.stack.forEach(vv => { if (!vv.value) return; const tr = document.createElement('tr'); table.appendChild(tr); @@ -30,6 +31,7 @@ FETCHSCRIPT(SCRIPTAGENT).then(v => { { const td = document.createElement('td'); tr.appendChild(td); const code = document.createElement('code'); td.appendChild(code); code.innerText = scripthash; } { const td = document.createElement('td'); tr.appendChild(td); const code = document.createElement('code'); td.appendChild(code); FETCHFUNC(NEO, 'balanceOf', [{ type: 'Hash160', value: scripthash }]).then(vvv => code.innerText = vvv.stack[0].value); } { const td = document.createElement('td'); tr.appendChild(td); const code = document.createElement('code'); td.appendChild(code); FETCHFUNC(GAS, 'balanceOf', [{ type: 'Hash160', value: scripthash }]).then(vvv => code.innerText = vvv.stack[0].value); } + { const td = document.createElement('td'); tr.appendChild(td); const code = document.createElement('code'); td.appendChild(code); FETCHFUNC(NEO, 'getAccountState', [{ type: 'Hash160', value: scripthash }]).then(vvv => code.innerText = `${[...atob(vvv.stack[0].value[2].value)].map(c => c.charCodeAt(0).toString(16).padStart(2, 0)).join('')}`); } { const td = document.createElement('td'); tr.appendChild(td); const code = document.createElement('code'); td.appendChild(code); FETCHFUNC('0xda65b600f7124ce6c79950c1772a36403104f2be', 'currentIndex', []).then(vvv => FETCHFUNC(NEO, 'unclaimedGas', [{ type: 'Hash160', value: scripthash }, { type: 'Integer', value: vvv.stack[0].value }])).then(vvv => code.innerText = vvv.stack[0].value); } }); }) From 41ab3c317b043ef2bd5e165a39121f1b9e9feb0c Mon Sep 17 00:00:00 2001 From: dusmart Date: Thu, 23 Sep 2021 12:05:07 +0800 Subject: [PATCH 2/5] refine code --- index.js | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/index.js b/index.js index 5c5962a..13fc9b4 100644 --- a/index.js +++ b/index.js @@ -17,22 +17,27 @@ FETCHSCRIPT(SCRIPTAGENT).then(v => { const title = document.getElementById('agent-info'); const p = document.createElement('p'); title.parentElement.insertBefore(p, title.nextSibling); p.innerText = `* represents 'multiplied by 10^8'` - const table = document.createElement('table'); title.parentElement.insertBefore(table, title.nextSibling); - const tr = document.createElement('tr'); table.appendChild(tr); - { const th = document.createElement('th'); th.innerText = 'script hash'; tr.appendChild(th); } - { const th = document.createElement('th'); th.innerText = 'neo balance'; tr.appendChild(th); } - { const th = document.createElement('th'); th.innerText = 'gas balance*'; tr.appendChild(th); } - { const th = document.createElement('th'); th.innerText = 'vote target'; tr.appendChild(th); } - { const th = document.createElement('th'); th.innerText = 'undistributed gas*'; tr.appendChild(th); } + const ul = document.createElement('ul'); title.parentElement.insertBefore(ul, title.nextSibling); v.stack.forEach(vv => { if (!vv.value) return; - const tr = document.createElement('tr'); table.appendChild(tr); + const li = document.createElement('li'); ul.appendChild(li); + const table = document.createElement('table'); li.appendChild(table); const scripthash = `0x${[...atob(vv.value)].map(c => c.charCodeAt(0).toString(16).padStart(2, 0)).reverse().join('')}`; - { const td = document.createElement('td'); tr.appendChild(td); const code = document.createElement('code'); td.appendChild(code); code.innerText = scripthash; } - { const td = document.createElement('td'); tr.appendChild(td); const code = document.createElement('code'); td.appendChild(code); FETCHFUNC(NEO, 'balanceOf', [{ type: 'Hash160', value: scripthash }]).then(vvv => code.innerText = vvv.stack[0].value); } - { const td = document.createElement('td'); tr.appendChild(td); const code = document.createElement('code'); td.appendChild(code); FETCHFUNC(GAS, 'balanceOf', [{ type: 'Hash160', value: scripthash }]).then(vvv => code.innerText = vvv.stack[0].value); } - { const td = document.createElement('td'); tr.appendChild(td); const code = document.createElement('code'); td.appendChild(code); FETCHFUNC(NEO, 'getAccountState', [{ type: 'Hash160', value: scripthash }]).then(vvv => code.innerText = `${[...atob(vvv.stack[0].value[2].value)].map(c => c.charCodeAt(0).toString(16).padStart(2, 0)).join('')}`); } - { const td = document.createElement('td'); tr.appendChild(td); const code = document.createElement('code'); td.appendChild(code); FETCHFUNC('0xda65b600f7124ce6c79950c1772a36403104f2be', 'currentIndex', []).then(vvv => FETCHFUNC(NEO, 'unclaimedGas', [{ type: 'Hash160', value: scripthash }, { type: 'Integer', value: vvv.stack[0].value }])).then(vvv => code.innerText = vvv.stack[0].value); } + const data = [ + ['script hash', new Promise(resolve => resolve(scripthash))], + ['neo balance', FETCHFUNC(NEO, 'balanceOf', [{ type: 'Hash160', value: scripthash }]).then(vvv => vvv.stack[0].value)], + ['gas balance*', FETCHFUNC(GAS, 'balanceOf', [{ type: 'Hash160', value: scripthash }]).then(vvv => vvv.stack[0].value)], + ['undistributed gas*', FETCHFUNC('0xda65b600f7124ce6c79950c1772a36403104f2be', 'currentIndex', []).then(vvv => FETCHFUNC(NEO, 'unclaimedGas', [{ type: 'Hash160', value: scripthash }, { type: 'Integer', value: vvv.stack[0].value }])).then(vvv => vvv.stack[0].value)], + ['vote target', FETCHFUNC(NEO, 'getAccountState', [{ type: 'Hash160', value: scripthash }]).then(vvv => `${[...atob(vvv.stack[0].value[2].value)].map(c => c.charCodeAt(0).toString(16).padStart(2, 0)).join('')}`)], + ]; + data.forEach(([k, f]) => { + const tr = document.createElement('tr'); table.appendChild(tr); + const th = document.createElement('th'); tr.appendChild(th); + const td = document.createElement('td'); tr.appendChild(td); + const code = document.createElement('code'); td.appendChild(code); + th.innerText = k; + f.then(vvv => {code.innerText = vvv}); + }) }); }) FETCHFUNC(NEO, 'getCandidates', []).then(v => { From 01a345880affb95d2ac241afcf6d26088d05a641 Mon Sep 17 00:00:00 2001 From: dusmart Date: Thu, 23 Sep 2021 15:45:47 +0800 Subject: [PATCH 3/5] fix base58->hex decoding fix base58->hex decoding as described in https://github.com/neoburger/dashboard/issues/3 --- account.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/account.js b/account.js index 4d32dd9..2d79a4e 100644 --- a/account.js +++ b/account.js @@ -4,7 +4,7 @@ const GAS = '0xd2a4cff31913016155e38e474a2c06d08be276cf'; const BNEO = '0x48c40d4666f93408be1bef038b6722404d9a4c2a'; const BASE58CHARS = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'; const ADDRESS = new URLSearchParams(location.search).get('address'); -const SCRIPTHASH = `0x${[...[...ADDRESS].map(c => BASE58CHARS.indexOf(c)).reduce((acc, i) => acc.map(j => {const x = j * 58 + i; i = x >> 8; return x;}), new Uint8Array(25))].map(c => c.toString(16)).join('').slice(8,48)}`; +const SCRIPTHASH = `0x${[...[...ADDRESS].map(c => BASE58CHARS.indexOf(c)).reduce((acc, i) => acc.map(j => {const x = j * 58 + i; i = x >> 8; return x;}), new Uint8Array(25))].map(c => c.toString(16).padStart(2,'0')).join('').slice(8,48)}`; const FETCHFUNC = (ctr, method, args) => fetch(ENDPOINT, { method: 'POST', body: JSON.stringify({ params: [ctr, method, args, [{ account: BNEO, scopes: 'CalledByEntry', 'allowedcontracts': [], 'allowedgroups': [] }]], method: 'invokefunction', jsonrpc: '2.0', id: 1 }) }).then(v => v.json()).then(v => v.result); const DISPLAY = (id, value) => { const element = document.createElement('code'); element.innerText = value; const title = document.getElementById(id); title.parentElement.insertBefore(element, title.nextSibling); } From 79b21b38920cf4f8655ebe31ab8db981baf02562 Mon Sep 17 00:00:00 2001 From: dusmart Date: Fri, 24 Sep 2021 11:16:11 +0800 Subject: [PATCH 4/5] add support for testnet --- _config.yml | 3 ++- account.js | 7 ++++++- index.js | 8 +++++++- index.md | 4 +++- 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/_config.yml b/_config.yml index c971de5..0db157d 100644 --- a/_config.yml +++ b/_config.yml @@ -1,4 +1,5 @@ theme: jekyll-theme-minimal title: NeoBurger Dashboard -description: NeoBurger Infomation Explorer +description: NeoBurger Infomation Explorer show_downloads: false +github: [metadata] diff --git a/account.js b/account.js index 2d79a4e..89a0d27 100644 --- a/account.js +++ b/account.js @@ -1,4 +1,5 @@ -const ENDPOINT = 'https://neofura.ngd.network:1927'; +const isTestNet = new URLSearchParams(location.search).get('network') == 'testnet' +const ENDPOINT = isTestNet ? 'https://n3seed2.ngd.network:10331' : 'https://neofura.ngd.network:1927'; const NEO = '0xef4073a0f2b305a38ec4050e4d3d28bc40ea63f5'; const GAS = '0xd2a4cff31913016155e38e474a2c06d08be276cf'; const BNEO = '0x48c40d4666f93408be1bef038b6722404d9a4c2a'; @@ -8,6 +9,10 @@ const SCRIPTHASH = `0x${[...[...ADDRESS].map(c => BASE58CHARS.indexOf(c)).reduce const FETCHFUNC = (ctr, method, args) => fetch(ENDPOINT, { method: 'POST', body: JSON.stringify({ params: [ctr, method, args, [{ account: BNEO, scopes: 'CalledByEntry', 'allowedcontracts': [], 'allowedgroups': [] }]], method: 'invokefunction', jsonrpc: '2.0', id: 1 }) }).then(v => v.json()).then(v => v.result); const DISPLAY = (id, value) => { const element = document.createElement('code'); element.innerText = value; const title = document.getElementById(id); title.parentElement.insertBefore(element, title.nextSibling); } +document.getElementById('network-select').value = isTestNet ? 'testnet' : 'mainnet'; +document.getElementById('network-select').onchange=async function() { + window.location.href = "?network=" + document.getElementById('network-select').value + "&address=" + ADDRESS +} new Promise(resolve => resolve(ADDRESS)).then(v => DISPLAY('account-address', v)); FETCHFUNC(BNEO, 'balanceOf', [{type: "Hash160", value: SCRIPTHASH}]).then(v => DISPLAY('bneo-balance', v.stack[0].value)); FETCHFUNC(BNEO, 'reward', [{type: "Hash160", value: SCRIPTHASH}]).then(v => DISPLAY('gas-unclaimed-multiplied-by-108', v.stack[0].value)); diff --git a/index.js b/index.js index 13fc9b4..1d0bf90 100644 --- a/index.js +++ b/index.js @@ -1,4 +1,5 @@ -const ENDPOINT = 'https://neofura.ngd.network:1927'; +const isTestNet = new URLSearchParams(location.search).get('network') == 'testnet' +const ENDPOINT = isTestNet ? 'https://n3seed1.ngd.network:10332' : 'https://neofura.ngd.network:1927'; const NEO = '0xef4073a0f2b305a38ec4050e4d3d28bc40ea63f5'; const GAS = '0xd2a4cff31913016155e38e474a2c06d08be276cf'; const BNEO = '0x48c40d4666f93408be1bef038b6722404d9a4c2a'; @@ -8,6 +9,11 @@ const FETCHFUNC = (ctr, method, args) => fetch(ENDPOINT, { method: 'POST', body: const FETCHSCRIPT = (script) => fetch(ENDPOINT, { method: 'POST', body: JSON.stringify({ params: [script, [{ account: BNEO, scopes: 'CalledByEntry', 'allowedcontracts': [], 'allowedgroups': [] }]], method: 'invokescript', jsonrpc: '2.0', id: 1 }) }).then(v => v.json()).then(v => v.result) const DISPLAY = (id, value) => { const element = document.createElement('code'); element.innerText = value; const title = document.getElementById(id); title.parentElement.insertBefore(element, title.nextSibling); } +document.getElementById('network_input').value = isTestNet ? 'testnet' : 'mainnet'; +document.getElementById('network-select').value = isTestNet ? 'testnet' : 'mainnet'; +document.getElementById('network-select').onchange=async function() { + window.location.href = "?network=" + document.getElementById('network-select').value +} new Promise(resolve => resolve(BNEO)).then(v => DISPLAY('bneo-script-hash', v)); new Promise(resolve => resolve(BNEOADDR)).then(v => DISPLAY('bneo-contract-address', v)) FETCHFUNC(BNEO, 'totalSupply', []).then(v => DISPLAY('bneo-total-supply-multiplied-by-108', v.stack[0].value)) diff --git a/index.md b/index.md index 55914cd..846729b 100644 --- a/index.md +++ b/index.md @@ -14,10 +14,12 @@ ## whitelisted candidates -# Account Infomation +# Account Information
+ +