コード例 #1
0
ファイル: fountain.py プロジェクト: bussiere/cll-sim
 def run(self, tx, contract, block):
     if tx.value < 1000 * block.basefee:
         stop("Insufficient fee")
     to = tx.data[0]
     value = tx.value - 1000 * block.basefee
     if block.account_balance(to) == 0:
         mktx(to, value, 0, 0)
     else:
         mktx(tx.sender, value, 0, 0)
コード例 #2
0
ファイル: escrow.py プロジェクト: bussiere/cll-sim
    def run(self, tx, contract, block):
        if tx.value < MIN_FEE * block.basefee:
            stop("Insufficient fee")

        state = contract.storage[I_STATUS]
        if state == S_START and tx.value >= PRICE_ETHER:
            contract.storage[I_STATUS] = S_CUSTOMER_PAID
            contract.storage[I_CUSTOMER_ADDRESS] = tx.sender
            contract.storage[I_CUSTOMER_PAID_AMOUNT] = tx.value
            contract.storage[I_CUSTOMER_PAID_TS] = block.timestamp
        elif state == S_CUSTOMER_PAID:
            if tx.sender == SHIPPER:
                contract.storage[I_STATUS] = S_SHIPPED
                mktx(MERCHANT, contract.storage[I_CUSTOMER_PAID_AMOUNT], 0, 0)
            elif block.timestamp >= contract.storage[I_CUSTOMER_PAID_TS] + CONFIRMATION_TIMEOUT:
                contract.storage[I_STATUS] = S_REFUNDED
                mktx(contract.storage[I_CUSTOMER_ADDRESS], contract.storage[I_CUSTOMER_PAID_AMOUNT], 0, 0)
        else:
            stop("Invalid state transition")
コード例 #3
0
ファイル: hedging.py プロジェクト: nivertech/cll-sim
 def run(self, tx, contract, block):
     if tx.value < 200 * block.basefee:
         stop("Insufficient fee")
     if contract.storage[1000] == 0:
         if tx.value < 1000 * 10 ** 18:
             stop("Insufficient value")
         contract.storage[1000] = 1  # XXX Bug in contract example flag should be set
         contract.storage[1001] = 998 * block.contract_storage(D)[I]
         contract.storage[1002] = block.timestamp + 30 * 86400
         contract.storage[1003] = tx.sender
         log("Contract initialized")
     else:
         ethervalue = contract.storage[1001] / block.contract_storage(D)[I]
         log("Ether Value = %s" % ethervalue)
         if ethervalue >= 5000:  # XXX Bug in contract example, value shouldn't be times 10 ** 18
             mktx(contract.storage[1003], 5000 * 10 ** 18, 0, 0)
         elif block.timestamp > contract.storage[1002]:
             # XXX Bug in contract example, values should be times 10 ** 18
             mktx(contract.storage[1003], ethervalue * 10 ** 18, 0, 0)
             mktx(A, (5000 - ethervalue) * 10 ** 18, 0, 0)
コード例 #4
0
    def run(self, tx, contract, block):
        if tx.value < MIN_FEE * block.basefee:
            stop("Insufficient fee")

        state = contract.storage[I_STATUS]
        if state == S_START and tx.value >= PRICE_ETHER:
            contract.storage[I_STATUS] = S_CUSTOMER_PAID
            contract.storage[I_CUSTOMER_ADDRESS] = tx.sender
            contract.storage[I_CUSTOMER_PAID_AMOUNT] = tx.value
            contract.storage[I_CUSTOMER_PAID_TS] = block.timestamp
        elif state == S_CUSTOMER_PAID:
            if tx.sender == SHIPPER:
                contract.storage[I_STATUS] = S_SHIPPED
                mktx(MERCHANT, contract.storage[I_CUSTOMER_PAID_AMOUNT], 0, 0)
            elif block.timestamp >= contract.storage[
                    I_CUSTOMER_PAID_TS] + CONFIRMATION_TIMEOUT:
                contract.storage[I_STATUS] = S_REFUNDED
                mktx(contract.storage[I_CUSTOMER_ADDRESS],
                     contract.storage[I_CUSTOMER_PAID_AMOUNT], 0, 0)
        else:
            stop("Invalid state transition")
コード例 #5
0
ファイル: subcurrency.py プロジェクト: inmathwetrust/cll-sim
 def run(self, tx, contract, block):
     if tx.value < 100 * block.basefee:
         stop("Insufficient fee")
     elif contract.storage[1000]:
         frm = tx.sender
         to = tx.data[0]
         value = tx.data[1]
         if to <= 1000:
             stop("Data[0] 'to' out of bounds: %s" % to)
         if contract.storage[frm] < value:
             stop("Insufficient funds, %s has %d needs %d" % (tx.sender, contract.storage[frm], value))
         log("Transfering %d from %s to %s" % (value, frm, to))
         contract.storage[frm] = contract.storage[frm] - value
         contract.storage[to] = contract.storage[to] + value
     else:
         log("Initializing storage for creator %s" % MYCREATOR)
         contract.storage[MYCREATOR] = 10 ** 18
         contract.storage[1000] = 1
