mirror of
https://github.com/aljazceru/btcpayserver.git
synced 2025-12-18 22:44:29 +01:00
Push rebase keypath and min fee logic down nbxplorer
This commit is contained in:
@@ -71,7 +71,7 @@ services:
|
|||||||
|
|
||||||
|
|
||||||
nbxplorer:
|
nbxplorer:
|
||||||
image: nicolasdorier/nbxplorer:2.0.0.39
|
image: nicolasdorier/nbxplorer:2.0.0.40
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
ports:
|
ports:
|
||||||
- "32838:32838"
|
- "32838:32838"
|
||||||
|
|||||||
@@ -50,7 +50,6 @@ namespace BTCPayServer
|
|||||||
public string CryptoCode { get; internal set; }
|
public string CryptoCode { get; internal set; }
|
||||||
public string BlockExplorerLink { get; internal set; }
|
public string BlockExplorerLink { get; internal set; }
|
||||||
public string UriScheme { get; internal set; }
|
public string UriScheme { get; internal set; }
|
||||||
public Money MinFee { get; internal set; }
|
|
||||||
public string DisplayName { get; set; }
|
public string DisplayName { get; set; }
|
||||||
|
|
||||||
[Obsolete("Should not be needed")]
|
[Obsolete("Should not be needed")]
|
||||||
|
|||||||
@@ -27,8 +27,7 @@ namespace BTCPayServer
|
|||||||
DefaultSettings = BTCPayDefaultSettings.GetDefaultSettings(NetworkType),
|
DefaultSettings = BTCPayDefaultSettings.GetDefaultSettings(NetworkType),
|
||||||
//https://github.com/satoshilabs/slips/blob/master/slip-0044.md
|
//https://github.com/satoshilabs/slips/blob/master/slip-0044.md
|
||||||
CoinType = NetworkType == NetworkType.Mainnet ? new KeyPath("5'")
|
CoinType = NetworkType == NetworkType.Mainnet ? new KeyPath("5'")
|
||||||
: new KeyPath("1'"),
|
: new KeyPath("1'")
|
||||||
MinFee = Money.Satoshis(1m)
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,8 +28,7 @@ namespace BTCPayServer
|
|||||||
},
|
},
|
||||||
CryptoImagePath = "imlegacy/dogecoin.png",
|
CryptoImagePath = "imlegacy/dogecoin.png",
|
||||||
DefaultSettings = BTCPayDefaultSettings.GetDefaultSettings(NetworkType),
|
DefaultSettings = BTCPayDefaultSettings.GetDefaultSettings(NetworkType),
|
||||||
CoinType = NetworkType == NetworkType.Mainnet ? new KeyPath("3'") : new KeyPath("1'"),
|
CoinType = NetworkType == NetworkType.Mainnet ? new KeyPath("3'") : new KeyPath("1'")
|
||||||
MinFee = Money.Coins(1m)
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,10 +47,10 @@
|
|||||||
<PrivateAssets>all</PrivateAssets>
|
<PrivateAssets>all</PrivateAssets>
|
||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
<PackageReference Include="NBitcoin" Version="4.1.2.15" />
|
<PackageReference Include="NBitcoin" Version="4.1.2.17" />
|
||||||
<PackageReference Include="NBitpayClient" Version="1.0.0.34" />
|
<PackageReference Include="NBitpayClient" Version="1.0.0.34" />
|
||||||
<PackageReference Include="DBriize" Version="1.0.0.4" />
|
<PackageReference Include="DBriize" Version="1.0.0.4" />
|
||||||
<PackageReference Include="NBXplorer.Client" Version="2.0.0.11" />
|
<PackageReference Include="NBXplorer.Client" Version="2.0.0.12" />
|
||||||
<PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
|
<PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
|
||||||
<PackageReference Include="NicolasDorier.CommandLine" Version="1.0.0.2" />
|
<PackageReference Include="NicolasDorier.CommandLine" Version="1.0.0.2" />
|
||||||
<PackageReference Include="NicolasDorier.CommandLine.Configuration" Version="1.0.0.3" />
|
<PackageReference Include="NicolasDorier.CommandLine.Configuration" Version="1.0.0.3" />
|
||||||
|
|||||||
@@ -204,7 +204,8 @@ namespace BTCPayServer.Controllers
|
|||||||
{
|
{
|
||||||
strategy = newStrategy;
|
strategy = newStrategy;
|
||||||
strategy.AccountKeyPath = vm.KeyPath == null ? null : KeyPath.Parse(vm.KeyPath);
|
strategy.AccountKeyPath = vm.KeyPath == null ? null : KeyPath.Parse(vm.KeyPath);
|
||||||
strategy.RootFingerprint = string.IsNullOrEmpty(vm.RootFingerprint)? (HDFingerprint?)null : new HDFingerprint(NBitcoin.DataEncoders.Encoders.Hex.DecodeData(vm.RootFingerprint));
|
strategy.RootFingerprint = string.IsNullOrEmpty(vm.RootFingerprint) ? (HDFingerprint?)null : new HDFingerprint(NBitcoin.DataEncoders.Encoders.Hex.DecodeData(vm.RootFingerprint));
|
||||||
|
strategy.ExplicitAccountKey = string.IsNullOrEmpty(vm.AccountKey) ? null : new BitcoinExtPubKey(vm.AccountKey, network.NBitcoinNetwork);
|
||||||
strategy.Source = vm.Source;
|
strategy.Source = vm.Source;
|
||||||
vm.DerivationScheme = strategy.AccountDerivation.ToString();
|
vm.DerivationScheme = strategy.AccountDerivation.ToString();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -282,38 +282,21 @@ namespace BTCPayServer.Controllers
|
|||||||
psbtRequest.ExplicitChangeAddress = psbtDestination.Destination;
|
psbtRequest.ExplicitChangeAddress = psbtDestination.Destination;
|
||||||
}
|
}
|
||||||
psbtDestination.SubstractFees = sendModel.SubstractFees;
|
psbtDestination.SubstractFees = sendModel.SubstractFees;
|
||||||
|
if (derivationSettings.AccountKeyPath != null && derivationSettings.AccountKeyPath.Indexes.Length != 0)
|
||||||
|
{
|
||||||
|
psbtRequest.RebaseKeyPaths = new List<PSBTRebaseKeyRules>()
|
||||||
|
{
|
||||||
|
new PSBTRebaseKeyRules()
|
||||||
|
{
|
||||||
|
AccountKeyPath = derivationSettings.AccountKeyPath,
|
||||||
|
AccountKey = derivationSettings.AccountKey,
|
||||||
|
MasterFingerprint = derivationSettings.RootFingerprint is HDFingerprint fp ? fp : default
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
var psbt = (await nbx.CreatePSBTAsync(derivationSettings.AccountDerivation, psbtRequest, cancellationToken));
|
var psbt = (await nbx.CreatePSBTAsync(derivationSettings.AccountDerivation, psbtRequest, cancellationToken));
|
||||||
if (psbt == null)
|
if (psbt == null)
|
||||||
throw new NotSupportedException("You need to update your version of NBXplorer");
|
throw new NotSupportedException("You need to update your version of NBXplorer");
|
||||||
|
|
||||||
if (network.MinFee != null)
|
|
||||||
{
|
|
||||||
psbt.PSBT.TryGetFee(out var fee);
|
|
||||||
if (fee < network.MinFee)
|
|
||||||
{
|
|
||||||
psbtRequest.FeePreference = new FeePreference() { ExplicitFee = network.MinFee };
|
|
||||||
psbt = (await nbx.CreatePSBTAsync(derivationSettings.AccountDerivation, psbtRequest, cancellationToken));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (derivationSettings.AccountKeyPath != null && derivationSettings.AccountKeyPath.Indexes.Length != 0)
|
|
||||||
{
|
|
||||||
// NBX only know the path relative to the account xpub.
|
|
||||||
// Here we rebase the hd_keys in the PSBT to have a keypath relative to the root HD so the wallet can sign
|
|
||||||
// Note that the fingerprint of the hd keys are now 0, which is wrong
|
|
||||||
// However, hardware wallets does not give a damn, and sometimes does not even allow us to get this fingerprint anyway.
|
|
||||||
foreach (var o in psbt.PSBT.Inputs.OfType<PSBTCoin>().Concat(psbt.PSBT.Outputs))
|
|
||||||
{
|
|
||||||
var rootFP = derivationSettings.RootFingerprint is HDFingerprint fp ? fp : default;
|
|
||||||
foreach (var keypath in o.HDKeyPaths.ToList())
|
|
||||||
{
|
|
||||||
var newKeyPath = derivationSettings.AccountKeyPath.Derive(keypath.Value.Item2);
|
|
||||||
o.HDKeyPaths.Remove(keypath.Key);
|
|
||||||
o.HDKeyPaths.Add(keypath.Key, Tuple.Create(rootFP, newKeyPath));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return psbt;
|
return psbt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -126,12 +126,23 @@ namespace BTCPayServer
|
|||||||
public BTCPayNetwork Network { get; set; }
|
public BTCPayNetwork Network { get; set; }
|
||||||
public string Source { get; set; }
|
public string Source { get; set; }
|
||||||
public KeyPath AccountKeyPath { get; set; }
|
public KeyPath AccountKeyPath { get; set; }
|
||||||
|
|
||||||
public DerivationStrategyBase AccountDerivation { get; set; }
|
public DerivationStrategyBase AccountDerivation { get; set; }
|
||||||
public string AccountOriginal { get; set; }
|
public string AccountOriginal { get; set; }
|
||||||
|
|
||||||
public HDFingerprint? RootFingerprint { get; set; }
|
public HDFingerprint? RootFingerprint { get; set; }
|
||||||
|
|
||||||
|
public BitcoinExtPubKey ExplicitAccountKey { get; set; }
|
||||||
|
|
||||||
|
[JsonIgnore]
|
||||||
|
public BitcoinExtPubKey AccountKey
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return ExplicitAccountKey ?? new BitcoinExtPubKey(AccountDerivation.GetExtPubKeys().First(), Network.NBitcoinNetwork);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public string Label { get; set; }
|
public string Label { get; set; }
|
||||||
|
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
|
|||||||
@@ -39,5 +39,6 @@ namespace BTCPayServer.Models.StoreViewModels
|
|||||||
public IFormFile ColdcardPublicFile{ get; set; }
|
public IFormFile ColdcardPublicFile{ get; set; }
|
||||||
public string Config { get; set; }
|
public string Config { get; set; }
|
||||||
public string Source { get; set; }
|
public string Source { get; set; }
|
||||||
|
public string AccountKey { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,6 +52,7 @@
|
|||||||
<input id="KeyPath" asp-for="KeyPath" type="hidden" />
|
<input id="KeyPath" asp-for="KeyPath" type="hidden" />
|
||||||
<input id="Source" asp-for="Source" type="hidden" />
|
<input id="Source" asp-for="Source" type="hidden" />
|
||||||
<input id="RootFingerprint" asp-for="RootFingerprint" type="hidden" />
|
<input id="RootFingerprint" asp-for="RootFingerprint" type="hidden" />
|
||||||
|
<input id="AccountKey" asp-for="AccountKey" type="hidden" />
|
||||||
<input id="Config" asp-for="Config" type="hidden" />
|
<input id="Config" asp-for="Config" type="hidden" />
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label asp-for="DerivationScheme"></label>
|
<label asp-for="DerivationScheme"></label>
|
||||||
@@ -141,6 +142,7 @@
|
|||||||
<input id="KeyPath" asp-for="KeyPath" type="hidden" />
|
<input id="KeyPath" asp-for="KeyPath" type="hidden" />
|
||||||
<input id="Source" asp-for="Source" type="hidden" />
|
<input id="Source" asp-for="Source" type="hidden" />
|
||||||
<input id="RootFingerprint" asp-for="RootFingerprint" type="hidden" />
|
<input id="RootFingerprint" asp-for="RootFingerprint" type="hidden" />
|
||||||
|
<input id="AccountKey" asp-for="AccountKey" type="hidden" />
|
||||||
<input type="hidden" asp-for="DerivationScheme" />
|
<input type="hidden" asp-for="DerivationScheme" />
|
||||||
<input type="hidden" asp-for="Enabled" />
|
<input type="hidden" asp-for="Enabled" />
|
||||||
<input id="Config" asp-for="Config" type="hidden" />
|
<input id="Config" asp-for="Config" type="hidden" />
|
||||||
|
|||||||
@@ -50,6 +50,7 @@
|
|||||||
|
|
||||||
$("#DerivationScheme").val(result.derivationScheme);
|
$("#DerivationScheme").val(result.derivationScheme);
|
||||||
$("#RootFingerprint").val(result.rootFingerprint);
|
$("#RootFingerprint").val(result.rootFingerprint);
|
||||||
|
$("#AccountKey").val(result.extPubKey);
|
||||||
$("#Source").val(result.source);
|
$("#Source").val(result.source);
|
||||||
$("#DerivationSchemeFormat").val("BTCPay");
|
$("#DerivationSchemeFormat").val("BTCPay");
|
||||||
$("#KeyPath").val(keypath);
|
$("#KeyPath").val(keypath);
|
||||||
|
|||||||
Reference in New Issue
Block a user