def tx_burn(tx, cursor): payload = json.loads(tx.payload) payload['amount'] = int(payload['amount']) udc_bal = models.UDCBalance(tx.chain_id, payload['udc'], tx.sender, cursor) udc_bal.balance -= payload['amount'] udc_bal.save(cursor)
def tx_lock(tx, cursor): payload = json.loads(tx.payload) payload['amount'] = int(payload['amount']) udc_bal = models.UDCBalance(tx.chain_id, payload['udc'], payload['holder'], cursor) udc_bal.balance_lock = payload['amount'] udc_bal.save(cursor)
def tx_lock(tx, cursor): payload = json.loads(tx.payload) amount = int(payload['amount']) udc = payload['udc'] udc_bal = models.UDCBalance(tx.chain_id, udc, payload['holder'], cursor) udc_bal.balance_lock = amount udc_bal.save(cursor) rel = models.RelBalanceTx(tx.chain_id, udc, tx.sender, tx.height, tx.index, cursor) rel.amount = 0 # zero amount relation just to record the lock event rel.save(cursor)
def tx_burn(tx, cursor): payload = json.loads(tx.payload) amount = int(payload['amount']) udc = models.UDC(tx.chain_id, payload['udc'], cursor) udc.total -= amount udc.save(cursor) udc_bal = models.UDCBalance(tx.chain_id, udc.udc_id, tx.sender, cursor) udc_bal.balance -= amount udc_bal.save(cursor) rel = models.RelBalanceTx(tx.chain_id, udc.udc_id, tx.sender, tx.height, tx.index, cursor) rel.amount -= amount rel.save(cursor)
def tx_issue(tx, cursor): payload = json.loads(tx.payload) payload['amount'] = int(payload['amount']) udc = models.UDC(tx.chain_id, payload['udc'], cursor) issuer = models.UDCBalance(tx.chain_id, udc.udc_id, tx.sender, cursor) if udc.total == 0: # initial issue udc.owner = tx.sender udc.desc = payload['desc'] if 'desc' in payload else '' udc.operators = json.dumps(payload.get('operators', [])) udc.total += payload['amount'] udc.save(cursor) issuer.balance += payload['amount'] issuer.save(cursor)
def tx_transfer(tx, cursor): payload = json.loads(tx.payload) # NOTE: This is line is for creating buyer account in s_accounts table. It # is necessary to satisfy the foreign key constraint. Even if we create a # row for each tx sender, it is not the case for the recipient for # `request` or `grant` tx. So, we need to explicitly create a grantee or # recipient account in s_accounts table. recp = models.Account(tx.chain_id, payload['to'], cursor) recp.save(cursor) if payload.get('parcel'): owner = models.Account(tx.chain_id, tx.sender, cursor) parcel = models.Parcel(tx.chain_id, payload['target'], owner.address, cursor) recp = models.Account(tx.chain_id, payload['to'], cursor) parcel.owner = recp.address parcel.save(cursor) if tx.sender not in yappers: rel = models.RelParcelTx(tx.chain_id, parcel.parcel_id, tx.height, tx.index) rel.save(cursor) else: amount = int(payload['amount']) udc = payload.get('udc') if udc is None: sender = models.Account(tx.chain_id, tx.sender, cursor) sender.balance -= amount sender.save(cursor) rel = models.RelAccountTx(tx.chain_id, tx.sender, tx.height, tx.index, cursor) rel.amount -= amount rel.save(cursor) recp = models.Account(tx.chain_id, payload['to'], cursor) recp.balance += amount recp.save(cursor) rel = models.RelAccountTx(tx.chain_id, payload['to'], tx.height, tx.index, cursor) rel.amount += amount rel.save(cursor) if recp.address == '000000000000000000000000000000000000DEAD': # This account is used for ad-hoc burning process, the balance # of this account is considered out of normal operation from # now. So let's decrease the amount of active coins # permanently. asset_stat = stats.Asset(tx.chain_id, cursor) asset_stat.active_coins -= amount asset_stat.save(cursor) else: sender = models.UDCBalance(tx.chain_id, udc, tx.sender, cursor) sender.balance -= amount sender.save(cursor) rel = models.RelBalanceTx(tx.chain_id, udc, tx.sender, tx.height, tx.index, cursor) rel.amount -= amount rel.save(cursor) recp = models.UDCBalance(tx.chain_id, udc, payload['to'], cursor) recp.balance += amount recp.save(cursor) rel = models.RelBalanceTx(tx.chain_id, udc, payload['to'], tx.height, tx.index, cursor) rel.amount += amount rel.save(cursor)