Skip to content

Commit 13e91e3

Browse files
committed
Update p2p transfer example by receipt identifier
1 parent 4c94285 commit 13e91e3

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

examples/p2p_transfer.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,21 @@
22
from starcoin import starcoin_stdlib as stdlib
33
from starcoin import serde_types as st
44
from starcoin.sdk import (utils, client, local_account, auth_key)
5+
from starcoin.sdk.receipt_identifier import ReceiptIdentifier
56
from cryptography.hazmat.primitives.asymmetric.ed25519 import (
67
Ed25519PrivateKey, Ed25519PublicKey)
78
import time
89
import typing
910

1011

11-
def transfer(cli: client.Client, sender: local_account.LocalAccount, payee: str, amount: st.uint128, payee_auth_key=typing.Union[auth_key.AuthKey, None]):
12+
def transfer(cli: client.Client, sender: local_account.LocalAccount, receipt: str, amount: st.uint128):
1213
seq_num = cli.get_account_sequence(
1314
"0x"+sender.account_address.bcs_serialize().hex())
14-
payee_account = utils.account_address(payee)
15+
receipt = ReceiptIdentifier.decode(receipt)
1516
script = stdlib.encode_peer_to_peer_script_function(
1617
token_type=utils.currency_code("STC"),
17-
payee=payee_account,
18-
payee_auth_key=payee_auth_key, # assert the payee address has been on chain
18+
payee=receipt.account_address,
19+
payee_auth_key=receipt.auth_key.data if receipt.auth_key is not None else b"",
1920
amount=amount,
2021
)
2122
node_info = cli.node_info()
@@ -38,20 +39,21 @@ def transfer(cli: client.Client, sender: local_account.LocalAccount, payee: str,
3839

3940

4041
if __name__ == "__main__":
41-
cli = client.Client("http://barnard1.seed.starcoin.org:9850")
42+
cli = client.Client("http://barnard.seed.starcoin.org:9850")
4243
# sender
4344
private_key = Ed25519PrivateKey.from_private_bytes(bytes.fromhex(
4445
"e424e16db235e3f3b9ef2475516c51d4c15aa5287ceb364213698bd551eab4f2"))
4546
sender = local_account.LocalAccount(private_key)
4647

4748
# reciver
48-
payee_public_key_hex = "a1d2f3e34563ef6e63e0d01e91bd53e9d27da758b25b01771572c240cb4f3113"
49+
payee_public_key_hex = "848a4e958af8f127a0b4797ab0a2868e2e15b5232ed1076fdf34228433f96a2f"
4950
pk = Ed25519PublicKey.from_public_bytes(
5051
bytes.fromhex(payee_public_key_hex))
5152
payee_auth_key = auth_key.AuthKey.from_public_key(pk)
5253
payee_address = payee_auth_key.account_address()
5354
if cli.is_account_exist("0x"+payee_address.bcs_serialize().hex()):
5455
payee_auth_key = auth_key.AuthKey(b"")
55-
transfer(cli, sender, payee_address, 1024, payee_auth_key.data)
56+
receipt = ReceiptIdentifier(payee_address, payee_auth_key).encode()
57+
transfer(cli, sender, receipt, 1024)
5658
print(cli.get_account_token(
5759
utils.account_address_hex(payee_address), "STC", "STC"))

0 commit comments

Comments
 (0)