Skip to content

Commit

Permalink
Merge pull request stratisproject#30 from dangershony/fix-cold-stake-…
Browse files Browse the repository at this point in the history
…setup-trx-segwit

Add cold stakaing to allowed scripts
  • Loading branch information
netsfx authored Oct 17, 2019
2 parents 98b1de2 + b8fe0df commit 51896e8
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

<ItemGroup>
<ProjectReference Include="..\NBitcoin\NBitcoin.csproj" />
<ProjectReference Include="..\Stratis.Bitcoin.Features.ColdStaking\Stratis.Bitcoin.Features.ColdStaking.csproj" />
<ProjectReference Include="..\Stratis.Bitcoin.Features.Consensus\Stratis.Bitcoin.Features.Consensus.csproj" />
<ProjectReference Include="..\Stratis.Bitcoin.Features.MemoryPool\Stratis.Bitcoin.Features.MemoryPool.csproj" />
<ProjectReference Include="..\Stratis.Bitcoin\Stratis.Bitcoin.csproj" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,11 +291,12 @@ internal HdAddress GetFirstUnusedColdStakingAddress(string walletName, bool isCo
/// <param name="walletPassword">The wallet password.</param>
/// <param name="amount">The amount to cold stake.</param>
/// <param name="feeAmount">The fee to pay for the cold staking setup transaction.</param>
/// <param name="useSegwitChangeAddress">Use a segwit style change address.</param>
/// <returns>The <see cref="Transaction"/> for setting up cold staking.</returns>
/// <exception cref="WalletException">Thrown if any of the rules listed in the remarks section of this method are broken.</exception>
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));
Expand Down Expand Up @@ -361,6 +362,7 @@ internal Transaction GetColdStakingSetupTransaction(IWalletTransactionHandler wa
TransactionFee = feeAmount,
MinConfirmations = 0,
Shuffle = false,
UseSegwitChangeAddress = useSegwitChangeAddress,
WalletPassword = walletPassword,
Recipients = new List<Recipient>() { new Recipient { Amount = amount, ScriptPubKey = destination } }
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,11 @@ public class SetupColdStakingRequest
[JsonProperty(PropertyName = "fees")]
public string Fees { get; set; }

/// <summary>
/// Whether to send the change to a P2WPKH (segwit bech32) addresses, or a regular P2PKH address
/// </summary>
public bool SegwitChangeAddress { get; set; }

/// <summary>Creates a string containing the properties of this object.</summary>
/// <returns>A string containing the properties of the object.</returns>
public override string ToString()
Expand Down

0 comments on commit 51896e8

Please sign in to comment.