示例#1
0
 def __init__(self):
     msg = read_message()
     self.seller = OrderID(msg[:16])
     self.price = uint128(msg[16:32]) # eos tokens per currency
     self.quantity = uint64(msg[32:40]) #sell currency amount
     self.expiration = uint64(msg[40:])
     self.fill_or_kill = msg[-1]
示例#2
0
 def __init__(self):
     self.msg = read_message()
     self.from_ = uint64(self.msg[:8])
     print(self.msg, self.msg[:8], self.msg[8:16])
     self.to_ = uint64(self.msg[8:16])
     self.amount = uint64(self.msg[16:24])
     self.memo = str(self.msg[24:],'utf8')
示例#3
0
文件: code.py 项目: anklee/pyeos
def apply(code, action):
    #    print(eoslib.n2s(code),eoslib.n2s(action))
    if code == test:
        eoslib.require_auth(test)
        if action == N(b'transfer'):
            msg = eoslib.read_message()
            result = struct.unpack('QQQ', msg)
            print(result)
            from_ = result[0]
            to_ = result[1]
            amount = result[2]
        elif action == N(b'testrwdb'):
            test_rw_db()
        elif action == N(b'testdb'):
            test_db()
        elif action == N(b'callwasm'):
            test_call_wasm_function()
        elif action == N(b'testmsg'):
            print('testmsg')
            test_message()
        elif action == N(b'testts'):
            test_transaction()
        elif action == N(b'testmem'):
            test_memory_limit()
        elif action == N(b'testtimeout'):
            test_time_out()
        elif action == N(b'testexec'):
            test_exec_code()
        elif action == N(b'testimport'):
            test_import()
        elif action == N(b'testloadstr'):
            test_load_str()
        elif action == N(b'testrecursive'):
            test_recursive()
示例#4
0
文件: code.py 项目: anklee/pyeos
def test_memory_limit():
    msg = eoslib.read_message()
    print(msg, len(msg))
    size = int.from_bytes(msg[:8], 'little')
    print('+++++++++++memory size:', size)
    arr = []
    for i in range(int(size / 1024)):
        a = bytes(1024)
        if i % 100 == 0:
            print(i)
        arr.append(a)
示例#5
0
def apply_exchange_cancel_sell():
    msg = read_message()
    order = OrderID()
    require_auth( order.name )
    
    bid_to_cancel = Bid.load_by_order_id(order)
    assert bid_to_cancel, "bid with this id does not exists"
    buyer_account = Account( order.name )
    buyer_account.eos_balance += bid_to_cancel.quantity
    if buyer_account.open_orders > 0:
        buyer_account.open_orders-=1
    bid_to_cancel.remove()
    buyer_account.save()
    print( "bid removed\n" )
示例#6
0
def train():
    eoslib.require_auth(eoslib.N(b'mnist'))
    data = eoslib.read_message()
    data = eoslib.unpack(data)
    print(len(data))
    data = zlib.decompress(data)
    data = pickle.loads(data)
    print('training start...')
#    print(data)
#    data0 = np.reshape(data[0], (784, 1))
#    data1 = vectorized_result(data[1])
    net = Network([784, 30, 10])
    net.SGD(data, 1, 1, 3.0, test_data=None)
    print('training end...')
示例#7
0
def dotest():
    msg = read_message()
    
    name = uint64(msg[:8])
    print(name)
    print(eoslib.n2s(name))
    
    id = uint64(msg[8:])
    require_auth(name)
    
    ask = Ask.front_by_price()
    print(ask)

    bid = Bid.front_by_price()
    print(bid)
示例#8
0
def apply_exchange_cancel_buy():
    msg = read_message()
    order = OrderID(msg)
    require_auth( order.name ); 
    
    bid_to_cancel = Bid.load_from_order_id(order)
    assert bid_to_cancel, "bid with this id does not exists";
    
    buyer_account = Account(order.name);
    buyer_account.eos_balance += bid_to_cancel.quantity;
    buyer_account.open_orders-=1;
    
    bid_to_cancel.remove();
    buyer_account.save();
    print( "bid removed\n" );
示例#9
0
文件: code.py 项目: anklee/pyeos
def test_db2():
    msg = eoslib.read_message()
    print(len(msg))
    test = N(b'eos')
    result = int.from_bytes(msg[:8], 'little')
    size = msg[8]
    for i in range(size):
        result = int.from_bytes(msg[9 + i * 8:9 + i * 8 + 8], 'little')
        print(result)
    keys = msg[:8]
    values = msg[8:]
    eoslib.store(test, test, keys, 0, values)
    keys = msg[:8]
    values = msg[8:]
    eoslib.load(test, test, test, keys, 0, 0, values)
    print(values)
示例#10
0
def apply(name, type):
    #    print('hello from python apply',name,type)
    print(eoslib.n2s(name), eoslib.n2s(type))
    if type == eoslib.N(b'transfer'):
        msg = eoslib.read_message()
        result = struct.unpack('QQQ', msg)
        #         print(result)
        from_ = result[0]
        to_ = result[1]
        amount = result[2]

        eoslib.require_auth(from_)
        eoslib.require_notice(from_)
        eoslib.require_notice(to_)

        from_ = Account(from_)
        to_ = Account(to_)
        if from_.balance >= amount:
            from_.balance -= amount
            to_.balance += amount
            from_.store()
            to_.store()