コード例 #6
0
ファイル: datafeed.py プロジェクト: nivertech/cll-sim
 def run(self, tx, contract, block):
     if tx.sender != FEEDOWNER:
         stop('Sender is not feed owner')
     contract.storage[tx.data[0]] = tx.data[1]
コード例 #7
0
ファイル: namecoin.py プロジェクト: nivertech/cll-sim
 def run(self, tx, contract, block):
     if tx.value < block.basefee * 200:
         stop("Insufficient fee")
     if contract.storage[tx.data[0]] or tx.data[0] < 100:
         stop("Key already reserved")
     contract.storage[tx.data[0]] = tx.data[1]
コード例 #8
0
 def run(self, tx, contract, block):
     if tx.value < block.basefee * STARTFEE:
         stop("Insufficient fee")
     if tx.datan == 0 or tx.sender != VIEWER :
         stop("Fill tank")
     from_block = tx.data[1] #Must be in attempt range
     to_block   = tx.data[1] + ATTEMPT_CNT
     if block.number < from_block or block.number > to_block :
         stop("Outside period")
     # Messages here are actually sent by server, punish command is also requesting
     #  command for viewer.
     command = tx.data[0]
     if command == CMD_PUNISH :
         if 2*tx.value > tx.data[3] :
             stop("Over punish")
         mktx(DESTRUCTION_ADDR,2*tx.value, 0,[])
         stop("Punish")
     #Note, the server predicts if it loses and doesnt bother, of course.
     if command == CMD_REDEEM :
         if block.parenthash < DIFFICULTY : 
             stop("Lost lottery")
         mktx(tx.data[2], tx.data[3], 0,[])
         stop("Got reward")
コード例 #9
0
ファイル: datafeed.py プロジェクト: bussiere/cll-sim
 def run(self, tx, contract, block):
     if tx.sender != FEEDOWNER:
         stop('Sender is not feed owner')
     contract.storage[tx.data[0]] = tx.data[1]
コード例 #10
0
ファイル: i_want_half.py プロジェクト: nivertech/cll-sim
    def run(self, tx, contract, block):
        if tx.value < 100 * block.basefee:
            stop("Insufficient fee")

        state = contract.storage[I_STATE]
        if state == S_START:
            contract.storage[I_PARTNER_1] = tx.sender
            contract.storage[I_PARTNER_2] = tx.data[0]
            contract.storage[I_STATE] = S_PROPOSED
            stop("Proposed")
        partner_1 = contract.storage[I_PARTNER_1]
        partner_2 = contract.storage[I_PARTNER_2]

        if state == S_PROPOSED:
            if tx.sender == partner_2 and tx.data[0] == partner_1:
                contract.storage[I_STATE] = S_MARRIED
                stop("Married")
            if tx.sender == partner_1 and tx.data[0] == partner_1:
                if block.timestamp < C_CANCEL_PERIOD:
                    stop("Cant cancel early")
                contract.storage[I_STATE] = S_START
                mktx(tx.sender, block.account_balance(contract.address), 0, 0)
                stop("Cancelled")
            stop("Invalid during proposal")
        if state == S_MARRIED and tx.sender == partner_1 or tx.sender == partner_2:
            if tx.data[0] == TX_WITHDRAW:
                creator = contract.storage[I_WITHDRAW_CREATOR]
                if (creator != 0 and contract.storage[I_WITHDRAW_TO] == tx.data[1] and
                        contract.storage[I_WITHDRAW_AMOUNT] == tx.data[2] and creator != tx.sender):
                    mktx(tx.data[1], tx.data[2], 0, 0)
                    contract.storage[I_WITHDRAW_TO] = 0
                    contract.storage[I_WITHDRAW_AMOUNT] = 0
                    contract.storage[I_WITHDRAW_CREATOR] = 0
                    stop("Withdrawed")
                else:
                    contract.storage[I_WITHDRAW_TO] = tx.data[1]
                    contract.storage[I_WITHDRAW_AMOUNT] = tx.data[2]
                    contract.storage[I_WITHDRAW_CREATOR] = tx.sender
                    stop("Withdraw requested")
            if tx.data[0] == TX_DIVORCE:
                creator = contract.storage[I_DIVORCE_CREATOR]
                if creator != 0 and creator != tx.sender:
                    balance = block.account_balance(contract.address)
                    mktx(partner_1, balance / 2, 0, 0)
                    mktx(partner_2, balance / 2, 0, 0)
                    contract.storage[I_STATE] = S_DIVORCED
                    stop("Divorced")
                else:
                    contract.storage[I_DIVORCE_CREATOR] = tx.sender
                    stop("Divorce requested")
            stop("Invalid during marriage")
        stop("Should be divorced")
