Browse Source

utxo (wip #3)

all-modes
Petr Balashov 8 years ago
parent
commit
ae8b31bb6e
  1. 29
      react/src/actions/actionCreators.js
  2. 12
      react/src/components/dashboard/coinTileItem.js
  3. 53
      react/src/components/dashboard/sendCoin.js
  4. 4
      react/src/components/dashboard/walletsData.js
  5. 5
      react/src/util/cacheFormat.js

29
react/src/actions/actionCreators.js

@ -1304,6 +1304,9 @@ export function getKMDAddressesNative(coin, mode, currentAddress) {
}
export function shepherdGroomPost(_filename, _payload) {
console.log('shepherdGroomPost to file ', _filename);
console.log('shepherdGroomPost payload ', _payload);
return dispatch => {
return fetch('http://127.0.0.1:' + Config.agamaPort + '/shepherd/groom/', {
method: 'POST',
@ -1324,6 +1327,30 @@ export function shepherdGroomPost(_filename, _payload) {
}
}
export function shepherdGroomPostPromise(_filename, _payload) {
console.log('shepherdGroomPostPromise to file ', _filename);
console.log('shepherdGroomPostPromise payload ', _payload);
return new Promise((resolve, reject) => {
fetch('http://127.0.0.1:' + Config.agamaPort + '/shepherd/groom/', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
'filename': _filename,
'payload': JSON.stringify(_payload),
}),
})
.catch(function(error) {
console.log(error);
dispatch(triggerToaster(true, 'shepherdGroomPostPromise', 'Error', 'error'));
})
.then(response => response.json())
.then(json => resolve(json))
})
}
export function fetchUtxoCache(_payload) {
const _userpass = '?userpass=tmpIgRPCUser@' + sessionStorage.getItem('IguanaRPCAuth'),
_pubkey = '&pubkey=' + _payload.pubkey,
@ -2156,7 +2183,7 @@ export function getCacheFile(pubkey) {
const _pubkey = pubkey || JSON.parse(sessionStorage.getItem('IguanaActiveAccount')).pubkey;
return new Promise((resolve, reject) => {
fetch('http://127.0.0.1:' + Config.agamaPort + '/shepherd/groom?pubkey=' + _pubkey, {
fetch('http://127.0.0.1:' + Config.agamaPort + '/shepherd/groom?filename=' + _pubkey, {
method: 'GET',
headers: {
'Content-Type': 'application/json',

12
react/src/components/dashboard/coinTileItem.js

@ -16,7 +16,8 @@ import {
getFullTransactionsList,
getBasiliskTransactionsList,
getShepherdCache,
fetchNewCacheData
fetchNewCacheData,
changeActiveAddress
} from '../../actions/actionCreators';
import Store from '../../store';
@ -32,6 +33,9 @@ class CoinTileItem extends React.Component {
// 3) limit req in basilisk as much as possible incl. activehandle
// 4) add pending requests store
// TODO: update all addresses once in 20 min, current address every 10 min
// always fetch main addr data and current selected address
dispatchCoinActions(coin, mode) {
if (mode === 'native') {
Store.dispatch(iguanaActiveHandle(true));
@ -83,11 +87,15 @@ class CoinTileItem extends React.Component {
Store.dispatch(startInterval('sync', _iguanaActiveHandle));
}
if (mode === 'basilisk') {
const _basiliskMainAddress = this.props.Dashboard.activeHandle[coin];
Store.dispatch(changeActiveAddress(_basiliskMainAddress));
Store.dispatch(fetchNewCacheData({
'pubkey': this.props.Dashboard.activeHandle.pubkey,
'allcoins': false,
'coin': coin,
'calls': 'listtransactions:getbalance',
'address': this.props.ActiveCoin.activeAddress,
}));
var _iguanaActiveHandle = setInterval(function() {
@ -101,7 +109,7 @@ class CoinTileItem extends React.Component {
'coin': this.props.ActiveCoin.coin,
'calls': 'listtransactions:getbalance',
}));
}.bind(this), 60000);
}.bind(this), 240000);
Store.dispatch(startInterval('sync', _iguanaActiveHandle));
Store.dispatch(startInterval('basilisk', _basiliskCache));
// basilisk

53
react/src/components/dashboard/sendCoin.js

@ -22,7 +22,7 @@ import {
basiliskRefresh,
edexGetTransaction,
getCacheFile,
shepherdGroomPost
shepherdGroomPostPromise
} from '../../actions/actionCreators';
import Store from '../../store';
@ -47,26 +47,6 @@ class SendCoin extends React.Component {
addressSelectorOpen: false,
currentStackLength: 0,
totalStackLength: 0,
vin: [
{
"txid": "8f5d3bc7ff1d8abdedefa4ed71c2a085a5fec62b8491c08e4a6ed53925df0235",
"vout": 0,
"scriptSig": {
"asm": "3045022100ea6442b209ab48b7109f13399fa12f85915ee2204a21698b85454987d9303fe1022025e4630c684af9b982b243420d69e094d0fc708aaccf11b83fd9320fe4dd45f701 02bee71575d87c7285eda952358175af10879081a0cc6b94623aac6cb2c6a51eae",
"hex": "483045022100ea6442b209ab48b7109f13399fa12f85915ee2204a21698b85454987d9303fe1022025e4630c684af9b982b243420d69e094d0fc708aaccf11b83fd9320fe4dd45f7012102bee71575d87c7285eda952358175af10879081a0cc6b94623aac6cb2c6a51eae"
},
"sequence": 4294967295
},
{
"txid": "4cfb597119d4239e8fa75486d1ba4c62cef615a52568aca1bc9be3b457c12eac",
"vout": 0,
"scriptSig": {
"asm": "3044022001c1481b5fb142a1f38f8387c8d0ba6e4d6c6a96a8c6765ce805ce841cb2a58b02206caec099e209a469b78c22c674be77d92698fff94b4521c0d5e462ac5b19627c01 02bee71575d87c7285eda952358175af10879081a0cc6b94623aac6cb2c6a51eae",
"hex": "473044022001c1481b5fb142a1f38f8387c8d0ba6e4d6c6a96a8c6765ce805ce841cb2a58b02206caec099e209a469b78c22c674be77d92698fff94b4521c0d5e462ac5b19627c012102bee71575d87c7285eda952358175af10879081a0cc6b94623aac6cb2c6a51eae"
},
"sequence": 4294967295
}
]
};
this.updateInput = this.updateInput.bind(this);
this.handleBasiliskSend = this.handleBasiliskSend.bind(this);
@ -75,6 +55,7 @@ class SendCoin extends React.Component {
this.getOAdress = this.getOAdress.bind(this);
this.toggleSendAPIType = this.toggleSendAPIType.bind(this);
this._fetchNewUTXOData = this._fetchNewUTXOData.bind(this);
this.testCacheFormat = this.testCacheFormat.bind(this);
socket.on('messages', msg => this.updateSocketsData(msg));
}
@ -128,6 +109,12 @@ class SendCoin extends React.Component {
isReadyToUpdate = true;
}
console.log(this.props.ActiveCoin.cache[this.props.ActiveCoin.coin][this.state.sendFrom].refresh);
if (this.props.ActiveCoin.cache[this.props.ActiveCoin.coin][this.state.sendFrom].refresh.data.error &&
this.props.ActiveCoin.cache[this.props.ActiveCoin.coin][this.state.sendFrom].refresh.data.error === 'request failed') {
timestamp = null;
}
return (
<div className="col-lg-12">
<hr />
@ -282,10 +269,23 @@ class SendCoin extends React.Component {
});
}
testCacheFormat() {
const txidListToRemove = ['5d5538179c524d511774de00a0b7f6ab1fa57780546d05b9da81c258c3b8db17', '3e629af281600e3d45b3f134c4b2045911104749575a2702f5d1cd9a45bfa7cb'];
console.log(this.props.Dashboard.activeHandle.pubkey);
getCacheFile(this.props.Dashboard.activeHandle.pubkey)
.then(function(result) {
console.log('got cache file', result);
let saveThisData = edexRemoveTXID(result.result, txidListToRemove);
console.log('saveThisData', saveThisData);
});
}
handleBasiliskSend() {
const refreshData = this.props.ActiveCoin.cache[this.props.ActiveCoin.coin][this.state.sendFrom].refresh;
const listunspentData = this.props.ActiveCoin.cache[this.props.ActiveCoin.coin][this.state.sendFrom].listunspent;
const utxoSet = (refreshData && refreshData.data) || (listunspentData && listunspentData.data);
const _pubkey = this.props.Dashboard.activeHandle.pubkey;
const sendData = {
'coin': this.props.ActiveCoin.coin,
'sendfrom': this.state.sendFrom,
@ -334,6 +334,8 @@ class SendCoin extends React.Component {
}
let processRefreshUTXOs = function(vinData) {
console.log('vin', vinData);
return new Promise(function(resolve, reject) {
let edexGetTxIDListRes = edexGetTxIDList(vinData);
resolve(edexGetTxIDListRes);
@ -345,11 +347,11 @@ class SendCoin extends React.Component {
console.log(txidListToRemove);
console.log(sendData);
getCacheFile(this.props.Dashboard.activeHandle.pubkey)
getCacheFile(_pubkey)
.then(function(result) {
console.log('got cache file', result);
let saveThisData = edexRemoveTXID(result, txidListToRemove);
console.log(saveThisData);
let saveThisData = edexRemoveTXID(result.result, txidListToRemove);
console.log('saveThisData', saveThisData);
resolve(saveThisData);
});
});
@ -359,7 +361,7 @@ class SendCoin extends React.Component {
return new Promise(function(resolve, reject) {
console.log('saveNewCacheData', saveThisData);
shepherdGroomPost(saveThisData)
shepherdGroomPostPromise(_pubkey, saveThisData)
.then(function(result) {
console.log('saveNewCacheData', saveThisData);
console.log(result);
@ -595,6 +597,7 @@ class SendCoin extends React.Component {
return (
<div className="col-sm-12 padding-top-10" data-edexcoin="COIN" id="edexcoin_send">
<div className="col-xlg-12 col-md-12 col-sm-12 col-xs-12">
<button onClick={this.testCacheFormat}>test</button>
<div className="steps row" style={{marginTop: '10px'}}>
<div className={this.state.currentStep === 0 ? 'step col-md-4 current' : 'step col-md-4'} id="edexcoin_send_step_1">
<span className="step-number">1</span>

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

@ -39,7 +39,7 @@ class WalletsData extends React.Component {
itemsPerPage: 10,
activePage: 1,
itemsList: null,
currentAddress: null,
currentAddress: this.props.Dashboard && this.props.Dashboard.activeHandle ? this.props.Dashboard.activeHandle[this.props.ActiveCoin.coin] : null,
addressSelectorOpen: false,
currentStackLength: 0,
totalStackLength: 0,
@ -331,7 +331,7 @@ class WalletsData extends React.Component {
updateAddressSelection(address, type, amount) {
Store.dispatch(changeActiveAddress(address));
this.setState(Object.assign({}, this.state, {
currentAddress: address,
addressSelectorOpen: false,

5
react/src/util/cacheFormat.js

@ -11,7 +11,7 @@ export function edexGetTxIDList(getTxData) {
}
export function edexRemoveTXID(_obj, txidArray) {
let txidToStr = txidArray.join(':');
let txidToStr = ':' + txidArray.join(':');
console.log(txidToStr);
@ -27,6 +27,7 @@ export function edexRemoveTXID(_obj, txidArray) {
_obj.basilisk[key][coinAddr].refresh.data.length > 0) {
for (let i = 0; i < _obj.basilisk[key][coinAddr].refresh.data.length; i++) {
if (txidToStr.indexOf(_obj.basilisk[key][coinAddr].refresh.data[i].txid) > -1) {
console.log('cacheformat remove node', _obj.basilisk[key][coinAddr].refresh.data[i].txid);
_obj.basilisk[key][coinAddr].refresh.data.splice(i, 1);
}
}
@ -38,4 +39,6 @@ export function edexRemoveTXID(_obj, txidArray) {
} else {
console.log('basilisk node is missing');
}
return _obj;
}
Loading…
Cancel
Save