Example #1
0
	def listsinceblock(self, block_hash):
		try:
			res = self.proxy.listsinceblock(block_hash)
			res['transactions'] = [TransactionInfo(**x) for x in res['transactions']]
			return res
		except JSONRPCException as e:
			raise _wrap_exception(e.error)
Example #2
0
	def sendmany(self, fromaccount, todict, minconf=1, comment=None):
		"""
        Sends specified amounts from account's balance to bitcoinaddresses.
        This method will fail if there is less than total amount bitcoins with
        minconf confirmations in the account's balance (unless account is the
        empty-string-named default account; Returns transaction ID on
        success.

        Arguments:

        - *fromaccount* -- Account to send from.
        - *todict* -- Dictionary with Bitcoin addresses as keys and amounts as
        values.
        - *minconf* -- Minimum number of confirmations required for transferred
        balance.
        - *comment* -- Comment for transaction.

		"""
		try:
			if comment is None:
				return self.proxy.sendmany(fromaccount, todict, minconf)
			else:
				return self.proxy.sendmany(fromaccount, todict, minconf, comment)
		except JSONRPCException as e:
			raise _wrap_exception(e.error)
Example #3
0
	def sendfrom(self, fromaccount, tobitcoinaddress, amount, minconf=1, comment=None,
				comment_to=None):
		"""
        Sends amount from account's balance to bitcoinaddress. This method will fail
        if there is less than amount bitcoins with minconf confirmations in the account's
        balance (unless account is the empty-string-named default account; it
        behaves like the sendtoaddress method). Returns transaction ID on success.

        Arguments:

        - *fromaccount* -- Account to send from.
        - *tobitcoinaddress* -- Bitcoin address to send to.
        - *amount* -- Amount to send (float, rounded to the nearest 0.01).
        - *minconf* -- Minimum number of confirmations required for transferred balance.
        - *comment* -- Comment for transaction.
        - *comment_to* -- Comment for to-address.

		"""
		try:
			if comment is None:
				return self.proxy.sendfrom(fromaccount, tobitcoinaddress, amount, minconf)
			elif comment_to is None:
				return self.proxy.sendfrom(fromaccount, tobitcoinaddress, amount, minconf, comment)
			else:
				return self.proxy.sendfrom(fromaccount, tobitcoinaddress, amount, minconf, comment, comment_to)
		except JSONRPCException as e:
			raise _wrap_exception(e.error)
Example #4
0
	def createrawtransaction(self, inputs, outputs):
		"""
        Creates a raw transaction spending given inputs
        (a list of dictionaries, each containing a transaction id and an output
        number), sending to given address(es).

        Returns hex-encoded raw transaction.

        Example usage:
        >>> conn.createrawtransaction(
               [{"txid": "a9d4599e15b53f3eb531608ddb31f48c695c3d0b3538a6bda871e8b34f2f430c",
               "vout": 0}],
               {"mkZBYBiq6DNoQEKakpMJegyDbw2YiNQnHT":50})


        Arguments:

        - *inputs* -- A list of {"txid": txid, "vout": n} dictionaries.
        - *outputs* -- A dictionary mapping (public) addresses to the amount
                    they are to be paid.
		"""
		try:
			return self.proxy.createrawtransaction(inputs, outputs)
		except JSONRPCException as e:
			raise _wrap_exception(e.error)
Example #5
0
	def gethashespersec(self):
		"""
        Returns a recent hashes per second performance measurement while generating.
		"""
		try:
			return self.proxy.gethashespersec()
		except JSONRPCException as e:
			raise _wrap_exception(e.error)
Example #6
0
	def getdifficulty(self):
		"""
        Returns the proof-of-work difficulty as a multiple of the minimum difficulty.
		"""
		try:
			return self.proxy.getdifficulty()
		except JSONRPCException as e:
			raise _wrap_exception(e.error)
Example #7
0
	def getconnectioncount(self):
		"""
        Returns the number of connections to other nodes.
		"""
		try:
			return self.proxy.getconnectioncount()
		except JSONRPCException as e:
			raise _wrap_exception(e.error)
Example #8
0
	def getblock(self, hash):
		"""
        Returns information about the given block hash.
		"""
		try:
			return self.proxy.getblock(hash)
		except JSONRPCException as e:
			raise _wrap_exception(e.error)
