Make AllowedScriptTypes configurable
MODIFY
WalletWasabi.Tests/UnitTests/WabiSabi/Backend/InputRegistrationTests.cs
WalletWasabi.Tests/UnitTests/WabiSabi/Backend/InputRegistrationTests.cs
@@ -120,7 +120,7 @@ namespace WalletWasabi.Tests.UnitTests.WabiSabi.Backend
}
[Fact]
- public async Task InputNonSegwitAsync()
+ public async Task InputScriptNotAllowedAsync()
{
MockArena arena = new();
Round round = new();
@@ -136,7 +136,7 @@ namespace WalletWasabi.Tests.UnitTests.WabiSabi.Backend
null!,
null!);
var ex = await Assert.ThrowsAnyAsync<WabiSabiProtocolException>(async () => await handler.RegisterInputAsync(req));
- Assert.Equal(WabiSabiProtocolErrorCode.InputNonSegwit, ex.ErrorCode);
+ Assert.Equal(WabiSabiProtocolErrorCode.InputScriptNotAllowed, ex.ErrorCode);
}
}
}

ADD
WalletWasabi/JsonConverters/Collections/DefaultValueStringCollectionAttribute.cs
+using Newtonsoft.Json;
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace WalletWasabi.JsonConverters.Collections
+{
+ public class DefaultValueStringCollectionAttribute : DefaultValueAttribute
+ {
+ public DefaultValueStringCollectionAttribute(string json)
+ : base(JsonConvert.DeserializeObject<IEnumerable<string>>(json))
+ {
+ }
+ }
+}

MODIFY
WalletWasabi/WabiSabi/Backend/Models/WabiSabiProtocolErrorCode.cs
WalletWasabi/WabiSabi/Backend/Models/WabiSabiProtocolErrorCode.cs
@@ -13,6 +13,6 @@ namespace WalletWasabi.WabiSabi.Backend.Models
InputSpent,
InputUnconfirmed,
InputImmature,
- InputNonSegwit
+ InputScriptNotAllowed
}
}

MODIFY
WalletWasabi/WabiSabi/Backend/PostRequests/PostRequestHandler.cs
WalletWasabi/WabiSabi/Backend/PostRequests/PostRequestHandler.cs
@@ -61,9 +61,9 @@ namespace WalletWasabi.WabiSabi.Backend.PostRequests
{
throw new WabiSabiProtocolException(WabiSabiProtocolErrorCode.InputImmature);
}
- if (txOutResponse.ScriptPubKeyType != "witness_v0_keyhash")
+ if (!Config.AllowedScriptTypes.Contains(txOutResponse.ScriptPubKeyType))
{
- throw new WabiSabiProtocolException(WabiSabiProtocolErrorCode.InputNonSegwit);
+ throw new WabiSabiProtocolException(WabiSabiProtocolErrorCode.InputScriptNotAllowed);
}
}

MODIFY
WalletWasabi/WabiSabi/Backend/WabiSabiConfig.cs
WalletWasabi/WabiSabi/Backend/WabiSabiConfig.cs
@@ -7,6 +7,7 @@ using System.Text;
using System.Threading.Tasks;
using WalletWasabi.Bases;
using WalletWasabi.Helpers;
+using WalletWasabi.JsonConverters.Collections;
using WalletWasabi.JsonConverters.Timing;
namespace WalletWasabi.WabiSabi.Backend
@@ -24,11 +25,15 @@ namespace WalletWasabi.WabiSabi.Backend
[DefaultValue(Constants.OneDayConfirmationTarget)]
[JsonProperty(PropertyName = "ConfirmationTarget", DefaultValueHandling = DefaultValueHandling.Populate)]
- public int ConfirmationTarget { get; set; }
+ public int ConfirmationTarget { get; set; } = Constants.OneDayConfirmationTarget;
[DefaultValueTimeSpan("0d 3h 0m 0s")]
[JsonProperty(PropertyName = "ReleaseUtxoFromPrisonAfter", DefaultValueHandling = DefaultValueHandling.Populate)]
[JsonConverter(typeof(TimeSpanJsonConverter))]
- public TimeSpan ReleaseUtxoFromPrisonAfter { get; set; }
+ public TimeSpan ReleaseUtxoFromPrisonAfter { get; set; } = TimeSpan.FromHours(3);
+
+ [DefaultValueStringCollection("[\"witness_v0_keyhash\"]")]
+ [JsonProperty(PropertyName = "AllowedScriptTypes", DefaultValueHandling = DefaultValueHandling.Populate)]
+ public IEnumerable<string> AllowedScriptTypes { get; set; } = new[] { "witness_v0_keyhash" };
}
}

Make AllowedScriptTypes configurable