mirror of
https://github.com/XRPLF/xrpl-dev-portal.git
synced 2025-12-06 17:27:57 +00:00
Re-level non-docs content to top of repo and rename content→docs
This commit is contained in:
55
_code-samples/quickstart/py/mod9.py
Normal file
55
_code-samples/quickstart/py/mod9.py
Normal file
@@ -0,0 +1,55 @@
|
||||
import xrpl
|
||||
from xrpl.clients import JsonRpcClient
|
||||
from xrpl.wallet import Wallet
|
||||
from datetime import datetime
|
||||
from xrpl.models.transactions import EscrowCreate, EscrowFinish
|
||||
|
||||
testnet_url = "https://s.altnet.rippletest.net:51234"
|
||||
|
||||
def add_seconds(numOfSeconds):
|
||||
new_date = datetime.now()
|
||||
if new_date != '':
|
||||
new_date = xrpl.utils.datetime_to_ripple_time(new_date)
|
||||
new_date = new_date + int(numOfSeconds)
|
||||
return new_date
|
||||
|
||||
|
||||
def create_conditional_escrow(seed, amount, destination, cancel, condition):
|
||||
wallet=Wallet.from_seed(seed)
|
||||
client=JsonRpcClient(testnet_url)
|
||||
cancel_date = add_seconds(cancel)
|
||||
|
||||
escrow_tx=xrpl.models.transactions.EscrowCreate(
|
||||
account=wallet.address,
|
||||
amount=amount,
|
||||
destination=destination,
|
||||
cancel_after=cancel_date,
|
||||
condition=condition
|
||||
)
|
||||
# Submit the transaction and report the results
|
||||
reply=""
|
||||
try:
|
||||
response=xrpl.transaction.submit_and_wait(escrow_tx,client,wallet)
|
||||
reply=response.result
|
||||
except xrpl.transaction.XRPLReliableSubmissionException as e:
|
||||
reply=f"Submit failed: {e}"
|
||||
return reply
|
||||
|
||||
def finish_conditional_escrow(seed, owner, sequence, condition, fulfillment):
|
||||
wallet=Wallet.from_seed(seed)
|
||||
client=JsonRpcClient(testnet_url)
|
||||
finish_tx=xrpl.models.transactions.EscrowFinish(
|
||||
account=wallet.address,
|
||||
owner=owner,
|
||||
offer_sequence=int(sequence),
|
||||
condition=condition,
|
||||
fulfillment=fulfillment
|
||||
)
|
||||
# Submit the transaction and report the results
|
||||
reply=""
|
||||
try:
|
||||
response=xrpl.transaction.submit_and_wait(finish_tx,client,wallet)
|
||||
reply=response.result
|
||||
except xrpl.transaction.XRPLReliableSubmissionException as e:
|
||||
reply=f"Submit failed: {e}"
|
||||
return reply
|
||||
Reference in New Issue
Block a user