Exemple #1
0
 def tx_for_tx_hash(self, tx_hash):
     """
     returns the pycoin.tx object for tx_hash
     """
     try:
         url_append = "?token=%s&includeHex=true" % self.api_key
         url = self.base_url("txs/%s%s" % (b2h_rev(tx_hash), url_append))
         result = json.loads(urlopen(url).read().decode("utf8"))
         tx = Tx.parse(io.BytesIO(h2b(result.get("hex"))))
         return tx
     except Exception:
         raise Exception
Exemple #2
0
 def tx_for_tx_hash(self, tx_hash):
     """
     returns the pycoin.tx object for tx_hash
     """
     try:
         url_append = "?token=%s&includeHex=true" % self.api_key
         url = self.base_url("txs/%s%s" % (b2h_rev(tx_hash), url_append))
         result = json.loads(urlopen(url).read().decode("utf8"))
         tx = Tx.parse(io.BytesIO(h2b(result.get("hex"))))
         return tx
     except Exception:
         raise Exception
Exemple #3
0
 def get(self, key):
     for path in self.paths_for_hash(key):
         try:
             tx = Tx.parse(open(path, "rb"))
             if tx and tx.hash() == key:
                 return tx
         except IOError:
             pass
     for method in self.lookup_methods:
         try:
             tx = method(key)
             if tx and tx.hash() == key:
                 self.put(tx)
                 return tx
         except Exception:
             pass
     return None
Exemple #4
0
 def get(self, key):
     for path in self.paths_for_hash(key):
         try:
             tx = Tx.parse(open(path, "rb"))
             if tx and tx.hash() == key:
                 return tx
         except IOError:
             pass
     for method in self.lookup_methods:
         try:
             tx = method(key)
             if tx and tx.hash() == key:
                 self.put(tx)
                 return tx
         except Exception:
             pass
     return None
    def parse(self, raw):
        # auto-detect and decode Base64 and Hex.
        if raw[0:10].lower() == b'70736274ff':
            raw = a2b_hex(raw.strip())
        if raw[0:6] == b'cHNidP':
            raw = b64decode(raw)
        assert raw[0:5] == b'psbt\xff', "bad magic"

        with io.BytesIO(raw[5:]) as fd:
            
            # globals
            while 1:
                ks = deser_compact_size(fd)
                if ks is None: break

                if ks == 0: break

                key = fd.read(ks)
                vs = deser_compact_size(fd)
                val = fd.read(vs)

                kt = key[0]
                if kt == PSBT_GLOBAL_UNSIGNED_TX:
                    self.txn = val

                    t = Tx.parse(io.BytesIO(val))
                    num_ins = len(t.txs_in)
                    num_outs = len(t.txs_out)
                elif kt == PSBT_GLOBAL_XPUB:
                    self.xpubs[key[1:]] = val
                else:
                    raise ValueError('unknown global key type: 0x%02x' % kt)

            assert self.txn, 'missing reqd section'

            self.inputs = [BasicPSBTInput(fd, idx) for idx in range(num_ins)]
            self.outputs = [BasicPSBTOutput(fd, idx) for idx in range(num_outs)]

            sep = fd.read(1)
            assert sep == b''

        return self
Exemple #6
0
 def tx_for_tx_hash(self, tx_hash):
     "Get a Tx by its hash."
     url = self.base_url("get_tx", b2h_rev(tx_hash))
     r = json.loads(urlopen(url).read().decode("utf8"))
     tx = Tx.parse(io.BytesIO(h2b(r.get("data").get("tx_hex"))))
     return tx
Exemple #7
0
 def tx_for_tx_hash(self, tx_hash):
     "Get a Tx by its hash."
     url = self.base_url("get_tx", b2h_rev(tx_hash))
     r = json.loads(urlopen(url).read().decode("utf8"))
     tx = Tx.parse(io.BytesIO(h2b(r.get("data").get("tx_hex"))))
     return tx