Skip to content

Commit eacc6ee

Browse files
committed
Update withdraw method to use transact
1 parent 0fc796d commit eacc6ee

File tree

1 file changed

+9
-21
lines changed

1 file changed

+9
-21
lines changed

pycardano/wallet.py

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1167,8 +1167,7 @@ def withdraw(
11671167
self,
11681168
withdrawal_amount: Optional[Union[Ada, Lovelace]] = None,
11691169
output_amount: Optional[Union[Ada, Lovelace]] = Lovelace(1000000),
1170-
await_confirmation: Optional[bool] = False,
1171-
context: Optional[ChainContext] = None,
1170+
**kwargs,
11721171
) -> str:
11731172
"""Withdraw staking rewards.
11741173
@@ -1188,31 +1187,20 @@ def withdraw(
11881187
if not self.stake_address:
11891188
raise ValueError("This wallet does not have staking keys.")
11901189

1191-
context = self._find_context(context)
1192-
11931190
if not withdrawal_amount:
11941191
# automatically detect rewards:
11951192
withdrawal_amount = self.withdrawable_amount
1193+
1194+
if not withdrawal_amount:
1195+
raise ValueError("No rewards to withdraw.")
11961196

1197-
builder = TransactionBuilder(context)
1198-
builder.add_input_address(self.address)
1199-
builder.add_output(TransactionOutput(self.address, output_amount.lovelace))
1200-
builder.withdrawals = Withdrawals(
1201-
{self.stake_address.to_primitive(): withdrawal_amount.lovelace}
1202-
)
1203-
1204-
signed_tx = builder.build_and_sign(
1205-
[self.signing_key, self.stake_signing_key], self.address
1197+
return self.transact(
1198+
inputs=[self],
1199+
outputs=[Output(self, output_amount)],
1200+
withdrawals={self: withdrawal_amount},
1201+
**kwargs,
12061202
)
12071203

1208-
context.submit_tx(signed_tx.to_cbor())
1209-
1210-
if await_confirmation:
1211-
confirmed = wait_for_confirmation(str(signed_tx.id), self.context)
1212-
self.query_utxos()
1213-
1214-
return str(signed_tx.id)
1215-
12161204
def mint_tokens(
12171205
self,
12181206
to: Union[str, Address],

0 commit comments

Comments
 (0)