Exemple #1
0
    def get_transaction(cls, txid):
        r = requests.get(cls.MAIN_TX_API.format(txid), timeout=DEFAULT_TIMEOUT)
        r.raise_for_status()  # pragma: no cover
        response = r.json(parse_float=Decimal)

        tx = Transaction(
            response['txid'], response['blockheight'],
            (Decimal(response['valueIn']) * BCH_TO_SAT_MULTIPLIER).normalize(),
            (Decimal(response['valueOut']) *
             BCH_TO_SAT_MULTIPLIER).normalize(),
            (Decimal(response['fees']) * BCH_TO_SAT_MULTIPLIER).normalize())

        for txin in response['vin']:
            part = TxPart(txin['addr'], txin['valueSat'],
                          txin['scriptSig']['asm'])
            tx.add_input(part)

        for txout in response['vout']:
            addr = None
            if 'addresses' in txout['scriptPubKey'] and txout['scriptPubKey'][
                    'addresses'] is not None:
                addr = txout['scriptPubKey']['addresses'][0]

            part = TxPart(addr, (Decimal(txout['value']) *
                                 BCH_TO_SAT_MULTIPLIER).normalize(),
                          txout['scriptPubKey']['asm'])
            tx.add_output(part)

        return tx
Exemple #2
0
    def get_transaction(cls, txid, network):
        API = cls.network_endpoint(network) + cls.TX_DETAILS_PATH
        r = requests.get(API.format(txid), timeout=DEFAULT_TIMEOUT)
        r.raise_for_status()
        response = r.json(parse_float=Decimal)

        tx = Transaction(
            response["txid"],
            response["blockheight"],
            (Decimal(response["valueIn"]) * BCH_TO_SAT_MULTIPLIER).normalize(),
            (Decimal(response["valueOut"]) *
             BCH_TO_SAT_MULTIPLIER).normalize(),
            (Decimal(response["fees"]) * BCH_TO_SAT_MULTIPLIER).normalize(),
        )

        for txin in response["vin"]:
            part = TxPart(txin["cashAddress"], txin["value"],
                          txin["scriptSig"]["asm"])
            tx.add_input(part)

        for txout in response["vout"]:
            addr = None
            if ("cashAddrs" in txout["scriptPubKey"]
                    and txout["scriptPubKey"]["cashAddrs"] is not None):
                addr = txout["scriptPubKey"]["cashAddrs"][0]

            part = TxPart(
                addr,
                (Decimal(txout["value"]) * BCH_TO_SAT_MULTIPLIER).normalize(),
                txout["scriptPubKey"]["asm"],
            )
            tx.add_output(part)

        return tx