Skip to content

Commit

Permalink
stop using rpc when updating address balances
Browse files Browse the repository at this point in the history
  • Loading branch information
jcramer committed May 24, 2019
1 parent 746fc8c commit 8114fcb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ The services `SlpServe` and `SlpSockServer` return query results as a JSON objec
* Node.js 8.15+
* TypeScript 3+ (`npm install -g typescript`)
* MongoDB 4.0+
* BCHD (recommended with "fastsync"), BitcoinABC, BitcoinUnlimited or other Bitcoin Cash full node with:
* BitcoinABC, BitcoinUnlimited or other Bitcoin Cash full node with:
* RPC-JSON and
* ZeroMQ event notifications

Expand Down
12 changes: 6 additions & 6 deletions SlpTokenGraph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export class SlpTokenGraph implements TokenGraph {
constructor(db: Db, manager: SlpGraphManager) {
this._manager = manager;
this._rpcClient = new RpcClient();
this._slpValidator = new LocalValidator(bitbox, async (txids) => [ <string>await this._rpcClient.getRawTransaction(txids[0]) ])
this._slpValidator = new LocalValidator(bitbox, async (txids) => [ <string>await this._rpcClient.getRawTransaction(txids[0]) ], console)
this._db = db;
this._graphUpdateQueue = new pQueue({ concurrency: 1 });
}
Expand Down Expand Up @@ -283,29 +283,29 @@ export class SlpTokenGraph implements TokenGraph {
await this.asyncForEach(Array.from(this._tokenUtxos), async (utxo: string) => {
let txid = utxo.split(':')[0];
let vout = parseInt(utxo.split(':')[1]);
let txout = <TxOutResult>(await this._rpcClient.getTxOut(txid, vout, true))
let txout = this._graphTxns.get(txid)!.outputs[vout-1]
if(txout) {
if(!this._graphTxns.get(txid)) {
await this.updateTokenGraphFrom(txid)
if(!this._tokenUtxos.has(utxo))
return
}
let txnDetails = this._graphTxns.get(txid)!.details
let addr = Utils.toSlpAddress(txout.scriptPubKey.addresses[0])
let addr = Utils.toSlpAddress(txout.address)
let bal;
if(this._addresses.has(addr)) {
bal = this._addresses.get(addr)!
bal.satoshis_balance+=txout.value*10**8
bal.satoshis_balance+=txout.bchSatoshis
if(txnDetails.transactionType === SlpTransactionType.SEND)
bal.token_balance = bal.token_balance.plus(txnDetails.sendOutputs![vout])
else if(vout === 1)
bal.token_balance = bal.token_balance.plus(txnDetails.genesisOrMintQuantity!)
}
else {
if(txnDetails.transactionType === SlpTransactionType.SEND)
bal = { satoshis_balance: txout.value*10**8, token_balance: txnDetails.sendOutputs![vout] }
bal = { satoshis_balance: txout.bchSatoshis, token_balance: txnDetails.sendOutputs![vout] }
else if(vout === 1)
bal = { satoshis_balance: txout.value*10**8, token_balance: txnDetails.genesisOrMintQuantity! }
bal = { satoshis_balance: txout.bchSatoshis, token_balance: txnDetails.genesisOrMintQuantity! }
}

if(bal) {
Expand Down

0 comments on commit 8114fcb

Please sign in to comment.