message: refine eosio.token
diff: @@ -114,13 +114,7 @@ class Balance(multi_index):
  def unpack(self, data):
  self.a.amount, self.a.symbol = struct.unpack('Q8s', data)
  -
  -def apply(receiver, account, act):
  - if act == N('create'):
  - eoslib.require_auth(_code)
  - msg = eoslib.read_action()
  - issuer, amount, symbol = struct.unpack('QQ8s', msg)
  -
  +def create(issuer, amount, symbol):
  cs = currency_stats(symbol)
  if cs.issuer:
  raise Exception('currency has already been created')
  @@ -128,10 +122,7 @@ def apply(receiver, account, act):
  cs.max_supply.amount = amount
  cs.store(_code)
  - elif act == N('issue'):
  - msg = eoslib.read_action()
  - _to, amount, symbol = struct.unpack('QQ8s', msg[:24])
  - memo = eoslib.unpack_bytes(msg[24:])
  +def issue(_to, amount, symbol):
  cs = currency_stats(symbol)
  assert cs.issuer, 'currency does not exists'
  eoslib.require_auth(cs.issuer)
  @@ -142,13 +133,26 @@ def apply(receiver, account, act):
  acc = Balance(_to, symbol)
  acc.add(amount, cs.issuer)
  - elif act == N('transfer'):
  - msg = eoslib.read_action()
  - _from, to, amount, symbol = struct.unpack('QQQ8s', msg[:32])
  - eoslib.require_auth(_from)
  - memo = eoslib.unpack_bytes(msg[32:])
  +def transfer(_from, to, amount, symbol):
  a1 = Balance(_from, symbol)
  a2 = Balance(to, symbol)
  a1.sub(amount)
  a2.add(amount, _from)
  +def apply(receiver, account, act):
  + if act == N('create'):
  + eoslib.require_auth(_code)
  + msg = eoslib.read_action()
  + issuer, amount, symbol = struct.unpack('QQ8s', msg)
  + create(issuer, amount, symbol)
  + elif act == N('issue'):
  + msg = eoslib.read_action()
  + _to, amount, symbol = struct.unpack('QQ8s', msg[:24])
  +# memo = eoslib.unpack_bytes(msg[24:])
  + issue(_to, amount, symbol)
  + elif act == N('transfer'):
  + msg = eoslib.read_action()
  + _from, to, amount, symbol = struct.unpack('QQQ8s', msg[:32])
  + eoslib.require_auth(_from)
  +# memo = eoslib.unpack_bytes(msg[32:])
  + transfer(_from, to, amount, symbol)
  