Exemplo n.º 1
0
    def listtransactions(self, account, count=10, address=None):
        """
        Returns a list of the last transactions for an account.
        
        Each transaction is represented with a :class:`~bitcoin.data.TransactionInfo` object.
        
        Arguments:
        
        - *minconf* -- Minimum number of confirmations before payments are included.
        - *count* -- Number of transactions to return.
        - *address* -- Receive address to consider

        """
        try:
            result = self.proxy.listtransactions(account, count)
            import json

            return json.dumps(result, indent=1)

        #    return [TransactionInfo(**x) for x in
        #         result
        #         if address is None or x["address"] == address]

        except JSONRPCException, e:
            raise _wrap_exception(e.error)
Exemplo n.º 2
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, e:
            raise _wrap_exception(e.error)
Exemplo n.º 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,e:
            raise _wrap_exception(e.error)
Exemplo n.º 4
0
    def sendtoaddress(self,
                      bitcoinaddress,
                      amount,
                      comment=None,
                      comment_to=None):
        """
        Sends *amount* from the server's available balance to *bitcoinaddress*.
        
        Arguments:
        
        - *bitcoinaddress* -- 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.sendtoaddress(bitcoinaddress, amount)
            elif comment_to is None:
                return self.proxy.sendtoaddress(bitcoinaddress, amount,
                                                comment)
            else:
                return self.proxy.sendtoaddress(bitcoinaddress, amount,
                                                comment, comment_to)
        except JSONRPCException, e:
            raise _wrap_exception(e.error)
Exemplo n.º 5
0
 def getconnectioncount(self):
     """
     Returns the number of connections to other nodes.
     """
     try:
         return self.proxy.getconnectioncount()
     except JSONRPCException, e:
         raise _wrap_exception(e.error)
Exemplo n.º 6
0
 def getpeerinfo(self):
     """
     Returns an peer info.
     """
     try:
         return self.proxy.getpeerinfo()
     except JSONRPCException,e:
         raise _wrap_exception(e.error)
Exemplo n.º 7
0
 def getpeerinfo(self):
     """
     Returns an peer info.
     """
     try:
         return self.proxy.getpeerinfo()
     except JSONRPCException, e:
         raise _wrap_exception(e.error)
Exemplo n.º 8
0
 def stop(self):
     """
     Stop bitcoin server.
     """
     try:
         self.proxy.stop()
     except JSONRPCException, e:
         raise _wrap_exception(e.error)
Exemplo n.º 9
0
 def gethashespersec(self):
     """
     Returns a recent hashes per second performance measurement while generating.
     """
     try:
         return self.proxy.gethashespersec()
     except JSONRPCException, e:
         raise _wrap_exception(e.error)
Exemplo n.º 10
0
 def getblocknumber(self):
     """
     Returns the block number of the latest block in the longest block chain.
     """
     try:
         return self.proxy.getblocknumber()
     except JSONRPCException, e:
         raise _wrap_exception(e.error)
Exemplo n.º 11
0
 def getinfo(self):
     """
     Returns an :class:`~bitcoin.data.ServerInfo` object containing various state info.
     """
     try:
         return self.proxy.getinfo()
     except JSONRPCException, e:
         raise _wrap_exception(e.error)
Exemplo n.º 12
0
 def stop(self):
     """
     Stop bitcoin server.
     """
     try:
         self.proxy.stop()
     except JSONRPCException, e:
         raise _wrap_exception(e.error)
Exemplo n.º 13
0
 def getdifficulty(self):
     """
     Returns the proof-of-work difficulty as a multiple of the minimum difficulty.
     """
     try:
         return self.proxy.getdifficulty()
     except JSONRPCException, e:
         raise _wrap_exception(e.error)
Exemplo n.º 14
0
 def getgenerate(self):
     """
     Returns :const:`True` or :const:`False`, depending on whether generation is enabled.
     """
     try:
         return self.proxy.getgenerate()
     except JSONRPCException, e:
         raise _wrap_exception(e.error)
Exemplo n.º 15
0
 def getconnectioncount(self):
     """
     Returns the number of connections to other nodes.
     """
     try:
         return self.proxy.getconnectioncount()
     except JSONRPCException, e:
         raise _wrap_exception(e.error)
Exemplo n.º 16
0
 def getgenerate(self):
     """
     Returns :const:`True` or :const:`False`, depending on whether generation is enabled.
     """
     try:
         return self.proxy.getgenerate()
     except JSONRPCException, e:
         raise _wrap_exception(e.error)
Exemplo n.º 17
0
 def getdifficulty(self):
     """
     Returns the proof-of-work difficulty as a multiple of the minimum difficulty.
     """
     try:
         return self.proxy.getdifficulty()
     except JSONRPCException, e:
         raise _wrap_exception(e.error)
Exemplo n.º 18
0
 def getinfo(self):
     """
     Returns an :class:`~bitcoin.data.ServerInfo` object containing various state info.
     """
     try:
         return ServerInfo(**self.proxy.getinfo())
     except JSONRPCException, e:
         raise _wrap_exception(e.error)
Exemplo n.º 19
0
 def gethashespersec(self):
     """
     Returns a recent hashes per second performance measurement while generating.
     """
     try:
         return self.proxy.gethashespersec()
     except JSONRPCException, e:
         raise _wrap_exception(e.error)
Exemplo n.º 20
0
 def getblockcount(self):
     """
     Returns the number of blocks in the longest block chain.
     """
     try:
         return self.proxy.getblockcount()
     except JSONRPCException, e:
         raise _wrap_exception(e.error)
Exemplo n.º 21
0
 def getblockcount(self):
     """
     Returns the number of blocks in the longest block chain.
     """
     try:
         return self.proxy.getblockcount()
     except JSONRPCException, e:
         raise _wrap_exception(e.error)
Exemplo n.º 22
0
 def getblocknumber(self):
     """
     Returns the block number of the latest block in the longest block chain.
     """
     try:
         return self.proxy.getblocknumber()
     except JSONRPCException, e:
         raise _wrap_exception(e.error)
Exemplo n.º 23
0
 def dumpprivkey(self, address):
     """
     Returns the dump.
     
     """
     try:
         return self.proxy.dumpprivkey(address)
     except JSONRPCException, e:
         raise _wrap_exception(e.error)
Exemplo n.º 24
0
 def __init__(self, user, password, host='localhost', port=8332):
     """
     Create a new bitcoin server connection.
     """
     url = 'http://%s:%s@%s:%s/' % (user, password, host, port)
     try:
         self.proxy = ServiceProxy(url)
     except JSONRPCException, e:
         raise _wrap_exception(e.error)
Exemplo n.º 25
0
    def addmultisigaddress(self, n, key1, account=None):

        try:
            if account is None:
                return self.proxy.addmultisigaddress(n, key1)
            else:
                return self.proxy.addmultisigaddress(n, key1, account)
        except JSONRPCException, e:
            raise _wrap_exception(e.error)
Exemplo n.º 26
0
 def __init__(self, user, password, host="localhost", port=8332):
     """
     Create a new bitcoin server connection.
     """
     url = "http://%s:%s@%s:%s/" % (user, password, host, port)
     try:
         self.proxy = ServiceProxy(url)
     except JSONRPCException, e:
         raise _wrap_exception(e.error)
Exemplo n.º 27
0
    def addmultisigaddress (self, n, key1, account=None):

        try:
            if account is None:
                return  self.proxy.addmultisigaddress(n,key1)
            else:
                return self.proxy.addmultisigaddress(n,key1,account)
        except JSONRPCException,e:
            raise _wrap_exception(e.error)
Exemplo n.º 28
0
    def createrawtransaction0(self, txid, vout, address1, amount):

        try:
            return self.proxy.createrawtransaction([{
                "txid": txid,
                "vout": vout
            }], {address1: amount})
        except JSONRPCException, e:
            raise _wrap_exception(e.error)
Exemplo n.º 29
0
 def dumpprivkey(self, address):
     """
     Returns the dump.
     
     """ 
     try:
         return self.proxy.dumpprivkey(address) 
     except JSONRPCException,e:
         raise _wrap_exception(e.error)
Exemplo n.º 30
0
 def importprivkey(self, address, label=None, rescan=False):
     """
     import the dump.
     
     """
     try:
         if label is None:
             return self.proxy.importprivkey(address, rescan)
         else:
             return self.proxy.importprivkey(address, label, rescan)
     except JSONRPCException, e:
         raise _wrap_exception(e.error)
Exemplo n.º 31
0
    def getucbalance(self, account="*", conf=0):
        """
        Get the current balance, either for an account or the total server balance.

        Arguments:
        - *account* -- If this parameter is specified, returns the balance in the account.

        """
        try:
            return self.proxy.getbalance(account, conf)
        except JSONRPCException, e:
            raise _wrap_exception(e.error)
Exemplo n.º 32
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, e:
         raise _wrap_exception(e.error)
Exemplo n.º 33
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, e:
         raise _wrap_exception(e.error)
Exemplo n.º 34
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, e:
         raise _wrap_exception(e.error)
Exemplo n.º 35
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, e:
         raise _wrap_exception(e.error)
Exemplo n.º 36
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, e:
            raise _wrap_exception(e.error)
Exemplo n.º 37
0
 def importprivkey(self, address, label=None, rescan=False):
     """
     import the dump.
     
     """ 
     try:
         if label is None:
             return self.proxy.importprivkey(address, rescan)
         else:
             return self.proxy.importprivkey(address, label, rescan)
     except JSONRPCException,e:
         raise _wrap_exception(e.error)
Exemplo n.º 38
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, e:
            raise _wrap_exception(e.error)
Exemplo n.º 39
0
    def getucbalance(self, account="*", conf=0):
        """
        Get the current balance, either for an account or the total server balance.

        Arguments:
        - *account* -- If this parameter is specified, returns the balance in the account.

        """
        try:
            return self.proxy.getbalance(account, conf)
        except JSONRPCException,e:
            raise _wrap_exception(e.error)
Exemplo n.º 40
0
 def listaccounts(self, minconf=1):
     """
     Returns a list of account names.
     
     Arguments:
     
     - *minconf* -- Minimum number of confirmations before payments are included.
     """
     try:
         # return [AccountInfo(**x) for x in self.proxy.listaccounts(minconf)]
         return [x for x in self.proxy.listaccounts(minconf)]
     except JSONRPCException, e:
         raise _wrap_exception(e.error)
Exemplo n.º 41
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, e:
            raise _wrap_exception(e.error)
Exemplo n.º 42
0
 def listaccounts(self, minconf=1):
     """
     Returns a list of account names.
     
     Arguments:
     
     - *minconf* -- Minimum number of confirmations before payments are included.
     """
     try:
         #return [AccountInfo(**x) for x in self.proxy.listaccounts(minconf)]
         return [x for x in self.proxy.listaccounts(minconf)]
     except JSONRPCException, e:
         raise _wrap_exception(e.error)
Exemplo n.º 43
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, e:
            raise _wrap_exception(e.error)
Exemplo n.º 44
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, e:
            raise _wrap_exception(e.error)
Exemplo n.º 45
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, e:
            raise _wrap_exception(e.error)
Exemplo n.º 46
0
    def validateaddress(self, validateaddress):
        """
        Validate a bitcoin address and return information for it.

        The information is represented by a :class:`~bitcoin.data.AddressValidation` object.
        
        Arguments:
        
        - *validateaddress* -- Address to validate.

        """
        try:
            return AddressValidation(**self.proxy.validateaddress(validateaddress))
        except JSONRPCException, e:
            raise _wrap_exception(e.error)
Exemplo n.º 47
0
    def validateaddress(self, address):
        """
        Validate a bitcoin address and return information for it.

        The information is represented by a :class:`~bitcoin.data.AddressValidation` object.
        
        Arguments:
        
        - *validateaddress* -- Address to validate.

        """
        try:
            return AddressValidation(**self.proxy.validateaddress(address))
        except JSONRPCException, e:
            raise _wrap_exception(e.error)
Exemplo n.º 48
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, e:
            raise _wrap_exception(e.error)
Exemplo n.º 49
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, e:
            raise _wrap_exception(e.error)
Exemplo n.º 50
0
    def listaccounts(self):
        """
        Returns a list of the last transactions for an account.

        Each transaction is represented with a :class:`~bitcoin.data.TransactionInfo` object.

        Arguments:

        - *minconf* -- Minimum number of confirmations before payments are included.
        - *count* -- Number of transactions to return.

        """
        try:
            return self.proxy.listaccounts()
        except JSONRPCException, e:
            raise _wrap_exception(e.error)
Exemplo n.º 51
0
 def listreceivedbyaccount(self, minconf=1, includeempty=False):
     """
     Returns a list of accounts.
     
     Each account is represented with a :class:`~bitcoin.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, e:
         raise _wrap_exception(e.error)
Exemplo n.º 52
0
    def listtransactions(self, account, count=10):
        """
        Returns a list of the last transactions for an account.
        
        Each transaction is represented with a :class:`~bitcoin.data.TransactionInfo` object.
        
        Arguments:
        
        - *minconf* -- Minimum number of confirmations before payments are included.
        - *count* -- Number of transactions to return.

        """
        try:
            return [TransactionInfo(**x) for x in self.proxy.listtransactions(account, count)]
        except JSONRPCException, e:
            raise _wrap_exception(e.error)
Exemplo n.º 53
0
 def listreceivedbyaccount(self, minconf=1, includeempty=False):
     """
     Returns a list of accounts.
     
     Each account is represented with a :class:`~bitcoin.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,e:
         raise _wrap_exception(e.error)
