Skip to content

Commit

Permalink
Add some clarity to mempool txs processing, make account amount function
Browse files Browse the repository at this point in the history
  • Loading branch information
aivve committed Jul 20, 2022
1 parent 53bd6a9 commit ee4493b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 28 deletions.
35 changes: 9 additions & 26 deletions src/model/Wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,47 +290,30 @@ export class Wallet extends Observable{
return news;
}

get amount() : number{
amount() : number{
return this.unlockedAmount(-1);
}

unlockedAmount(currentBlockHeight : number = -1) : number{
let amount = 0;

for(let transaction of this.transactions){
if(!transaction.isFullyChecked())
continue;

// if(transaction.ins.length > 0){
// amount -= transaction.fees;
// }
if(transaction.isConfirmed(currentBlockHeight) || currentBlockHeight === -1)
for(let out of transaction.outs){
amount += out.amount;
}
for(let nin of transaction.ins){
amount -= nin.amount;
}
if(currentBlockHeight === -1 || transaction.isConfirmed(currentBlockHeight))
amount += transaction.getAmount();
}

//console.log(this.txsMem);
for(let transaction of this.txsMem){
//console.log(transaction.paymentId);
// for(let out of transaction.outs){
// amount += out.amount;
// }
if(transaction.isConfirmed(currentBlockHeight) || currentBlockHeight === -1)
for(let nout of transaction.outs){
amount += nout.amount;
//console.log('+'+nout.amount);
}
if(currentBlockHeight === -1) {
for(let transaction of this.txsMem){
//if(!transaction.isFullyChecked())
// continue;

for(let nin of transaction.ins){
amount -= nin.amount;
//console.log('-'+nin.amount);
amount += transaction.getAmount();
}
}


return amount;
}

Expand Down
4 changes: 2 additions & 2 deletions src/pages/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ class AccountView extends DestructableView{

refreshWallet(){
this.currentScanBlock = wallet.lastHeight;
this.walletAmount = wallet.amount;
this.walletAmount = wallet.amount();
this.unlockedWalletAmount = wallet.unlockedAmount(this.currentScanBlock);
if(wallet.getAll().length+wallet.txsMem.length !== this.transactions.length) {
if(wallet.getAll().length + wallet.txsMem.length !== this.transactions.length) {
this.transactions = wallet.txsMem.concat(wallet.getTransactionsCopy().reverse());
}
}
Expand Down

0 comments on commit ee4493b

Please sign in to comment.