Skip to content

Commit

Permalink
Start change to electrumx servers
Browse files Browse the repository at this point in the history
  • Loading branch information
primal100 committed Feb 4, 2018
1 parent bb3dade commit c5654e0
Show file tree
Hide file tree
Showing 13 changed files with 1,356 additions and 7 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ https://live.blockcypher.com/ltc/tx/3b936180daf05adcd7e9f04b60e1ba9a4a6db486c0ad
Aim is to provide a simple, class-based API which makes switching between different coins and mainnet and testnet, and adding new coins, all very easy.

Roadmap:
* Replaceable transactions
* Change from explorers to electrumx servers
* Correct fee detection algorithm
* Extend wallets to make transactions
Expand Down
24 changes: 23 additions & 1 deletion cryptos/coins/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from ..blocks import mk_merkle_proof
from .. import segwit_addr
from ..explorers import blockchain
from ..electrumx_client.rpc import ElectrumXClient
from ..keystore import *
from ..wallet import *
from ..py3specials import *
Expand All @@ -21,6 +22,16 @@ class BaseCoin(object):
script_magicbyte = None
segwit_hrp = None
explorer = blockchain
client = ElectrumXClient
client_kwargs = {
'server_file': 'bitcoin.json',
'servers': (),
'host': None,
'port': 50001,
'timeout': 15,
'max_servers': 5,
'loop': None
}
is_testnet = False
address_prefixes = ()
testnet_overrides = {}
Expand Down Expand Up @@ -73,12 +84,23 @@ def __init__(self, testnet=False, **kwargs):
else:
self.script_prefixes = ()
self.secondary_hashcode = self.secondary_hashcode or self.hashcode
self._rpc_client = None

@property
def rpc_client(self):
"""
Connect to remove server
"""
if not self._rpc_client:
self._rpc_client = self.client(**self.client_kwargs)
return self._rpc_client


def unspent(self, *addrs):
"""
Get unspent transactions for addresses
"""
return self.explorer.unspent(*addrs, coin_symbol=self.coin_symbol)
return self.rpc_client.unspent(*addrs)

def history(self, *addrs, **kwargs):
"""
Expand Down
6 changes: 6 additions & 0 deletions cryptos/coins/bitcoin.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ class Bitcoin(BaseCoin):
magicbyte = 0
script_magicbyte = 5
segwit_hrp = "bc"
client_kwargs = {
'server_file': 'bitcoin.json',
}

testnet_overrides = {
'display_name': "Bitcoin Testnet",
Expand All @@ -19,6 +22,9 @@ class Bitcoin(BaseCoin):
'segwit_hrp': 'tb',
'hd_path': 1,
'wif_prefix': 0xef,
'client_kwargs': {
'server_file': 'bitcoin_testnet.json',
},
'xprv_headers': {
'p2pkh': 0x04358394,
'p2wpkh-p2sh': 0x044a4e28,
Expand Down
1 change: 1 addition & 0 deletions cryptos/electrumx_client/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .rpc import *
Loading

0 comments on commit c5654e0

Please sign in to comment.