additional nano fixes

This commit is contained in:
Matthew Fosse 2024-04-23 09:36:49 -07:00
parent 541e0f23bd
commit 2ac3587ec7

View file

@ -294,7 +294,6 @@ class NanoClient {
Future<void> receiveBlock({ Future<void> receiveBlock({
required String blockHash, required String blockHash,
required String source,
required String amountRaw, required String amountRaw,
required String destinationAddress, required String destinationAddress,
required String privateKey, required String privateKey,
@ -319,9 +318,15 @@ class NanoClient {
representative = infoData.representative; representative = infoData.representative;
} }
if ((BigInt.tryParse(amountRaw) ?? BigInt.zero) <= BigInt.zero) {
throw Exception("amountRaw must be greater than zero");
}
BlockContentsResponse? frontierContents;
if (!openBlock) { if (!openBlock) {
// get the block info of the frontier block: // get the block info of the frontier block:
BlockContentsResponse? frontierContents = await getBlockContents(frontier); frontierContents = await getBlockContents(frontier);
if (frontierContents == null) { if (frontierContents == null) {
throw Exception("error while getting frontier block info"); throw Exception("error while getting frontier block info");
@ -349,7 +354,12 @@ class NanoClient {
} }
// first get the account balance: // 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 txAmount = BigInt.parse(amountRaw);
final BigInt balanceAfterTx = currentBalance + txAmount; final BigInt balanceAfterTx = currentBalance + txAmount;
@ -448,10 +458,8 @@ class NanoClient {
for (final blockHash in blocks.keys) { for (final blockHash in blocks.keys) {
final block = blocks[blockHash]; final block = blocks[blockHash];
final String amountRaw = block["amount"] as String; final String amountRaw = block["amount"] as String;
final String source = block["source"] as String;
await receiveBlock( await receiveBlock(
blockHash: blockHash, blockHash: blockHash,
source: source,
amountRaw: amountRaw, amountRaw: amountRaw,
privateKey: privateKey, privateKey: privateKey,
destinationAddress: destinationAddress, destinationAddress: destinationAddress,