Browse Source

Merge pull request #141 from SuperNETorg/cli

Cli
all-modes
pbca26 8 years ago
committed by GitHub
parent
commit
533d9f1ca6
  1. 6
      react/change.log
  2. 116
      react/src/actions/actions/addressBalance.js
  3. 75
      react/src/actions/actions/iguanaHelpers.js
  4. 31
      react/src/actions/actions/nativeBalance.js
  5. 47
      react/src/actions/actions/nativeNewAddress.js
  6. 93
      react/src/actions/actions/nativeSend.js
  7. 34
      react/src/actions/actions/nativeSyncInfo.js
  8. 27
      react/src/actions/actions/nativeTxHistory.js
  9. 2
      react/src/components/dashboard/settings/settings.js
  10. 4
      react/src/components/dashboard/walletsNativeSend/walletsNativeSend.js
  11. 44
      react/src/components/dashboard/walletsNativeSend/walletsNativeSend.render.js
  12. 4
      react/src/config.js

6
react/change.log

@ -12,6 +12,10 @@ front:
- sort http stack history desc
- swapped gettotalbalance interest with getinfo interest
- extended settings / export keys ui
- added error message if coin is already running in another mode
- added explicit "new address generated" message
- added cli / rpc passphru
back:
- added cli route
- added cli route
- rpc passphru

