Skip to content

Commit

Permalink
chore: clean code
Browse files Browse the repository at this point in the history
  • Loading branch information
0xmove committed Oct 24, 2023
1 parent 48daa7d commit 3ea248d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 12 deletions.
10 changes: 5 additions & 5 deletions lib/builder/transaction_block.dart
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,13 @@ List<List<T>> chunk<T>(List<T> 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 {
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -469,7 +469,7 @@ class TransactionBlock {
}

Future<void> _prepareGasPrice(BuildOptions options) async {
if (options.onlyTransactionKind != null || _blockData.gasConfig.price != null) {
if (options.onlyTransactionKind || _blockData.gasConfig.price != null) {
return;
}

Expand Down Expand Up @@ -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<void> _prepare(BuildOptions options) async {
if (options.onlyTransactionKind == null && _blockData.sender == null) {
if (options.onlyTransactionKind && _blockData.sender == null) {
throw ArgumentError('Missing transaction sender');
}

Expand Down
4 changes: 2 additions & 2 deletions lib/builder/transaction_block_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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"]);
Expand All @@ -191,7 +191,7 @@ class TransactionBlockDataBuilder {
},
};

if (onlyTransactionKind != null && onlyTransactionKind) {
if (onlyTransactionKind) {
final options = BcsWriterOptions(maxSize: maxSizeBytes);
return builder.ser('TransactionKind', kind, options).toBytes();
}
Expand Down
7 changes: 2 additions & 5 deletions test/sui_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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)]));
Expand Down

0 comments on commit 3ea248d

Please sign in to comment.