Skip to content

Commit

Permalink
refactor(WalletParser.cs): change GetOutputDescriptor method to an ex…
Browse files Browse the repository at this point in the history
…tension method to improve code organization and readability

refactor(Wallets.razor): update usage of GetOutputDescriptor method to use it as an extension method on the Wallet object for better code organization and readability

refactor(WalletParserTests.cs): update tests to use GetOutputDescriptor method as an extension method on the Wallet object for better code organization and readability
  • Loading branch information
markettes committed Oct 27, 2023
1 parent 6a662e3 commit 4f4330c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/Helpers/WalletParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ DerivationStrategyBase Parse(string str)
}
}

public static string GetOutputDescriptor(Wallet wallet, string bitcoinNetwork)
public static string GetOutputDescriptor(this Wallet wallet, string bitcoinNetwork)
{
var network = Network.GetNetwork(bitcoinNetwork);
OutputDescriptor outputDescriptor = null;
Expand Down
2 changes: 1 addition & 1 deletion src/Pages/Wallets.razor
Original file line number Diff line number Diff line change
Expand Up @@ -1662,7 +1662,7 @@
{
try
{
_outputDescriptorContentModal = WalletParser.GetOutputDescriptor(contextItem, Constants.BITCOIN_NETWORK);
_outputDescriptorContentModal = contextItem.GetOutputDescriptor(Constants.BITCOIN_NETWORK);
_keysContentModal = contextItem.Keys as HashSet<Key> ?? new HashSet<Key>();
await _exportOutputDescriptorModal.Show();
}
Expand Down
16 changes: 8 additions & 8 deletions test/NodeGuard.Tests/Helpers/WalletParserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,8 @@ public void GetOutputDescriptor_NativeSegwits()
};

// Act
var outputDescriptor1 = WalletParser.GetOutputDescriptor(wallet1HotWalletCreated, "mainnet");
var outputDescriptor2 = WalletParser.GetOutputDescriptor(wallet1ColdWallet, "mainnet");
var outputDescriptor1 = wallet1HotWalletCreated.GetOutputDescriptor("mainnet");
var outputDescriptor2 = wallet1ColdWallet.GetOutputDescriptor("mainnet");

// Assert
outputDescriptor1.Should().Contain("wpkh([ed0210c8/48'/0'/0']xpub661MyMwAqRbcFW31YEwpkMuc5THy2PSt5bDMsktWQcFF8syAmRUapSCGu8ED9W6oDMSgv6Zz8idoc4a6mr8BDzTJY47LJhkJ8UB7WEGuduB/0/*)#");
Expand Down Expand Up @@ -268,8 +268,8 @@ public void GetOutputDescriptor_NestedSegwits()
};

//Act
var outputDescriptor1 = WalletParser.GetOutputDescriptor(wallet1HotWalletCreated, "mainnet");
var outputDescriptor2 = WalletParser.GetOutputDescriptor(wallet1ColdWallet, "mainnet");
var outputDescriptor1 = wallet1HotWalletCreated.GetOutputDescriptor("mainnet");
var outputDescriptor2 = wallet1ColdWallet.GetOutputDescriptor("mainnet");

// Assert
outputDescriptor1.Should().Contain("sh(wpkh([ed0210c8/48'/0'/0']xpub661MyMwAqRbcFW31YEwpkMuc5THy2PSt5bDMsktWQcFF8syAmRUapSCGu8ED9W6oDMSgv6Zz8idoc4a6mr8BDzTJY47LJhkJ8UB7WEGuduB/0/*))#");
Expand Down Expand Up @@ -335,8 +335,8 @@ public void GetOutputDescriptor_Legacy()
};

// Act
var outputDescriptor1 = WalletParser.GetOutputDescriptor(wallet1HotWalletCreated, "mainnet");
var outputDescriptor2 = WalletParser.GetOutputDescriptor(wallet1ColdWallet, "mainnet");
var outputDescriptor1 = wallet1HotWalletCreated.GetOutputDescriptor("mainnet");
var outputDescriptor2 = wallet1ColdWallet.GetOutputDescriptor("mainnet");

// Assert
outputDescriptor1.Should().Contain("pkh([ed0210c8/48'/0'/0']xpub661MyMwAqRbcFW31YEwpkMuc5THy2PSt5bDMsktWQcFF8syAmRUapSCGu8ED9W6oDMSgv6Zz8idoc4a6mr8BDzTJY47LJhkJ8UB7WEGuduB/0/*)#");
Expand Down Expand Up @@ -400,8 +400,8 @@ public void GetOutputDescriptor_Taproot()
};

// Act
var taprootFunction1 = () => WalletParser.GetOutputDescriptor(wallet1HotWalletCreated, "mainnet");
var taprootFunction2 = () => WalletParser.GetOutputDescriptor(wallet1ColdWallet, "mainnet");
var taprootFunction1 = () => wallet1HotWalletCreated.GetOutputDescriptor("mainnet");
var taprootFunction2 = () => wallet1ColdWallet.GetOutputDescriptor("mainnet");

// Assert
taprootFunction1.Should().Throw<NotImplementedException>();
Expand Down

0 comments on commit 4f4330c

Please sign in to comment.