Esempio n. 1
0
 def lockunspent(self, unlock, outpoints):
     """Lock or unlock outpoints"""
     json_outpoints = [{
         'txid': b2lx(outpoint.hash),
         'vout': outpoint.n
     } for outpoint in outpoints]
     return self._call('lockunspent', unlock, json_outpoints)
Esempio n. 2
0
    def getrawtransaction(self, txid, verbose=False):
        """Return transaction with hash txid

        Raises IndexError if transaction not found.

        verbose - If true a dict is returned instead with additional
        information on the transaction.

        Note that if all txouts are spent and the transaction index is not
        enabled the transaction may not be available.
        """
        try:
            r = self._call("getrawtransaction", b2lx(txid), 1 if verbose else 0)
        except JSONRPCError as ex:
            raise IndexError(
                "%s.getrawtransaction(): %s (%d)" % (self.__class__.__name__, ex.error["message"], ex.error["code"])
            )
        if verbose:
            r["tx"] = CTransaction.deserialize(unhexlify(r["hex"]))
            del r["hex"]
            del r["txid"]
            del r["version"]
            del r["locktime"]
            del r["vin"]
            del r["vout"]
            r["blockhash"] = lx(r["blockhash"]) if "blockhash" in r else None
        else:
            r = CTransaction.deserialize(unhexlify(r))

        return r
Esempio n. 3
0
    def getrawtransaction(self, txid, verbose=False):
        """Return transaction with hash txid

        Raises IndexError if transaction not found.

        verbose - If true a dict is returned instead with additional
        information on the transaction.

        Note that if all txouts are spent and the transaction index is not
        enabled the transaction may not be available.
        """
        try:
            r = self._call('getrawtransaction', b2lx(txid),
                           1 if verbose else 0)
        except JSONRPCError as ex:
            raise IndexError('%s.getrawtransaction(): %s (%d)' %
                             (self.__class__.__name__, ex.error['message'],
                              ex.error['code']))
        if verbose:
            r['tx'] = CTransaction.deserialize(unhexlify(r['hex']))
            del r['hex']
            del r['txid']
            del r['version']
            del r['locktime']
            del r['vin']
            del r['vout']
            r['blockhash'] = lx(r['blockhash']) if 'blockhash' in r else None
        else:
            r = CTransaction.deserialize(unhexlify(r))

        return r
Esempio n. 4
0
    def getrawtransaction(self, txid, verbose=False):
        """Return transaction with hash txid

        Raises IndexError if transaction not found.

        verbose - If true a dict is returned instead with additional
        information on the transaction.

        Note that if all txouts are spent and the transaction index is not
        enabled the transaction may not be available.
        """
        try:
            r = self._call('getrawtransaction', b2lx(txid), 1 if verbose else 0)
        except JSONRPCError as ex:
            raise IndexError('%s.getrawtransaction(): %s (%d)' %
                    (self.__class__.__name__, ex.error['message'], ex.error['code']))
        if verbose:
            r['tx'] = CTransaction.deserialize(unhexlify(r['hex']))
            del r['hex']
            del r['txid']
            del r['version']
            del r['locktime']
            del r['vin']
            del r['vout']
            r['blockhash'] = lx(r['blockhash']) if 'blockhash' in r else None
        else:
            r = CTransaction.deserialize(unhexlify(r))

        return r
Esempio n. 5
0
    def gettransaction(self, txid):
        """Get detailed information about in-wallet transaction txid

        Raises IndexError if transaction not found in the wallet.

        FIXME: Returned data types are not yet converted.
        """
        try:
            r = self._call('gettransaction', b2lx(txid))
        except JSONRPCError as ex:
            raise IndexError('%s.getrawtransaction(): %s (%d)' %
                    (self.__class__.__name__, ex.error['message'], ex.error['code']))
        return r
Esempio n. 6
0
    def gettransaction(self, txid):
        """Get detailed information about in-wallet transaction txid

        Raises IndexError if transaction not found in the wallet.

        FIXME: Returned data types are not yet converted.
        """
        try:
            r = self._call('gettransaction', b2lx(txid))
        except JSONRPCError as ex:
            raise IndexError('%s.getrawtransaction(): %s (%d)' %
                             (self.__class__.__name__, ex.error['message'],
                              ex.error['code']))
        return r
