|
|
@ -15,7 +15,6 @@ class PendingBalanceCalculator { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
async getBalance() { |
|
|
|
async getBalance() { |
|
|
|
console.log('getting balance') |
|
|
|
|
|
|
|
const results = await Promise.all([ |
|
|
|
const results = await Promise.all([ |
|
|
|
this.getNetworkBalance(), |
|
|
|
this.getNetworkBalance(), |
|
|
|
this.getPendingTransactions(), |
|
|
|
this.getPendingTransactions(), |
|
|
@ -24,23 +23,16 @@ class PendingBalanceCalculator { |
|
|
|
const balance = results[0] |
|
|
|
const balance = results[0] |
|
|
|
const pending = results[1] |
|
|
|
const pending = results[1] |
|
|
|
|
|
|
|
|
|
|
|
console.dir(pending) |
|
|
|
|
|
|
|
console.dir(balance.toString()) |
|
|
|
|
|
|
|
console.trace('but why') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const pendingValue = pending.reduce((total, tx) => { |
|
|
|
const pendingValue = pending.reduce((total, tx) => { |
|
|
|
return total.add(this.valueFor(tx)) |
|
|
|
return total.add(this.valueFor(tx)) |
|
|
|
}, new BN(0)) |
|
|
|
}, new BN(0)) |
|
|
|
|
|
|
|
|
|
|
|
console.log(`subtracting ${pendingValue.toString()} from ${balance.toString()}`) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return `0x${ balance.sub(pendingValue).toString(16) }` |
|
|
|
return `0x${ balance.sub(pendingValue).toString(16) }` |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
valueFor (tx) { |
|
|
|
valueFor (tx) { |
|
|
|
const txValue = tx.txParams.value |
|
|
|
const txValue = tx.txParams.value |
|
|
|
const normalized = normalize(txValue).substring(2) |
|
|
|
const normalized = normalize(txValue).substring(2) |
|
|
|
console.log({ txValue, normalized }) |
|
|
|
|
|
|
|
const value = this.hexToBn(txValue) |
|
|
|
const value = this.hexToBn(txValue) |
|
|
|
return value |
|
|
|
return value |
|
|
|
} |
|
|
|
} |
|
|
|