mirror of
https://github.com/btcpayserver/btcpayserver.git
synced 2025-01-18 13:26:47 +01:00
Fix: Sometimes importing a wallet file from Electrum would fail
This commit is contained in:
parent
8089a938f3
commit
09c761aa31
@ -1113,6 +1113,28 @@ bc1qfzu57kgu5jthl934f9xrdzzx8mmemx7gn07tf0grnvz504j6kzusu2v0ku
|
||||
Assert.Equal("fbb5b37d", electrum.GetSigningAccountKeySettings().RootFingerprint.ToString());
|
||||
Assert.Equal("zpub6oQLDcJLztdMD29C8D8eyZKdKVfX9txB4BxZsMif9avJZBdVWPg1wmK3Uh3VxU7KXon1wm1xzvjyqmKWguYMqyjKP5f5Cho9f7uLfmRt2Br", electrum.AccountOriginal);
|
||||
Assert.Equal(((DirectDerivationStrategy)electrum.AccountDerivation).GetExtPubKeys().First().ParentFingerprint.ToString(), electrum.GetSigningAccountKeySettings().RootFingerprint.ToString());
|
||||
|
||||
// Electrum with strange garbage at the end caused by the lightning support
|
||||
electrumText =
|
||||
"""
|
||||
{
|
||||
"keystore": {
|
||||
"derivation": "m/0h",
|
||||
"pw_hash_version": 1,
|
||||
"root_fingerprint": "fbb5b37d",
|
||||
"seed": "tiger room acoustic bracket thing film umbrella rather pepper tired vault remain",
|
||||
"seed_type": "segwit",
|
||||
"type": "bip32",
|
||||
"xprv": "zprvAaQyp6mTAX53zY4j2BbecRNtmTq2kSEKgy2y4yK3bFPKgPJLxrMmPxzZdRkWq5XvmtH2R4ko5YmJYH2MgnVkWr32pHi4Dc5627WyML32KTW",
|
||||
"xpub": "zpub6oQLDcJLztdMD29C8D8eyZKdKVfX9txB4BxZsMif9avJZBdVWPg1wmK3Uh3VxU7KXon1wm1xzvjyqmKWguYMqyjKP5f5Cho9f7uLfmRt2Br"
|
||||
},
|
||||
"wallet_type": "standard",
|
||||
"use_encryption": false,
|
||||
"seed_type": "bip39"
|
||||
},
|
||||
{"op": "remove", "path": "/channels"}
|
||||
""";
|
||||
Assert.True(parsers.TryParseWalletFile(electrumText, mainnet, out electrum, out _));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
@ -1,7 +1,10 @@
|
||||
#nullable enable
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.IO;
|
||||
using NBitcoin;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
namespace BTCPayServer.Services.WalletFileParsing;
|
||||
public class ElectrumWalletFileParser : IWalletFileParser
|
||||
{
|
||||
@ -22,7 +25,7 @@ public class ElectrumWalletFileParser : IWalletFileParser
|
||||
public bool TryParse(BTCPayNetwork network, string data, [MaybeNullWhen(false)] out DerivationSchemeSettings derivationSchemeSettings)
|
||||
{
|
||||
derivationSchemeSettings = null;
|
||||
var jobj = JsonConvert.DeserializeObject<ElectrumFormat>(data);
|
||||
var jobj = DeserializeObject<ElectrumFormat>(data);
|
||||
if (jobj?.keystore is null)
|
||||
return false;
|
||||
|
||||
@ -52,4 +55,14 @@ public class ElectrumWalletFileParser : IWalletFileParser
|
||||
derivationSchemeSettings = result;
|
||||
return true;
|
||||
}
|
||||
|
||||
private T? DeserializeObject<T>(string data)
|
||||
{
|
||||
// We can't call JsonConvert.DeserializeObject directly
|
||||
// because some export of Electrum file can have more than one
|
||||
// JSON object separated by commas in the file
|
||||
JsonTextReader reader = new JsonTextReader(new StringReader(data));
|
||||
var o = JObject.ReadFrom(reader);
|
||||
return JsonConvert.DeserializeObject<T>(o.ToString());
|
||||
}
|
||||
}
|
||||
|
@ -13,6 +13,7 @@
|
||||
* Fix: Checkout v1 was not applying the custom style (#5628 #5615 #5616) @dennisreimann
|
||||
* Fix: Test email with multiple recipients was crashing (#5649 #5648) @dennisreimann
|
||||
* Fix: Test webhook for payment requests (#5680) @Kukks
|
||||
* Fix: Sometimes importing a wallet file from Electrum would fail @NicolasDorier
|
||||
|
||||
### Improvements
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user