Example #9
0
	def getblockcount(self):
		"""
        Returns the number of blocks in the longest block chain.
		"""
		try:
			return self.proxy.getblockcount()
		except JSONRPCException as e:
			raise _wrap_exception(e.error)
Example #10
0
	def stop(self):
		"""
        Stop bitcoin server.
		"""
		try:
			self.proxy.stop()
		except JSONRPCException as e:
			raise _wrap_exception(e.error)
Example #11
0
	def getmininginfo(self):
		"""
        Returns an :class:`~mmgen.rpc.data.MiningInfo` object containing various
        mining state info.
		"""
		try:
			return MiningInfo(**self.proxy.getmininginfo())
		except JSONRPCException as e:
			raise _wrap_exception(e.error)
Example #12
0
	def getgenerate(self):
		"""
        Returns :const:`True` or :const:`False`, depending on whether
        generation is enabled.
		"""
		try:
			return self.proxy.getgenerate()
		except JSONRPCException as e:
			raise _wrap_exception(e.error)
Example #13
0
	def walletlock(self):
		"""
        Removes the wallet encryption key from memory, locking the wallet.
        After calling this method, you will need to call walletpassphrase
        again before being able to call any methods which require the wallet
        to be unlocked.
		"""
		try:
			return self.proxy.walletlock()
		except JSONRPCException as e:
			raise _wrap_exception(e.error)
Example #14
0
	def getblockhash(self, index):
		"""
        Returns hash of block in best-block-chain at index.

        :param index: index ob the block

		"""
		try:
			return self.proxy.getblockhash(index)
		except JSONRPCException as e:
			raise _wrap_exception(e.error)
Example #15
0
	def decoderawtransaction(self, hexstring):
		"""
        Produces a human-readable JSON object for a raw transaction.

        Arguments:

        - *hexstring* -- A hex string of the transaction to be decoded.
		"""
		try:
			return dict(self.proxy.decoderawtransaction(hexstring))
		except JSONRPCException as e:
			raise _wrap_exception(e.error)
Example #16
0
	def getaccount(self, bitcoinaddress):
		"""
        Returns the account associated with the given address.

        Arguments:

        - *bitcoinaddress* -- Bitcoin address to get account for.
		"""
		try:
			return self.proxy.getaccount(bitcoinaddress)
		except JSONRPCException as e:
			raise _wrap_exception(e.error)
Example #17
0
	def getaddressesbyaccount(self, account):
		"""
        Returns the list of addresses for the given account.

        Arguments:

        - *account* -- Account to get list of addresses for.
		"""
		try:
			return self.proxy.getaddressesbyaccount(account)
		except JSONRPCException as e:
			raise _wrap_exception(e.error)
Example #18
0
	def __init__(self, user, password, host='localhost', port=8332, use_https=False):
		"""
        Create a new bitcoin server connection.
		"""
		url = 'http{s}://{user}:{password}@{host}:{port}/'.format(
			s='s' if use_https else '',
			user=user, password=password, host=host, port=port)
		self.url = url
		try:
			self.proxy = AuthServiceProxy(url)
		except JSONRPCException as e:
			raise _wrap_exception(e.error)
Example #19
0
	def backupwallet(self, destination):
		"""
        Safely copies ``wallet.dat`` to *destination*, which can be a directory or a path
        with filename.

        Arguments:
        - *destination* -- directory or path with filename to backup wallet to.

		"""
		try:
			return self.proxy.backupwallet(destination)
		except JSONRPCException as e:
			raise _wrap_exception(e.error)
Example #20
0
	def gettransaction(self, txid):
		"""
        Get detailed information about transaction

        Arguments:

        - *txid* -- Transactiond id for which the info should be returned

		"""
		try:
			return TransactionInfo(**self.proxy.gettransaction(txid))
		except JSONRPCException as e:
			raise _wrap_exception(e.error)
Example #21
0
	def getaccountaddress(self, account):
		"""
        Returns the current bitcoin address for receiving payments to an account.

        Arguments:

        - *account* -- Account for which the address should be returned.

		"""
		try:
			return self.proxy.getaccountaddress(account)
		except JSONRPCException as e:
			raise _wrap_exception(e.error)
Example #22
0
	def setaccount(self, bitcoinaddress, account):
		"""
        Sets the account associated with the given address.

        Arguments:

        - *bitcoinaddress* -- Bitcoin address to associate.
        - *account* -- Account to associate the address to.

		"""
		try:
			return self.proxy.setaccount(bitcoinaddress, account)
		except JSONRPCException as e:
			raise _wrap_exception(e.error)
