Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,45 @@ public void SetupColdStakingWithHotWalletSucceeds()
Assert.True(this.mempoolManager.Validator.AcceptToMemoryPool(state, transaction).GetAwaiter().GetResult(), "Transaction failed mempool validation.");
}

/// <summary>
/// Verify that the ScriptPubKey can be check with the script template.
/// </summary>
[Fact]
public void VerifyThatColdStakeTransactionCanBeFiltered()
{
this.Initialize();
this.CreateMempoolManager();

this.coldStakingManager.CreateWallet(walletPassword, walletName1, walletPassphrase, new Mnemonic(walletMnemonic1));

Wallet.Wallet wallet1 = this.coldStakingManager.GetWalletByName(walletName1);

Transaction prevTran = this.AddSpendableTransactionToWallet(wallet1);

IActionResult result = this.coldStakingController.SetupColdStaking(new SetupColdStakingRequest
{
HotWalletAddress = hotWalletAddress1,
ColdWalletAddress = coldWalletAddress2,
WalletName = walletName1,
WalletAccount = walletAccount,
WalletPassword = walletPassword,
Amount = "100",
Fees = "0.01"
});

var jsonResult = Assert.IsType<JsonResult>(result);
var response = Assert.IsType<SetupColdStakingResponse>(jsonResult.Value);
var transaction = Assert.IsType<PosTransaction>(this.Network.CreateTransaction(response.TransactionHex));

Assert.Equal("OP_DUP OP_HASH160 OP_ROT OP_IF OP_CHECKCOLDSTAKEVERIFY 90c582cb91d6b6d777c31c891d4943fed4edac3a OP_ELSE 92dfb829d31cefe6a0731f3432dea41596a278d9 OP_ENDIF OP_EQUALVERIFY OP_CHECKSIG", transaction.Outputs[1].ScriptPubKey.ToString());

// Get the ColdStaking script template if available.
Dictionary<string, ScriptTemplate> templates = this.coldStakingManager.GetValidStakingTemplates();
ScriptTemplate coldStakingTemplate = templates["ColdStaking"];

Assert.True(coldStakingTemplate.CheckScriptPubKey(transaction.Outputs[1].ScriptPubKey));
}

/// <summary>
/// Confirms that cold staking setup with the hot wallet will succeed if no issues (as per above test cases) are encountered.
/// </summary>
Expand Down
10 changes: 10 additions & 0 deletions src/Blockcore.Features.Wallet/WalletRPCController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -419,9 +419,19 @@ public GetTransactionModel GetTransaction(string txid)
}
}

// Get the ColdStaking script template if available.
Dictionary<string, ScriptTemplate> templates = this.walletManager.GetValidStakingTemplates();
ScriptTemplate coldStakingTemplate = templates.ContainsKey("ColdStaking") ? templates["ColdStaking"] : null;

// Receive transactions details.
foreach (TransactionData trxInWallet in receivedTransactions)
{
// Skip the details if the script pub key is cold staking.
if (coldStakingTemplate != null && coldStakingTemplate.CheckScriptPubKey(trxInWallet.ScriptPubKey))
{
continue;
}

GetTransactionDetailsCategoryModel category;
if (isGenerated)
{
Expand Down