Ejemplo n.º 1
0
 def addtagtoaddress(self, tag_name, to_address, change_address="", asset_data=""):
     if asset_data == "":
        r = self._call('addtagtoaddress', str(tag_name), str(to_address), str(change_address))
     else:
        r = self._call('addtagtoaddress', str(tag_name), str(to_address), str(change_address), str(asset_data))
     txid = r[0]
     return lx(txid)
    def fundrawtransaction(self, given_transaction, *args, **kwargs):
        """
        Make up some inputs for the given transaction.
        """
        # just use any txid here
        vintxid = lx("99264749804159db1e342a0c8aa3279f6ef4031872051a1e52fb302e51061bef")

        if isinstance(given_transaction, str):
            given_bytes = x(given_transaction)
        elif isinstance(given_transaction, CMutableTransaction):
            given_bytes = given_transaction.serialize()
        else:
            raise FakeRavencoinProxyException("Wrong type passed to fundrawtransaction.")

        # this is also a clever way to not cause a side-effect in this function
        transaction = CMutableTransaction.deserialize(given_bytes)

        for vout_counter in range(0, self._num_fundrawtransaction_inputs):
            txin = CMutableTxIn(COutPoint(vintxid, vout_counter))
            transaction.vin.append(txin)

        # also allocate a single output (for change)
        txout = make_txout()
        transaction.vout.append(txout)

        transaction_hex = b2x(transaction.serialize())

        return {"hex": transaction_hex, "fee": 5000000}
Ejemplo n.º 3
0
    def getblockheader(self, block_hash, verbose=False):
        """Get block header <block_hash>

        verbose - If true a dict is returned with the values returned by
                  getblockheader that are not in the block header itself
                  (height, nextblockhash, etc.)

        Raises IndexError if block_hash is not valid.
        """
        try:
            block_hash = b2lx(block_hash)
        except TypeError:
            raise TypeError('%s.getblockheader(): block_hash must be bytes; got %r instance' %
                            (self.__class__.__name__, block_hash.__class__))
        try:
            r = self._call('getblockheader', block_hash, verbose)
        except InvalidAddressOrKeyError as ex:
            raise IndexError('%s.getblockheader(): %s (%d)' %
                             (self.__class__.__name__, ex.error['message'], ex.error['code']))

        if verbose:
            nextblockhash = None
            if 'nextblockhash' in r:
                nextblockhash = lx(r['nextblockhash'])
            return {'confirmations': r['confirmations'],
                    'height': r['height'],
                    'mediantime': r['mediantime'],
                    'nextblockhash': nextblockhash,
                    'chainwork': x(r['chainwork'])}
        else:
            return CBlockHeader.deserialize(unhexlify(r))
Ejemplo 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 InvalidAddressOrKeyError 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
Ejemplo n.º 5
0
    def listunspent(self, minconf=0, maxconf=9999999, addrs=None):
        """Return unspent transaction outputs in wallet

        Outputs will have between minconf and maxconf (inclusive)
        confirmations, optionally filtered to only include txouts paid to
        addresses in addrs.
        """
        r = None
        if addrs is None:
            r = self._call('listunspent', minconf, maxconf)
        else:
            addrs = [str(addr) for addr in addrs]
            r = self._call('listunspent', minconf, maxconf, addrs)

        r2 = []
        for unspent in r:
            unspent['outpoint'] = COutPoint(lx(unspent['txid']), unspent['vout'])
            del unspent['txid']
            del unspent['vout']

            # address isn't always available as Ravencoin Core allows scripts w/o
            # an address type to be imported into the wallet, e.g. non-p2sh
            # segwit
            try:
                unspent['address'] = CRavencoinAddress(unspent['address'])
            except KeyError:
                pass
            unspent['scriptPubKey'] = CScript(unhexlify(unspent['scriptPubKey']))
            unspent['amount'] = int(unspent['amount'] * COIN)
            r2.append(unspent)
        return r2
Ejemplo n.º 6
0
 def issueunique(self, root_name, asset_tags, ipfs_hashes=None, to_address="", change_address=""):
     """Creates a unique asset from a pool of assets with a specific name.
     Example: If the asset name is SOFTLICENSE, then this could make unique assets like SOFTLICENSE#38293 and SOFTLICENSE#48382
     """
     asset_tags_str = [str(x) for x in asset_tags]
     r = self._call('issueunique', str(root_name), asset_tags_str, ipfs_hashes, str(to_address), str(change_address))
     txid = r[0]
     return lx(txid)
Ejemplo n.º 7
0
    def getrawmempool(self, verbose=False):
        """Return the mempool"""
        if verbose:
            return self._call('getrawmempool', verbose)

        else:
            r = self._call('getrawmempool')
            r = [lx(txid) for txid in r]
            return r
Ejemplo n.º 8
0
    def getblockhash(self, height):
        """Return hash of block in best-block-chain at height.

        Raises IndexError if height is not valid.
        """
        try:
            return lx(self._call('getblockhash', height))
        except InvalidParameterError as ex:
            raise IndexError('%s.getblockhash(): %s (%d)' %
                             (self.__class__.__name__, ex.error['message'], ex.error['code']))
Ejemplo n.º 9
0
    def sendmany(self, fromaccount, payments, minconf=1, comment='', subtractfeefromamount=None):
        """Send amount to given addresses.

        payments - dict with {address: amount}
        """
        if subtractfeefromamount is None:
            subtractfeefromamount = []
        json_payments = {str(addr): float(amount) / COIN
                         for addr, amount in payments.items()}
        r = self._call('sendmany', fromaccount, json_payments, minconf, comment, subtractfeefromamount)
        return lx(r)
