Skip to content

Commit

Permalink
refactor: Make param order for signing/submitting consistent (#600)
Browse files Browse the repository at this point in the history
* Update the CHANGELOG

* Update `autofill_and_sign` and `sign_and_submit`
  • Loading branch information
JST5000 authored Jun 15, 2023
1 parent aba2141 commit 10d4e6d
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 21 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Core keypairs formatting for ED25519 is now padded with zeros if length of keystring is less than 64
- Removed deprecated request wrappers (the preferred method is to directly do client.request instead)
- `sign` is now synchronous instead of async (done by removing the optional `check_fee` param & moving checks up to other functions)
- In order to be internally consistent, all signing/submitting functions will follow the parameter order of `transaction`, `client`, `wallet`, and then other parameters. (This is because `wallet` is optional for `submit_and_wait` and so must come after `client`)

### Removed:
- Longer aliases for signing/submitting functions have been removed. Specifically
- `submit_transaction` is now `submit`
- `safe_sign_transaction` is now `sign`
- `safe_sign_and_submit_transaction` is now `sign_and_submit`
- `safe_sign_and_autofill_transaction` is now `sign_and_autofill`
- The param order for `sign_and_submit` moves `wallet` after `client` to be consistent with `submit_and_wait`
- `safe_sign_and_autofill_transaction` is now `autofill_and_sign`
- The param order for `autofill_and_sign` moves `wallet` after `client` to be consistent with `submit_and_wait`

## [[Unreleased]]
### Added:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ my_tx_payment = Payment(

# sign the transaction with the autofill method
# (this will auto-populate the fee, sequence, and last_ledger_sequence)
my_tx_payment_signed = autofill_and_sign(my_tx_payment, test_wallet, client)
my_tx_payment_signed = autofill_and_sign(my_tx_payment, client, test_wallet)
print(my_tx_payment_signed)
# Payment(
# account='rMPUKmzmDWEX1tQhzQ8oGFNfAEhnWNFwz',
Expand Down
2 changes: 1 addition & 1 deletion snippets/paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,4 @@
paths=paths,
)

print("signed: ", autofill_and_sign(payment_tx, wallet, client))
print("signed: ", autofill_and_sign(payment_tx, client, wallet))
8 changes: 4 additions & 4 deletions tests/integration/it_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def fund_wallet_sync(wallet: Wallet) -> None:
destination=wallet.classic_address,
amount=FUNDING_AMOUNT,
)
sign_and_submit(payment, MASTER_WALLET, client, check_fee=True)
sign_and_submit(payment, client, MASTER_WALLET, check_fee=True)
client.request(LEDGER_ACCEPT_REQUEST)


Expand All @@ -112,7 +112,7 @@ async def fund_wallet(
destination=wallet.classic_address,
amount=FUNDING_AMOUNT,
)
await sign_and_submit_async(payment, MASTER_WALLET, client, check_fee=True)
await sign_and_submit_async(payment, client, MASTER_WALLET, check_fee=True)
await client.request(LEDGER_ACCEPT_REQUEST)


Expand All @@ -124,7 +124,7 @@ def submit_transaction(
check_fee: bool = True,
) -> Response:
"""Signs and submits a transaction to the XRPL."""
return sign_and_submit(transaction, wallet, client, check_fee=check_fee)
return sign_and_submit(transaction, client, wallet, check_fee=check_fee)


# just submits a transaction to the ledger, asynchronously
Expand All @@ -134,7 +134,7 @@ async def submit_transaction_async(
client: AsyncClient,
check_fee: bool = True,
) -> Response:
return await sign_and_submit_async(transaction, wallet, client, check_fee=check_fee)
return await sign_and_submit_async(transaction, client, wallet, check_fee=check_fee)


# submits a transaction to the ledger and closes a ledger, synchronously
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/reqs/test_submit_only.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
class TestSubmitOnly(IntegrationTestCase):
@test_async_and_sync(globals(), ["xrpl.transaction.autofill_and_sign"])
async def test_basic_functionality(self, client):
transaction = await autofill_and_sign(TX, WALLET, client)
transaction = await autofill_and_sign(TX, client, WALLET)