116
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 &&
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);
})
}
});
@ -227,8 +253,19 @@ export function getKMDAddressesNative(coin, mode, currentAddress) {
}
}
let newAddressArray = [];
// remove addr duplicates
if (result[0]) {
result[0] = result[0].filter(function(elem, pos) {
return result[0].indexOf(elem) === pos;
});
}
if (result[1]) {
result[1] = result[1].filter(function(elem, pos) {
return result[1].indexOf(elem) === pos;
});
}
let newAddressArray = [];
for (let a = 0; a < result.length; a++) {
newAddressArray[a] = [];
@ -260,7 +297,7 @@ export function getKMDAddressesNative(coin, mode, currentAddress) {
Promise.all(result[1].map((_address, index) => {
return new Promise((resolve, reject) => {
const _timestamp = Date.now();
let ajaxDataToHex = `["${_address}"]`;
let ajaxDataToHex = `[\"${_address}\"]`;
iguanaHashHex(ajaxDataToHex, dispatch)
.then((hashHexJson) => {
@ -286,16 +323,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 &&
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 +390,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 +514,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 &&
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 +558,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',

75
react/src/actions/actions/iguanaHelpers.js

@ -28,44 +28,49 @@ 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);
// skip iguana hashing in cli mode
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);
})
}
})
}

31
react/src/actions/actions/nativeBalance.js

@ -32,21 +32,44 @@ export function getKMDBalanceTotal(coin) {
};
}
if (Config.cli.default) {
payload = {
mode: null,
chain: coin,
cmd: 'z_gettotalbalance'
};
}
return dispatch => {
const _timestamp = Date.now();
dispatch(logGuiHttp({
'timestamp': _timestamp,
'function': 'getKMDBalanceTotal',
'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',
}));
return fetch(`http://127.0.0.1:${Config.iguanaCorePort}`, {
let _fetchConfig = {
method: 'POST',
body: JSON.stringify(payload),
})
};
if (Config.cli.default) {
_fetchConfig = {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ 'payload': payload }),
};
}
return fetch(
Config.cli.default ? `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({
@ -80,6 +103,6 @@ export function getKMDBalanceTotal(coin) {
export function getNativeBalancesState(json) {
return {
type: DASHBOARD_ACTIVE_COIN_NATIVE_BALANCE,
balance: json && !json.error ? json : 0,
balance: json && !json.error ? (Config.cli.default ? json.result : json) : 0,
}
}

47
react/src/actions/actions/nativeNewAddress.js

@ -10,13 +10,21 @@ import {
guiLogState
} from './log';
function handleGetNewKMDAddresses(pubpriv, coin, dispatch) {
dispatch(
function handleGetNewKMDAddresses(pubpriv, coin, dispatch, json) {
/*dispatch(
triggerToaster(
translate('KMD_NATIVE.NEW_ADDR_GENERATED'),
translate('TOASTR.WALLET_NOTIFICATION'),
'success'
)
);*/
dispatch(
triggerToaster(
json.result ? json.result : json,
translate('KMD_NATIVE.NEW_ADDR_GENERATED'),
'info',
false
)
);
dispatch(getKMDAddressesNative(coin));
@ -45,7 +53,7 @@ export function getNewKMDAddresses(coin, pubpriv) {
};
} else {
payload = {
'userpass': 'tmpIgRPCUser@' + sessionStorage.getItem('IguanaRPCAuth'),
'userpass': `tmpIgRPCUser@${sessionStorage.getItem('IguanaRPCAuth')}`,
'agent': coin,
'method': 'passthru',
'function': ajaxFunctionInput,
@ -59,15 +67,36 @@ export function getNewKMDAddresses(coin, pubpriv) {
'timestamp': _timestamp,
'function': 'getNewKMDAddresses',
'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',
}));
return fetch(`http://127.0.0.1:${Config.iguanaCorePort}`, {
let _fetchConfig = {
method: 'POST',
body: JSON.stringify(payload),
})
};
if (Config.cli.default) {
payload = {
mode: null,
chain: coin,
cmd: payload.function
};
_fetchConfig = {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ 'payload': payload }),
};
}
return fetch(
Config.cli.default ? `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({
@ -85,6 +114,9 @@ export function getNewKMDAddresses(coin, pubpriv) {
})
.then(response => response.json())
.then(json => {
if (Config.cli.default) {
json = json.result;
}
dispatch(logGuiHttp({
'timestamp': _timestamp,
'status': 'success',
@ -94,7 +126,8 @@ export function getNewKMDAddresses(coin, pubpriv) {
handleGetNewKMDAddresses(
pubpriv,
coin,
dispatch
dispatch,
json
)
);
})

93
react/src/actions/actions/nativeSend.js

@ -51,15 +51,50 @@ export function sendNativeTx(coin, _payload) {
'timestamp': _timestamp,
'function': 'sendNativeTx',
'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) {
payload = {
mode: null,
chain: coin,
cmd: payload.function,
params:
_payload.addressType === 'public' && _payload.sendTo.length !== 95 ?
[
_payload.sendTo,
_payload.amount
]
:
[
_payload.sendFrom,
[{
address: _payload.sendTo,
amount: _payload.amount
}]
]
};
_fetchConfig = {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ 'payload': payload }),
};
}
fetch(
Config.cli.default ? `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({
@ -77,7 +112,7 @@ export function sendNativeTx(coin, _payload) {
})
.then(function(response) {
const _response = response.text().then(function(text) { return text; });
return response.json();
return _response;
})
.then(function(json) {
dispatch(logGuiHttp({
@ -86,15 +121,29 @@ export function sendNativeTx(coin, _payload) {
'response': json,
}));
if (json.error &&
json.error.toString().indexOf('code:') > -1) {
if (json.indexOf('"code":') > -1) {
const _message = json.substring(json.indexOf('"message":"') + 11, json.indexOf('"},"id":"jl777"'));
dispatch(
triggerToaster(
'Send failed',
true,
_message,
translate('TOASTR.WALLET_NOTIFICATION'),
'error'
)
);
if (json.indexOf('"code":-4') > -1) {
dispatch(
triggerToaster(
true,
translate('TOASTR.WALLET_NOTIFICATION'),
'Your wallet.dat is not matching the blockchain. Please resync from the scratch.',
'info',
false
)
);
}
} else {
dispatch(
triggerToaster(
@ -160,15 +209,36 @@ export function getKMDOPID(opid, coin) {
'timestamp': _timestamp,
'function': 'getKMDOPID',
'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) {
payload = {
mode: null,
chain: coin,
cmd: 'z_getoperationstatus'
};
_fetchConfig = {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ 'payload': payload }),
};
}
fetch(
Config.cli.default ? `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({
@ -186,6 +256,9 @@ export function getKMDOPID(opid, coin) {
})
.then(response => response.json())
.then(json => {
if (Config.cli.default) {
json = json.result;
}
dispatch(logGuiHttp({
'timestamp': _timestamp,
'status': 'success',

34
react/src/actions/actions/nativeSyncInfo.js

@ -67,13 +67,13 @@ function getSyncInfoNativeState(json, coin, skipDebug) {
} else {
return {
type: SYNCING_NATIVE_MODE,
progress: json,
progress: Config.cli.default ? json.result : json,
}
}
}
export function getSyncInfoNative(coin, skipDebug) {
const payload = {
let payload = {
'userpass': `tmpIgRPCUser@${sessionStorage.getItem('IguanaRPCAuth')}`,
'agent': getPassthruAgent(coin),
'method': 'passthru',
@ -82,21 +82,43 @@ export function getSyncInfoNative(coin, skipDebug) {
'hex': '',
};
if (Config.cli.default) {
payload = {
mode: null,
chain: coin,
cmd: 'getinfo'
};
}
return dispatch => {
const _timestamp = Date.now();
dispatch(logGuiHttp({
'timestamp': _timestamp,
'function': 'getSyncInfo',
'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',
}));
return fetch(`http://127.0.0.1:${Config.iguanaCorePort}`, {
let _fetchConfig = {
method: 'POST',
body: JSON.stringify(payload),
})
};
if (Config.cli.default) {
_fetchConfig = {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ 'payload': payload }),
};
}
return fetch(
Config.cli.default ? `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({

27
react/src/actions/actions/nativeTxHistory.js

@ -37,15 +37,36 @@ export function getNativeTxHistory(coin) {
'timestamp': _timestamp,
'function': 'getNativeTxHistory',
'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',
}));
return fetch(`http://127.0.0.1:${Config.iguanaCorePort}`, {
let _fetchConfig = {
method: 'POST',
body: JSON.stringify(payload),
})
};
if (Config.cli.default) {
payload = {
mode: null,
chain: coin,
cmd: 'listtransactions'
};
_fetchConfig = {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ 'payload': payload }),
};
}
return fetch(
Config.cli.default ? `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({

2
react/src/components/dashboard/settings/settings.js

@ -315,7 +315,7 @@ class Settings extends React.Component {
let _cliResponseParsed;
try {
_cliResponseParsed = JSON.parse(_cliResponse.result)
_cliResponseParsed = JSON.parse(_cliResponse.result);
} catch(e) {
_cliResponseParsed = _cliResponse.result;
}

4
react/src/components/dashboard/walletsNativeSend/walletsNativeSend.js

@ -79,7 +79,7 @@ class WalletsNativeSend extends React.Component {
if (this.state.sendFrom) {
return (
<span>
<i className={ this.state.addressType === 'public' ? 'icon fa-eye' : 'icon fa-eye-slash' }></i>
<i className={ this.state.addressType === 'public' ? 'icon fa-eye' : 'icon fa-eye-slash' }></i>
<span className="text">
[ { this.state.sendFromAmount } { this.props.ActiveCoin.coin } ]
{ this.state.sendFrom }
@ -119,7 +119,7 @@ class WalletsNativeSend extends React.Component {
return (
<span className={ `label label-${_satatusDef[opid.status].icon}` }>
<i className="icon fa-eye"></i>
<i className="icon fa-eye"></i>&nbsp;
<span>{ translate(`KMD_NATIVE.${_satatusDef[opid.status].label}`) }</span>
</span>
);

44
react/src/components/dashboard/walletsNativeSend/walletsNativeSend.render.js

@ -11,8 +11,8 @@ export const AddressListRender = function() {
onClick={ this.openDropMenu }>
<span className="filter-option pull-left">{ this.renderSelectorCurrentLabel() } </span>
<span className="bs-caret">
<span className="caret"></span>
</span>
<span className="caret"></span>
</span>
</button>
<div className="dropdown-menu open">
<ul className="dropdown-menu inner">
@ -115,7 +115,9 @@ export const WalletsNativeSendRender = function() {
<div className="col-lg-6 form-group form-material">
<label
className="control-label"
htmlFor="kmdWalletFee">{ translate('INDEX.FEE') }</label>
htmlFor="kmdWalletFee">
{ translate('INDEX.FEE') }
</label>
<input
type="text"
className="form-control"
@ -128,8 +130,8 @@ export const WalletsNativeSendRender = function() {
</div>
<div className="col-lg-12">
<span>
<strong>{ translate('INDEX.TOTAL') }:</strong>
{ this.state.amount } - { this.state.fee }/kb = { Number(this.state.amount) - Number(this.state.fee) }
<strong>{ translate('INDEX.TOTAL') }:</strong>
{ this.state.amount } - { this.state.fee }/kb = { Number(this.state.amount) - Number(this.state.fee) }
{ this.props.ActiveCoin.coin }
</span>
</div>
@ -155,30 +157,32 @@ export const WalletsNativeSendRender = function() {
<div className="col-xlg-12 col-lg-12 col-sm-12 col-xs-12">
<div className="panel">
<header className="panel-heading">
<h3 className="panel-title">{ translate('INDEX.OPERATIONS_STATUSES') }</h3>
<h3 className="panel-title">
{ translate('INDEX.OPERATIONS_STATUSES') }
</h3>
</header>
<div className="panel-body">
<table
className="table table-hover dataTable table-striped"
width="100%">
<thead>
<tr>
<th>{ translate('INDEX.STATUS') }</th>
<th>ID</th>
<th>{ translate('INDEX.TIME') }</th>
<th>{ translate('INDEX.RESULT') }</th>
</tr>
</thead>
<tr>
<th>{ translate('INDEX.STATUS') }</th>
<th>ID</th>
<th>{ translate('INDEX.TIME') }</th>
<th>{ translate('INDEX.RESULT') }</th>
</tr>
</thead>
<tbody>
{ this.renderOPIDList() }
{ this.renderOPIDList() }
</tbody>
<tfoot>
<tr>
<th>{ translate('INDEX.STATUS') }</th>
<th>ID</th>
<th>{ translate('INDEX.TIME') }</th>
<th>{ translate('INDEX.RESULT') }</th>
</tr>
<tr>
<th>{ translate('INDEX.STATUS') }</th>
<th>ID</th>
<th>{ translate('INDEX.TIME') }</th>
<th>{ translate('INDEX.RESULT') }</th>
</tr>
</tfoot>
</table>
</div>

4
react/src/config.js

@ -6,4 +6,8 @@ module.exports = {
openAlias: false,
debug: true,
defaultLang: 'EN',
cli: {
passthru: true,
default: true
}
};

Loading…
Cancel
Save