示例#1
0
async def get_unbound_offset(request, address):
    #756e626f756e6454696d654f6666736574 = unboundTimeOffset
    result, err = await get_rpc_ont(request, 'getstorage', [
        '0100000000000000000000000000000000000000',
        '756e626f756e6454696d654f6666736574' +
        Tool.address_to_scripthash(address)
    ])
    if err or not result: return 0
    return int(big_or_little(result), 16)
示例#2
0
async def get_nep5_asset_balance(request, address, asset):
    result = await get_rpc(request, 'invokefunction', [
        asset, "balanceOf",
        [{
            "type": "Hash160",
            "value": big_or_little(Tool.address_to_scripthash(address))
        }]
    ])
    if result and "HALT, BREAK" == result["state"]:
        hex_str = result['stack'][0]['value']
        if hex_str: return Tool.hex_to_num_str(hex_str)
        return '0'
    return '0'
示例#3
0
async def ong(net, request, *, publicKey, **kw):
    #params validation
    if not valid_net(net, request):
        return {'result': False, 'error': 'wrong net'}
    if not Tool.validate_cpubkey(publicKey):
        return {'result': False, 'error': 'wrong publicKey'}
    #get gas
    address = Tool.cpubkey_to_address(publicKey)
    amount = await get_unclaim_ong(request, address)
    tx, result, msg = Tool.ong_claim_transaction(address, amount)
    if result:
        return {
            'result': True,
            'transaction': tx,
            'sigdata': big_or_little(Tool.compute_txid(tx))
        }
    return {'result': False, 'error': msg}
示例#4
0
async def transfer_ont(net, request, *, source, dests, amounts, assetId, **kw):
    #params validation
    if not valid_net(net, request):
        return {'result': False, 'error': 'wrong net'}
    if not Tool.validate_address(source):
        return {'result': False, 'error': 'wrong source'}
    if assetId.startswith('0x'): assetId = assetId[2:]
    aname = get_asset_name(assetId)
    if not aname: return {'result': False, 'error': 'wrong assetId'}
    ad = get_asset_decimal(aname)
    dests, amounts = dests.split(','), amounts.split(',')
    ld, la = len(dests), len(amounts)
    if ld != la:
        return {
            'result': False,
            'error': 'length of dests != length of amounts'
        }
    if 1 != ld:
        return {
            'result': False,
            'error': "NEP5 token transfer only support One to One"
        }
    if False in map(Tool.validate_address, dests):
        return {'error': 'wrong dests'}
    try:
        amounts = [D(a) for a in amounts]
    except:
        return {'result': False, 'error': 'wrong amounts'}
    if [a for a in amounts if a <= D(0)]: return {'error': 'wrong amounts'}
    if False in [check_decimal(a, ad) for a in amounts]:
        return {'result': False, 'error': 'wrong amounts'}
    #check balance && transaction
    tran_num = sum(amounts)
    balance = D(await get_ont_balance(request, source, aname))
    if balance < tran_num:
        return {'result': False, 'error': 'insufficient balance'}
    transaction = Tool.transfer_ontology(assetId, source, dests[0], amounts[0],
                                         ad)
    result, msg = True, ''
    if result:
        return {
            'result': True,
            'sigdata': big_or_little(Tool.compute_txid(transaction)),
            'transaction': transaction
        }
    return {'result': False, 'error': msg}
示例#5
0
async def broadcast_ont(net, request, *, publicKey, signature, transaction):
    #params validation
    if not valid_net(net, request):
        return {'result': False, 'error': 'wrong net'}
    if not Tool.validate_cpubkey(publicKey):
        return {'result': False, 'error': 'wrong publicKey'}
    sigdata = big_or_little(Tool.compute_txid(transaction))
    result, msg = Tool.verify(publicKey, signature, sigdata)
    if not result: return {'result': False, 'error': msg}
    tx = Tool.get_transaction_ontology(publicKey, signature, transaction)
    logging.info('tx:\n%s\n' % tx)
    txid = Tool.compute_txid(transaction)
    result, msg = await ont_send_raw_transaction(tx, request)
    if result:
        if txid != result:
            return {
                'result': True,
                'error': 'result:%s != txid:%s' % (result, txid)
            }
        return {'result': True, 'txid': result}
    return {'result': False, 'error': msg}