Integrate Decred with wallet encryption.

dcrwallet requires the password to be entered at the first startup when encrypted.
basicswap-run with --startonlycoin=decred and the WALLET_ENCRYPTION_PWD environment var set can be used for the initial sync.
This commit is contained in:
tecnovert
2024-05-22 09:59:57 +02:00
parent fcf234ef34
commit 76445146fb
7 changed files with 102 additions and 10 deletions

View File

@@ -6861,6 +6861,12 @@ class BasicSwap(BaseApp):
self.ci(coin).setAnonTxRingSize(new_anon_tx_ring_size)
break
if 'wallet_pwd' in data:
new_wallet_pwd = data['wallet_pwd']
if settings_cc.get('wallet_pwd', '') != new_wallet_pwd:
settings_changed = True
settings_cc['wallet_pwd'] = new_wallet_pwd
if settings_changed:
settings_path = os.path.join(self.data_dir, cfg.CONFIG_FILENAME)
settings_path_new = settings_path + '.new'

View File

@@ -1379,7 +1379,7 @@ class BTCInterface(Secp256k1Interface):
return True
return False
def isWalletEncryptedLocked(self):
def isWalletEncryptedLocked(self) -> (bool, bool):
wallet_info = self.rpc_wallet('getwalletinfo')
encrypted = 'unlocked_until' in wallet_info
locked = encrypted and wallet_info['unlocked_until'] <= 0

View File

@@ -320,6 +320,44 @@ class DCRInterface(Secp256k1Interface):
# Load with --create
pass
def isWalletEncrypted(self) -> bool:
return True
def isWalletLocked(self) -> bool:
walletislocked = self.rpc_wallet('walletislocked')
return walletislocked
def isWalletEncryptedLocked(self) -> (bool, bool):
walletislocked = self.rpc_wallet('walletislocked')
return True, walletislocked
def changeWalletPassword(self, old_password: str, new_password: str):
self._log.info('changeWalletPassword - {}'.format(self.ticker()))
if old_password == '':
# Read initial pwd from settings
settings = self._sc.getChainClientSettings(self.coin_type())
old_password = settings['wallet_pwd']
self.rpc_wallet('walletpassphrasechange', [old_password, new_password])
# Lock wallet to match other coins
self.rpc_wallet('walletlock')
# Clear initial password
self._sc.editSettings(self.coin_name().lower(), {'wallet_pwd': ''})
def unlockWallet(self, password: str):
if password == '':
return
self._log.info('unlockWallet - {}'.format(self.ticker()))
# Max timeout value, ~3 years
self.rpc_wallet('walletpassphrase', [password, 100000000])
self._sc.checkWalletSeed(self.coin_type())
def lockWallet(self):
self._log.info('lockWallet - {}'.format(self.ticker()))
self.rpc_wallet('walletlock')
def getWalletSeedID(self):
masterpubkey = self.rpc_wallet('getmasterpubkey')
masterpubkey_data = self.decode_address(masterpubkey)[4:]