Exemplo n.º 1
0
 async def to_buffer(cls, md):
     output = struct.pack("Q", md['deposit'])
     output += hash_from_address(md['agentAddress'])
     output += hash_from_address(md['packingAddress'])
     output += hash_from_address(md['rewardAddress'])
     output += struct.pack("d", md['commissionRate'])
     return output
Exemplo n.º 2
0
async def prepare_businessdata_tx(address, utxo, content):
    # we take the first 10, hoping it's enough... bad, bad, bad!
    # TODO: do a real utxo management here
    # tx = transaction.Transaction()
    tx = await Transaction.from_dict({
        "type":
        10,
        "time":
        int(time.time() * 1000),
        "blockHeight":
        None,
        "fee":
        0,
        "remark":
        b"",
        "scriptSig":
        b"",
        "info": {
            "logicData": content.hex()
        },
        "inputs": [{
            'fromHash': inp['hash'],
            'fromIndex': inp['idx'],
            'value': inp['value'],
            'lockTime': inp['lockTime']
        } for inp in utxo],
        "outputs": [{
            "address": hash_from_address(address),
            "value": sum([inp['value'] for inp in utxo]),
            "lockTime": 0
        }]
    })
    tx.coin_data.outputs[0].na = (sum([inp['value'] for inp in utxo]) -
                                  (await tx.calculate_fee()))
    return tx
Exemplo n.º 3
0
 async def to_buffer(cls, md):
     output = hash_from_address(md['sender'])
     output += hash_from_address(md['contractAddress'])
     output += struct.pack("q", md['value'])
     output += struct.pack("I", md['codeLen'])
     output += write_with_length(unhexlify(md['code']))
     output += struct.pack("q", md['gasLimit'])
     output += struct.pack("q", md['price'])
     output += bytes([len(md['args'])])
     for arg in md['args']:
         output += bytes([len(arg)])
         for argitem in arg:
             try:
                 argitem = argitem.encode('utf-8')
             except UnicodeEncodeError:
                 LOGGER.warning(
                     "Unicode encode error here, passing raw value.")
             output += write_with_length(argitem)
     return output
Exemplo n.º 4
0
 async def to_buffer(cls, md):
     output = write_with_length(hash_from_address(md['address']))
     output += write_with_length(md['alias'].encode('utf-8'))
     return output
Exemplo n.º 5
0
    async def to_buffer(cls, md):
        output = unhexlify(md['originTxHash'])
        output += hash_from_address(md['contractAddress'])
        output += bytes([len(md['success'])])

        return output
Exemplo n.º 6
0
 async def to_buffer(cls, md):
     output = hash_from_address(md['sender'])
     output += hash_from_address(md['contractAddress'])
     return output
Exemplo n.º 7
0
 async def to_buffer(cls, md):
     output = VarInt(md['count']).encode()
     for address in md['addresses']:
         output += hash_from_address(address)
     return output
Exemplo n.º 8
0
 async def to_buffer(cls, md):
     output = struct.pack("Q", md['deposit'])
     output += hash_from_address(md['address'])
     output += unhexlify(md['agentHash'])
     return output
Exemplo n.º 9
0
 async def to_buffer(cls, md):
     #output = write_with_length(hash_from_address(md['address']))
     output = hash_from_address(md['address'])
     output += VarInt(md['reason']).encode()
     output += write_with_length(unhexlify(md['evidence']))
     return output