From 5eb58cd90ecfe166e94aa410006ecc5a8d473491 Mon Sep 17 00:00:00 2001 From: pbca26 Date: Sat, 17 Jun 2017 19:19:46 +0300 Subject: [PATCH] native rpc addr balance --- react/src/actions/actions/addressBalance.js | 101 +++++++++++++++++-- react/src/actions/actions/iguanaHelpers.js | 74 +++++++------- react/src/actions/actions/nativeBalance.js | 4 +- react/src/actions/actions/nativeSyncInfo.js | 2 +- react/src/actions/actions/nativeTxHistory.js | 2 +- 5 files changed, 134 insertions(+), 49 deletions(-) diff --git a/react/src/actions/actions/addressBalance.js b/react/src/actions/actions/addressBalance.js index 6efd174..36205de 100644 --- a/react/src/actions/actions/addressBalance.js +++ b/react/src/actions/actions/addressBalance.js @@ -106,20 +106,46 @@ export function getKMDAddressesNative(coin, mode, currentAddress) { } }) } else { + if (Config.cli.default && + mode === 'native') { + payload = { + mode: null, + chain: coin, + cmd: payload.function, + params: [""] + }; + } + const _timestamp = Date.now(); dispatch(logGuiHttp({ 'timestamp': _timestamp, 'function': 'getKMDAddressesNative', 'type': 'post', - 'url': `http://127.0.0.1:${Config.iguanaCorePort}`, + 'url': Config.cli.default ? `http://127.0.0.1:${Config.agamaPort}/shepherd/cli` : `http://127.0.0.1:${Config.iguanaCorePort}`, 'payload': payload, 'status': 'pending', })); - fetch(`http://127.0.0.1:${Config.iguanaCorePort}`, { + let _fetchConfig = { method: 'POST', body: JSON.stringify(payload), - }) + }; + + if (Config.cli.default === true && + mode === 'native') { + _fetchConfig = { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ 'payload': payload }), + }; + } + + fetch( + Config.cli.default && mode === 'native' ? `http://127.0.0.1:${Config.agamaPort}/shepherd/cli` : `http://127.0.0.1:${Config.iguanaCorePort}`, + _fetchConfig + ) .catch(function(error) { console.log(error); dispatch(logGuiHttp({ @@ -142,7 +168,7 @@ export function getKMDAddressesNative(coin, mode, currentAddress) { 'status': 'success', 'response': json, })); - resolve(json); + resolve(Config.cli.default && mode === 'native' ? json.result : json); }) } }); @@ -286,16 +312,40 @@ export function getKMDAddressesNative(coin, mode, currentAddress) { 'timestamp': _timestamp, 'function': 'getKMDAddressesNative+ZBalance', 'type': 'post', - 'url': `http://127.0.0.1:${Config.iguanaCorePort}`, + 'url': Config.cli.default ? `http://127.0.0.1:${Config.agamaPort}/shepherd/cli` : `http://127.0.0.1:${Config.iguanaCorePort}`, 'payload': payload, 'status': 'pending', })); - fetch(`http://127.0.0.1:${Config.iguanaCorePort}`, - { + let _fetchConfig = { method: 'POST', body: JSON.stringify(payload), - }) + }; + + if (Config.cli.default === true && + mode === 'native') { + payload = { + mode: null, + chain: coin, + cmd: 'z_getbalance', + params: [ + _address + ] + }; + + _fetchConfig = { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ 'payload': payload }), + }; + } + + fetch( + Config.cli.default && mode === 'native' ? `http://127.0.0.1:${Config.agamaPort}/shepherd/cli` : `http://127.0.0.1:${Config.iguanaCorePort}`, + _fetchConfig + ) .catch(function(error) { console.log(error); dispatch(logGuiHttp({ @@ -329,6 +379,10 @@ export function getKMDAddressesNative(coin, mode, currentAddress) { ) ); } else { + if (Config.cli.default && + mode === 'native') { + json = json.result; + } resolve(json); newAddressArray[1][index] = { address: _address, @@ -449,10 +503,33 @@ export function getKMDAddressesNative(coin, mode, currentAddress) { 'status': 'pending', })); - fetch(`http://127.0.0.1:${(Config.useBasiliskInstance && mode === 'basilisk' ? Config.iguanaCorePort + 1 : Config.iguanaCorePort)}`, { + let _fetchConfig = { method: 'POST', body: JSON.stringify(payload), - }) + }; + + if (Config.cli.default === true && + mode === 'native') { + payload = { + mode: null, + chain: coin, + cmd: payload.function, + params: payload.params + }; + + _fetchConfig = { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ 'payload': payload }), + }; + } + + fetch( + Config.cli.default && mode === 'native' ? `http://127.0.0.1:${Config.agamaPort}/shepherd/cli` : `http://127.0.0.1:${(Config.useBasiliskInstance && mode === 'basilisk' ? Config.iguanaCorePort + 1 : Config.iguanaCorePort)}`, + _fetchConfig + ) .catch(function(error) { console.log(error); dispatch(logGuiHttp({ @@ -470,6 +547,10 @@ export function getKMDAddressesNative(coin, mode, currentAddress) { }) .then(response => response.json()) .then(function(json) { + if (Config.cli.default && + mode === 'native') { + json = json.result; + } dispatch(logGuiHttp({ 'timestamp': _timestamp, 'status': 'success', diff --git a/react/src/actions/actions/iguanaHelpers.js b/react/src/actions/actions/iguanaHelpers.js index f989c3b..11179e3 100644 --- a/react/src/actions/actions/iguanaHelpers.js +++ b/react/src/actions/actions/iguanaHelpers.js @@ -28,44 +28,48 @@ export function iguanaHashHex(data, dispatch) { }; return new Promise((resolve, reject) => { - const _timestamp = Date.now(); - dispatch(logGuiHttp({ - 'timestamp': _timestamp, - 'function': 'iguanaHashHex', - 'type': 'post', - 'url': `http://127.0.0.1:${Config.iguanaCorePort}`, - 'payload': payload, - 'status': 'pending', - })); - - fetch(`http://127.0.0.1:${Config.iguanaCorePort}`, { - method: 'POST', - body: JSON.stringify(payload), - }) - .catch(function(error) { - console.log(error); + if (Config.cli.default) { + resolve(true); + } else { + const _timestamp = Date.now(); dispatch(logGuiHttp({ 'timestamp': _timestamp, - 'status': 'error', - 'response': error, + 'function': 'iguanaHashHex', + 'type': 'post', + 'url': `http://127.0.0.1:${Config.iguanaCorePort}`, + 'payload': payload, + 'status': 'pending', })); - dispatch( - triggerToaster( - 'iguanaHashHex', - 'Error', - 'error' - ) - ); - }) - .then(response => response.json()) - .then(json => { - dispatch(logGuiHttp({ - 'timestamp': _timestamp, - 'status': 'success', - 'response': json, - })); - resolve(json.hex); - }) + + fetch(`http://127.0.0.1:${Config.iguanaCorePort}`, { + method: 'POST', + body: JSON.stringify(payload), + }) + .catch(function(error) { + console.log(error); + dispatch(logGuiHttp({ + 'timestamp': _timestamp, + 'status': 'error', + 'response': error, + })); + dispatch( + triggerToaster( + 'iguanaHashHex', + 'Error', + 'error' + ) + ); + }) + .then(response => response.json()) + .then(json => { + dispatch(logGuiHttp({ + 'timestamp': _timestamp, + 'status': 'success', + 'response': json, + })); + resolve(json.hex); + }) + } }) } diff --git a/react/src/actions/actions/nativeBalance.js b/react/src/actions/actions/nativeBalance.js index 07a6cb9..56f604b 100644 --- a/react/src/actions/actions/nativeBalance.js +++ b/react/src/actions/actions/nativeBalance.js @@ -35,7 +35,7 @@ export function getKMDBalanceTotal(coin) { if (Config.cli.default === true) { payload = { mode: null, - coin, + chain: coin, cmd: 'z_gettotalbalance' }; } @@ -103,6 +103,6 @@ export function getKMDBalanceTotal(coin) { export function getNativeBalancesState(json) { return { type: DASHBOARD_ACTIVE_COIN_NATIVE_BALANCE, - balance: json && !json.error ? (Config.cli.default ? json.result : json) : 0, + balance: json && !json.error ? (Config.cli.default === true ? json.result : json) : 0, } } \ No newline at end of file diff --git a/react/src/actions/actions/nativeSyncInfo.js b/react/src/actions/actions/nativeSyncInfo.js index 7b12b25..8065158 100644 --- a/react/src/actions/actions/nativeSyncInfo.js +++ b/react/src/actions/actions/nativeSyncInfo.js @@ -85,7 +85,7 @@ export function getSyncInfoNative(coin, skipDebug) { if (Config.cli.default === true) { payload = { mode: null, - coin, + chain: coin, cmd: 'getinfo' }; } diff --git a/react/src/actions/actions/nativeTxHistory.js b/react/src/actions/actions/nativeTxHistory.js index 5d0df51..cc585cd 100644 --- a/react/src/actions/actions/nativeTxHistory.js +++ b/react/src/actions/actions/nativeTxHistory.js @@ -34,7 +34,7 @@ export function getNativeTxHistory(coin) { if (Config.cli.default === true) { payload = { mode: null, - coin, + chain: coin, cmd: 'listtransactions' }; }