mirror of
https://github.com/basicswap/basicswap.git
synced 2025-11-06 10:48:11 +01:00
Get Decred account key from seed.
This commit is contained in:
@@ -5,6 +5,8 @@
|
||||
# Distributed under the MIT software license, see the accompanying
|
||||
# file LICENSE or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
import logging
|
||||
|
||||
from basicswap.chainparams import Coins
|
||||
from basicswap.interface.btc import Secp256k1Interface
|
||||
from basicswap.util.address import (
|
||||
@@ -13,8 +15,10 @@ from basicswap.util.address import (
|
||||
)
|
||||
from basicswap.util.crypto import (
|
||||
blake256,
|
||||
hash160,
|
||||
ripemd160,
|
||||
)
|
||||
from basicswap.util.extkey import ExtKeyPair
|
||||
from basicswap.interface.dcr.rpc import make_rpc_func
|
||||
|
||||
|
||||
@@ -45,7 +49,15 @@ class DCRInterface(Secp256k1Interface):
|
||||
self._rpc_host = coin_settings.get('rpchost', '127.0.0.1')
|
||||
self._rpcport = coin_settings['rpcport']
|
||||
self._rpcauth = coin_settings['rpcauth']
|
||||
self._sc = swap_client
|
||||
self._log = self._sc.log if self._sc and self._sc.log else logging
|
||||
self.rpc = make_rpc_func(self._rpcport, self._rpcauth, host=self._rpc_host)
|
||||
if 'walletrpcport' in coin_settings:
|
||||
self.rpc_wallet = make_rpc_func(coin_settings['walletrpcport'], self._rpcauth, host=self._rpc_host)
|
||||
else:
|
||||
self.rpc_wallet = None
|
||||
|
||||
self._use_segwit = coin_settings['use_segwit']
|
||||
|
||||
def pkh(self, pubkey: bytes) -> bytes:
|
||||
return ripemd160(blake256(pubkey))
|
||||
@@ -69,6 +81,41 @@ class DCRInterface(Secp256k1Interface):
|
||||
|
||||
def testDaemonRPC(self, with_wallet=True) -> None:
|
||||
if with_wallet:
|
||||
self.rpc_wallet('getwalletinfo')
|
||||
self.rpc_wallet('getinfo')
|
||||
else:
|
||||
self.rpc('getblockchaininfo')
|
||||
|
||||
def checkWallets(self) -> int:
|
||||
# Only one wallet possible?
|
||||
return 1
|
||||
|
||||
def initialiseWallet(self, key: bytes) -> None:
|
||||
# Load with --create
|
||||
pass
|
||||
|
||||
def getDaemonVersion(self):
|
||||
return self.rpc('getnetworkinfo')['version']
|
||||
|
||||
def getBlockchainInfo(self):
|
||||
return self.rpc('getblockchaininfo')
|
||||
|
||||
def using_segwit(self) -> bool:
|
||||
return self._use_segwit
|
||||
|
||||
def getWalletInfo(self):
|
||||
rv = self.rpc_wallet('getinfo')
|
||||
return rv
|
||||
|
||||
def getSeedHash(self, seed: bytes) -> bytes:
|
||||
# m / purpose' / coin_type' / account' / change / address_index
|
||||
# m/44'/coin_type'/0'/0/0
|
||||
|
||||
ek = ExtKeyPair(self.coin_type())
|
||||
ek.set_seed(seed)
|
||||
|
||||
coin_type = self.chainparams_network()['bip44']
|
||||
ek_purpose = ek.derive(44 | (1 << 31))
|
||||
ek_coin = ek_purpose.derive(coin_type | (1 << 31))
|
||||
ek_account = ek_coin.derive(0 | (1 << 31))
|
||||
|
||||
return hash160(ek_account.encode_p())
|
||||
|
||||
@@ -16,7 +16,6 @@ def callrpc(rpc_port, auth, method, params=[], host='127.0.0.1'):
|
||||
x.__handler = None
|
||||
v = x.json_request(method, params)
|
||||
x.close()
|
||||
print('[rm] v', v)
|
||||
r = json.loads(v.decode('utf-8'))
|
||||
except Exception as ex:
|
||||
traceback.print_exc()
|
||||
|
||||
Reference in New Issue
Block a user