w0801_escrow asnap
20220831
The escrow contract
This page is a report on the scripted implementation of the marlowe escrow contract. The first section is for reading, the rest (the sources of all scripts) are for reference.

Every transition from one state to the next corresponds to the execution of one or more scripts. Eg. when the seller disputes the problem, this corresponds to executing script: 404_seller_disputes.sh
Each and every flow is implemented except for flow 100 -> 270, where the buyer doesn’t deposit, and the mediator tries to get his funds back after the deadline passed: I’ll look later if I can get it to work.
Scripts
- Here is a zip with the scripts and other data: scripts_801.zip.
- Look at the files in the ‘core’ directory in the zip-file. These scripts are also documented in the 2nd half of this page.
Notes
- The price of the item bought/sold is 100 ADA.
- Short deadlines: to be able to test the ‘deadline passed’ flows, the deadlines are set at 15 .. 18 minutes in the future. The ‘red’ squares in above diagram all have a deadline in their flow. (these take long to execute, because of waiting 20min for the deadlines to pass).
- A release request is the transaction that moves the funds from the contract to the payout address after deadline expiry
- In case you want to execute the scripts: at the starting point the buyer, mediator, and seller addresses are expected to have been created, the tokens (BUY, MED,and SEL) minted and distributed. Those scripts are not included.
- A python script (which uses pandas) is used for computing the balance (install on linux with: apt-get install python3-pandas), but this is not needed for core execution.
- The tool used for querying the blockchain is asnap, this is its gitlab repo: gitlab.com/wmoco/asnap (also see: usage and advanced_usage ). If you want to execute the scripts, you’ll need at least version v0.1.2 of asnap. Install it like this:
go install gitlab.com/wmoco/asnap@v0.1.2 .
Report
- Following is a generated report, which details the scripts that are executed in each flow, and what the before/after balance difference (ADA) is for buyer, seller, mediator after execution.
- The most expensive flow (highest cost) is flow550.sh which costs 6.26 ADA.
- The flows are numbered according to the end-state, eg. Flow 550 is from “100-start” to “550-end”.
flow330.sh
102_create_escrow_contract.sh
104_mediator_funds_contract.sh
202_buyer_deposits.sh
302_buyer_approves.sh
322_seller_withdraws.sh
324_mediator_withdraws.sh
Difference before/after execution
ALIAS DIFF
buyer -102.532313
mediator -0.657771
seller 99.579051
TOTAL -3.611033
flow430.sh
102_create_escrow_contract.sh
104_mediator_funds_contract.sh
202_buyer_deposits.sh
304_buyer_objects.sh
402_seller_confirms.sh
422_buyer_withdraws.sh
424_mediator_withdraws.sh
Difference before/after execution
ALIAS DIFF
buyer -3.083517
mediator -0.653429
seller -1.195388
TOTAL -4.932334
flow530.sh
102_create_escrow_contract.sh
104_mediator_funds_contract.sh
202_buyer_deposits.sh
304_buyer_objects.sh
404_seller_disputes.sh
502_mediator_confirms.sh
522_buyer_withdraws.sh
524_mediator_withdraws.sh
Difference before/after execution
ALIAS DIFF
buyer -3.079175
mediator -1.808434
seller -1.301125
TOTAL -6.188734
flow550.sh
102_create_escrow_contract.sh
104_mediator_funds_contract.sh
202_buyer_deposits.sh
304_buyer_objects.sh
404_seller_disputes.sh
504_mediator_dismisses.sh
542_seller_withdraws.sh
544_mediator_withdraws.sh
Difference before/after execution
ALIAS DIFF
buyer -102.709091
mediator -1.892715
seller 98.341982
TOTAL -6.259824
flow370_deadline.sh
102_create_escrow_contract.sh
104_mediator_funds_contract.sh
202_buyer_deposits.sh
# BUYER DEPOSITS, BUT DOESN'T EVALUATE. SLEEP UNTIL PAYMENT DEADLINE PASSED -> 20min
echo "Sleeping for 20 minutes, until deadlines have passed"
sleep 1200
echo "Awake again ... at `date "+%a %Hh%M"` "
306_seller_requests_release.sh
362_seller_withdraws.sh
364_mediator_withdraws.sh
Difference before/after execution
ALIAS DIFF
buyer -101.349774
mediator -0.653429
seller 98.478028
TOTAL -3.525175
flow470_deadline.sh
102_create_escrow_contract.sh
104_mediator_funds_contract.sh
202_buyer_deposits.sh
304_buyer_objects.sh
# SELLER DOESN'T CONFIRM NOR DISPUTE , SLEEP UNTIL PAYMENT DEADLINE PASSED -> 20min
echo "Sleeping for 20 minutes, until deadlines have passed"
sleep 1200
echo "Awake again ... at `date "+%a %Hh%M"` "
406_buyer_requests_release.sh
462_buyer_withdraws.sh
464_mediator_withdraws.sh
Difference before/after execution
ALIAS DIFF
buyer -4.143685
mediator -0.657771
seller 0.000000
TOTAL -4.801456
flow570_deadline.sh
102_create_escrow_contract.sh
104_mediator_funds_contract.sh
202_buyer_deposits.sh
304_buyer_objects.sh
404_seller_disputes.sh
# MEDIATOR DOESN'T DISMISS NOR CONFIRMS, SLEEP UNTIL PAYMENT DEADLINE PASSED -> 20min
echo "Sleeping for 20 minutes, until deadlines have passed"
sleep 1200
echo "Awake again ... at `date "+%a %Hh%M"` "
506_buyer_requests_release.sh
562_buyer_withdraws.sh
564_mediator_withdraws.sh
# Note: I tried first to run seller withdraw, but that didn't work, it should be the buyer withdrawing
# The 562_seller_withdraws.sh gave this error:
# TxBodyErrorMinUTxONotMet (TxOutInAnyEra AlonzoEra (TxOut (AddressInEra (ShelleyAddressInEra ShelleyBasedEraAlonzo)
# (ShelleyAddress Testnet (KeyHashObj (KeyHash "d70c3139e3c5f4c90c52f78829c57b0044dd3566f753b62e0509f75a")) StakeRefNull))
# (TxOutValue MultiAssetInAlonzoEra (valueFromList [])) TxOutDatumNone)) (Lovelace 999978)
Difference before/after execution
ALIAS DIFF
buyer -4.190786
mediator -0.647625
seller -1.301125
TOTAL -6.139536
All the scripts
000_setenv.sh
010_clean_for_collateral.sh
102_create_escrow_contract.sh
202_buyer_deposits.sh
302_buyer_approves.sh
304_buyer_objects.sh
306_seller_requests_release.sh
322_seller_withdraws.sh
362_seller_withdraws.sh
402_seller_confirms.sh
404_seller_disputes.sh
406_buyer_requests_release.sh
422_buyer_withdraws.sh
462_buyer_withdraws.sh
506_buyer_requests_release.sh
522_buyer_withdraws.sh
542_seller_withdraws.sh
562_buyer_withdraws.sh
|