mirror of
https://github.com/XRPLF/xrpl-dev-portal.git
synced 2025-12-06 17:27:57 +00:00
Update with review comments
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Create, claim and verify a Payment Channel.
|
||||
* Reference: https://xrpl.org/paychannel.html
|
||||
* Reference: https://xrpl.org/docs/references/protocol/ledger-data/ledger-entry-types/paychannel
|
||||
*/
|
||||
import {
|
||||
AccountObjectsRequest,
|
||||
|
||||
@@ -35,7 +35,7 @@ payment_channel_create = PaymentChannelCreate(
|
||||
public_key=wallet1.public_key,
|
||||
)
|
||||
|
||||
print("Submitting a PaymentChannelCreate transaction...")
|
||||
print("\nSubmitting a PaymentChannelCreate transaction...")
|
||||
payment_channel_response = submit_and_wait(
|
||||
payment_channel_create,
|
||||
client,
|
||||
@@ -53,15 +53,16 @@ account_objects = account_objects_response.result["account_objects"]
|
||||
|
||||
# Find the PayChannel object to get the correct channel ID
|
||||
channel_id = None
|
||||
for obj in account_objects:
|
||||
if obj["LedgerEntryType"] == "PayChannel":
|
||||
channel_id = obj["index"]
|
||||
break
|
||||
if 'meta' in payment_channel_response.result and 'AffectedNodes' in payment_channel_response.result['meta']:
|
||||
for node in payment_channel_response.result["meta"]["AffectedNodes"]:
|
||||
if 'CreatedNode' in node and node["CreatedNode"]["LedgerEntryType"] == 'PayChannel':
|
||||
channel_id = node['CreatedNode']['LedgerIndex']
|
||||
break
|
||||
|
||||
if not channel_id:
|
||||
raise Exception("PayChannel not found in account objects")
|
||||
raise Exception("Payment Channel ID not found in the response.")
|
||||
|
||||
print(f"PayChannel ID: {channel_id}")
|
||||
print(f"Payment Channel ID: {channel_id}")
|
||||
|
||||
# Destination claims the Payment Channel and we see the balances to verify.
|
||||
payment_channel_claim = PaymentChannelClaim(
|
||||
@@ -70,7 +71,7 @@ payment_channel_claim = PaymentChannelClaim(
|
||||
amount="100",
|
||||
)
|
||||
|
||||
print("Submitting a PaymentChannelClaim transaction...")
|
||||
print("\nSubmitting a PaymentChannelClaim transaction...")
|
||||
channel_claim_response = submit_and_wait(
|
||||
payment_channel_claim,
|
||||
client,
|
||||
|
||||
@@ -44,7 +44,7 @@ async function main() {
|
||||
"Destination": wallet.address,
|
||||
"Amount": "6000000", //drops XRP
|
||||
"DestinationTag": 2023,
|
||||
"Condition": conditionHex,
|
||||
"Condition": conditionHex, // Omit this for time-held escrows
|
||||
"Fee": "12",
|
||||
"FinishAfter": xrpl.isoTimeToRippleTime(finishAfter.toISOString()),
|
||||
};
|
||||
|
||||
@@ -35,9 +35,11 @@ const main = async () => {
|
||||
"Owner": wallet.address,
|
||||
// This should equal the sequence number of the escrow transaction
|
||||
"OfferSequence": offerSequence,
|
||||
// Crypto condition that must be met before escrow can be completed, passed on escrow creation
|
||||
// Crypto condition that must be met before escrow can be completed, passed on escrow creation.
|
||||
// Omit this for time-held escrows.
|
||||
"Condition": condition,
|
||||
// Fulfillment of the condition, passed on escrow creation
|
||||
// Fulfillment of the condition, passed on escrow creation.
|
||||
// Omit this for time-held escrows.
|
||||
"Fulfillment": fulfillment,
|
||||
};
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ create_txn = EscrowCreate(
|
||||
destination=receiver_addr,
|
||||
finish_after=claim_date,
|
||||
cancel_after=expiry_date,
|
||||
condition=condition
|
||||
condition=condition # Omit this for time-held escrows
|
||||
)
|
||||
|
||||
# Autofill, sign, then submit transaction and wait for result
|
||||
|
||||
@@ -29,8 +29,8 @@ finish_txn = EscrowFinish(
|
||||
account=sender_wallet.address,
|
||||
owner=escrow_creator,
|
||||
offer_sequence=escrow_sequence, # The sequence number of the escrow transaction
|
||||
condition=condition,
|
||||
fulfillment=fulfillment
|
||||
condition=condition, # Omit this for time-held escrows
|
||||
fulfillment=fulfillment # Omit this for time-held escrows
|
||||
)
|
||||
|
||||
# Autofill, sign, then submit transaction and wait for result
|
||||
|
||||
Reference in New Issue
Block a user