From bfa136ff55ced8098724edeb1a5f36be8804e7d1 Mon Sep 17 00:00:00 2001 From: cmasta9 Date: Thu, 7 Aug 2025 16:47:01 -0500 Subject: [PATCH 1/4] add new function to send with fixed balance (8/7/25) --- wallet.ts | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/wallet.ts b/wallet.ts index 8c071f5..79d3954 100644 --- a/wallet.ts +++ b/wallet.ts @@ -94,6 +94,36 @@ export class Wallet { const block = { ...block_ns, signature, work }; return await this.send_process(block, "send"); } + /* Send by passing in a fixed final balance */ + async send_fixed_bal(to: Address, end_bal: util.Whole, gen_work?: boolean, representative?: Address, cached_account_info?: AccountInfoRPC): Promise { + const raw_end = util.whole_to_raw(end_bal, this.rpc.DECIMALS); + const info = cached_account_info ?? (await this.get_account_info(undefined, true)); //this should be lazy. the true makes sure representative is included + const pub_receive = util.get_public_key_from_address(to); + if (representative === undefined) { + if (info.representative === undefined) throw Error("Missing field 'representative' in `cached_account_info`"); + representative = info.representative; + } + const new_balance = BigInt(raw_end); + if (new_balance < 0n) { + throw Error(`End balance cannot be negative`); + } + const block_ns: BlockNoSignature = { + type: "state", + account: this.address, + previous: info.frontier, + representative, + balance: new_balance.toString() as `${number}`, //you gotta trust me here typescript + //link is public key of account to send to + link: pub_receive, + link_as_account: to, + }; + const s_block_hash = util.hash_block(block_ns); //block hash of the send block + let work = undefined; + if (gen_work && this.work_function) work = await this.work_function(info.frontier); + const signature = util.sign_block_hash(this.private_key, s_block_hash); + const block = { ...block_ns, signature, work }; + return await this.send_process(block, "send"); + } /* Send all Bananos */ async send_all(to: Address, work?: boolean, representative?: Address): Promise { const info = await this.get_account_info(undefined, true); From bee2f9e47c4f8711d7d0f3709cfd78c8e381c212 Mon Sep 17 00:00:00 2001 From: cmasta9 Date: Thu, 7 Aug 2025 16:51:50 -0500 Subject: [PATCH 2/4] optimize, rm redundant variable (8/7b) --- wallet.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/wallet.ts b/wallet.ts index 79d3954..ba9d458 100644 --- a/wallet.ts +++ b/wallet.ts @@ -103,8 +103,7 @@ export class Wallet { if (info.representative === undefined) throw Error("Missing field 'representative' in `cached_account_info`"); representative = info.representative; } - const new_balance = BigInt(raw_end); - if (new_balance < 0n) { + if (raw_end < 0n) { throw Error(`End balance cannot be negative`); } const block_ns: BlockNoSignature = { @@ -112,7 +111,7 @@ export class Wallet { account: this.address, previous: info.frontier, representative, - balance: new_balance.toString() as `${number}`, //you gotta trust me here typescript + balance: raw_end.toString() as `${number}`, //you gotta trust me here typescript //link is public key of account to send to link: pub_receive, link_as_account: to, From 79c32208ce98ffc5829d9f65a9c4c1a14e1ba1b3 Mon Sep 17 00:00:00 2001 From: cmasta9 <141727846+cmasta9@users.noreply.github.com> Date: Thu, 7 Aug 2025 17:12:29 -0500 Subject: [PATCH 3/4] Update README.md (8/7) added prussia name --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index dbf2b52..c5aa8f5 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ > ~~how to buy banani from beatrice~~ > how to install banani on react.js -Banani is a library for the Banano cryptocurrency that will support sending, receiving, changing rep, RPC calls, message signing, wallet management, etc. It aims to be a more powerful and sensible version of @bananocoin/bananojs. Banani takes heavy inspiration from the Python [bananopie](https://github.com/stjet/bananopie) (which I also wrote), which in turn takes some inspiration from my experiences with ethers.js. +Banani is a library for the Banano cryptocurrency that will support sending, receiving, changing rep, RPC calls, message signing, wallet management, etc. It aims to be a more powerful and sensible version of @bananocoin/bananojs. Banani takes heavy inspiration from the Python [bananopie](https://github.com/stjet/bananopie) (which I [prussia] also wrote), which in turn takes some inspiration from my experiences with ethers.js. **Please report any bugs or request features by opening an Github issue.** You can ask for help or ask questions in the #frankensteins-lab channel of the Banano discord and people will be typically be eager to assist if they can. From 7c682710584b590f9284851e585740d508cc72a4 Mon Sep 17 00:00:00 2001 From: Jon Dough <49297268+stjet@users.noreply.github.com> Date: Thu, 7 Aug 2025 23:40:42 +0000 Subject: [PATCH 4/4] change name to `send_fixed_final_bal` --- wallet.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wallet.ts b/wallet.ts index ba9d458..2a77bba 100644 --- a/wallet.ts +++ b/wallet.ts @@ -95,7 +95,7 @@ export class Wallet { return await this.send_process(block, "send"); } /* Send by passing in a fixed final balance */ - async send_fixed_bal(to: Address, end_bal: util.Whole, gen_work?: boolean, representative?: Address, cached_account_info?: AccountInfoRPC): Promise { + async send_fixed_final_bal(to: Address, end_bal: util.Whole, gen_work?: boolean, representative?: Address, cached_account_info?: AccountInfoRPC): Promise { const raw_end = util.whole_to_raw(end_bal, this.rpc.DECIMALS); const info = cached_account_info ?? (await this.get_account_info(undefined, true)); //this should be lazy. the true makes sure representative is included const pub_receive = util.get_public_key_from_address(to);