Esempio n. 1
0
def helloblock_fetchtx(txhash, network='btc'):
    if not re.match('^[0-9a-fA-F]*$', txhash):
        txhash = safe_hexlify(txhash)
    if network == 'testnet':
        url = 'https://testnet.helloblock.io/v1/transactions/'
    elif network == 'btc':
        url = 'https://mainnet.helloblock.io/v1/transactions/'
    else:
        raise Exception('Unsupported network {0} for helloblock_fetchtx'.format(network))
    data = request(url + txhash)["data"]["transaction"]
    o = {
        "locktime": data["locktime"],
        "version": data["version"],
        "ins": [],
        "outs": []
    }
    for inp in data["inputs"]:
        o["ins"].append({
            "script": inp["scriptSig"],
            "outpoint": {
                "index": inp["prevTxoutIndex"],
                "hash": inp["prevTxHash"],
            },
            "sequence": 4294967295
        })
    for outp in data["outputs"]:
        o["outs"].append({
            "value": outp["value"],
            "script": outp["scriptPubKey"]
        })
    from bitcoin.transaction import serialize
    from bitcoin.transaction import txhash as TXHASH
    tx = serialize(o)
    assert TXHASH(tx) == txhash
    return tx
Esempio n. 2
0
def blockcypher_fetchtx(txhash, network=''):
    if not re.match('^[0-9a-fA-F]*$', txhash):
        txhash = safe_hexlify(txhash)
    network = set_network(txhash) if network=="" else network
    base_url = 'http://api.blockcypher.com/v1/btc/{network}/txs/{txid}?includeHex=true&limit=50'
    if network == 'testnet':
        url = base_url.format(network="test3", txid=txhash.lower())
    elif network == 'btc':
        url = base_url.format(network="main", txid=txhash.lower())
    else:
        raise Exception('Unsupported network {0} for blockcypher_fetchtx'.format(network))
    jdata = json.loads(make_request(url))
    txhex = jdata.get('hex')
    from bitcoin.transaction import txhash as TXHASH
    assert TXHASH(unhexlify(txhex)) == txhash
    return txhex.encode()