Fix after (Select coins for round abstraction)
MODIFY
WalletWasabi/Blockchain/TransactionOutputs/ISmartCoin.cs
WalletWasabi/Blockchain/TransactionOutputs/ISmartCoin.cs
@@ -6,6 +6,8 @@ public interface ISmartCoin
{
Money Amount { get; }
+ /// <summary>Script type if available, throw an exception if it is not available.</summary>
+ /// <remarks>Note there might be a new script type that even NBitcoin does not support.</remarks>
ScriptType ScriptType { get; }
double AnonymitySet { get; }

MODIFY
WalletWasabi/Crypto/Bip322Signature.cs
WalletWasabi/Crypto/Bip322Signature.cs
@@ -41,7 +41,7 @@ public record Bip322Signature : IBitcoinSerializable
NBitcoinExtensions.FromBytes<Bip322Signature>(bip322SignatureBytes);
public bool Verify(uint256 hash, Script scriptPubKey) =>
- scriptPubKey.GetScriptType() switch
+ scriptPubKey.TryGetScriptType() switch
{
ScriptType.P2WPKH => VerifyP2wpkh(hash, scriptPubKey),
ScriptType.Taproot => VerifyP2tr(hash, scriptPubKey),

MODIFY
WalletWasabi/Crypto/OwnershipProof.cs
WalletWasabi/Crypto/OwnershipProof.cs
@@ -47,7 +47,7 @@ public record OwnershipProof : IBitcoinSerializable
Bip322Signature.Generate(key, proofBody.SignatureHash(key.PubKey.GetScriptPubKey(scriptPubKeyType), commitmentData), scriptPubKeyType));
public bool VerifyOwnership(Script scriptPubKey, byte[] commitmentData, bool requireUserConfirmation) =>
- scriptPubKey.GetScriptType() switch
+ scriptPubKey.TryGetScriptType() switch
{
ScriptType.P2WPKH or ScriptType.Taproot => VerifyOwnershipProof(scriptPubKey, commitmentData, requireUserConfirmation),
_ => throw new NotImplementedException("Only P2WPKH and P2TR scripts are supported."),

MODIFY
WalletWasabi/Extensions/NBitcoinExtensions.cs
WalletWasabi/Extensions/NBitcoinExtensions.cs
@@ -475,14 +475,14 @@ public static class NBitcoinExtensions
output.Value + feeRate.GetFee(output.ScriptPubKey.EstimateOutputVsize());
public static Money EffectiveValue(this ICoin coin, FeeRate feeRate, CoordinationFeeRate coordinationFeeRate)
- => EffectiveValue(coin.TxOut.Value, coin.TxOut.ScriptPubKey.GetScriptType(), feeRate, coordinationFeeRate);
+ => EffectiveValue(coin.TxOut.Value, virtualSize: coin.TxOut.ScriptPubKey.EstimateInputVsize(), feeRate, coordinationFeeRate);
public static Money EffectiveValue(this ISmartCoin coin, FeeRate feeRate, CoordinationFeeRate coordinationFeeRate)
- => EffectiveValue(coin.Amount, coin.ScriptType, feeRate, coordinationFeeRate);
+ => EffectiveValue(coin.Amount, virtualSize: coin.ScriptType.EstimateInputVsize(), feeRate, coordinationFeeRate);
- private static Money EffectiveValue(Money amount, ScriptType scriptType, FeeRate feeRate, CoordinationFeeRate coordinationFeeRate)
+ private static Money EffectiveValue(Money amount, int virtualSize, FeeRate feeRate, CoordinationFeeRate coordinationFeeRate)
{
- var netFee = feeRate.GetFee(scriptType.EstimateInputVsize());
+ var netFee = feeRate.GetFee(virtualSize);
var coordFee = coordinationFeeRate.GetFee(amount);
return amount - netFee - coordFee;
@@ -511,11 +511,11 @@ public static class NBitcoinExtensions
}
/// <summary>
- /// Extracts a unique public key identifier. If it can't do that, then it returns the scriptpubkey byte array.
+ /// Extracts a unique public key identifier. If it can't do that, then it returns the scriptPubKey byte array.
/// </summary>
public static byte[] ExtractKeyId(this Script scriptPubKey)
{
- return scriptPubKey.GetScriptType() switch
+ return scriptPubKey.TryGetScriptType() switch
{
ScriptType.P2WPKH => PayToWitPubKeyHashTemplate.Instance.ExtractScriptPubKeyParameters(scriptPubKey)!.ToBytes(),
ScriptType.P2PKH => PayToPubkeyHashTemplate.Instance.ExtractScriptPubKeyParameters(scriptPubKey)!.ToBytes(),
@@ -525,6 +525,11 @@ public static class NBitcoinExtensions
}
public static ScriptType GetScriptType(this Script script)
+ {
+ return TryGetScriptType(script) ?? throw new NotImplementedException($"Unsupported script type.");
+ }
+
+ public static ScriptType? TryGetScriptType(this Script script)
{
foreach (ScriptType scriptType in new ScriptType[] { ScriptType.P2WPKH, ScriptType.P2PKH, ScriptType.P2PK, ScriptType.Taproot })
{
@@ -534,6 +539,6 @@ public static class NBitcoinExtensions
}
}
- throw new NotImplementedException($"Unsupported script type.");
+ return null;
}
}

Fix after #9123 (Select coins for round abstraction) (#9615)