tx_json = transaction.to_xrpl()
tx_blob = encode(tx_json)
Expand Down
6 changes: 3 additions & 3 deletions tests/integration/sugar/test_transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ async def test_payment_high_fee_authorized_with_submit_alias(self, client):
fee=FEE,
destination=DESTINATION,
),
WALLET,
client,
WALLET,
check_fee=False,
)

Expand Down Expand Up @@ -275,7 +275,7 @@ async def test_submit_and_wait_signed(self, client):
destination=DESTINATION,
)
payment_transaction_signed = await autofill_and_sign(
payment_transaction, WALLET, client
payment_transaction, client, WALLET
)
await accept_ledger_async(delay=1)
response = await submit_and_wait(payment_transaction_signed, client)
Expand All @@ -301,7 +301,7 @@ async def test_submit_and_wait_blob(self, client):
destination=DESTINATION,
)
payment_transaction_signed = await autofill_and_sign(
payment_transaction, WALLET, client
payment_transaction, client, WALLET
)
await accept_ledger_async(delay=1)
payment_transaction_signed_blob = encode(payment_transaction_signed.to_xrpl())
Expand Down
8 changes: 4 additions & 4 deletions xrpl/asyncio/transaction/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@

async def sign_and_submit(
transaction: Transaction,
wallet: Wallet,
client: Client,
wallet: Wallet,
autofill: bool = True,
check_fee: bool = True,
) -> Response:
Expand All @@ -41,8 +41,8 @@ async def sign_and_submit(
Args:
transaction: the transaction to be signed and submitted.
wallet: the wallet with which to sign the transaction.
client: the network client with which to submit the transaction.
wallet: the wallet with which to sign the transaction.
autofill: whether to autofill the relevant fields. Defaults to True.
check_fee: whether to check if the fee is higher than the expected transaction
type fee. Defaults to True.
Expand All @@ -51,7 +51,7 @@ async def sign_and_submit(
The response from the ledger.
"""
if autofill:
transaction = await autofill_and_sign(transaction, wallet, client, check_fee)
transaction = await autofill_and_sign(transaction, client, wallet, check_fee)
else:
if check_fee:
await _check_fee(transaction, client)
Expand Down Expand Up @@ -109,8 +109,8 @@ def sign(

async def autofill_and_sign(
transaction: Transaction,
wallet: Wallet,
client: Client,
wallet: Wallet,
check_fee: bool = True,
) -> Transaction:
"""
Expand Down
12 changes: 6 additions & 6 deletions xrpl/transaction/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

def sign_and_submit(
transaction: Transaction,
wallet: Wallet,
client: SyncClient,
wallet: Wallet,
autofill: bool = True,
check_fee: bool = True,
) -> Response:
Expand All @@ -22,8 +22,8 @@ def sign_and_submit(
Args:
transaction: the transaction to be signed and submitted.
wallet: the wallet with which to sign the transaction.
client: the network client with which to submit the transaction.
wallet: the wallet with which to sign the transaction.
autofill: whether to autofill the relevant fields. Defaults to True.
check_fee: whether to check if the fee is higher than the expected transaction
type fee. Defaults to True.
Expand All @@ -34,8 +34,8 @@ def sign_and_submit(
return asyncio.run(
main.sign_and_submit(
transaction,
wallet,
client,
wallet,
autofill,
check_fee,
)
Expand Down Expand Up @@ -78,8 +78,8 @@ def submit(

def autofill_and_sign(
transaction: Transaction,
wallet: Wallet,
client: SyncClient,
wallet: Wallet,
check_fee: bool = True,
) -> Transaction:
"""
Expand All @@ -88,8 +88,8 @@ def autofill_and_sign(
Args:
transaction: the transaction to be signed.
wallet: the wallet with which to sign the transaction.
client: a network client.
wallet: the wallet with which to sign the transaction.
check_fee: whether to check if the fee is higher than the expected transaction
type fee. Defaults to True.
Expand All @@ -99,8 +99,8 @@ def autofill_and_sign(
return asyncio.run(
main.autofill_and_sign(
transaction,
wallet,
client,
wallet,
check_fee,
)
)
Expand Down

0 comments on commit 10d4e6d

Please sign in to comment.