def __init__(self): msg = readMessage() 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]
def apply(code, action): # print(eoslib.n2s(code),eoslib.n2s(action)) if code == test: eoslib.requireAuth(test) if action == N(b'transfer'): msg = eoslib.readMessage() result = struct.unpack('QQQ', msg) print(result) from_ = result[0] to_ = result[1] amount = result[2] elif action == N(b'test'): 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()
def test_memory_limit(): msg = eoslib.readMessage() 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)
def apply_exchange_cancel_sell(): msg = readMessage() order = OrderID() requireAuth(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")
def train(): eoslib.requireAuth(eoslib.N(b'mnist')) data = eoslib.readMessage() 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...')
def dotest(): msg = readMessage() name = uint64(msg[:8]) print(name) print(eoslib.n2s(name)) id = uint64(msg[8:]) requireAuth(name) ask = Ask.front_by_price() print(ask) bid = Bid.front_by_price() print(bid)
def test_db2(): msg = eoslib.readMessage() 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, test, keys, 0, values) keys = msg[:8] values = msg[8:] eoslib.load(test, test, test, keys, 0, 0, values) print(values)
def __init__(self): self.msg = readMessage() self.from_ = uint64(self.msg[:8]) self.to_ = uint64(self.msg[8:16]) self.amount = uint64(self.msg[16:24]) self.memo = str(self.msg[24:], 'utf8')