def tx_discard(tx, cursor): payload = json.loads(tx.payload) parcel = models.Parcel(tx.chain_id, payload['target'], None, cursor) parcel.on_sale = False parcel.save(cursor)
def tx_request(tx, cursor): payload = json.loads(tx.payload) payload['payment'] = int(payload['payment']) payload['dealer_fee'] = int(payload.get('dealer_fee', '0')) buyer = models.Account(tx.chain_id, tx.sender, cursor) parcel = models.Parcel(tx.chain_id, payload['target'], None, cursor) request = models.Request(tx.chain_id, parcel.parcel_id, buyer.address, cursor) request.payment = payload['payment'] request.dealer = payload.get('dealer', None) request.dealer_fee = payload['dealer_fee'] request.extra = json.dumps(payload.get('extra', {})) request.save(cursor) if tx.sender not in yappers: rel = models.RelParcelTx(tx.chain_id, parcel.parcel_id, tx.height, tx.index) rel.save(cursor) if request.dealer is not None: buyer.balance -= request.dealer_fee buyer.balance -= request.payment buyer.save(cursor) rel = models.RelAccountTx(tx.chain_id, buyer.address, tx.height, tx.index, cursor) rel.amount -= request.payment rel.save(cursor)
def tx_grant(tx, cursor): payload = json.loads(tx.payload) parcel = models.Parcel(tx.chain_id, payload['target'], None, cursor) storage = models.Storage(tx.chain_id, parcel.storage_id, None, cursor) host = models.Account(tx.chain_id, storage.owner, cursor) owner = models.Account(tx.chain_id, parcel.owner, cursor) request = models.Request(tx.chain_id, payload['target'], payload['grantee'], cursor) usage = models.Usage(tx.chain_id, payload['target'], payload['grantee'], cursor) usage.custody = payload['custody'] usage.extra = payload.get('extra', '{}') usage.save(cursor) owner.balance += request.payment if request.dealer is not None: dealer = models.Account(tx.chain_id, request.dealer, cursor) dealer.balance += request.dealer_fee dealer.save(cursor) owner.balance -= storage.hosting_fee owner.save(cursor) host.balance += storage.hosting_fee host.save(cursor) request.delete(cursor)
def tx_discard(tx, cursor): payload = json.loads(tx.payload) parcel = models.Parcel(tx.chain_id, payload['target'], None, cursor) parcel.on_sale = False 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)
def tx_grant(tx, cursor): payload = json.loads(tx.payload) grantee = '' if 'grantee' in payload: grantee = payload['grantee'] elif 'recipient' in payload: grantee = payload['recipient'] parcel = models.Parcel(tx.chain_id, payload['target'], None, cursor) storage = models.Storage(tx.chain_id, parcel.storage_id, None, cursor) host = models.Account(tx.chain_id, storage.owner, cursor) owner = models.Account(tx.chain_id, parcel.owner, cursor) # 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. buyer = models.Account(tx.chain_id, grantee, cursor) buyer.save(cursor) request = models.Request(tx.chain_id, payload['target'], grantee, cursor) usage = models.Usage(tx.chain_id, payload['target'], grantee, cursor) usage.custody = payload['custody'] usage.extra = json.dumps(payload.get('extra', {})) usage.save(cursor) if tx.sender not in yappers: rel = models.RelParcelTx(tx.chain_id, parcel.parcel_id, tx.height, tx.index) rel.save(cursor) owner.balance += request.payment if request.dealer is not None: dealer = models.Account(tx.chain_id, request.dealer, cursor) dealer.balance += request.dealer_fee dealer.save(cursor) owner.balance -= storage.hosting_fee owner.save(cursor) if storage.hosting_fee > 0: rel = models.RelAccountTx(tx.chain_id, owner.address, tx.height, tx.index, cursor) rel.amount -= storage.hosting_fee rel.save(cursor) host.balance += storage.hosting_fee host.save(cursor) rel = models.RelAccountTx(tx.chain_id, host.address, tx.height, tx.index, cursor) rel.amount += storage.hosting_fee rel.save(cursor) request.delete(cursor)
def tx_request(tx, cursor): payload = json.loads(tx.payload) payload['payment'] = int(payload['payment']) payload['dealer_fee'] = int(payload.get('dealer_fee', '0')) buyer = models.Account(tx.chain_id, tx.sender, cursor) parcel = models.Parcel(tx.chain_id, payload['target'], None, cursor) request = models.Request(tx.chain_id, parcel.parcel_id, buyer.address, cursor) request.payment = payload['payment'] request.dealer = payload.get('dealer', None) request.dealer_fee = payload['dealer_fee'] request.extra = payload.get('extra', '{}') request.save(cursor) if request.dealer is not None: buyer.balance -= request.dealer_fee buyer.balance -= request.payment buyer.save(cursor)
def tx_grant(tx, cursor): payload = json.loads(tx.payload) parcel = models.Parcel(tx.chain_id, payload['target'], None, cursor) storage = models.Storage(tx.chain_id, parcel.storage_id, None, cursor) host = models.Account(tx.chain_id, storage.owner, cursor) owner = models.Account(tx.chain_id, parcel.owner, cursor) request = models.Request(tx.chain_id, payload['target'], payload['grantee'], cursor) usage = models.Usage(tx.chain_id, payload['target'], payload['grantee'], cursor) usage.custody = payload['custody'] usage.extra = json.dumps(payload.get('extra', {})) usage.save(cursor) # rel = models.RelParcelTx(tx.chain_id, parcel.parcel_id, tx.height, # tx.index, cursor) # rel.save(cursor) owner.balance += request.payment if request.dealer is not None: dealer = models.Account(tx.chain_id, request.dealer, cursor) dealer.balance += request.dealer_fee dealer.save(cursor) owner.balance -= storage.hosting_fee owner.save(cursor) if storage.hosting_fee > 0: rel = models.RelAccountTx(tx.chain_id, owner.address, tx.height, tx.index, cursor) rel.amount -= storage.hosting_fee rel.save(cursor) host.balance += storage.hosting_fee host.save(cursor) rel = models.RelAccountTx(tx.chain_id, host.address, tx.height, tx.index, cursor) rel.amount += storage.hosting_fee rel.save(cursor) request.delete(cursor)
def tx_register(tx, cursor): payload = json.loads(tx.payload) owner = models.Account(tx.chain_id, tx.sender, cursor) parcel = models.Parcel(tx.chain_id, payload['target'], owner.address, cursor) storage = models.Storage(tx.chain_id, parcel.storage_id, None, cursor) parcel.custody = payload['custody'] if parcel.custody is not None and len(parcel.custody) > 100: parcel.custody = parcel.custody[:100] parcel.proxy_account = payload.get('proxy_account', None) if parcel.proxy_account is not None and len(parcel.proxy_account) > 40: parcel.proxy_account = parcel.proxy_account[:40] parcel.extra = json.dumps(payload.get('extra', {})) parcel.on_sale = True 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) if storage.registration_fee > 0: owner.balance -= storage.registration_fee owner.save(cursor) rel = models.RelAccountTx(tx.chain_id, owner.address, tx.height, tx.index, cursor) rel.amount -= storage.registration_fee rel.save(cursor) host = models.Account(tx.chain_id, storage.owner, cursor) host.balance += storage.registration_fee host.save(cursor) rel = models.RelAccountTx(tx.chain_id, host.address, tx.height, tx.index, cursor) rel.amount += storage.registration_fee rel.save(cursor)
def tx_register(tx, cursor): payload = json.loads(tx.payload) owner = models.Account(tx.chain_id, tx.sender, cursor) parcel = models.Parcel(tx.chain_id, payload['target'], owner.address, cursor) storage = models.Storage(tx.chain_id, parcel.storage_id, None, cursor) host = models.Account(tx.chain_id, storage.owner, cursor) parcel.custody = payload['custody'] if parcel.custody != None and len(parcel.custody) > 100: parcel.custody = parcel.custody[:100] parcel.proxy_account = payload.get('proxy_account', None) if parcel.proxy_account != None and len(parcel.proxy_account) > 40: parcel.proxy_account = parcel.proxy_account[:40] parcel.extra = payload.get('extra', '{}') parcel.on_sale = True parcel.save(cursor) owner.balance -= storage.registration_fee owner.save(cursor) host.balance += storage.registration_fee host.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)