Skip to content

Instantly share code, notes, and snippets.

@rergw
Created September 12, 2018 04:31
Show Gist options
  • Save rergw/d20835f3586f0a6a4d3d68083df0d0fb to your computer and use it in GitHub Desktop.
Save rergw/d20835f3586f0a6a4d3d68083df0d0fb to your computer and use it in GitHub Desktop.
escrow api
classes = %i(Escrows Escrow)
classes.each do |klass|
Object.send(:remove_const, klass) if Object.constants.include?(klass)
end
escrow_attrs = %i(seller_address buyer_address optional_arbitrer
optional_product)
Escrow = Struct.new(*escrow_attrs) do
def buyer_proof
end
def send_product
end
def seller_proof
end
def buyer_satisfied?
end
def release_if_satisfied
end
def release
end
def buyer_complain
end
def seller_complain
end
def arbitrate(arbitrators)
end
def release
end
def refund
end
end
escrows_attrs = %i(deployer_signature optional_network)
Escrows = Struct.new(*escrows_attrs) do
def deploy
end
def tx(*attrs); Escrow.new *attrs end
end
# will be fetched from 3rd API?
arbitrators = %w(0xarb1 0xarb2 0xarb3)
# created functions ts and t to test on irb/pry
def ts
deployer_signature = 'dep_sign'
# name or ticker of network
optional_network = 'ethereum|stellar|eos|neo|icon|etc'
Escrows.new deployer_signature, optional_network
end
def t
# a new contract to handle escrows
es = ts
ts.deploy
# a new escrow
seller_address = '0xseller'
buyer_address = '0xbuyer'
optional_arbitrer = '0xarbitrer'
optional_product = nil
es.tx seller_address, buyer_address, optional_arbitrer, optional_product
end
escrow = t
# buyer pays before product is sent, funding escrow
# escrow can read buyer submitted data, seller sees this
escrow.buyer_proof
# case 1: escrow does not deliver, product arrives buyer notifies if product is right
# seller notifies escrow product sent, form submit, data(or ref) is saved in contract
# case 2: escrow does deliver, buyer notifies if product is right
# for example contract will send URL/user/pass to buyer address so he can access data
# escrow might be connected to a system to create an user and pass for buyer
# in that case escrow needs to store credentials
# but if in a public blockchain, app needs to allow contract identifying it
# using encryption
escrow.send_product
# escrow can read seller submitted data, buyer can see this
escrow.seller_proof
# both parties can see if buyer is buyer_satisfied
escrow.buyer_satisfied?
# # a cron job can be setup to release when both parties comply
# while true do
# sleep 5
# escrow.release if escrow.buyer_satisfied?
# # or an equivalent function escrow.release_if_satisfied
# end
# or buyer can also release when he wants calling
escrow.release
# buyer can complain
escrow.buyer_complain
# if buyer does not release, seller can complain
escrow.seller_complain
# v1: human arbitration
# escrow picks arbitrator
escrow.arbitrate(arbitrators.sample)
# v2: better picking, commented since for_product might be on arbitrators or escrow
# escrow.arbitrate(arbitrators.for_product(product))
# in both v1 and v2 human decides release or refund
escrow.release
escrow.refund
# v3: AI
# return escrow? did not work
# escrow
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment