Skip to content

Commit

Permalink
Add CoinbaseDevReward payment support
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaolin1579 committed Jul 5, 2024
1 parent 48667c2 commit a36c634
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/Miningcore/Blockchain/Bitcoin/BitcoinJob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,9 @@ protected virtual Transaction CreateOutputTransaction()
if(coin.HasCommunityAddress)
rewardToPool = CreateCommunityAddressOutputs(tx, rewardToPool);

if(coin.HasCoinbaseDevReward)
rewardToPool = CreateCoinbaseDevRewardOutputs(tx, rewardToPool);

if(coin.HasFoundation)
rewardToPool = CreateFoundationOutputs(tx, rewardToPool);

Expand Down Expand Up @@ -574,6 +577,32 @@ protected virtual Money CreateCommunityAddressOutputs(Transaction tx, Money rewa
}
#endregion // CommunityAddres

#region CoinbaseDevReward

protected CoinbaseDevRewardTemplateExtra CoinbaseDevRewardParams;

protected virtual Money CreateCoinbaseDevRewardOutputs(Transaction tx, Money reward)
{
if(CoinbaseDevRewardParams.CoinbaseDevReward != null)
{
CoinbaseDevReward[] CBRewards;
CBRewards = new[] { CoinbaseDevRewardParams.CoinbaseDevReward.ToObject<CoinbaseDevReward>() };

foreach(var CBReward in CBRewards)
{
if(!string.IsNullOrEmpty(CBReward.ScriptPubkey))
{
Script payeeAddress = new (CBReward.ScriptPubkey.HexToByteArray());
var payeeReward = CBReward.Value;
tx.Outputs.Add(payeeReward, payeeAddress);
}
}
}
return reward;
}

#endregion // CoinbaseDevReward

#region Foundation

protected FoundationBlockTemplateExtra foundationParameters;
Expand Down Expand Up @@ -684,6 +713,9 @@ public void Init(BlockTemplate blockTemplate, string jobId,
if (coin.HasMinerFund)
minerFundParameters = BlockTemplate.Extra.SafeExtensionDataAs<MinerFundTemplateExtra>("coinbasetxn", "minerfund");

if(coin.HasCoinbaseDevReward)
CoinbaseDevRewardParams = BlockTemplate.Extra.SafeExtensionDataAs<CoinbaseDevRewardTemplateExtra>();

if(coin.HasFoundation)
foundationParameters = BlockTemplate.Extra.SafeExtensionDataAs<FoundationBlockTemplateExtra>();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Text;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace Miningcore.Blockchain.Bitcoin.DaemonResponses
{
public class CoinbaseDevReward
{
public string ScriptPubkey { get; set; }
public long Value { get; set; }
}

public class CoinbaseDevRewardTemplateExtra
{
public JToken CoinbaseDevReward { get; set; }
}
}
3 changes: 3 additions & 0 deletions src/Miningcore/Configuration/ClusterConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,9 @@ public class BitcoinNetworkParams
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
public bool HasCommunityAddress { get; set; }

[JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
public bool HasCoinbaseDevReward { get; set; }

[JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
public bool HasFoundation { get; set; }

Expand Down

0 comments on commit a36c634

Please sign in to comment.