Esempio n. 7
0
    def getblock(self, block_hash):
        """Get block <block_hash>

        Raises IndexError if block_hash is not valid.
        """
        try:
            block_hash = b2lx(block_hash)
        except TypeError:
            raise TypeError('%s.getblock(): block_hash must be bytes; got %r instance' %
                    (self.__class__.__name__, block_hash.__class__))
        try:
            r = self._call('getblock', block_hash, False)
        except JSONRPCError as ex:
            raise IndexError('%s.getblock(): %s (%d)' %
                    (self.__class__.__name__, ex.error['message'], ex.error['code']))
        return CBlock.deserialize(unhexlify(r))
Esempio n. 8
0
    def gettxout(self, outpoint, includemempool=True):
        """Return details about an unspent transaction output.

        Raises IndexError if outpoint is not found or was spent.

        includemempool - Include mempool txouts
        """
        r = self._call("gettxout", b2lx(outpoint.hash), outpoint.n, includemempool)

        if r is None:
            raise IndexError("%s.gettxout(): unspent txout %r not found" % (self.__class__.__name__, outpoint))

        r["txout"] = CTxOut(int(r["value"] * COIN), CScript(unhexlify(r["scriptPubKey"]["hex"])))
        del r["value"]
        del r["scriptPubKey"]
        r["bestblock"] = lx(r["bestblock"])
        return r
Esempio n. 9
0
    def getblock(self, block_hash):
        """Get block <block_hash>

        Raises IndexError if block_hash is not valid.
        """
        try:
            block_hash = b2lx(block_hash)
        except TypeError:
            raise TypeError(
                '%s.getblock(): block_hash must be bytes; got %r instance' %
                (self.__class__.__name__, block_hash.__class__))
        try:
            r = self._call('getblock', block_hash, False)
        except JSONRPCError as ex:
            raise IndexError('%s.getblock(): %s (%d)' %
                             (self.__class__.__name__, ex.error['message'],
                              ex.error['code']))
        return CBlock.deserialize(unhexlify(r))
Esempio n. 10
0
    def gettxout(self, outpoint, includemempool=True):
        """Return details about an unspent transaction output.

        Raises IndexError if outpoint is not found or was spent.

        includemempool - Include mempool txouts
        """
        r = self._call('gettxout', b2lx(outpoint.hash), outpoint.n, includemempool)

        if r is None:
            raise IndexError('%s.gettxout(): unspent txout %r not found' % (self.__class__.__name__, outpoint))

        r['txout'] = CTxOut(int(r['value'] * COIN),
                            CScript(unhexlify(r['scriptPubKey']['hex'])))
        del r['value']
        del r['scriptPubKey']
        r['bestblock'] = lx(r['bestblock'])
        return r
Esempio n. 11
0
    def gettxout(self, outpoint, includemempool=True):
        """Return details about an unspent transaction output.

        Raises IndexError if outpoint is not found or was spent.

        includemempool - Include mempool txouts
        """
        r = self._call('gettxout', b2lx(outpoint.hash), outpoint.n,
                       includemempool)

        if r is None:
            raise IndexError('%s.gettxout(): unspent txout %r not found' %
                             (self.__class__.__name__, outpoint))

        r['txout'] = CTxOut(int(r['value'] * COIN),
                            CScript(unhexlify(r['scriptPubKey']['hex'])))
        del r['value']
        del r['scriptPubKey']
        r['bestblock'] = lx(r['bestblock'])
        return r
Esempio n. 12
0
 def __repr__(self):
     return "CInv(type=%s hash=%s)" % (self.typemap[self.type],
                                       b2lx(self.hash))
Esempio n. 13
0
 def __repr__(self):
     return "CInv(type=%s hash=%s)" % (self.typemap[self.type], b2lx(self.hash))
Esempio n. 14
0
 def lockunspent(self, unlock, outpoints):
     """Lock or unlock outpoints"""
     json_outpoints = [{"txid": b2lx(outpoint.hash), "vout": outpoint.n} for outpoint in outpoints]
     return self._call("lockunspent", unlock, json_outpoints)
Esempio n. 15
0
 def lockunspent(self, unlock, outpoints):
     """Lock or unlock outpoints"""
     json_outpoints = [{'txid':b2lx(outpoint.hash), 'vout':outpoint.n}
                       for outpoint in outpoints]
     return self._call('lockunspent', unlock, json_outpoints)