From b30fa94d7be63497076f4e375a88275a3c7b7b79 Mon Sep 17 00:00:00 2001 From: dangershony Date: Thu, 17 Oct 2019 15:34:12 +0100 Subject: [PATCH 1/2] Add cold stkaing to allowed scripts --- .../Obsidian.Networks.ObsidianX.csproj | 1 + .../Rules/ObsidianXNativeSegWitSpendsOnlyRule.cs | 3 +++ 2 files changed, 4 insertions(+) diff --git a/src/Obsidian.Networks.ObsidianX/Obsidian.Networks.ObsidianX.csproj b/src/Obsidian.Networks.ObsidianX/Obsidian.Networks.ObsidianX.csproj index 783f90c79da..c7599c3dbd6 100644 --- a/src/Obsidian.Networks.ObsidianX/Obsidian.Networks.ObsidianX.csproj +++ b/src/Obsidian.Networks.ObsidianX/Obsidian.Networks.ObsidianX.csproj @@ -6,6 +6,7 @@ + diff --git a/src/Obsidian.Networks.ObsidianX/Rules/ObsidianXNativeSegWitSpendsOnlyRule.cs b/src/Obsidian.Networks.ObsidianX/Rules/ObsidianXNativeSegWitSpendsOnlyRule.cs index 74ea5a3f0cd..014d8b9c7e6 100644 --- a/src/Obsidian.Networks.ObsidianX/Rules/ObsidianXNativeSegWitSpendsOnlyRule.cs +++ b/src/Obsidian.Networks.ObsidianX/Rules/ObsidianXNativeSegWitSpendsOnlyRule.cs @@ -3,6 +3,7 @@ using NBitcoin; using Stratis.Bitcoin.Consensus; using Stratis.Bitcoin.Consensus.Rules; +using Stratis.Bitcoin.Features.ColdStaking; namespace Obsidian.Networks.ObsidianX.Rules { @@ -33,6 +34,8 @@ public override Task RunAsync(RuleContext context) continue; // allowed are P2WPKH and P2WSH if (TxNullDataTemplate.Instance.CheckScriptPubKey(output.ScriptPubKey)) continue; // allowed are also all kinds of valid OP_RETURN pushes + if (ColdStakingScriptTemplate.Instance.CheckScriptPubKey(output.ScriptPubKey)) + continue; // allowed cold staking setup trx this.Logger.LogTrace("(-)[NOT_NATIVE_SEGWIT_OR_DATA]"); new ConsensusError("legacy-tx", "Only P2WPKH, P2WSH is allowed outside Coinstake transactions.").Throw(); From b8fe0df82e74b79b61ab881dbba0d09f5d40c528 Mon Sep 17 00:00:00 2001 From: dangershony Date: Thu, 17 Oct 2019 14:54:26 +0100 Subject: [PATCH 2/2] Specify a segwit change address --- .../ColdStakingManager.cs | 4 +++- .../Controllers/ColdStakingController.cs | 2 +- .../Models/ColdStakingModels.cs | 5 +++++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/Stratis.Bitcoin.Features.ColdStaking/ColdStakingManager.cs b/src/Stratis.Bitcoin.Features.ColdStaking/ColdStakingManager.cs index 6573922a7fd..c10252b3eac 100644 --- a/src/Stratis.Bitcoin.Features.ColdStaking/ColdStakingManager.cs +++ b/src/Stratis.Bitcoin.Features.ColdStaking/ColdStakingManager.cs @@ -291,11 +291,12 @@ internal HdAddress GetFirstUnusedColdStakingAddress(string walletName, bool isCo /// The wallet password. /// The amount to cold stake. /// The fee to pay for the cold staking setup transaction. + /// Use a segwit style change address. /// The for setting up cold staking. /// Thrown if any of the rules listed in the remarks section of this method are broken. internal Transaction GetColdStakingSetupTransaction(IWalletTransactionHandler walletTransactionHandler, string coldWalletAddress, string hotWalletAddress, string walletName, string walletAccount, - string walletPassword, Money amount, Money feeAmount) + string walletPassword, Money amount, Money feeAmount, bool useSegwitChangeAddress = false) { Guard.NotNull(walletTransactionHandler, nameof(walletTransactionHandler)); Guard.NotEmpty(coldWalletAddress, nameof(coldWalletAddress)); @@ -361,6 +362,7 @@ internal Transaction GetColdStakingSetupTransaction(IWalletTransactionHandler wa TransactionFee = feeAmount, MinConfirmations = 0, Shuffle = false, + UseSegwitChangeAddress = useSegwitChangeAddress, WalletPassword = walletPassword, Recipients = new List() { new Recipient { Amount = amount, ScriptPubKey = destination } } }; diff --git a/src/Stratis.Bitcoin.Features.ColdStaking/Controllers/ColdStakingController.cs b/src/Stratis.Bitcoin.Features.ColdStaking/Controllers/ColdStakingController.cs index 4b98d435fae..7848234cfa9 100644 --- a/src/Stratis.Bitcoin.Features.ColdStaking/Controllers/ColdStakingController.cs +++ b/src/Stratis.Bitcoin.Features.ColdStaking/Controllers/ColdStakingController.cs @@ -188,7 +188,7 @@ public IActionResult SetupColdStaking([FromBody]SetupColdStakingRequest request) Transaction transaction = this.ColdStakingManager.GetColdStakingSetupTransaction( this.walletTransactionHandler, request.ColdWalletAddress, request.HotWalletAddress, - request.WalletName, request.WalletAccount, request.WalletPassword, amount, feeAmount); + request.WalletName, request.WalletAccount, request.WalletPassword, amount, feeAmount, request.SegwitChangeAddress); var model = new SetupColdStakingResponse { diff --git a/src/Stratis.Bitcoin.Features.ColdStaking/Models/ColdStakingModels.cs b/src/Stratis.Bitcoin.Features.ColdStaking/Models/ColdStakingModels.cs index 2d9c0ac5ac4..3898304229e 100644 --- a/src/Stratis.Bitcoin.Features.ColdStaking/Models/ColdStakingModels.cs +++ b/src/Stratis.Bitcoin.Features.ColdStaking/Models/ColdStakingModels.cs @@ -241,6 +241,11 @@ public class SetupColdStakingRequest [JsonProperty(PropertyName = "fees")] public string Fees { get; set; } + /// + /// Whether to send the change to a P2WPKH (segwit bech32) addresses, or a regular P2PKH address + /// + public bool SegwitChangeAddress { get; set; } + /// Creates a string containing the properties of this object. /// A string containing the properties of the object. public override string ToString()