Exemplo n.º 54
0
    def getnewaddress(self, account=None):
        """
        Returns a new bitcoin address for receiving payments.
        
        Arguments:

        - *account* -- If account is specified (recommended), it is added to the address book
          so that payments received with the address will be credited to it.

        """
        try:
            if account is None:
                return self.proxy.getnewaddress()
            else:
                return self.proxy.getnewaddress(account)
        except JSONRPCException, e:
            raise _wrap_exception(e.error)
Exemplo n.º 55
0
    def setgenerate(self, generate, genproclimit=None):
        """
        Enable or disable generation (mining) of coins.
        
        Arguments:

        - *generate* -- is :const:`True` or :const:`False` to turn generation on or off.
        - *genproclimit* -- Number of processors that are used for generation, -1 is unlimited.

        """
        try:
            if genproclimit is None:
                return self.proxy.setgenerate(generate)
            else:
                return self.proxy.setgenerate(generate, genproclimit)
        except JSONRPCException, e:
            raise _wrap_exception(e.error)
Exemplo n.º 56
0
    def getnewaddress(self, account=None):
        """
        Returns a new bitcoin address for receiving payments.
        
        Arguments:

        - *account* -- If account is specified (recommended), it is added to the address book
          so that payments received with the address will be credited to it.

        """
        try:
            if account is None:
                return self.proxy.getnewaddress()
            else:
                return self.proxy.getnewaddress(account)
        except JSONRPCException, e:
            raise _wrap_exception(e.error)
