Skip to content

Commit 1f27bd8

Browse files
committed
move create HTLC to return tx fees
1 parent 8405ea3 commit 1f27bd8

File tree

14 files changed

+38
-45
lines changed

14 files changed

+38
-45
lines changed

wallet/src/wallet/mod.rs

+2-19
Original file line numberDiff line numberDiff line change
@@ -1178,23 +1178,6 @@ where
11781178
)
11791179
}
11801180

1181-
fn for_account_rw_unlocked_and_check_tx(
1182-
&mut self,
1183-
account_index: U31,
1184-
additional_info: TxAdditionalInfo,
1185-
f: impl FnOnce(&mut Account<P::K>, &mut StoreTxRwUnlocked<B>) -> WalletResult<SendRequest>,
1186-
) -> WalletResult<SignedTransaction> {
1187-
Ok(self
1188-
.for_account_rw_unlocked_and_check_tx_generic(
1189-
account_index,
1190-
additional_info,
1191-
|account, db_tx| Ok((f(account, db_tx)?, ())),
1192-
|err| err,
1193-
)?
1194-
.0
1195-
.tx)
1196-
}
1197-
11981181
fn for_account_rw_unlocked_and_check_tx_with_fees(
11991182
&mut self,
12001183
account_index: U31,
@@ -2134,9 +2117,9 @@ where
21342117
current_fee_rate: FeeRate,
21352118
consolidate_fee_rate: FeeRate,
21362119
additional_info: TxAdditionalInfo,
2137-
) -> WalletResult<SignedTransaction> {
2120+
) -> WalletResult<SignedTxWithFees> {
21382121
let latest_median_time = self.latest_median_time;
2139-
self.for_account_rw_unlocked_and_check_tx(
2122+
self.for_account_rw_unlocked_and_check_tx_with_fees(
21402123
account_index,
21412124
additional_info,
21422125
|account, db_tx| {

wallet/src/wallet/tests.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -5553,7 +5553,8 @@ fn create_htlc_and_spend(#[case] seed: Seed) {
55535553
FeeRate::from_amount_per_kb(Amount::ZERO),
55545554
TxAdditionalInfo::new(),
55555555
)
5556-
.unwrap();
5556+
.unwrap()
5557+
.tx;
55575558
let create_htlc_tx_id = create_htlc_tx.transaction().get_id();
55585559
let (_, block2) = create_block(
55595560
&chain_config,
@@ -5693,7 +5694,8 @@ fn create_htlc_and_refund(#[case] seed: Seed) {
56935694
FeeRate::from_amount_per_kb(Amount::ZERO),
56945695
TxAdditionalInfo::new(),
56955696
)
5696-
.unwrap();
5697+
.unwrap()
5698+
.tx;
56975699
let create_htlc_tx_id = create_htlc_tx.transaction().get_id();
56985700

56995701
let refund_tx = Transaction::new(

wallet/types/src/lib.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,20 @@ pub mod wallet_tx;
2828
pub mod wallet_type;
2929
pub mod with_locked;
3030

31-
use std::collections::BTreeMap;
32-
3331
pub use account_id::{
3432
AccountDerivationPathId, AccountId, AccountKeyPurposeId, AccountWalletCreatedTxId,
3533
AccountWalletTxId,
3634
};
3735
pub use account_info::AccountInfo;
36+
pub use currency::Currency;
37+
pub use keys::{KeyPurpose, KeychainUsageState, RootKeys};
38+
pub use wallet_tx::{BlockInfo, WalletTx};
39+
3840
use common::{
3941
chain::{SignedTransaction, Transaction},
4042
primitives::Amount,
4143
};
42-
pub use currency::Currency;
43-
pub use keys::{KeyPurpose, KeychainUsageState, RootKeys};
44-
pub use wallet_tx::{BlockInfo, WalletTx};
44+
use std::collections::BTreeMap;
4545

4646
#[derive(Debug, Clone, PartialEq, Eq)]
4747
pub struct SignedTxWithFees {

wallet/wallet-cli-commands/src/command_handler/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ where
140140
let hex = new_tx.tx.to_string();
141141
let summary = new_tx.tx.take().transaction().text_summary(chain_config);
142142

143-
format!("{summary}\nThe transaction was created and ready to be submitted:\n{hex}",)
143+
format!("{summary}\nThe transaction was created and is ready to be submitted:\n{hex}",)
144144
};
145145

146146
ConsoleCommand::Print(status_text)

wallet/wallet-cli-commands/src/lib.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -302,9 +302,12 @@ pub enum WalletCommand {
302302
#[command(flatten)]
303303
ColdCommands(ColdWalletCommand),
304304

305-
/// Configure broadcasting to Mempool to true of false.
306-
/// By default it is set to true. If set to false, any command that creates a transaction will
307-
/// return it to the user and will need to be submitted manually with the command `node-submit-transaction`
305+
/// Configure broadcasting to Mempool to true or false.
306+
///
307+
/// If set to false, any command that creates a transaction will return it to the user and not submit it automatically.
308+
/// The transaction will need to be submitted manually with the command `node-submit-transaction`.
309+
///
310+
/// The effect of this is not preserved when the CLI wallet is closed.
308311
#[clap(name = "config-broadcast")]
309312
ConfigBroadcast { broadcast: bool },
310313

wallet/wallet-controller/src/runtime_wallet.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1123,7 +1123,7 @@ impl<B: storage::Backend + 'static> RuntimeWallet<B> {
11231123
current_fee_rate: FeeRate,
11241124
consolidate_fee_rate: FeeRate,
11251125
additional_info: TxAdditionalInfo,
1126-
) -> WalletResult<SignedTransaction> {
1126+
) -> WalletResult<SignedTxWithFees> {
11271127
match self {
11281128
RuntimeWallet::Software(w) => w.create_htlc_tx(
11291129
account_index,

wallet/wallet-controller/src/synced_controller.rs

+10-3
Original file line numberDiff line numberDiff line change
@@ -1111,19 +1111,26 @@ where
11111111
output_value: OutputValue,
11121112
htlc: HashedTimelockContract,
11131113
additional_info: TxAdditionalInfo,
1114-
) -> Result<SignedTransaction, ControllerError<T>> {
1114+
) -> Result<NewTransaction, ControllerError<T>> {
11151115
let (current_fee_rate, consolidate_fee_rate) =
11161116
self.get_current_and_consolidation_fee_rate().await?;
11171117

1118-
let result = self.wallet.create_htlc_tx(
1118+
let SignedTxWithFees { tx, fees } = self.wallet.create_htlc_tx(
11191119
self.account_index,
11201120
output_value,
11211121
htlc,
11221122
current_fee_rate,
11231123
consolidate_fee_rate,
11241124
additional_info,
11251125
)?;
1126-
Ok(result)
1126+
1127+
let fees = into_balances(&self.rpc_client, self.chain_config, fees).await?;
1128+
1129+
Ok(NewTransaction {
1130+
tx,
1131+
fees,
1132+
broadcasted: false,
1133+
})
11271134
}
11281135

11291136
pub async fn create_order(

wallet/wallet-controller/src/types/mod.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,8 @@ use common::{
3535
};
3636
pub use seed_phrase::SeedWithPassPhrase;
3737
pub use standalone_key::AccountStandaloneKeyDetails;
38-
pub use transaction::NewTransaction;
3938
pub use transaction::{
40-
InspectTransaction, SignatureStats, TransactionToInspect, ValidatedSignatures,
39+
InspectTransaction, NewTransaction, SignatureStats, TransactionToInspect, ValidatedSignatures,
4140
};
4241
use utils::ensure;
4342
use wallet::signer::trezor_signer::FoundDevice;

wallet/wallet-rpc-client/src/handles_client/mod.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1107,7 +1107,7 @@ where
11071107
token_id: Option<String>,
11081108
htlc: RpcHashedTimelockContract,
11091109
config: ControllerConfig,
1110-
) -> Result<HexEncoded<SignedTransaction>, Self::Error> {
1110+
) -> Result<RpcNewTransaction, Self::Error> {
11111111
self.wallet_rpc
11121112
.create_htlc_transaction(
11131113
account_index,
@@ -1117,7 +1117,6 @@ where
11171117
config,
11181118
)
11191119
.await
1120-
.map(HexEncoded::new)
11211120
.map_err(WalletRpcHandlesClientError::WalletRpcError)
11221121
}
11231122

wallet/wallet-rpc-client/src/rpc_client/client_impl.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1015,7 +1015,7 @@ impl WalletInterface for ClientWalletRpc {
10151015
token_id: Option<String>,
10161016
htlc: RpcHashedTimelockContract,
10171017
config: ControllerConfig,
1018-
) -> Result<HexEncoded<SignedTransaction>, Self::Error> {
1018+
) -> Result<RpcNewTransaction, Self::Error> {
10191019
let options = TransactionOptions::from_controller_config(&config);
10201020
WalletRpcClient::create_htlc_transaction(
10211021
&self.http_client,

wallet/wallet-rpc-client/src/wallet_rpc_traits.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ pub trait WalletInterface {
506506
token_id: Option<String>,
507507
htlc: RpcHashedTimelockContract,
508508
config: ControllerConfig,
509-
) -> Result<HexEncoded<SignedTransaction>, Self::Error>;
509+
) -> Result<RpcNewTransaction, Self::Error>;
510510

511511
#[allow(clippy::too_many_arguments)]
512512
async fn create_order(

wallet/wallet-rpc-lib/src/rpc/interface.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -739,7 +739,7 @@ trait WalletRpc {
739739
token_id: Option<RpcAddress<TokenId>>,
740740
htlc: RpcHashedTimelockContract,
741741
options: TransactionOptions,
742-
) -> rpc::RpcResult<HexEncoded<SignedTransaction>>;
742+
) -> rpc::RpcResult<RpcNewTransaction>;
743743

744744
/// Create an order for exchanging "given" amount of an arbitrary currency (coins or tokens) for
745745
/// an arbitrary amount of "asked" currency.

wallet/wallet-rpc-lib/src/rpc/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1511,7 +1511,7 @@ where
15111511
token_id: Option<RpcAddress<TokenId>>,
15121512
htlc: RpcHashedTimelockContract,
15131513
config: ControllerConfig,
1514-
) -> WRpcResult<SignedTransaction, N> {
1514+
) -> WRpcResult<RpcNewTransaction, N> {
15151515
let secret_hash = HtlcSecretHash::decode_all(&mut htlc.secret_hash.as_bytes())
15161516
.map_err(|_| RpcError::InvalidHtlcSecretHash)?;
15171517

@@ -1571,6 +1571,7 @@ where
15711571
.create_htlc_tx(value, htlc, additional_info)
15721572
.await
15731573
.map_err(RpcError::Controller)
1574+
.map(RpcNewTransaction::new)
15741575
})
15751576
})
15761577
.await?

wallet/wallet-rpc-lib/src/rpc/server_impl.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1110,16 +1110,15 @@ where
11101110
token_id: Option<RpcAddress<TokenId>>,
11111111
htlc: RpcHashedTimelockContract,
11121112
options: TransactionOptions,
1113-
) -> rpc::RpcResult<HexEncoded<SignedTransaction>> {
1113+
) -> rpc::RpcResult<RpcNewTransaction> {
11141114
let config = ControllerConfig {
11151115
in_top_x_mb: options.in_top_x_mb(),
11161116
broadcast_to_mempool: true,
11171117
};
11181118

11191119
rpc::handle_result(
11201120
self.create_htlc_transaction(account_arg.index::<N>()?, amount, token_id, htlc, config)
1121-
.await
1122-
.map(HexEncoded::new),
1121+
.await,
11231122
)
11241123
}
11251124

0 commit comments

Comments
 (0)