Example #23
0
	def getreceivedbyaccount(self, account, minconf=1):
		"""
        Returns the total amount received by addresses with an account in
        transactions with at least a certain number of confirmations.

        Arguments:

        - *account* -- Account to query for total amount.
        - *minconf* -- Number of confirmations to require, defaults to 1.

		"""
		try:
			return self.proxy.getreceivedbyaccount(account, minconf)
		except JSONRPCException as e:
			raise _wrap_exception(e.error)
Example #24
0
	def importaddress(self,address,label=None,rescan=True):
		try:
#			return self.proxy.badmethod(address,label) # DEBUG
			return self.proxy.importaddress(address,label,rescan)
		except JSONRPCException as e:
			if e.error['message'] == "Method not found":
				from mmgen.util import msg
				msg("""
*******************************************************************************
*******************************************************************************
ERROR: 'importaddress' not found.  Does your bitcoind support watch-only addrs?
*******************************************************************************
*******************************************************************************
""")
			raise _wrap_exception(e.error)
Example #25
0
	def validateaddress(self, validateaddress):
		"""
        Validate a bitcoin address and return information for it.

        The information is represented by a :class:`~mmgen.rpc.data.AddressValidation` object.

        Arguments: -- Address to validate.


        - *validateaddress*
		"""
		try:
			return AddressValidation(**self.proxy.validateaddress(validateaddress))
		except JSONRPCException as e:
			raise _wrap_exception(e.error)
Example #26
0
	def getrawtransaction(self, txid, verbose=True):
		"""
        Get transaction raw info

        Arguments:

        - *txid* -- Transactiond id for which the info should be returned.
        - *verbose* -- If False, return only the "hex" of the transaction.

		"""
		try:
			if verbose:
				return TransactionInfo(**self.proxy.getrawtransaction(txid, 1))
			return self.proxy.getrawtransaction(txid, 0)
		except JSONRPCException as e:
			raise _wrap_exception(e.error)
Example #27
0
	def walletpassphrasechange(self, oldpassphrase, newpassphrase, dont_raise=False):
		"""
        Changes the wallet passphrase from <oldpassphrase> to <newpassphrase>.

        Arguments:

        - *dont_raise* -- instead of raising
               `~mmgen.rpc.exceptions.WalletPassphraseIncorrect` return False.
		"""
		try:
			self.proxy.walletpassphrasechange(oldpassphrase, newpassphrase)
			return True
		except JSONRPCException as e:
			json_exception = _wrap_exception(e.error)
			if dont_raise and isinstance(json_exception, WalletPassphraseIncorrect):
				return False
			raise json_exception
Example #28
0
	def listunspent(self, minconf=1, maxconf=999999):
		"""
        Returns a list of unspent transaction inputs in the wallet.

        Arguments:

        - *minconf* -- Minimum number of confirmations required to be listed.

        - *maxconf* -- Maximal number of confirmations allowed to be listed.


		"""
		try:
			return [TransactionInfo(**tx) for tx in
					self.proxy.listunspent(minconf, maxconf)]
		except JSONRPCException as e:
			raise _wrap_exception(e.error)
Example #29
0
	def verifymessage(self, bitcoinaddress, signature, message):
		"""
        Verifies a signature given the bitcoinaddress used to sign,
        the signature itself, and the message that was signed.
        Returns :const:`True` if the signature is valid, and :const:`False` if it is invalid.

        Arguments:

        - *bitcoinaddress* -- the bitcoinaddress used to sign the message
        - *signature* -- the signature to be verified
        - *message* -- the message that was originally signed

		"""
		try:
			return self.proxy.verifymessage(bitcoinaddress, signature, message)
		except JSONRPCException as e:
			raise _wrap_exception(e.error)
Example #30
0
	def listreceivedbyaccount(self, minconf=1, includeempty=False):
		"""
        Returns a list of accounts.

        Each account is represented with a :class:`~mmgen.rpc.data.AccountInfo` object.

        Arguments:

        - *minconf* -- Minimum number of confirmations before payments are included.

        - *includeempty* -- Whether to include addresses that haven't received any payments.
		"""
		try:
			return [AccountInfo(**x) for x in
					self.proxy.listreceivedbyaccount(minconf, includeempty)]
		except JSONRPCException as e:
			raise _wrap_exception(e.error)