Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return self.msg
try:
import configparser
except ImportError:
import ConfigParser as configparser
def _read_from_config(configparser, section, value, fallback=None):
try:
return configparser.get(section, value)
except Exception:
return fallback
class LitecoindClient(BaseClient):
"""
Class to interact with litecoind, the Litecoin deamon
"""
@staticmethod
def from_config(configfile=None, network='litecoin'):
"""
Read settings from litecoind config file
:param configfile: Path to config file. Leave empty to look in default places
:type: str
:param network: Litecoin mainnet or testnet. Default is litecoin mainnet
:type: str
:return LitecoindClient:
"""
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see .
#
from datetime import datetime
import struct
from bitcoinlib.main import MAX_TRANSACTIONS
from bitcoinlib.services.baseclient import BaseClient
from bitcoinlib.transactions import Transaction
PROVIDERNAME = 'litecoinblockexplorer'
REQUEST_LIMIT = 50
class LitecoinBlockexplorerClient(BaseClient):
def __init__(self, network, base_url, denominator, *args):
super(self.__class__, self).__init__(network, PROVIDERNAME, base_url, denominator, *args)
def compose_request(self, category, data, cmd='', variables=None, method='get', offset=0):
url_path = category
if data:
url_path += '/' + data + '/' + cmd
if variables is None:
variables = {}
variables.update({'from': offset, 'to': offset+REQUEST_LIMIT})
return self.request(url_path, variables, method=method)
def _convert_to_transaction(self, tx):
if tx['confirmations']:
status = 'confirmed'
#
import logging
import struct
from datetime import datetime
from bitcoinlib.main import MAX_TRANSACTIONS
from bitcoinlib.services.baseclient import BaseClient
from bitcoinlib.transactions import Transaction
PROVIDERNAME = 'blockchaininfo'
_logger = logging.getLogger(__name__)
class BlockchainInfoClient(BaseClient):
def __init__(self, network, base_url, denominator, *args):
super(self.__class__, self).__init__(network, PROVIDERNAME, base_url, denominator, *args)
def compose_request(self, cmd, parameter='', variables=None, method='get'):
url_path = cmd
if parameter:
url_path += '/' + parameter
return self.request(url_path, variables, method=method)
def getbalance(self, addresslist):
addresses = {'active': '|'.join(addresslist)}
res = self.compose_request('balance', variables=addresses)
balance = 0
for address in res:
balance += res[address]['final_balance']
# along with this program. If not, see .
#
import logging
from datetime import datetime
from bitcoinlib.main import MAX_TRANSACTIONS
from bitcoinlib.services.baseclient import BaseClient, ClientError
from bitcoinlib.transactions import Transaction
from bitcoinlib.encoding import to_hexstring
PROVIDERNAME = 'blockcypher'
_logger = logging.getLogger(__name__)
class BlockCypher(BaseClient):
def __init__(self, network, base_url, denominator, *args):
super(self.__class__, self).__init__(network, PROVIDERNAME, base_url, denominator, *args)
def compose_request(self, function, data, parameter='', variables=None, method='get'):
url_path = function + '/' + data
if parameter:
url_path += '/' + parameter
if variables is None:
variables = {}
if self.api_key:
variables.update({'token': self.api_key})
return self.request(url_path, variables, method)
def getbalance(self, addresslist):
addresslist = self._addresslist_convert(addresslist)
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see .
#
from datetime import datetime
import struct
from bitcoinlib.services.baseclient import BaseClient, ClientError
from bitcoinlib.transactions import Transaction
PROVIDERNAME = 'blockexplorer'
class BlockExplorerClient(BaseClient):
def __init__(self, network, base_url, denominator, *args):
super(self.__class__, self).__init__(network, PROVIDERNAME, base_url, denominator, *args)
def compose_request(self, category, data, cmd='', variables=None, method='get'):
url_path = category
if data:
url_path += '/' + data + '/' + cmd
return self.request(url_path, variables, method=method)
def getutxos(self, addresslist):
addresses = ','.join(addresslist)
res = self.compose_request('addrs', addresses, 'utxo')
txs = []
for tx in res:
txs.append({
import math
import logging
from datetime import datetime
from bitcoinlib.main import MAX_TRANSACTIONS
from bitcoinlib.services.baseclient import BaseClient, ClientError
from bitcoinlib.transactions import Transaction
from bitcoinlib.keys import deserialize_address
from bitcoinlib.encoding import EncodingError, varstr, to_bytes
_logger = logging.getLogger(__name__)
PROVIDERNAME = 'blockchair'
REQUEST_LIMIT = 100
class BlockChairClient(BaseClient):
def __init__(self, network, base_url, denominator, *args):
super(self.__class__, self).__init__(network, PROVIDERNAME, base_url, denominator, *args)
def compose_request(self, command, query_vars=None, data=None, offset=0):
url_path = ''
variables = {}
if command != 'stats':
variables.update({'limit': REQUEST_LIMIT})
if offset:
variables.update({'offset': offset})
if command:
url_path += command
if data:
if url_path[-1:] != '/':
url_path += '/'
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see .
#
from bitcoinlib.services.baseclient import BaseClient
PROVIDERNAME = 'coinfees'
class CoinfeesClient(BaseClient):
def __init__(self, network, base_url, denominator, api_key=''):
super(self.__class__, self).__init__(network, PROVIDERNAME, base_url, denominator, api_key)
def compose_request(self, category, cmd, method='get'):
url_path = category
if cmd:
url_path += '/' + cmd
return self.request(url_path, method=method)
def estimatefee(self, blocks):
res = self.compose_request('fees', 'recommended')
if blocks < 1:
return res['fastestFee'] * 1024
elif blocks <= 3:
return res['halfHourFee'] * 1024
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see .
#
from bitcoinlib.services.baseclient import BaseClient
PROVIDERNAME = 'estimatefee'
class EstimateFeeClient(BaseClient):
def __init__(self, network, base_url, denominator, *args):
super(self.__class__, self).__init__(network, PROVIDERNAME, base_url, denominator, *args)
def compose_request(self, cmd, parameter, method='get'):
url_path = cmd + '/' + parameter
res = self.request(url_path, method=method)
return int(float(res) * self.units)
def estimatefee(self, blocks):
return self.compose_request('n', str(blocks))
# along with this program. If not, see .
#
import logging
from datetime import datetime
from bitcoinlib.main import MAX_TRANSACTIONS
from bitcoinlib.services.baseclient import BaseClient, ClientError
from bitcoinlib.transactions import Transaction
_logger = logging.getLogger(__name__)
PROVIDERNAME = 'bitgo'
LIMIT_TX = 49
class BitGoClient(BaseClient):
def __init__(self, network, base_url, denominator, *args):
super(self.__class__, self).__init__(network, PROVIDERNAME, base_url, denominator, *args)
def compose_request(self, category, data, cmd='', variables=None, method='get'):
if data:
data = '/' + data
url_path = category + data
if cmd != '':
url_path += '/' + cmd
return self.request(url_path, variables, method=method)
def getbalance(self, addresslist):
balance = 0
for address in addresslist:
res = self.compose_request('address', address)
import logging
from datetime import datetime
from bitcoinlib.main import MAX_TRANSACTIONS
from bitcoinlib.services.baseclient import BaseClient, ClientError
from bitcoinlib.transactions import Transaction
from bitcoinlib.encoding import varstr, to_bytes, to_hexstring
_logger = logging.getLogger(__name__)
PROVIDERNAME = 'smartbit'
# Please note: In the Bitaps API, the first couple of Bitcoin blocks are not correctly indexed,
# so transactions from these blocks are missing.
class SmartbitClient(BaseClient):
def __init__(self, network, base_url, denominator, *args):
super(self.__class__, self).__init__(network, PROVIDERNAME, base_url, denominator, *args)
def compose_request(self, category, command='', data='', variables=None, type='blockchain', method='get'):
url_path = type + '/' + category
if data:
if url_path[-1:] != '/':
url_path += '/'
url_path += data
if command:
url_path += '/' + command
return self.request(url_path, variables=variables, method=method)
def _parse_transaction(self, tx):
status = 'unconfirmed'