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}
Beispiel #2
0
async def broadcast(net, request, *, publicKey, signature, transaction):
    #params validation
    if not valid_net(net): return {'result': False, 'error': 'wrong net'}
    if not Tool.validate_cpubkey(publicKey):
        return {'result': False, 'error': 'wrong publicKey'}
    result, msg = Tool.verify(publicKey, signature, transaction)
    if not result: return {'result': False, 'error': msg}
    tx = Tool.get_transaction(publicKey, signature, transaction)
    txid = Tool.compute_txid(transaction)
    result, msg = await send_raw_transaction(tx, request)
    if result:
        return {'result': True, 'txid': txid}
    return {'result': False, 'error': msg}
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}
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}