Skip to content

Commit 5234be0

Browse files
authored
Merge pull request #1904 from mintlayer/feature/wallet-sweep-all-addresses
Feature/wallet sweep all addresses
2 parents 71536a9 + 291f5a1 commit 5234be0

File tree

28 files changed

+1721
-890
lines changed

28 files changed

+1721
-890
lines changed

node-gui/backend/src/backend_impl.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -819,7 +819,8 @@ impl Backend {
819819
},
820820
)
821821
.await
822-
.map_err(|e| BackendError::WalletError(e.to_string()))?;
822+
.map_err(|e| BackendError::WalletError(e.to_string()))?
823+
.tx;
823824

824825
Ok(TransactionInfo {
825826
wallet_id,
@@ -872,7 +873,8 @@ impl Backend {
872873
},
873874
)
874875
.await
875-
.map_err(|e| BackendError::WalletError(e.to_string()))?;
876+
.map_err(|e| BackendError::WalletError(e.to_string()))?
877+
.tx;
876878

877879
Ok(TransactionInfo {
878880
wallet_id,
@@ -904,7 +906,8 @@ impl Backend {
904906
},
905907
)
906908
.await
907-
.map_err(|e| BackendError::WalletError(e.to_string()))?;
909+
.map_err(|e| BackendError::WalletError(e.to_string()))?
910+
.tx;
908911

909912
Ok(TransactionInfo {
910913
wallet_id,
@@ -940,7 +943,7 @@ impl Backend {
940943

941944
Ok(TransactionInfo {
942945
wallet_id,
943-
tx: SignedTransactionWrapper::new(tx),
946+
tx: SignedTransactionWrapper::new(tx.tx),
944947
})
945948
}
946949

@@ -975,7 +978,8 @@ impl Backend {
975978
},
976979
)
977980
.await
978-
.map_err(|e| BackendError::WalletError(e.to_string()))?;
981+
.map_err(|e| BackendError::WalletError(e.to_string()))?
982+
.tx;
979983

980984
Ok(TransactionInfo {
981985
wallet_id,
@@ -1018,7 +1022,8 @@ impl Backend {
10181022
},
10191023
)
10201024
.await
1021-
.map_err(|e| BackendError::WalletError(e.to_string()))?;
1025+
.map_err(|e| BackendError::WalletError(e.to_string()))?
1026+
.tx;
10221027

10231028
Ok(TransactionInfo {
10241029
wallet_id,

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, 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_multisig_address.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ async def async_test(self):
180180
await wallet.open_wallet('wallet0')
181181
output = await wallet.send_to_address(multisig_address, 1)
182182
assert_in("The transaction was submitted successfully", output)
183-
multisig_tx_id = output.splitlines()[1]
183+
multisig_tx_id = output.splitlines()[-1]
184184
self.generate_block()
185185
assert not node.mempool_contains_tx(multisig_tx_id)
186186
assert_not_in("No transaction found", await wallet.get_raw_signed_transaction(multisig_tx_id))

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')

0 commit comments

Comments
 (0)