コード例 #11
0
ファイル: lockin-escrow.py プロジェクト: bussiere/cll-sim
    def run(self, tx, contract, block):
        if tx.value < MIN_FEE * block.basefee:
            stop("Insufficient fee")

        customer = contract.storage[I_CUSTOMER]

        if tx.sender == MERCHANT:
            if block.account_balance(contract.address) < MIN_BALANCE:
                stop("Below funds of operation")
            if tx.data[0] == C_ALLOW:
                if customer != 0:  # ..when earlier customer still busy.
                    stop("Customer change blocked")
                contract.storage[I_CUSTOMER]  = tx.data[1]
                contract.storage[I_TOTAL]     = tx.data[2]
                contract.storage[I_INCENTIVE] = tx.data[3]
                stop("Customer allowed")
            if tx.data[0] == C_REFUND and customer != 0:
                refund =  contract.storage[I_PAID]
                refund += contract.storage[I_PAID]*MIN_BALANCE/contract.storage[I_TOTAL]

                mktx(customer, min(refund, contract.storage[I_TOTAL]+MIN_BALANCE), 0, [])
                contract.storage[I_CUSTOMER]  = 0
                contract.storage[I_TOTAL]     = 0
                contract.storage[I_INCENTIVE] = 0
                contract.storage[I_PAID]      = 0
                stop("Customer refunded")
            stop("Merchant topping up")

        if tx.sender == customer:
            contract.storage[I_PAID] = contract.storage[I_PAID] + tx.value - MIN_FEE*block.basefee
            if tx.datan == 1 and tx.data[0] == C_SATISFIED:
                if contract.storage[I_PAID] <= contract.storage[I_TOTAL]:
                    stop("Customer didnt pay enough")
                incentive = contract.storage[I_INCENTIVE]
                mktx(MERCHANT, contract.storage[I_PAID]-incentive, 0, [])
                mktx(customer, incentive, 0, [])
                contract.storage[I_CUSTOMER]  = 0
                contract.storage[I_TOTAL]     = 0
                contract.storage[I_INCENTIVE] = 0
                contract.storage[I_PAID]      = 0
                stop("Customer paid and happy")
            stop("Customer paid(part)")
        stop("Donation")
コード例 #12
0
ファイル: lockin-escrow.py プロジェクト: nivertech/cll-sim
    def run(self, tx, contract, block):
        if tx.value < MIN_FEE * block.basefee:
            stop("Insufficient fee")

        customer = contract.storage[I_CUSTOMER]

        if tx.sender == MERCHANT:
            if block.account_balance(contract.address) < MIN_BALANCE:
                stop("Below funds of operation")
            if tx.data[0] == C_ALLOW:
                if customer != 0:  # ..when earlier customer still busy.
                    stop("Customer change blocked")
                contract.storage[I_CUSTOMER] = tx.data[1]
                contract.storage[I_TOTAL] = tx.data[2]
                contract.storage[I_INCENTIVE] = tx.data[3]
                stop("Customer allowed")
            if tx.data[0] == C_REFUND and customer != 0:
                refund = contract.storage[I_PAID]
                refund += contract.storage[
                    I_PAID] * MIN_BALANCE / contract.storage[I_TOTAL]

                mktx(customer,
                     min(refund, contract.storage[I_TOTAL] + MIN_BALANCE), 0,
                     [])
                contract.storage[I_CUSTOMER] = 0
                contract.storage[I_TOTAL] = 0
                contract.storage[I_INCENTIVE] = 0
                contract.storage[I_PAID] = 0
                stop("Customer refunded")
            stop("Merchant topping up")

        if tx.sender == customer:
            contract.storage[I_PAID] = contract.storage[
                I_PAID] + tx.value - MIN_FEE * block.basefee
            if tx.datan == 1 and tx.data[0] == C_SATISFIED:
                if contract.storage[I_PAID] <= contract.storage[I_TOTAL]:
                    stop("Customer didnt pay enough")
                incentive = contract.storage[I_INCENTIVE]
                mktx(MERCHANT, contract.storage[I_PAID] - incentive, 0, [])
                mktx(customer, incentive, 0, [])
                contract.storage[I_CUSTOMER] = 0
                contract.storage[I_TOTAL] = 0
                contract.storage[I_INCENTIVE] = 0
                contract.storage[I_PAID] = 0
                stop("Customer paid and happy")
            stop("Customer paid(part)")
        stop("Donation")