From 8fe06847481feba5a82d9e4ef17457bd1f8a2e8d Mon Sep 17 00:00:00 2001 From: Heorhii Azarov Date: Mon, 24 Jun 2024 17:59:32 +0300 Subject: [PATCH] Fix clippy --- .../scanner-lib/src/blockchain_state/mod.rs | 6 +-- .../scanner-lib/src/sync/tests/simulation.rs | 6 +-- .../src/tests/orders_constraints.rs | 4 +- .../test-framework/src/random_tx_maker.rs | 6 +-- .../test-suite/src/tests/orders_tests.rs | 40 +++++++++---------- .../tests/outputs_utils.rs | 4 +- .../src/transaction_verifier/mod.rs | 2 +- common/src/chain/transaction/output/mod.rs | 2 +- mintscript/src/tests/translate/mod.rs | 2 +- wallet/src/account/currency_grouper/mod.rs | 4 +- wallet/src/account/mod.rs | 8 ++-- wallet/src/account/output_cache/mod.rs | 18 ++++----- 12 files changed, 51 insertions(+), 51 deletions(-) diff --git a/api-server/scanner-lib/src/blockchain_state/mod.rs b/api-server/scanner-lib/src/blockchain_state/mod.rs index e9f1e0c499..aac28720e3 100644 --- a/api-server/scanner-lib/src/blockchain_state/mod.rs +++ b/api-server/scanner-lib/src/blockchain_state/mod.rs @@ -737,7 +737,7 @@ async fn tx_fees( let pools = prefetch_pool_data(&inputs_utxos, db_tx).await?; let pos_accounting_adapter = PoSAccountingAdapterToCheckFees { pools }; - // TODO: support orders + // TODO(orders) let orders_store = orders_accounting::InMemoryOrdersAccounting::new(); let orders_db = orders_accounting::OrdersAccountingDB::new(&orders_store); @@ -1107,7 +1107,7 @@ async fn update_tables_from_transaction_inputs( .await; } AccountCommand::CancelOrder(_) | AccountCommand::FillOrder(_, _, _) => { - // TODO: support orders + // TODO(orders) } }, TxInput::Account(outpoint) => { @@ -1674,7 +1674,7 @@ async fn update_tables_from_transaction_outputs( } TxOutput::Htlc(_, _) => {} // TODO(HTLC) TxOutput::AnyoneCanTake(_) => { - // TODO: support orders + // TODO(orders) } } } diff --git a/api-server/scanner-lib/src/sync/tests/simulation.rs b/api-server/scanner-lib/src/sync/tests/simulation.rs index 61dbb115d9..ca65b3a196 100644 --- a/api-server/scanner-lib/src/sync/tests/simulation.rs +++ b/api-server/scanner-lib/src/sync/tests/simulation.rs @@ -211,7 +211,7 @@ async fn simulation( let mut delegations = BTreeSet::new(); let mut token_ids = BTreeSet::new(); - // FIXME: proper impl + // TODO(orders) let orders_store = orders_accounting::InMemoryOrdersAccounting::new(); let orders_db = orders_accounting::OrdersAccountingDB::new(&orders_store); @@ -406,7 +406,7 @@ async fn simulation( | TxOutput::LockThenTransfer(_, _, _) | TxOutput::ProduceBlockFromStake(_, _) | TxOutput::Htlc(_, _) => {} - TxOutput::AnyoneCanTake(_) => unimplemented!(), // TODO: support orders + TxOutput::AnyoneCanTake(_) => unimplemented!(), // TODO(orders) }); tx.inputs().iter().for_each(|inp| match inp { @@ -454,7 +454,7 @@ async fn simulation( burn_coins(&mut statistics, token_change_authority_fee); } AccountCommand::CancelOrder(_) | AccountCommand::FillOrder(_, _, _) => { - unimplemented!() // TODO: support orders + unimplemented!() // TODO(orders) } }, }); diff --git a/chainstate/constraints-value-accumulator/src/tests/orders_constraints.rs b/chainstate/constraints-value-accumulator/src/tests/orders_constraints.rs index 802d7c3c98..4b7e733efc 100644 --- a/chainstate/constraints-value-accumulator/src/tests/orders_constraints.rs +++ b/chainstate/constraints-value-accumulator/src/tests/orders_constraints.rs @@ -46,11 +46,11 @@ fn create_order_constraints(#[case] seed: Seed) { let give_amount = Amount::from_atoms(rng.gen_range(100..1000)); let token_id = TokenId::random_using(&mut rng); let ask_amount = Amount::from_atoms(rng.gen_range(100..1000)); - let order_data = OrderData::new( + let order_data = Box::new(OrderData::new( Destination::AnyoneCanSpend, OutputValue::TokenV1(token_id, ask_amount), OutputValue::Coin(give_amount), - ); + )); let orders_store = InMemoryOrdersAccounting::new(); let orders_db = OrdersAccountingDB::new(&orders_store); diff --git a/chainstate/test-framework/src/random_tx_maker.rs b/chainstate/test-framework/src/random_tx_maker.rs index 16ecf9f2e5..9a8fd637f7 100644 --- a/chainstate/test-framework/src/random_tx_maker.rs +++ b/chainstate/test-framework/src/random_tx_maker.rs @@ -964,7 +964,7 @@ impl<'a> RandomTxMaker<'a> { // Transfer output is created intentionally besides order output to not waste utxo // (e.g. single genesis output on issuance) let outputs = vec![ - TxOutput::AnyoneCanTake(order_data), + TxOutput::AnyoneCanTake(Box::new(order_data)), TxOutput::Transfer( OutputValue::Coin(change), key_manager.new_destination(self.chainstate.get_chain_config(), rng), @@ -1287,7 +1287,7 @@ impl<'a> RandomTxMaker<'a> { let give_value = OutputValue::TokenV1(token_id, Amount::from_atoms(atoms)); let order_data = OrderData::new(Destination::AnyoneCanSpend, ask_value, give_value); - result_outputs.push(TxOutput::AnyoneCanTake(order_data)); + result_outputs.push(TxOutput::AnyoneCanTake(Box::new(order_data))); self.order_can_be_created = false; } else { // burn @@ -1377,7 +1377,7 @@ impl<'a> RandomTxMaker<'a> { } TxOutput::AnyoneCanTake(data) => { let order_id = make_order_id(inputs[0].utxo_outpoint().unwrap()); - let _ = orders_cache.create_order(order_id, data.clone()).unwrap(); + let _ = orders_cache.create_order(order_id, *data.clone()).unwrap(); Some(output) } }) diff --git a/chainstate/test-suite/src/tests/orders_tests.rs b/chainstate/test-suite/src/tests/orders_tests.rs index 929593513e..517cf3b4d0 100644 --- a/chainstate/test-suite/src/tests/orders_tests.rs +++ b/chainstate/test-suite/src/tests/orders_tests.rs @@ -118,7 +118,7 @@ fn create_order_check_storage(#[case] seed: Seed) { let order_id = make_order_id(&tokens_outpoint); let tx = TransactionBuilder::new() .add_input(tokens_outpoint.into(), InputWitness::NoSignature(None)) - .add_output(TxOutput::AnyoneCanTake(order_data.clone())) + .add_output(TxOutput::AnyoneCanTake(Box::new(order_data.clone()))) .build(); tf.make_block_builder().add_transaction(tx).build_and_process(&mut rng).unwrap(); @@ -149,11 +149,11 @@ fn create_two_same_orders_in_tx(#[case] seed: Seed) { let ask_amount = Amount::from_atoms(rng.gen_range(1u128..1000)); let give_amount = Amount::from_atoms(rng.gen_range(1u128..1000)); - let order_data = OrderData::new( + let order_data = Box::new(OrderData::new( Destination::AnyoneCanSpend, OutputValue::Coin(ask_amount), OutputValue::TokenV1(token_id, give_amount), - ); + )); let order_id = make_order_id(&tokens_outpoint); let tx = TransactionBuilder::new() @@ -203,8 +203,8 @@ fn create_two_orders_same_tx(#[case] seed: Seed) { let order_id = make_order_id(&tokens_outpoint); let tx = TransactionBuilder::new() .add_input(tokens_outpoint.into(), InputWitness::NoSignature(None)) - .add_output(TxOutput::AnyoneCanTake(order_data_1)) - .add_output(TxOutput::AnyoneCanTake(order_data_2)) + .add_output(TxOutput::AnyoneCanTake(Box::new(order_data_1))) + .add_output(TxOutput::AnyoneCanTake(Box::new(order_data_2))) .build(); let result = tf.make_block_builder().add_transaction(tx).build_and_process(&mut rng); @@ -233,11 +233,11 @@ fn create_two_orders_same_block(#[case] seed: Seed) { let ask_amount = Amount::from_atoms(rng.gen_range(1u128..1000)); let give_amount = Amount::from_atoms(rng.gen_range(1u128..1000)); - let order_data = OrderData::new( + let order_data = Box::new(OrderData::new( Destination::AnyoneCanSpend, OutputValue::Coin(ask_amount), OutputValue::TokenV1(token_id, give_amount), - ); + )); let tx1 = TransactionBuilder::new() .add_input( @@ -293,7 +293,7 @@ fn create_order_check_currencies(#[case] seed: Seed) { tokens_outpoint.clone().into(), InputWitness::NoSignature(None), ) - .add_output(TxOutput::AnyoneCanTake(order_data)) + .add_output(TxOutput::AnyoneCanTake(Box::new(order_data))) .build(); let tx_id = tx.transaction().get_id(); let result = tf.make_block_builder().add_transaction(tx).build_and_process(&mut rng); @@ -326,7 +326,7 @@ fn create_order_check_currencies(#[case] seed: Seed) { tokens_outpoint.clone().into(), InputWitness::NoSignature(None), ) - .add_output(TxOutput::AnyoneCanTake(order_data)) + .add_output(TxOutput::AnyoneCanTake(Box::new(order_data))) .build(); let tx_id = tx.transaction().get_id(); let result = tf.make_block_builder().add_transaction(tx).build_and_process(&mut rng); @@ -357,7 +357,7 @@ fn create_order_check_currencies(#[case] seed: Seed) { .add_transaction( TransactionBuilder::new() .add_input(tokens_outpoint.into(), InputWitness::NoSignature(None)) - .add_output(TxOutput::AnyoneCanTake(order_data.clone())) + .add_output(TxOutput::AnyoneCanTake(Box::new(order_data))) .build(), ) .build_and_process(&mut rng) @@ -392,7 +392,7 @@ fn create_order_tokens_for_tokens(#[case] seed: Seed) { .add_transaction( TransactionBuilder::new() .add_input(tokens_outpoint_2.into(), InputWitness::NoSignature(None)) - .add_output(TxOutput::AnyoneCanTake(order_data.clone())) + .add_output(TxOutput::AnyoneCanTake(Box::new(order_data))) .build(), ) .build_and_process(&mut rng) @@ -421,7 +421,7 @@ fn cancel_order_check_storage(#[case] seed: Seed) { let order_id = make_order_id(&tokens_outpoint); let tx = TransactionBuilder::new() .add_input(tokens_outpoint.into(), InputWitness::NoSignature(None)) - .add_output(TxOutput::AnyoneCanTake(order_data.clone())) + .add_output(TxOutput::AnyoneCanTake(Box::new(order_data))) .build(); tf.make_block_builder().add_transaction(tx).build_and_process(&mut rng).unwrap(); @@ -474,7 +474,7 @@ fn fill_order_check_storage(#[case] seed: Seed) { let order_id = make_order_id(&tokens_outpoint); let tx = TransactionBuilder::new() .add_input(tokens_outpoint.into(), InputWitness::NoSignature(None)) - .add_output(TxOutput::AnyoneCanTake(order_data.clone())) + .add_output(TxOutput::AnyoneCanTake(Box::new(order_data.clone()))) .build(); tf.make_block_builder().add_transaction(tx).build_and_process(&mut rng).unwrap(); @@ -584,7 +584,7 @@ fn fill_partially_then_cancel(#[case] seed: Seed) { let order_id = make_order_id(&tokens_outpoint); let tx = TransactionBuilder::new() .add_input(tokens_outpoint.into(), InputWitness::NoSignature(None)) - .add_output(TxOutput::AnyoneCanTake(order_data.clone())) + .add_output(TxOutput::AnyoneCanTake(Box::new(order_data))) .build(); tf.make_block_builder().add_transaction(tx).build_and_process(&mut rng).unwrap(); @@ -673,7 +673,7 @@ fn cancel_order_check_signature(#[case] seed: Seed) { let order_id = make_order_id(&tokens_outpoint); let tx = TransactionBuilder::new() .add_input(tokens_outpoint.into(), InputWitness::NoSignature(None)) - .add_output(TxOutput::AnyoneCanTake(order_data.clone())) + .add_output(TxOutput::AnyoneCanTake(Box::new(order_data))) .build(); tf.make_block_builder().add_transaction(tx).build_and_process(&mut rng).unwrap(); @@ -822,7 +822,7 @@ fn reorg_before_create(#[case] seed: Seed) { let order_id = make_order_id(&tokens_outpoint); let tx = TransactionBuilder::new() .add_input(tokens_outpoint.into(), InputWitness::NoSignature(None)) - .add_output(TxOutput::AnyoneCanTake(order_data.clone())) + .add_output(TxOutput::AnyoneCanTake(Box::new(order_data.clone()))) .build(); tf.make_block_builder().add_transaction(tx).build_and_process(&mut rng).unwrap(); @@ -910,7 +910,7 @@ fn reorg_after_create(#[case] seed: Seed) { let order_id = make_order_id(&tokens_outpoint); let tx = TransactionBuilder::new() .add_input(tokens_outpoint.into(), InputWitness::NoSignature(None)) - .add_output(TxOutput::AnyoneCanTake(order_data.clone())) + .add_output(TxOutput::AnyoneCanTake(Box::new(order_data.clone()))) // transfer output just to be able to spend something in alternative branch .add_output(TxOutput::Transfer( OutputValue::TokenV1(token_id, Amount::from_atoms(100)), @@ -1045,11 +1045,11 @@ fn test_activation(#[case] seed: Seed) { let (token_id, tokens_outpoint, _) = issue_and_mint_token_from_genesis(&mut rng, &mut tf); - let order_data = OrderData::new( + let order_data = Box::new(OrderData::new( Destination::AnyoneCanSpend, OutputValue::Coin(Amount::from_atoms(rng.gen_range(1u128..1000))), OutputValue::TokenV1(token_id, Amount::from_atoms(rng.gen_range(1u128..1000))), - ); + )); // Try to produce order output before activation, check an error let tx = TransactionBuilder::new() @@ -1083,7 +1083,7 @@ fn test_activation(#[case] seed: Seed) { .add_transaction( TransactionBuilder::new() .add_input(tokens_outpoint.into(), InputWitness::NoSignature(None)) - .add_output(TxOutput::AnyoneCanTake(order_data.clone())) + .add_output(TxOutput::AnyoneCanTake(order_data)) .build(), ) .build_and_process(&mut rng) diff --git a/chainstate/tx-verifier/src/transaction_verifier/input_output_policy/tests/outputs_utils.rs b/chainstate/tx-verifier/src/transaction_verifier/input_output_policy/tests/outputs_utils.rs index ad284eae0c..4544e4b374 100644 --- a/chainstate/tx-verifier/src/transaction_verifier/input_output_policy/tests/outputs_utils.rs +++ b/chainstate/tx-verifier/src/transaction_verifier/input_output_policy/tests/outputs_utils.rs @@ -238,11 +238,11 @@ pub fn data_deposit() -> TxOutput { } pub fn create_order() -> TxOutput { - TxOutput::AnyoneCanTake(OrderData::new( + TxOutput::AnyoneCanTake(Box::new(OrderData::new( Destination::AnyoneCanSpend, OutputValue::Coin(Amount::ZERO), OutputValue::Coin(Amount::ZERO), - )) + ))) } pub fn issue_nft() -> TxOutput { diff --git a/chainstate/tx-verifier/src/transaction_verifier/mod.rs b/chainstate/tx-verifier/src/transaction_verifier/mod.rs index 61ecbfeba1..2a50f557c1 100644 --- a/chainstate/tx-verifier/src/transaction_verifier/mod.rs +++ b/chainstate/tx-verifier/src/transaction_verifier/mod.rs @@ -796,7 +796,7 @@ where let order_id = make_order_id(input_utxo_outpoint); let result = self .orders_accounting_cache - .create_order(order_id, order_data.clone()) + .create_order(order_id, *order_data.clone()) .map_err(ConnectTransactionError::OrdersAccountingError); Some(result) } diff --git a/common/src/chain/transaction/output/mod.rs b/common/src/chain/transaction/output/mod.rs index 68fad37c99..1d4e0a7c1e 100644 --- a/common/src/chain/transaction/output/mod.rs +++ b/common/src/chain/transaction/output/mod.rs @@ -142,7 +142,7 @@ pub enum TxOutput { #[codec(index = 10)] Htlc(OutputValue, Box), #[codec(index = 11)] - AnyoneCanTake(OrderData), + AnyoneCanTake(Box), } impl TxOutput { diff --git a/mintscript/src/tests/translate/mod.rs b/mintscript/src/tests/translate/mod.rs index f618605ccd..b6bf4ecc62 100644 --- a/mintscript/src/tests/translate/mod.rs +++ b/mintscript/src/tests/translate/mod.rs @@ -220,7 +220,7 @@ fn order0() -> (OrderId, OrderData) { } fn anyonecantake(data: OrderData) -> TestInputInfo { - tii(TxOutput::AnyoneCanTake(data)) + tii(TxOutput::AnyoneCanTake(Box::new(data))) } fn account_spend(deleg: DelegationId, amount: u128) -> TestInputInfo { diff --git a/wallet/src/account/currency_grouper/mod.rs b/wallet/src/account/currency_grouper/mod.rs index be7ff06af9..4c3208c356 100644 --- a/wallet/src/account/currency_grouper/mod.rs +++ b/wallet/src/account/currency_grouper/mod.rs @@ -58,7 +58,7 @@ pub(crate) fn group_outputs( get_tx_output(&output).clone(), ))) } - // TODO: support orders + // TODO(orders) TxOutput::AnyoneCanTake(_) => unimplemented!(), }; @@ -114,7 +114,7 @@ pub fn group_outputs_with_issuance_fee( get_tx_output(&output).clone(), ))) } - // TODO: support orders + // TODO(orders) TxOutput::AnyoneCanTake(_) => unimplemented!(), }; diff --git a/wallet/src/account/mod.rs b/wallet/src/account/mod.rs index f9254395d1..920aa9cc17 100644 --- a/wallet/src/account/mod.rs +++ b/wallet/src/account/mod.rs @@ -1347,7 +1347,7 @@ impl Account { .token_data(token_id) .map(|data| (None, Some(data.authority.clone()))) .ok_or(WalletError::UnknownTokenId(*token_id)), - // TODO: support orders + // TODO(orders) AccountCommand::CancelOrder(_) => unimplemented!(), AccountCommand::FillOrder(_, _, _) => unimplemented!(), } @@ -1828,7 +1828,7 @@ impl Account { self.find_token(token_id).is_ok() || self.is_destination_mine_or_watched(address) } - // TODO: support orders + // TODO(orders) AccountCommand::CancelOrder(_) => unimplemented!(), AccountCommand::FillOrder(_, _, _) => unimplemented!(), }, @@ -2194,7 +2194,7 @@ fn group_preselected_inputs( output.clone(), ))) } - // TODO: support orders + // TODO(orders) TxOutput::AnyoneCanTake(_) => unimplemented!(), }; update_preselected_inputs(currency, value, *fee)?; @@ -2239,7 +2239,7 @@ fn group_preselected_inputs( .ok_or(WalletError::OutputAmountOverflow)?, )?; } - // TODO: support orders + // TODO(orders) AccountCommand::CancelOrder(_) => unimplemented!(), AccountCommand::FillOrder(_, _, _) => unimplemented!(), }, diff --git a/wallet/src/account/output_cache/mod.rs b/wallet/src/account/output_cache/mod.rs index 886394e390..4f2193472b 100644 --- a/wallet/src/account/output_cache/mod.rs +++ b/wallet/src/account/output_cache/mod.rs @@ -721,7 +721,7 @@ impl OutputCache { | TxOutput::CreateDelegationId(_, _) | TxOutput::IssueFungibleToken(_) | TxOutput::ProduceBlockFromStake(_, _) => false, - // TODO: support orders + // TODO(orders) TxOutput::AnyoneCanTake(_) => unimplemented!(), } }), @@ -732,7 +732,7 @@ impl OutputCache { | AccountCommand::UnfreezeToken(token_id) | AccountCommand::ChangeTokenAuthority(token_id, _) | AccountCommand::UnmintTokens(token_id) => frozen_token_id == token_id, - // TODO: support orders + // TODO(orders) AccountCommand::CancelOrder(_) => unimplemented!(), AccountCommand::FillOrder(_, _, _) => unimplemented!(), }, @@ -837,7 +837,7 @@ impl OutputCache { } } TxOutput::IssueNft(_, _, _) => {} - // TODO: support orders + // TODO(orders) TxOutput::AnyoneCanTake(_) => unimplemented!(), }; } @@ -927,7 +927,7 @@ impl OutputCache { self.token_issuance.insert(*token_id, data); } } - // TODO: support orders + // TODO(orders) AccountCommand::CancelOrder(_) => unimplemented!(), AccountCommand::FillOrder(_, _, _) => unimplemented!(), }, @@ -1030,7 +1030,7 @@ impl OutputCache { data.unconfirmed_txs.remove(tx_id); } } - // TODO: support orders + // TODO(orders) AccountCommand::CancelOrder(_) => unimplemented!(), AccountCommand::FillOrder(_, _, _) => unimplemented!(), }, @@ -1058,7 +1058,7 @@ impl OutputCache { | TxOutput::CreateDelegationId(_, _) | TxOutput::IssueFungibleToken(_) | TxOutput::Htlc(_, _) => {} - // TODO: support orders + // TODO(orders) TxOutput::AnyoneCanTake(_) => unimplemented!(), } } @@ -1323,7 +1323,7 @@ impl OutputCache { data.unconfirmed_txs.remove(&tx_id.into()); } } - // TODO: support orders + // TODO(orders) AccountCommand::CancelOrder(_) => unimplemented!(), AccountCommand::FillOrder(_, _, _) => unimplemented!(), }, @@ -1532,7 +1532,7 @@ fn apply_freeze_mutations_from_tx( | AccountCommand::UnmintTokens(_) | AccountCommand::LockTokenSupply(_) | AccountCommand::ChangeTokenAuthority(_, _) => {} - // TODO: support orders + // TODO(orders) AccountCommand::CancelOrder(_) => unimplemented!(), AccountCommand::FillOrder(_, _, _) => unimplemented!(), }, @@ -1574,7 +1574,7 @@ fn apply_total_supply_mutations_from_tx( AccountCommand::FreezeToken(_, _) | AccountCommand::UnfreezeToken(_) | AccountCommand::ChangeTokenAuthority(_, _) => {} - // TODO: support orders + // TODO(orders) AccountCommand::CancelOrder(_) => unimplemented!(), AccountCommand::FillOrder(_, _, _) => unimplemented!(), },