Example #1
0
 def _get_transaction(self, txid, parent_block=None):
     meta = {'parent_block': parent_block}
     if self.async:
         return chain(txid,
                      lambda txid: self.btcd.get_raw_transaction(txid, async=True),
                      lambda rawtx: self.btcd.decode_raw_transaction(rawtx.get('result'), async=True),
                      asyncio.coroutine(lambda json_obj: BTCDTransaction(json_obj.get('result'),
                                                                         meta=meta)))
     else:
         rawtx = self.btcd.get_raw_transaction(txid)
         json_obj = self.btcd.decode_raw_transaction(rawtx.get('result'))
         return BTCDTransaction(json_obj.get('result'))
Example #2
0
 def _get_transaction(self, txid, parent_block=None):
     meta = {'parent_block': parent_block}
     """
     Since we already have the txid information
     """
     if self.async:
         return chain(txid,
                      lambda txid: self.btcd.get_raw_transaction(txid, async=True),
                      asyncio.coroutine(lambda rawtx: PyBitcoinToolsTransaction(rawtx.get('result'),
                                                                                txid,
                                                                                network=self.network,
                                                                                meta=meta)))
     else:
         return PyBitcoinToolsTransaction(self.btcd.get_raw_transaction(txid).get('result'),
                                          txid,
                                          meta=meta)
Example #3
0
            "jsonrpc": "2.0",
            "id": 0,
        }
        if async:
            return self.__aiohttp_routine(payload)
        else:
            btcd_headers = {"content-type": "application/json", "Authorization": self.btcd_auth_header}
            res = requests.post(self.btcd_url,
                                data=json.dumps(payload),
                                headers=btcd_headers).text
            return self.__parse_res(res, method, params)
    
    def get_raw_transaction(self, txid, async=False):
        try:
            if async:
                return chain(txid, lambda txid: self.call("getrawtransaction", txid, async=async))
            else:
                return self.call("getrawtransaction", txid)
        except BitcoinCliException as btcde:
            if isinstance(btcde.msg, dict) and btcde.msg.get('code') == -5:
                raise TransactionNotFound(btcde.msg, 'getrawtransaction', txid)
            else:
                raise btcde

    def decode_raw_transaction(self, raw_transaction, async=False):
        if async:
            return chain(raw_transaction,
                         lambda txid: self.call("decoderawtransaction", raw_transaction, async=async))
        else:
            return self.call("decoderawtransaction", raw_transaction)