-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/11-validation' into feature/15-pytest
- Loading branch information
Showing
7 changed files
with
96 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
from . import * | ||
from .base import CoinBaseData |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,57 @@ | ||
# Copyright (c) 2020 The Atomic Swap Network Developers | ||
# Licensed under the GNU General Public License, Version 3. | ||
|
||
import json | ||
|
||
from dataclasses import dataclass | ||
from typing import List, Dict | ||
from typing import List, Dict, Tuple | ||
|
||
from ..util import resource_path | ||
|
||
|
||
@dataclass | ||
class CoinBaseData: | ||
name: str = None | ||
symbol: str = None | ||
insight: List[str] = None | ||
blockbook: List[str] = None | ||
electrumx: Dict = None | ||
p2pkh_prefix: bytes = None | ||
p2sh_prefix: bytes = None | ||
bech32_prefix: str = None | ||
|
||
@classmethod | ||
def from_json(cls, coin_name: str) -> 'CoinBaseData': | ||
low = coin_name.lower() | ||
if "Testnet" in coin_name: | ||
low, testnet = low.split() | ||
with open(resource_path("coins", low + "_" + testnet + ".json")) as f: | ||
coin_json = json.loads(f.read()) | ||
else: | ||
with open(resource_path("coins", low + ".json")) as f: | ||
coin_json = json.loads(f.read()) | ||
|
||
shaped_data = {} | ||
|
||
data_list: List[Tuple[str, type]] = [ | ||
("name", str), | ||
("symbol", str), | ||
("insight", list), | ||
("blockbook", list), | ||
("electrumx", dict), | ||
("p2pkh_prefix", int), | ||
("p2sh_prefix", int), | ||
("bech32_prefix", str) | ||
] | ||
|
||
for d in data_list: | ||
data = coin_json.get(d[0]) | ||
shaped_data[d[0]] = None if not isinstance(data, d[1]) else data | ||
if shaped_data[d[0]] is not None and d[0].endswith("prefix") and d[1] == int: | ||
try: | ||
shaped_data[d[0]] = bytes([data]) | ||
except Exception: | ||
pass | ||
|
||
return CoinBaseData(**shaped_data) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"name": "Bitcoin", | ||
"symbol": "BTC", | ||
"insight": [ | ||
"https://api.bitcore.io/api/BTC/mainnet/" | ||
], | ||
"blockbook": [ | ||
"https://btc1.trezor.io/api/", | ||
"https://btc2.trezor.io/api/", | ||
"https://btc3.trezor.io/api/" | ||
], | ||
"electrumx": { | ||
"electrum.blockstream.info": { | ||
"s": 50002, | ||
"t": 50001 | ||
}, | ||
"b.1209k.com": { | ||
"s": 50002, | ||
"t": 50001 | ||
} | ||
}, | ||
"p2pkh_prefix": 0, | ||
"p2sh_prefix": 5, | ||
"bech32_prefix": "bc" | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters