From 3ea248de129d19dd230d1899676c94dac4ae667c Mon Sep 17 00:00:00 2001 From: 0xmove <0xmovebuilder@gmail.com> Date: Tue, 24 Oct 2023 21:09:36 +0800 Subject: [PATCH] chore: clean code --- lib/builder/transaction_block.dart | 10 +++++----- lib/builder/transaction_block_data.dart | 4 ++-- test/sui_test.dart | 7 ++----- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/lib/builder/transaction_block.dart b/lib/builder/transaction_block.dart index dbf040c..b72c94d 100644 --- a/lib/builder/transaction_block.dart +++ b/lib/builder/transaction_block.dart @@ -100,13 +100,13 @@ List> chunk(List arr, int size) { class BuildOptions { SuiClient? client; - bool? onlyTransactionKind; + bool onlyTransactionKind; /// Define a protocol config to build against, instead of having it fetched from the provider at build time. dynamic protocolConfig; /// Define limits that are used when building the transaction. In general, we recommend using the protocol configuration instead of defining limits. Limits? limits; - BuildOptions({this.client, this.onlyTransactionKind, this.protocolConfig, this.limits}); + BuildOptions({this.client, this.onlyTransactionKind = false, this.protocolConfig, this.limits}); } class SignOptions extends BuildOptions { @@ -430,7 +430,7 @@ class TransactionBlock { } // Early return if the payment is already set: - if ((options.onlyTransactionKind ?? false) || _blockData.gasConfig.payment != null) { + if ((options.onlyTransactionKind) || _blockData.gasConfig.payment != null) { return; } @@ -469,7 +469,7 @@ class TransactionBlock { } Future _prepareGasPrice(BuildOptions options) async { - if (options.onlyTransactionKind != null || _blockData.gasConfig.price != null) { + if (options.onlyTransactionKind || _blockData.gasConfig.price != null) { return; } @@ -673,7 +673,7 @@ class TransactionBlock { /// Prepare the transaction by valdiating the transaction data and resolving all inputs /// so that it can be built into bytes. Future _prepare(BuildOptions options) async { - if (options.onlyTransactionKind == null && _blockData.sender == null) { + if (options.onlyTransactionKind && _blockData.sender == null) { throw ArgumentError('Missing transaction sender'); } diff --git a/lib/builder/transaction_block_data.dart b/lib/builder/transaction_block_data.dart index 919ab40..10ad816 100644 --- a/lib/builder/transaction_block_data.dart +++ b/lib/builder/transaction_block_data.dart @@ -179,7 +179,7 @@ class TransactionBlockDataBuilder { String? sender, GasConfig? gasConfig, TransactionExpiration? expiration, - bool? onlyTransactionKind, + bool onlyTransactionKind = false, }) { // Resolve inputs down to values: final inputs = this.inputs.map((input) => input["value"]); @@ -191,7 +191,7 @@ class TransactionBlockDataBuilder { }, }; - if (onlyTransactionKind != null && onlyTransactionKind) { + if (onlyTransactionKind) { final options = BcsWriterOptions(maxSize: maxSizeBytes); return builder.ser('TransactionKind', kind, options).toBytes(); } diff --git a/test/sui_test.dart b/test/sui_test.dart index b97b4c7..82fcecb 100644 --- a/test/sui_test.dart +++ b/test/sui_test.dart @@ -299,17 +299,14 @@ test('test programmable transaction blocks', () async { final account = SuiAccount.fromMnemonics(mnemonics, SignatureScheme.ED25519); final client = SuiClient(Constants.devnetAPI, account: account); - var coins = await client.getCoins(account.getAddress()); - if (coins.data.isEmpty) { + final suiBalance = await client.getBalance(account.getAddress()); + if (suiBalance.totalBalance == BigInt.zero) { final faucet = FaucetClient(Constants.faucetDevAPI); final resp = await faucet.requestSuiFromFaucetV0(account.getAddress()); assert(resp.transferredGasObjects.isNotEmpty); } - final gasCoin = coins.data.first; - final tx = TransactionBlock(); - tx.setGasPayment([gasCoin]); tx.setGasBudget(BigInt.from(2000000)); final coin = tx.add(Transactions.splitCoins(tx.gas, [tx.pureInt(1000)]));