Ejemplo n.º 10
0
 def issuequalifierasset(self, asset_name, qty=1, to_address="", change_address="", has_ipfs=False, ipfs_hash=""):
     check_numeric(qty)
     has_ipfs = bool(has_ipfs)
     if has_ipfs:
         r = self._call('issuequalifierasset', str(asset_name), qty, str(to_address), str(change_address),
                        has_ipfs, str(ipfs_hash))
     else:
         r = self._call('issuequalifierasset', str(asset_name), qty, str(to_address), str(change_address),
                        has_ipfs)
     txid = r[0]
     return lx(txid)
Ejemplo n.º 11
0
 def issue(self, asset_name, qty=1, to_address="", change_address="", units=0, reissuable=True, has_ipfs=False,
           ipfs_hash=""):
     """Issue an asset with unique name.
     Unit as 0 for whole units, or 8 for satoshi-like units (0.00000001).
     Qty should be whole number.
     Reissuable is true/false for whether additional units can be issued by the original issuer."""
     check_numeric(qty)
     r = self._call('issue', str(asset_name), qty, str(to_address), str(change_address), int(units), reissuable,
                    has_ipfs, ipfs_hash)
     txid = r[0]
     return lx(txid)
Ejemplo n.º 12
0
    def sendrawtransaction(self, tx, allowhighfees=False):
        """Submit transaction to local node and network.

        allowhighfees - Allow even if fees are unreasonably high.
        """
        hextx = hexlify(tx.serialize())
        r = None
        if allowhighfees:
            r = self._call('sendrawtransaction', hextx, True)
        else:
            r = self._call('sendrawtransaction', hextx)
        return lx(r)
Ejemplo n.º 13
0
    def generatetoaddress(self, numblocks, addr):
        """Mine blocks immediately (before the RPC call returns) and
        allocate block reward to passed address. Replaces deprecated 
        "generate(self,numblocks)" method.

        numblocks - How many blocks are generated immediately.
        addr     - Address to receive block reward (CRavencoinAddress instance)

        Returns iterable of block hashes generated.
        """
        r = self._call('generatetoaddress', numblocks, str(addr))
        return (lx(blk_hash) for blk_hash in r)
Ejemplo n.º 14
0
    def generate(self, numblocks):
        """
        DEPRECATED (will be removed in ravencoin-core v0.19)
        
        Mine blocks immediately (before the RPC call returns)

        numblocks - How many blocks are generated immediately.

        Returns iterable of block hashes generated.
        """
        r = self._call('generate', numblocks)
        return (lx(blk_hash) for blk_hash in r)
Ejemplo n.º 15
0
 def issuerestrictedasset(self, asset_name, qty, verifier, to_address, change_address="", units=0, reissuable=True,
                          has_ipfs=False, ipfs_hash=""):
     check_numeric(qty)
     has_ipfs = bool(has_ipfs)
     if has_ipfs:
         r = self._call('issuerestrictedasset', str(asset_name), qty, str(verifier), str(to_address),
                        str(change_address), int(units), bool(reissuable), has_ipfs, str(ipfs_hash))
     else:
         r = self._call('issuerestrictedasset', str(asset_name), qty, str(verifier), str(to_address),
                        str(change_address), int(units), bool(reissuable), has_ipfs)
     txid = r[0]
     return lx(txid)
Ejemplo n.º 16
0
    def test_getblock_with_bytes(self):
        blockhash0 = "00008c0c84aee66413f1e8ff95fdca5e8ebf35c94b090290077cdcea64936301"

        blocks = [
            {
                "hash": blockhash0
            },
        ]

        proxy = FakeRavencoinProxy(blocks=blocks)
        result = proxy.getblock(lx(blockhash0))

        self.assertEqual(type(result), dict)
Ejemplo n.º 17
0
 def reissue(self, reissue_asset_name, qty, to_address, change_address="", reissuable=True, new_unit=-1,
             new_ipfs=None):
     """Issue more of a specific asset. This is only allowed by the original issuer of the asset
     and if the reissuable flag was set to true at the time of original issuance."""
     new_unit = int(new_unit)
     check_numeric(qty)
     if new_ipfs is not None:
         r = self._call('reissue', str(reissue_asset_name), qty, str(to_address), str(change_address), reissuable,
                        new_unit, new_ipfs)
     else:
         r = self._call('reissue', str(reissue_asset_name), qty, str(to_address), str(change_address), reissuable,
                        new_unit)
     txid = r[0]
     return lx(txid)
Ejemplo n.º 18
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
Ejemplo n.º 19
0
 def getbestblockhash(self):
     """Return hash of best (tip) block in longest block chain."""
     return lx(self._call('getbestblockhash'))
Ejemplo n.º 20
0
 def transfer(self, asset_name, qty, to_address):
     """This sends assets from one asset holder to another"""
     check_numeric(qty)
     r = self._call('transfer', str(asset_name), qty, str(to_address))
     txid = r[0]
     return lx(txid)
Ejemplo n.º 21
0
 def sendtoaddress(self, addr, amount, comment='', commentto='', subtractfeefromamount=False):
     """Send amount to a given address"""
     addr = str(addr)
     amount = float(amount) / COIN
     r = self._call('sendtoaddress', addr, amount, comment, commentto, subtractfeefromamount)
     return lx(r)