Esempio n. 1
0
File: mnist.py Progetto: eos21/pyeos
def apply(code, action):
    print(code, action)
    if code == mnist:
        if action == eoslib.N(b'train'):
            train()
        elif action == eoslib.N(b'test'):
            pass
Esempio n. 2
0
def init():
    print('hello from micropython.init')
    print('--------------------------------')
    db_keys = struct.pack('Q', eoslib.N('currency'))
    values = struct.pack('QQ', 0x778899, 0x112233)
    print("mp:", mp)
    print(eoslib.uint64_to_string(mp))
    ret = eoslib.store(mp, mp, db_keys, 0, values)
    print('++++++++eoslib.store return:', ret)
Esempio n. 3
0
File: code.py Progetto: anklee/pyeos
class Account(object):
    key = eoslib.N(b'account')
    code = eoslib.N(b'currency')
    table = eoslib.N(b'account')

    def __init__(self, scope, balance=0):
        self.scope = scope
        if balance == 0:
            self.load()
        else:
            self.balance = balance

    def isEmpty(self):
        return self.balance == 0

    def store(self):
        eoslib.store_u64(self.scope, Account.table, Account.key, self.balance)

    def load(self):
        self.balance = eoslib.load_u64(self.scope, Account.code, Account.table,
                                       Account.key)
Esempio n. 4
0
File: mnist.py Progetto: eos21/pyeos
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...')
Esempio n. 5
0
File: code.py Progetto: anklee/pyeos
def test_load_str():
    code = N(b'test')
    table = N(b'test')

    ret = eoslib.remove_str(code, table, b'abc')
    print(ret)

    ret = eoslib.remove_str(code, table, b'abc')
    print(ret)

    test = eoslib.N(b'test')
    ret = eoslib.load_str(code, code, table, b'abc')
    print(ret)

    ret = eoslib.store_str(code, table, b'abc', b'def')
    print(ret)

    ret = eoslib.load_str(code, code, table, b'abc')
    print(ret)
Esempio n. 6
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()
Esempio n. 7
0
class Account(object):
    key = eoslib.N(b'account')
    key = int.to_bytes(key, 8, 'little')

    def __init__(self, scope, balance=0):
        self.scope = scope
        if balance == 0:
            self.load()
        else:
            self.balance = balance

    def isEmpty(self):
        return self.balance == 0

    def store(self):
        value = int.to_bytes(self.balance, 8, 'little')
        eoslib.store(self.scope, table, Account.key, 0, value)

    def load(self):
        value = bytes(8)
        eoslib.load(self.scope, code, table, Account.key, 0, 0, value)
        self.balance = int.from_bytes(value, 'little')
Esempio n. 8
0
         "quantity" : "UInt64",
         "expiration" : "Time"
    fill_or_kill
'''
if __name__ == '__main__':
    import sys
    sys.path.insert(0, '..')
    from exchange import *
    import eoslib as eoslib
    from eoslib import N, readMessage, writeMessage

    init()
    writeMessage(bytes(512))
    order = BuyOrder()
    order.buyer = OrderID()
    order.buyer.name = eoslib.N(b'buyer')
    order.buyer.id = 0

    order.price = uint128(11)
    order.quantity = 12
    order.expiration = int(time.time()) + 100
    writeMessage(order())
    apply(exchange, N(b'buy'))

    order = SellOrder()
    order.seller = OrderID()
    order.seller.name = eoslib.N(b'seller')
    order.seller.id = 0

    order.price = uint128(11)
    order.quantity = 12
Esempio n. 9
0
import eoslib
try:
    import struct
except Exception as e:
    #load struct module in micropython
    import ustruct as struct

code = eoslib.N(b'currency')
table = eoslib.N(b'account')


class Account(object):
    key = eoslib.N(b'account')
    key = int.to_bytes(key, 8, 'little')

    def __init__(self, scope, balance=0):
        self.scope = scope
        if balance == 0:
            self.load()
        else:
            self.balance = balance

    def isEmpty(self):
        return self.balance == 0

    def store(self):
        value = int.to_bytes(self.balance, 8, 'little')
        eoslib.store(self.scope, table, Account.key, 0, value)

    def load(self):
        value = bytes(8)
Esempio n. 10
0
import eoslib
try:
    import struct
except Exception as e:
    import ustruct as struct
mp = eoslib.N('micropython')
print('hello,world from mp')


def init():
    print('hello from micropython.init')
    print('--------------------------------')
    db_keys = struct.pack('Q', eoslib.N('currency'))
    values = struct.pack('QQ', 0x778899, 0x112233)
    print("mp:", mp)
    print(eoslib.uint64_to_string(mp))
    ret = eoslib.store(mp, mp, db_keys, 0, values)
    print('++++++++eoslib.store return:', ret)


def apply(name, type):
    print(name, type)