Skip to content

Commit

Permalink
[python] support inserting sequence numbers in transaction helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
davidiw committed May 18, 2023
1 parent 0df3c66 commit a8860d9
Show file tree
Hide file tree
Showing 3 changed files with 284 additions and 173 deletions.
29 changes: 23 additions & 6 deletions ecosystem/python/sdk/aptos_sdk/async_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,11 +374,19 @@ async def create_multi_agent_bcs_transaction(
return SignedTransaction(raw_transaction.inner(), authenticator)

async def create_bcs_transaction(
self, sender: Account, payload: TransactionPayload
self,
sender: Account,
payload: TransactionPayload,
sequence_number: Optional[int] = None,
) -> RawTransaction:
sequence_number = (
sequence_number
if sequence_number is not None
else await self.account_sequence_number(sender.address())
)
return RawTransaction(
sender.address(),
await self.account_sequence_number(sender.address()),
sequence_number,
payload,
self.client_config.max_gas_amount,
self.client_config.gas_unit_price,
Expand All @@ -387,9 +395,14 @@ async def create_bcs_transaction(
)

async def create_bcs_signed_transaction(
self, sender: Account, payload: TransactionPayload
self,
sender: Account,
payload: TransactionPayload,
sequence_number: Optional[int] = None,
) -> SignedTransaction:
raw_transaction = await self.create_bcs_transaction(sender, payload)
raw_transaction = await self.create_bcs_transaction(
sender, payload, sequence_number
)
signature = sender.sign(raw_transaction.keyed())
authenticator = Authenticator(
Ed25519Authenticator(sender.public_key(), signature)
Expand Down Expand Up @@ -419,7 +432,11 @@ async def transfer(

# :!:>bcs_transfer
async def bcs_transfer(
self, sender: Account, recipient: AccountAddress, amount: int
self,
sender: Account,
recipient: AccountAddress,
amount: int,
sequence_number: Optional[int] = None,
) -> str:
transaction_arguments = [
TransactionArgument(recipient, Serializer.struct),
Expand All @@ -434,7 +451,7 @@ async def bcs_transfer(
)

signed_transaction = await self.create_bcs_signed_transaction(
sender, TransactionPayload(payload)
sender, TransactionPayload(payload), sequence_number=sequence_number
)
return await self.submit_bcs_transaction(signed_transaction)

Expand Down
6 changes: 6 additions & 0 deletions ecosystem/python/sdk/examples/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,9 @@
"APTOS_FAUCET_URL",
"https://faucet.devnet.aptoslabs.com",
) # <:!:section_1

NODE_URL = os.getenv("APTOS_NODE_URL", "http://127.0.0.1:8080/v1")
FAUCET_URL = os.getenv(
"APTOS_FAUCET_URL",
"http://127.0.0.1:8081",
) # <:!:section_1
Loading

0 comments on commit a8860d9

Please sign in to comment.