Skip to content

API description in progress

Ariel edited this page Jul 14, 2017 · 10 revisions

API draft:
Will be written in Javascript

Assuming Seller is always ETH side
Buyer is always Zcash side.
Class Trade :
contains addresses:
Z_contract = (Z_buyer, Z_seller,Z_amount,Z_p2sh,Z_redeemscript,Z_fund_txid,Z_lock_increment)
E_seller, E_buyer
E_amount
secret
E_lock_time – number of blocks from lock when fund unlocked
E_tradeid
Role = {seller,buyer}

BuyerTrade(E_buyer,E_seller,E_tradeid,E_amount,Z_amount,Z_seller){
Z_contract = Zcash_get_contract(Z_buyer,Z_seller,hash_of_secret,Z_lock_increment)

taking these parameters, except Z_lock_time, and Z_p2sh

that he computes farom the others; Z_p2sh and Z_redeemscript using .
Zcash_getredeemscript_and_p2sh(Z_seller_ad,Z_buyer_ad,Z_amount,Z_lock_time)

and E_tradeid is obtained from running the Ethereum Lock function
//Funding the seller side
Seller_Fund(){

E_tradeid = Eth_lock(E_seller_ad, E_buyer_ad, E_lock_time,E_amount, Hash(secret))
}
Buyer_fund(){

Z_fundtxid = Zcash_Fund(Z_p2sh,Z_amount)
}
Seller_Redeem(){
Zcash_redeem(Z_redeemscript,Z_seller_ad,secret,Z_p2sh)
//This Zcash method can find the transaction to the p2sh.
}
Buyer_Redeem(){
secret = Zcash_parse_secret(Z_p2sh)
Eth_unlock(tradeid,secret)
Zcash_refund(Z_redeemscript,Z_buyer_ad,Z_p2sh,Z_fund_txid) //tries also to refund their own fundtx
}

Clone this wiki locally