Exemplo n.º 57
0
    def setgenerate(self, generate, genproclimit=None):
        """
        Enable or disable generation (mining) of coins.
        
        Arguments:

        - *generate* -- is :const:`True` or :const:`False` to turn generation on or off.
        - *genproclimit* -- Number of processors that are used for generation, -1 is unlimited.

        """
        try:
            if genproclimit is None:
                return self.proxy.setgenerate(generate)
            else:
                return self.proxy.setgenerate(generate, genproclimit)
        except JSONRPCException, e:
            raise _wrap_exception(e.error)
Exemplo n.º 58
0
    def getbalance(self, account=None, minconf=None):
        """
        Get the current balance, either for an account or the total server balance.
        
        Arguments:
        - *account* -- If this parameter is specified, returns the balance in the account.
        - *minconf* -- Minimum number of confirmations required for transferred balance.

        """
        args = []
        if account:
            args.append(account)
            if minconf is not None:
                args.append(minconf)
        try:
            return self.proxy.getbalance(*args)
        except JSONRPCException,e:
            raise _wrap_exception(e.error)
Exemplo n.º 59
0
    def getbalance(self, account=None, minconf=None):
        """
        Get the current balance, either for an account or the total server balance.
        
        Arguments:
        - *account* -- If this parameter is specified, returns the balance in the account.
        - *minconf* -- Minimum number of confirmations required for transferred balance.

        """
        args = []
        if account:
            args.append(account)
            if minconf is not None:
                args.append(minconf)
        try:
            return self.proxy.getbalance(*args)
        except JSONRPCException, e:
            raise _wrap_exception(e.error)
Exemplo n.º 60
0
 def move(self, fromaccount, toaccount, amount, minconf=1, comment=None):
     """
     Move from one account in your wallet to another.
     
     Arguments:
     
     - *fromaccount* -- Source account name.
     - *toaccount* -- Destination account name.
     - *amount* -- Amount to transfer.
     - *minconf* -- Minimum number of confirmations required for transferred balance.
     - *comment* -- Comment to add to transaction log.
     
     """
     try:
         if comment is None:
             return self.proxy.move(fromaccount, toaccount, amount, minconf)
         else:
             return self.proxy.move(fromaccount, toaccount, amount, minconf, comment)
     except JSONRPCException, e:
         raise _wrap_exception(e.error)