From 2ac3587ec7ba2e041be92b476c8ed3d28d9c6087 Mon Sep 17 00:00:00 2001 From: Matthew Fosse Date: Tue, 23 Apr 2024 09:36:49 -0700 Subject: [PATCH] additional nano fixes --- cw_nano/lib/nano_client.dart | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/cw_nano/lib/nano_client.dart b/cw_nano/lib/nano_client.dart index e36c7d4d3..267ac888f 100644 --- a/cw_nano/lib/nano_client.dart +++ b/cw_nano/lib/nano_client.dart @@ -294,7 +294,6 @@ class NanoClient { Future receiveBlock({ required String blockHash, - required String source, required String amountRaw, required String destinationAddress, required String privateKey, @@ -319,9 +318,15 @@ class NanoClient { representative = infoData.representative; } + if ((BigInt.tryParse(amountRaw) ?? BigInt.zero) <= BigInt.zero) { + throw Exception("amountRaw must be greater than zero"); + } + + BlockContentsResponse? frontierContents; + if (!openBlock) { // get the block info of the frontier block: - BlockContentsResponse? frontierContents = await getBlockContents(frontier); + frontierContents = await getBlockContents(frontier); if (frontierContents == null) { throw Exception("error while getting frontier block info"); @@ -349,7 +354,12 @@ class NanoClient { } // first get the account balance: - final BigInt currentBalance = (await getBalance(destinationAddress)).currentBalance; + late BigInt currentBalance; + if (!openBlock) { + currentBalance = BigInt.parse(frontierContents!.balance); + } else { + currentBalance = BigInt.zero; + } final BigInt txAmount = BigInt.parse(amountRaw); final BigInt balanceAfterTx = currentBalance + txAmount; @@ -448,10 +458,8 @@ class NanoClient { for (final blockHash in blocks.keys) { final block = blocks[blockHash]; final String amountRaw = block["amount"] as String; - final String source = block["source"] as String; await receiveBlock( blockHash: blockHash, - source: source, amountRaw: amountRaw, privateKey: privateKey, destinationAddress: destinationAddress,