Skip to content

Commit 05413da

Browse files
committed
fix comments
1 parent bc312ea commit 05413da

File tree

17 files changed

+130
-66
lines changed

17 files changed

+130
-66
lines changed

test/functional/test_framework/wallet_cli_controller.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -301,8 +301,9 @@ async def create_from_cold_address(self, address: str, amount: int, selected_utx
301301
change_address_str = '' if change_address is None else f"--change {change_address}"
302302
return await self._write_command(f"transaction-create-from-cold-input {address} {amount} {str(selected_utxo)} {change_address_str}\n")
303303

304-
async def sweep_addresses(self, destination_address: str, from_addresses: List[str] = []) -> str:
305-
return await self._write_command(f"address-sweep-spendable {destination_address} {' '.join(from_addresses)}\n")
304+
async def sweep_addresses(self, destination_address: str, from_addresses: List[str] = [], all_addresses: bool = False) -> str:
305+
all_addresses_str = "--all" if all_addresses else ""
306+
return await self._write_command(f"address-sweep-spendable {destination_address} {' '.join(from_addresses)} {all_addresses_str}\n")
306307

307308
async def sweep_delegation(self, destination_address: str, delegation_id: str) -> str:
308309
return await self._write_command(f"staking-sweep-delegation {destination_address} {delegation_id}\n")

test/functional/test_framework/wallet_rpc_controller.py

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import base64
2626
from operator import itemgetter
2727

28-
from typing import Optional, List, Union
28+
from typing import Optional, List, Union, TypedDict
2929

3030
from test_framework.util import assert_in, rpc_port
3131
from test_framework.wallet_controller_common import PartialSigInfo, TokenTxOutput, UtxoOutpoint, WalletCliControllerBase
@@ -46,6 +46,16 @@ def to_json(self):
4646
else:
4747
return {'Transfer': [ { 'Coin': {"atoms": str(self.atoms)} }, f"HexifiedDestination{{0x02{self.pub_key_hex}}}" ]}
4848

49+
@dataclass
50+
class Balances:
51+
coins: str
52+
tokens: dict
53+
54+
class NewTxResult(TypedDict):
55+
tx_id: str
56+
tx: str
57+
fees: Balances
58+
broadcasted: bool
4959

5060
@dataclass
5161
class PoolData:
@@ -295,30 +305,30 @@ async def issue_new_token(self,
295305
else:
296306
return None, result['error']
297307

298-
async def mint_tokens(self, token_id: str, address: str, amount: int) -> str:
308+
async def mint_tokens(self, token_id: str, address: str, amount: int) -> NewTxResult:
299309
return self._write_command("token_mint", [self.account, token_id, address, {'decimal': str(amount)}, {'in_top_x_mb': 5}])['result']
300310

301311
# Note: unlike mint_tokens, this function behaves identically both for wallet_cli_controller and wallet_rpc_controller.
302312
async def mint_tokens_or_fail(self, token_id: str, address: str, amount: int):
303313
# self.mint_tokens already fails on error
304314
await self.mint_tokens(token_id, address, amount)
305315

306-
async def unmint_tokens(self, token_id: str, amount: int) -> str:
316+
async def unmint_tokens(self, token_id: str, amount: int) -> NewTxResult:
307317
return self._write_command("token_unmint", [self.account, token_id, {'decimal': str(amount)}, {'in_top_x_mb': 5}])['result']
308318

309-
async def lock_token_supply(self, token_id: str) -> str:
319+
async def lock_token_supply(self, token_id: str) -> NewTxResult:
310320
return self._write_command("token_lock_supply", [self.account, token_id, {'in_top_x_mb': 5}])['result']
311321

312-
async def freeze_token(self, token_id: str, is_unfreezable: str) -> str:
322+
async def freeze_token(self, token_id: str, is_unfreezable: str) -> NewTxResult:
313323
return self._write_command("token_freeze", [self.account, token_id, is_unfreezable, {'in_top_x_mb': 5}])['result']
314324

315-
async def unfreeze_token(self, token_id: str) -> str:
325+
async def unfreeze_token(self, token_id: str) -> NewTxResult:
316326
return self._write_command("token_unfreeze", [self.account, token_id, {'in_top_x_mb': 5}])['result']
317327

318-
async def change_token_authority(self, token_id: str, new_authority: str) -> str:
328+
async def change_token_authority(self, token_id: str, new_authority: str) -> NewTxResult:
319329
return self._write_command("token_change_authority", [self.account, token_id, new_authority, {'in_top_x_mb': 5}])['result']
320330

321-
async def change_token_metadata_uri(self, token_id: str, new_metadata_uri: str) -> str:
331+
async def change_token_metadata_uri(self, token_id: str, new_metadata_uri: str) -> NewTxResult:
322332
return self._write_command("token_change_metadata_uri", [self.account, token_id, new_metadata_uri, {'in_top_x_mb': 5}])['result']
323333

324334
async def issue_new_nft(self,
@@ -571,7 +581,7 @@ async def create_htlc_transaction(self,
571581
secret_hash: str,
572582
spend_address: str,
573583
refund_address: str,
574-
refund_lock_for_blocks: int) -> str:
584+
refund_lock_for_blocks: int) -> NewTxResult:
575585
timelock = { "type": "ForBlockCount", "content": refund_lock_for_blocks }
576586
htlc = { "secret_hash": secret_hash, "spend_address": spend_address, "refund_address": refund_address, "refund_timelock": timelock }
577587
object = [self.account, {'decimal': str(amount)}, token_id, htlc, {'in_top_x_mb': 5}]

test/functional/wallet_htlc_refund.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ async def async_test(self):
128128
assert_equal(await wallet.get_best_block(), block_id)
129129

130130
balance = await wallet.get_balance()
131-
assert_in(f"Coins amount: 151", balance)
131+
assert_in("Coins amount: 151", balance)
132132
assert_not_in("Tokens", balance)
133133

134134
# issue a valid token
@@ -142,7 +142,7 @@ async def async_test(self):
142142
self.generate_block()
143143
assert_in("Success", await wallet.sync())
144144
balance = await wallet.get_balance()
145-
assert_in(f"Coins amount: 50", balance)
145+
assert_in("Coins amount: 50", balance)
146146
assert_not_in("Tokens", balance)
147147

148148
amount_to_mint = random.randint(1, 10000)
@@ -153,7 +153,7 @@ async def async_test(self):
153153
assert_in("Success", await wallet.sync())
154154
balance = await wallet.get_balance()
155155
print(balance)
156-
assert_in(f"Coins amount: 0", balance)
156+
assert_in("Coins amount: 0", balance)
157157
assert_in(f"Token: {token_id} amount: {amount_to_mint}", balance)
158158

159159
########################################################################################
@@ -165,7 +165,7 @@ async def async_test(self):
165165

166166
alice_amount_to_swap = amount_to_mint
167167
alice_htlc_tx = await wallet.create_htlc_transaction(alice_amount_to_swap, token_id, alice_secret_hash, bob_address, refund_address, 6)
168-
alice_signed_tx_obj = signed_tx_obj.decode(ScaleBytes("0x" + alice_htlc_tx))
168+
alice_signed_tx_obj = signed_tx_obj.decode(ScaleBytes("0x" + alice_htlc_tx['tx']))
169169
alice_htlc_outputs = alice_signed_tx_obj['transaction']['outputs']
170170
alice_htlc_change_dest = alice_htlc_outputs[1]['Transfer'][1]
171171
alice_htlc_tx_id = hash_object(base_tx_obj, alice_signed_tx_obj['transaction'])
@@ -200,7 +200,7 @@ async def async_test(self):
200200

201201
bob_amount_to_swap = 150
202202
bob_htlc_tx = await wallet.create_htlc_transaction(bob_amount_to_swap, None, alice_secret_hash, alice_address, refund_address, 6)
203-
bob_signed_tx_obj = signed_tx_obj.decode(ScaleBytes("0x" + bob_htlc_tx))
203+
bob_signed_tx_obj = signed_tx_obj.decode(ScaleBytes("0x" + bob_htlc_tx['tx']))
204204
bob_htlc_outputs = bob_signed_tx_obj['transaction']['outputs']
205205
bob_htlc_change_dest = bob_htlc_outputs[1]['Transfer'][1]
206206
bob_htlc_tx_id = hash_object(base_tx_obj, bob_signed_tx_obj['transaction'])
@@ -227,7 +227,7 @@ async def async_test(self):
227227
alice_refund_ptx = output.split('\n')[2]
228228

229229
# Alice's htlc tx can now be broadcasted
230-
output = await wallet.submit_transaction(alice_htlc_tx)
230+
output = await wallet.submit_transaction(alice_htlc_tx['tx'])
231231
assert_in("The transaction was submitted successfully", output)
232232

233233
# Alice signs Bob's refund
@@ -238,22 +238,22 @@ async def async_test(self):
238238
bob_refund_ptx = output.split('\n')[2]
239239

240240
# Bob's htlc tx can now be broadcasted
241-
output = await wallet.submit_transaction(bob_htlc_tx)
241+
output = await wallet.submit_transaction(bob_htlc_tx['tx'])
242242
assert_in("The transaction was submitted successfully", output)
243243

244244
self.generate_block()
245245
assert_in("Success", await wallet.sync())
246246

247247
# Check Alice's balance
248248
balance = await wallet.get_balance()
249-
assert_in(f"Coins amount: 0", balance)
249+
assert_in("Coins amount: 0", balance)
250250
assert_not_in("Tokens", balance)
251251

252252
# Check Bob's balance now
253253
await self.switch_to_wallet(wallet, 'bob_wallet')
254254
assert_in("Success", await wallet.sync())
255255
balance = await wallet.get_balance()
256-
assert_in(f"Coins amount: 0", balance)
256+
assert_in("Coins amount: 0", balance)
257257
assert_not_in("Tokens", balance)
258258

259259
########################################################################################
@@ -270,7 +270,7 @@ async def async_test(self):
270270
assert_in("Spending at height 9, locked until height 10", output)
271271

272272
balance = await wallet.get_balance()
273-
assert_in(f"Coins amount: 0", balance)
273+
assert_in("Coins amount: 0", balance)
274274
assert_not_in("Tokens", balance)
275275

276276
# Bob signs and spends the refund
@@ -286,7 +286,7 @@ async def async_test(self):
286286
assert_in("Spending at height 9, locked until height 10", output)
287287

288288
balance = await wallet.get_balance()
289-
assert_in(f"Coins amount: 0", balance)
289+
assert_in("Coins amount: 0", balance)
290290
assert_not_in("Tokens", balance)
291291

292292
########################################################################################
@@ -304,7 +304,7 @@ async def async_test(self):
304304
self.generate_block()
305305
assert_in("Success", await wallet.sync())
306306
balance = await wallet.get_balance()
307-
assert_in(f"Coins amount: 0", balance)
307+
assert_in("Coins amount: 0", balance)
308308
assert_not_in("Tokens", balance)
309309

310310
self.generate_block()
@@ -316,13 +316,13 @@ async def async_test(self):
316316
await self.switch_to_wallet(wallet, 'alice_wallet')
317317
assert_in("Success", await wallet.sync())
318318
balance = await wallet.get_balance()
319-
assert_in(f"Coins amount: 0", balance)
319+
assert_in("Coins amount: 0", balance)
320320
assert_in(f"Token: {token_id} amount: {alice_amount_to_swap}", balance)
321321

322322
await self.switch_to_wallet(wallet, 'bob_wallet')
323323
assert_in("Success", await wallet.sync())
324324
balance = await wallet.get_balance()
325-
assert_in(f"Coins amount: 150", balance)
325+
assert_in(f"Coins amount: {bob_amount_to_swap}", balance)
326326
assert_not_in("Tokens", balance)
327327

328328

test/functional/wallet_htlc_spend.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ async def async_test(self):
131131
assert_equal(await wallet.get_best_block(), block_id)
132132

133133
balance = await wallet.get_balance()
134-
assert_in(f"Coins amount: 151", balance)
134+
assert_in("Coins amount: 151", balance)
135135
assert_not_in("Tokens", balance)
136136

137137
# issue a valid token
@@ -142,7 +142,7 @@ async def async_test(self):
142142
self.generate_block()
143143
assert_in("Success", await wallet.sync())
144144
balance = await wallet.get_balance()
145-
assert_in(f"Coins amount: 50", balance)
145+
assert_in("Coins amount: 50", balance)
146146
assert_not_in("Tokens", balance)
147147

148148
amount_to_mint = random.randint(1, 10000)
@@ -152,7 +152,7 @@ async def async_test(self):
152152
self.generate_block()
153153
assert_in("Success", await wallet.sync())
154154
balance = await wallet.get_balance()
155-
assert_in(f"Coins amount: 0", balance)
155+
assert_in("Coins amount: 0", balance)
156156
assert_in(f"Token: {token_id} amount: {amount_to_mint}", balance)
157157

158158
########################################################################################
@@ -164,7 +164,7 @@ async def async_test(self):
164164
alice_amount_to_swap = amount_to_mint
165165
refund_address = await wallet.add_standalone_multisig_address(2, [alice_pub_key, bob_pub_key], None)
166166
alice_htlc_tx = await wallet.create_htlc_transaction(alice_amount_to_swap, token_id, alice_secret_hash, bob_address, refund_address, 2)
167-
output = await wallet.submit_transaction(alice_htlc_tx)
167+
output = await wallet.submit_transaction(alice_htlc_tx['tx'])
168168
alice_htlc_tx_id = output.split('\n')[2]
169169
self.generate_block()
170170
assert_in("Success", await wallet.sync())
@@ -175,7 +175,7 @@ async def async_test(self):
175175

176176
bob_amount_to_swap = 150
177177
bob_htlc_tx = await wallet.create_htlc_transaction(bob_amount_to_swap, None, alice_secret_hash, alice_address, refund_address, 2)
178-
output = await wallet.submit_transaction(bob_htlc_tx)
178+
output = await wallet.submit_transaction(bob_htlc_tx['tx'])
179179
bob_htlc_tx_id = output.split('\n')[2]
180180
self.generate_block()
181181
assert_in("Success", await wallet.sync())
@@ -189,7 +189,7 @@ async def async_test(self):
189189
random_secret_hex = random_secret.hex()
190190

191191
balance = await wallet.get_balance()
192-
assert_in(f"Coins amount: 0", balance)
192+
assert_in("Coins amount: 0", balance)
193193
assert_not_in("Tokens", balance)
194194

195195
# Alice can't spend Alice's htlc without a secret
@@ -214,7 +214,7 @@ async def async_test(self):
214214
assert_in("Success", await wallet.sync())
215215

216216
balance = await wallet.get_balance()
217-
assert_in(f"Coins amount: 0", balance)
217+
assert_in("Coins amount: 0", balance)
218218
assert_not_in("Tokens", balance)
219219

220220
# Bob can't spend it without secret
@@ -264,7 +264,7 @@ async def async_test(self):
264264
assert_in("Success", await wallet.sync())
265265

266266
balance = await wallet.get_balance()
267-
assert_in(f"Coins amount: 150", balance)
267+
assert_in(f"Coins amount: {bob_amount_to_swap}", balance)
268268
assert_not_in("Tokens", balance)
269269

270270
########################################################################################
@@ -283,7 +283,7 @@ async def async_test(self):
283283
assert_in("Success", await wallet.sync())
284284

285285
balance = await wallet.get_balance()
286-
assert_in(f"Coins amount: 0", balance)
286+
assert_in("Coins amount: 0", balance)
287287
assert_in(f"Token: {token_id} amount: {alice_amount_to_swap}", balance)
288288

289289

test/functional/wallet_sweep_address.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,14 +149,14 @@ def make_locked_output(pub_key_bytes):
149149
acc1_address = await wallet.new_address()
150150

151151
await wallet.select_account(0)
152-
assert_in("The transaction was submitted successfully", await wallet.sweep_addresses(acc1_address, addresses))
152+
assert_in("The transaction was submitted successfully", await wallet.sweep_addresses(acc1_address, all_addresses=True))
153153

154154
block_id = self.generate_block()
155155
assert_in("Success", await wallet.sync())
156156

157157
# check we sent all our coins
158158
balance = await wallet.get_balance()
159-
assert_in(f"Coins amount: 0", balance)
159+
assert_in("Coins amount: 0", balance)
160160
# check we still have the locked balance
161161

162162
balance = await wallet.get_balance('locked')

wallet/src/account/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ impl<K: AccountKeyChains> Account<K> {
507507
pub fn sweep_addresses(
508508
&mut self,
509509
destination: Destination,
510-
request: SendRequest,
510+
mut request: SendRequest,
511511
current_fee_rate: FeeRate,
512512
) -> WalletResult<SendRequest> {
513513
let mut grouped_inputs = group_preselected_inputs(
@@ -566,6 +566,7 @@ impl<K: AccountKeyChains> Account<K> {
566566
destination,
567567
);
568568
outputs.push(coin_output);
569+
request.add_fee(Currency::Coin, total_fee)?;
569570

570571
Ok(request.with_outputs(outputs))
571572
}

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,14 +131,17 @@ where
131131

132132
pub fn new_tx_command(new_tx: RpcNewTransaction, chain_config: &ChainConfig) -> ConsoleCommand {
133133
let status_text = if new_tx.broadcasted {
134-
let summary = new_tx.tx.take().transaction().text_summary(chain_config);
134+
let mut summary = new_tx.tx.take().transaction().text_summary(chain_config);
135+
format_fees(&mut summary, &new_tx.fees);
136+
135137
format!(
136138
"{summary}\nThe transaction was submitted successfully with ID:\n{}",
137139
id_to_hex_string(*new_tx.tx_id.as_hash())
138140
)
139141
} else {
140142
let hex = new_tx.tx.to_string();
141-
let summary = new_tx.tx.take().transaction().text_summary(chain_config);
143+
let mut summary = new_tx.tx.take().transaction().text_summary(chain_config);
144+
format_fees(&mut summary, &new_tx.fees);
142145

143146
format!("{summary}\nThe transaction was created and is ready to be submitted:\n{hex}",)
144147
};
@@ -805,7 +808,7 @@ where
805808
}
806809

807810
WalletCommand::ConfigBroadcast { broadcast } => {
808-
self.config.broadcast_to_mempool = broadcast;
811+
self.config.broadcast_to_mempool = broadcast.to_bool();
809812
Ok(ConsoleCommand::Print(format!(
810813
"Broadcast to Mempool set to: {broadcast:?}"
811814
)))
@@ -1430,6 +1433,7 @@ where
14301433
selected_account,
14311434
destination_address,
14321435
addresses,
1436+
all,
14331437
self.config,
14341438
)
14351439
.await?;

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,10 @@ pub enum WalletCommand {
309309
///
310310
/// The effect of this is not preserved when the CLI wallet is closed.
311311
#[clap(name = "config-broadcast")]
312-
ConfigBroadcast { broadcast: bool },
312+
ConfigBroadcast {
313+
#[arg(value_enum)]
314+
broadcast: YesNo,
315+
},
313316

314317
#[clap(name = "account-create")]
315318
CreateNewAccount { name: Option<String> },

wallet/wallet-controller/src/synced_controller.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ use wallet_types::{
6868
use crate::{
6969
helpers::{fetch_token_info, fetch_utxo, into_balances, tx_to_partially_signed_tx},
7070
runtime_wallet::RuntimeWallet,
71-
types::{Balances, GenericCurrencyTransfer, NewTransaction},
71+
types::{Balances, GenericCurrencyTransfer, NewTransaction, SweepFromAddresses},
7272
ControllerConfig, ControllerError,
7373
};
7474

@@ -568,7 +568,7 @@ where
568568
pub async fn sweep_addresses(
569569
&mut self,
570570
destination_address: Destination,
571-
from_addresses: BTreeSet<Destination>,
571+
from_addresses: SweepFromAddresses,
572572
) -> Result<NewTransaction, ControllerError<T>> {
573573
let selected_utxos = self.wallet.get_utxos(
574574
self.account_index,
@@ -584,7 +584,7 @@ where
584584
.into_iter()
585585
.filter(|(_, output)| {
586586
get_tx_output_destination(output, &|_| None, HtlcSpendingCondition::Skip)
587-
.is_some_and(|dest| from_addresses.is_empty() || from_addresses.contains(&dest))
587+
.is_some_and(|dest| from_addresses.should_sweep_address(&dest))
588588
})
589589
.collect::<Vec<_>>();
590590

0 commit comments

Comments
 (0)