def set_buyer_address(order_id, buyer):
    saved_initiator = Get(context, ConcatKey(order_id, INITIATOR))
    WitnessRequire(saved_initiator)

    Put(context, ConcatKey(order_id, BUYER), buyer)
    timelock = GetTime() + REFUND_TIMELOCK_DURATION
    Put(context, ConcatKey(order_id, REFUND_TIMELOCK), timelock)
def refund(order_id):
    saved_initiator = Get(context, ConcatKey(order_id, INITIATOR))
    WitnessRequire(saved_initiator)

    timelock = Get(context, ConcatKey(order_id, REFUND_TIMELOCK))
    if timelock is None:
        timelock = 0
    Require(GetTime() >= timelock)
    ont_to_sell = Get(context, ConcatKey(order_id, ONT_TO_SELL))
    transfer_ont(GetExecutingScriptHash(), saved_initiator, ont_to_sell)
def claim(order_id, secret):
    claimed = Get(context, ConcatKey(order_id, CLAIMED))
    if claimed == True:
        Revert()

    hashlock = Get(context, ConcatKey(sha256(secret), HASH))
    if order_id != hashlock:
        Revert()

    saved_buyer = Get(context, ConcatKey(order_id, BUYER))
    WitnessRequire(saved_buyer)

    Put(context, ConcatKey(order_id, CLAIMED), True)
    ont_to_sell = Get(context, ConcatKey(order_id, ONT_TO_SELL))
    transfer_ont(GetExecutingScriptHash(), saved_buyer, ont_to_sell)
def intiate_order(ont_to_sell, eth_to_buy, hashlock, initiator):
    WitnessRequire(initiator)
    order_id = hashlock
    if len(Get(context, ConcatKey(order_id, HASH))) != 0:
        Revert()
    Put(context, ConcatKey(order_id, HASH), hashlock)
    Put(context, ConcatKey(order_id, ETH_TO_BUY), eth_to_buy)
    Put(context, ConcatKey(order_id, ONT_TO_SELL), ont_to_sell)
    Put(context, ConcatKey(order_id, INITIATOR), initiator)
    Put(context, ConcatKey(order_id, CLAIMED), False)

    transfer_ont(initiator, GetExecutingScriptHash(), ont_to_sell)
def get_initiator(order_id):
    return Get(context, ConcatKey(order_id, INITIATOR))
def get_hashlock(order_id):
    return Get(context, ConcatKey(order_id, HASH))
def get_amount_of_eth_to_buy(order_id):
    return Get(context, ConcatKey(order_id, ETH_TO_BUY))
def get_amount_of_ont_to_sell(order_id):
    return Get(context, ConcatKey(order_id, ONT_TO_SELL))
def get_refund_timelock(order_id):
    timelock = Get(context, ConcatKey(order_id, REFUND_TIMELOCK))
    return timelock if timelock is not None else 0
def get_buyer(order_id):
    return Get(context, ConcatKey(order_id, BUYER))
示例#11
0
def get_amount_of_usdt_to_buy(order_id):
    return Get(context, ConcatKey(order_id, USDT_TO_BUY))
示例#12
0
def get_amount_of_sin_to_sell(order_id):
    return Get(context, ConcatKey(order_id, SIN_TO_SELL))