Пример #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)
Пример #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)
Пример #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)
Пример #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)
Пример #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)
Пример #6
0
 def getpeerinfo(self):
     """
     Returns an peer info.
     """
     try:
         return self.proxy.getpeerinfo()
     except JSONRPCException,e:
         raise _wrap_exception(e.error)
Пример #7
0
 def getpeerinfo(self):
     """
     Returns an peer info.
     """
     try:
         return self.proxy.getpeerinfo()
     except JSONRPCException, e:
         raise _wrap_exception(e.error)
Пример #8
0
 def stop(self):
     """
     Stop bitcoin server.
     """
     try:
         self.proxy.stop()
     except JSONRPCException, e:
         raise _wrap_exception(e.error)
Пример #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)
Пример #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)
Пример #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)
Пример #12
0
 def stop(self):
     """
     Stop bitcoin server.
     """
     try:
         self.proxy.stop()
     except JSONRPCException, e:
         raise _wrap_exception(e.error)
Пример #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)
Пример #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)
Пример #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)
Пример #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)
Пример #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)
Пример #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)
Пример #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)
Пример #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)
Пример #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)
Пример #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)
Пример #23
0
 def dumpprivkey(self, address):
     """
     Returns the dump.
     
     """
     try:
         return self.proxy.dumpprivkey(address)
     except JSONRPCException, e:
         raise _wrap_exception(e.error)
Пример #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)
Пример #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)
Пример #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)
Пример #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)
Пример #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)
Пример #29
0
 def dumpprivkey(self, address):
     """
     Returns the dump.
     
     """ 
     try:
         return self.proxy.dumpprivkey(address) 
     except JSONRPCException,e:
         raise _wrap_exception(e.error)
Пример #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)
Пример #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)
Пример #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)
Пример #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)
Пример #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)
Пример #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)
Пример #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)
Пример #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)
Пример #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)
Пример #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)
Пример #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)
Пример #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)
Пример #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)
Пример #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)
Пример #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)
Пример #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)
Пример #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)
Пример #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)
Пример #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)
Пример #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)
Пример #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)
Пример #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)
Пример #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)
Пример #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)
Пример #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)
Пример #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)
Пример #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)
Пример #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)
Пример #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)
Пример #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)
Пример #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)