|
7 | 7 | from xrpl.clients import JsonRpcClient
|
8 | 8 | from xrpl.models import AccountObjects, EscrowCreate, EscrowFinish
|
9 | 9 | from xrpl.transaction.reliable_submission import submit_and_wait
|
10 |
| -from xrpl.utils import datetime_to_ripple_time |
| 10 | +from xrpl.utils import datetime_to_ripple_time, xrp_to_drops |
11 | 11 | from xrpl.wallet import generate_faucet_wallet
|
12 | 12 |
|
13 | 13 | # References
|
|
19 | 19 | client = JsonRpcClient("https://s.altnet.rippletest.net:51234")
|
20 | 20 |
|
21 | 21 | # Creating two wallets to send money between
|
22 |
| -wallet1 = generate_faucet_wallet(client, debug=True) |
23 |
| -wallet2 = generate_faucet_wallet(client, debug=True) |
| 22 | +wallet = generate_faucet_wallet(client, debug=True) |
| 23 | +destination = "rPT1Sjq2YGrBMTttX4GZHjKu9dyfzbpAYe" |
24 | 24 |
|
25 | 25 | # Both balances should be zero since nothing has been sent yet
|
26 | 26 | print("Balances of wallets before Escrow tx was created:")
|
27 |
| -print(get_balance(wallet1.address, client)) |
28 |
| -print(get_balance(wallet2.address, client)) |
| 27 | +print(get_balance(wallet.address, client)) |
| 28 | +print(get_balance(destination, client)) |
29 | 29 |
|
30 | 30 | # Create a finish time (8 seconds from last ledger close)
|
31 | 31 | finish_after = datetime_to_ripple_time(datetime.now()) + 8
|
32 | 32 |
|
33 | 33 | # Create an EscrowCreate transaction, then sign, autofill, and send it
|
34 | 34 | create_tx = EscrowCreate(
|
35 |
| - account=wallet1.address, |
36 |
| - destination=wallet2.address, |
37 |
| - amount="1000000", |
| 35 | + account=wallet.address, |
| 36 | + destination=destination, |
| 37 | + amount=xrp_to_drops(50), |
38 | 38 | finish_after=finish_after,
|
39 | 39 | )
|
40 | 40 |
|
41 |
| -create_escrow_response = submit_and_wait(create_tx, client, wallet1) |
| 41 | +create_escrow_response = submit_and_wait(create_tx, client, wallet) |
42 | 42 | print(create_escrow_response)
|
43 | 43 |
|
44 | 44 | # Create an AccountObjects request and have the client call it to see if escrow exists
|
45 |
| -account_objects_request = AccountObjects(account=wallet1.address) |
| 45 | +account_objects_request = AccountObjects(account=wallet.address) |
46 | 46 | account_objects = (client.request(account_objects_request)).result["account_objects"]
|
47 | 47 |
|
48 |
| -print("Escrow object exists in wallet1's account:") |
| 48 | +print("Escrow object exists in wallet's account:") |
49 | 49 | print(account_objects)
|
50 | 50 |
|
51 | 51 | print("Waiting for the escrow finish time to pass...")
|
|
54 | 54 |
|
55 | 55 | # Create an EscrowFinish transaction, then sign, autofill, and send it
|
56 | 56 | finish_tx = EscrowFinish(
|
57 |
| - account=wallet1.address, |
58 |
| - owner=wallet1.address, |
| 57 | + account=wallet.address, |
| 58 | + owner=wallet.address, |
59 | 59 | offer_sequence=create_escrow_response.result["tx_json"]["Sequence"],
|
60 | 60 | )
|
61 | 61 |
|
62 |
| -submit_and_wait(finish_tx, client, wallet1) |
| 62 | +submit_and_wait(finish_tx, client, wallet) |
63 | 63 |
|
64 |
| -# If escrow went through successfully, 1000000 exchanged |
| 64 | +# If escrow went through successfully, 50 XRP exchanged |
65 | 65 | print("Balances of wallets after Escrow was sent:")
|
66 |
| -print(get_balance(wallet1.address, client)) |
67 |
| -print(get_balance(wallet2.address, client)) |
| 66 | +print(get_balance(wallet.address, client)) |
| 67 | +print(get_balance(destination, client)) |
0 commit comments