Skip to content

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
mlibre committed May 31, 2024
1 parent f5c1b11 commit 146d59b
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 59 deletions.
27 changes: 2 additions & 25 deletions dist/library/wallet.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/library/wallet.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "goodchain",
"version": "3.0.1",
"version": "3.0.2",
"description": "GoodChain: Blockchain for Everyone",
"main": "index.js",
"type": "module",
Expand Down
34 changes: 2 additions & 32 deletions src/library/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ class Wallet
{
this.cacheWallet = {};
const newTransactions: TransactionData[] = [];
const wallets = await this.allWallets();
for ( const tmpTrx of transactions )
{
try
Expand All @@ -69,9 +68,9 @@ class Wallet
console.warn( "Dropping transaction with transaction number less than wallet transaction number" );
continue;
}
minusBalance( trx.from, trx.amount + trx.fee );
await this.minusBalance( trx.from, trx.amount + trx.fee );
}
await addBalance( trx.to, trx.amount ); // todo you can use this.addbalance again
await this.addBalance( trx.to, trx.amount ); // todo you can use this.addbalance again
newTransactions.push( trx.data );
}
catch ( error )
Expand All @@ -81,35 +80,6 @@ class Wallet
}
this.cacheWallet = {};
return newTransactions;

function minusBalance ( address: string, amount: number )
{
if ( !wallets[address] )
{
wallets[address] = {
balance: 0,
transaction_number: 0
};
}
if ( wallets[address].balance < amount )
{
throw new Error( "Insufficient balance", { cause: { address, amount } });
}
wallets[address].balance -= amount;
wallets[address].transaction_number++;
}

function addBalance ( address: string, amount: number )
{
if ( !wallets[address] )
{
wallets[address] = {
balance: 0,
transaction_number: 0
};
}
wallets[address].balance += amount;
}
}

async getBalance ( address: string ): Promise<UserWallet>
Expand Down

0 comments on commit 146d59b

Please sign in to comment.