Parse script type to enum
MODIFY
WalletWasabi.Tests/UnitTests/BitcoinCore/RpcBasedTests.cs
WalletWasabi.Tests/UnitTests/BitcoinCore/RpcBasedTests.cs
@@ -4,6 +4,7 @@ using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using WalletWasabi.BitcoinCore;
+using WalletWasabi.BitcoinCore.RpcModels;
using WalletWasabi.Services;
using WalletWasabi.Tests.Helpers;
using Xunit;
@@ -74,10 +75,15 @@ namespace WalletWasabi.Tests.UnitTests.BitcoinCore
Assert.Equal(2, blockInfo.Transactions.ElementAt(1).Outputs.Count());
Assert.Equal("01660101", blockInfo.Transactions.ElementAt(0).Inputs.ElementAt(0).Coinbase);
+ Assert.Equal(RpcPubkeyType.TxPubkeyhash, blockInfo.Transactions.ElementAt(0).Outputs.ElementAt(0).PubkeyType);
+ Assert.Equal(RpcPubkeyType.TxNullData, blockInfo.Transactions.ElementAt(0).Outputs.ElementAt(1).PubkeyType);
Assert.Equal(Money.Coins(50), blockInfo.Transactions.ElementAt(1).Inputs.ElementAt(0).PrevOutput.Value);
Assert.Equal(Money.Coins((decimal)48.99995500), blockInfo.Transactions.ElementAt(1).Outputs.ElementAt(0).Value);
Assert.Equal(Money.Coins((decimal)1.00000000), blockInfo.Transactions.ElementAt(1).Outputs.ElementAt(1).Value);
+ Assert.Equal(RpcPubkeyType.TxPubkeyhash, blockInfo.Transactions.ElementAt(1).Inputs.ElementAt(0).PrevOutput.PubkeyType);
+ Assert.Equal(RpcPubkeyType.TxPubkeyhash, blockInfo.Transactions.ElementAt(1).Outputs.ElementAt(0).PubkeyType);
+ Assert.Equal(RpcPubkeyType.TxPubkeyhash, blockInfo.Transactions.ElementAt(1).Outputs.ElementAt(1).PubkeyType);
}
#region Mocked RPC response

ADD
WalletWasabi/BitcoinCore/RpcModels/RpcPubkeyType.cs
+namespace WalletWasabi.BitcoinCore.RpcModels
+{
+ public enum RpcPubkeyType
+ {
+ Unknown,
+ TxNonstandard,
+ TxPubkey,
+ TxPubkeyhash,
+ TxScripthash,
+ TxMultisig,
+ TxNullData,
+ TxWitnessV0Keyhash,
+ TxWitnessV0Scripthash,
+ TxWitnessUnknown,
+ }
+}

MODIFY
WalletWasabi/BitcoinCore/RpcModels/VerboseOutputInfo.cs
WalletWasabi/BitcoinCore/RpcModels/VerboseOutputInfo.cs
@@ -4,14 +4,17 @@ namespace WalletWasabi.BitcoinCore.RpcModels
{
public class VerboseOutputInfo
{
- public VerboseOutputInfo(Money value, Script scriptPubKey)
+ public VerboseOutputInfo(Money value, Script scriptPubKey, string pubkeyType)
{
Value = value;
ScriptPubKey = scriptPubKey;
+ PubkeyType = RpcParser.ConvertPubkeyType(pubkeyType);
}
public Money Value { get; }
public Script ScriptPubKey { get; }
+
+ public RpcPubkeyType PubkeyType { get; }
}
}

MODIFY
WalletWasabi/BitcoinCore/RpcParser.cs
WalletWasabi/BitcoinCore/RpcParser.cs
@@ -10,6 +10,23 @@ namespace WalletWasabi.BitcoinCore
{
public class RpcParser
{
+ public static RpcPubkeyType ConvertPubkeyType(string pubKeyType)
+ {
+ return pubKeyType switch
+ {
+ "nonstandard" => RpcPubkeyType.TxNonstandard,
+ "pubkey" => RpcPubkeyType.TxPubkey,
+ "pubkeyhash" => RpcPubkeyType.TxPubkeyhash,
+ "scripthash" => RpcPubkeyType.TxScripthash,
+ "multisig" => RpcPubkeyType.TxMultisig,
+ "nulldata" => RpcPubkeyType.TxNullData,
+ "witness_v0_keyhash" => RpcPubkeyType.TxWitnessV0Keyhash,
+ "witness_v0_scripthash" => RpcPubkeyType.TxWitnessV0Scripthash,
+ "witness_unknown" => RpcPubkeyType.TxWitnessUnknown,
+ _ => RpcPubkeyType.Unknown
+ };
+ }
+
public static VerboseBlockInfo ParseVerboseBlockResponse(string getBlockResponse)
{
var blockInfoJson = JObject.Parse(getBlockResponse);
@@ -45,7 +62,8 @@ namespace WalletWasabi.BitcoinCore
outPoint: new OutPoint(uint256.Parse(txinJson.Value<string>("txid")), txinJson.Value<uint>("vout")),
prevOutput: new VerboseOutputInfo(
value: Money.Coins(txinJson["prevout"].Value<decimal>("value")),
- scriptPubKey: Script.FromHex(txinJson["prevout"]["scriptPubKey"].Value<string>("hex")))
+ scriptPubKey: Script.FromHex(txinJson["prevout"]["scriptPubKey"].Value<string>("hex")),
+ pubkeyType: txinJson["prevout"]["scriptPubKey"].Value<string>("type"))
);
}
@@ -56,7 +74,8 @@ namespace WalletWasabi.BitcoinCore
{
var output = new VerboseOutputInfo(
value: Money.Coins(txoutJson.Value<decimal>("value")),
- scriptPubKey: Script.FromHex(txoutJson["scriptPubKey"].Value<string>("hex"))
+ scriptPubKey: Script.FromHex(txoutJson["scriptPubKey"].Value<string>("hex")),
+ pubkeyType: txoutJson["scriptPubKey"].Value<string>("type")
);
outputs.Add(output);

Parse script type to enum