22from starcoin import starcoin_stdlib as stdlib
33from starcoin import serde_types as st
44from starcoin .sdk import (utils , client , local_account , auth_key )
5+ from starcoin .sdk .receipt_identifier import ReceiptIdentifier
56from cryptography .hazmat .primitives .asymmetric .ed25519 import (
67 Ed25519PrivateKey , Ed25519PublicKey )
78import time
89import 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
4041if __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