Update vsize estimation methods
MODIFY
WalletWasabi/Extensions/NBitcoinExtensions.cs
WalletWasabi/Extensions/NBitcoinExtensions.cs
@@ -456,29 +456,19 @@ namespace NBitcoin
return sanityFee;
}
- public static int EstimateOutputVsize(this Script script)
+ public static int EstimateOutputVsize(this Script scriptPubKey) =>
+ StandardScripts.IsStandardScriptPubKey(scriptPubKey) switch
{
- if (script.IsScriptType(ScriptType.P2WPKH))
- {
- return Constants.OutputSizeInBytes;
- }
- else
- {
- throw new NotImplementedException($"Weight estimation isn't implemented for provided script type.");
- }
- }
+ true => new TxOut(Money.Zero, scriptPubKey).GetSerializedSize(),
+ false => throw new NotImplementedException($"Size estimation isn't implemented for provided script type.")
+ };
- public static int EstimateInputVsize(this Script script)
+ public static int EstimateInputVsize(this Script scriptPubKey) =>
+ scriptPubKey.IsScriptType(ScriptType.P2WPKH) switch
{
- if (script.IsScriptType(ScriptType.P2WPKH))
- {
- return Constants.P2wpkhInputVirtualSize;
- }
- else
- {
- throw new NotImplementedException($"Weight estimation isn't implemented for provided script type.");
- }
- }
+ true => Constants.P2wpkhInputVirtualSize,
+ false => throw new NotImplementedException($"Size estimation isn't implemented for provided script type.")
+ };
public static T FromBytes<T>(byte[] input) where T : IBitcoinSerializable, new()
{

MODIFY
WalletWasabi/Helpers/Constants.cs
WalletWasabi/Helpers/Constants.cs
@@ -21,7 +21,7 @@ namespace WalletWasabi.Helpers
public const int WitnessScaleFactor = 4;
public const int P2wpkhInputSizeInBytes = 41;
- public const int P2wpkhInputVirtualSize = 68;
+ public const int P2wpkhInputVirtualSize = 69;
public const int P2pkhInputSizeInBytes = 145;
public const int OutputSizeInBytes = 33;

Update vsize estimation methods