From 48ad8dfd4299c2ba9c08e4dd30b3746c91bbfe5c Mon Sep 17 00:00:00 2001 From: Obiajulu <47371105+ObiajuluM@users.noreply.github.com> Date: Tue, 4 Oct 2022 00:50:00 -0700 Subject: [PATCH] Update account_escrows.py --- .../escrow/py/account_escrows.py | 35 +++++++++---------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/content/_code-samples/escrow/py/account_escrows.py b/content/_code-samples/escrow/py/account_escrows.py index e435179f4f..abfb2a159d 100644 --- a/content/_code-samples/escrow/py/account_escrows.py +++ b/content/_code-samples/escrow/py/account_escrows.py @@ -4,50 +4,47 @@ from xrpl.utils import drops_to_xrp, ripple_time_to_datetime # Retreive all escrows created or received by an account, formatted -client = JsonRpcClient("https://s.altnet.rippletest.net:51234") # connect to the testnetwork +client = JsonRpcClient("https://s.altnet.rippletest.net:51234") # Connect to the testnetwork account_address = "r9CEVt4Cmcjt68ME6GKyhf2DyEGo2rG8AW" -escrow_dict = {} # a dict to store all escrows -sent = [] # a list to store sent/ created escrows -received = [] # a list to store received escrows +all_escrows_dict = {} +sent_escrows = [] +received_escrows = [] -# build and make request +# Build and make request req = AccountObjects(account=account_address, ledger_index="validated", type="escrow") response = client.request(req) -# return account escrows +# Return account escrows escrows = response.result["account_objects"] -# loop through result and parse account escrows +# Loop through result and parse account escrows for escrow in escrows: - escrow_data = {} # new dict per escrow for storing each escrow info + escrow_data = {} if isinstance(escrow["Amount"], str): - escrow_data["escrow_id"] = escrow["index"] # escrow id - escrow_data["sender"] = escrow["Account"] # escrow sender AKA creator - escrow_data["receiver"] = escrow["Destination"] # escrow receiver - escrow_data["amount"] = str(drops_to_xrp(escrow["Amount"])) # amount held in escrow + escrow_data["escrow_id"] = escrow["index"] + escrow_data["sender"] = escrow["Account"] + escrow_data["receiver"] = escrow["Destination"] + escrow_data["amount"] = str(drops_to_xrp(escrow["Amount"])) if "PreviousTxnID" in escrow: - escrow_data["prex_txn_id"] = escrow["PreviousTxnID"] # needed to cancel or complete the escrow + escrow_data["prex_txn_id"] = escrow["PreviousTxnID"] if "FinishAfter" in escrow: - # date when and after ecsrow can be claimed if available escrow_data["redeem_date"] = str(ripple_time_to_datetime(escrow["FinishAfter"])) if "CancelAfter" in escrow: - # date when and after escrow expires if available escrow_data["expiry_date"] = str(ripple_time_to_datetime(escrow["CancelAfter"])) if "Condition" in escrow: - # return crypto condition if available escrow_data["condition"] = escrow["Condition"] - # arrange escrows into sent and received lists + # Sort escrows if escrow_data["sender"] == account_address: sent.append(escrow_data) else: received.append(escrow_data) -# add lists to escrow dict +# Add lists to escrow dict escrow_dict["sent"] = sent escrow_dict["received"] = received -# print escrow dict +# Print escrow dict print(escrow_dict)