예제 #1
0
파일: currency.py 프로젝트: 51weekend/pyeos
class Account(object):
    key = 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, table, Account.key, self.balance)
    def load(self):
        self.balance = eoslib.load_u64(self.scope, code, table, Account.key)
예제 #2
0
파일: currency.py 프로젝트: 51weekend/pyeos
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.readMessage()
        result = struct.unpack('QQQ', msg)
#         print(result)
        from_ = result[0]
        to_ = result[1]
        amount = result[2]
        
        eoslib.requireAuth(from_);
        eoslib.requireNotice(from_);
        eoslib.requireNotice(to_)

        from_ = Account(from_)
        to_ = Account(to_)
        if from_.balance >= amount:
            from_.balance -= amount
            to_.balance += amount
            from_.store()
            to_.store()
예제 #3
0
파일: currency.py 프로젝트: 51weekend/pyeos
if __name__ == '__main__':
    import eoslib_dummy as eoslib
else:
    import eoslib
import struct
import logging
print = logging.info 

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

class Account(object):
    key = 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, table, Account.key, self.balance)
    def load(self):
        self.balance = eoslib.load_u64(self.scope, code, table, Account.key)

def init():
    print('hello from currency.init')
    a = Account(code)
    # avoid overwrite balance already exists.
    if a.balance == 0: