Skip to content

Commit

Permalink
Added acceptFirstOutput parameter for peercoin variants to Transactio…
Browse files Browse the repository at this point in the history
…n.cs:GetPoolOutput().

Both BlockProcessor.cs and ShareManager.cs now honors this acceptFirstOutput parameter using the coin configuration.
  • Loading branch information
bonesoul committed Sep 24, 2014
1 parent b9e1b19 commit 9e3e73a
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/CoiniumServ/Blocks/BlockProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ private void QueryBlock(IPersistedBlock block)
return; // in case we have a null, status will be already decided by GetGenerationTx() function.

// get the output transaction that targets pools central wallet.
var poolOutput = genTx.GetPoolOutput(_poolConfig.Wallet.Adress, _poolAccount);
var poolOutput = genTx.GetPoolOutput(_poolConfig.Wallet.Adress, _poolAccount, _poolConfig.Coin.Options.GenTx.AcceptFirstOutput);

// make sure we have a valid reference to poolOutput
if (poolOutput == null)
Expand Down
22 changes: 15 additions & 7 deletions src/CoiniumServ/Daemon/Responses/Transaction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,9 @@ public class Transaction
/// </summary>
/// <param name="poolAddress"></param>
/// <param name="poolAccount"></param>
/// <param name="acceptFirstOutput"></param>
/// <returns></returns>
public TransactionDetail GetPoolOutput(string poolAddress, string poolAccount)
public TransactionDetail GetPoolOutput(string poolAddress, string poolAccount, bool acceptFirstOutput = false)
{
if (Details == null) // make sure we have valid outputs.
return null;
Expand All @@ -69,15 +70,22 @@ public TransactionDetail GetPoolOutput(string poolAddress, string poolAccount)
// bitcoin variants;
// case 1) some of bitcoin variants can include the "address" in the transaction detail and we can basically find the output comparing against it.
// case 2) some other bitcoin variants can include "address account" name in transaction detail and we again find the output comparing against it.
// case 3) peercoin variants is where things get complicated, even if you set an account name to an address, they peercoin variants will refuse use the name in details.
// TODO: case 3 should be only allowed by configuration
// case 3) peercoin variants is where things get complicated, even if you set an account name to an address, they peercoin variants will refuse use the name in details.
// for peercoin variants, acceptFirstOutput parameter can make it work by just returning the very first output of the transaction.

if (Details.Any(x => x.Address == poolAddress)) // check for case 1.
// check for case 1.
if (Details.Any(x => x.Address == poolAddress))
return Details.First(x => x.Address == poolAddress); // return the output that matches pool address.
else if (Details.Any(x => x.Account == poolAccount)) // check for case 2.
return Details.First(x => x.Account == poolAccount);
else // case 3 - if we can't match pool address or pool account, just return the very first output.

// check for case 2.
if (Details.Any(x => x.Account == poolAccount))
return Details.First(x => x.Account == poolAccount); // return the output that matches pool account.

// case 3 - if we can't match pool address or pool account, just return the very first output given that acceptFirstOutput is true.
if (acceptFirstOutput)
return Details.FirstOrDefault();

return null;
}

// not sure if fields below even exists / used
Expand Down
2 changes: 1 addition & 1 deletion src/CoiniumServ/Shares/ShareManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ private bool SubmitBlock(IShare share)
return false;
}

var poolOutput = genTx.GetPoolOutput(_poolConfig.Wallet.Adress, _poolAccount); // get the output that targets pool's central address.
var poolOutput = genTx.GetPoolOutput(_poolConfig.Wallet.Adress, _poolAccount, _poolConfig.Coin.Options.GenTx.AcceptFirstOutput); // get the output that targets pool's central address.

// make sure the blocks generation transaction contains our central pool wallet address
if (poolOutput == null)
Expand Down
4 changes: 0 additions & 4 deletions src/Tests/Blocks/BlockProcessorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,6 @@ private void QueryBlockTest_WithIncorrectPoolOutputAddress_ShouldBeOrphaned()
[Fact]
private void QueryBlockTest_WithIncorrectPoolOutputAccount_ShouldBeOrphaned()
{
// todo: latest change in Transaction.cs:GetPoolOutput() makes this test fail, case 3 should be only allowed by configuration

// test case: generation transaction output doesn't match pool output account.
var block = new PersistedBlock(1, false, false, false, "BLOCK_HASH", "TX_HASH", 0, 0, DateTime.Now);

Expand All @@ -196,8 +194,6 @@ private void QueryBlockTest_WithIncorrectPoolOutputAccount_ShouldBeOrphaned()
[Fact]
private void QueryBlockTest_ShouldSetReward()
{
// todo: latest change in Transaction.cs:GetPoolOutput() makes this test fail, case 3 should be only a configuration option.

// test case: set block reward based on pool output value.
var block = new PersistedBlock(1, false, false, false, "BLOCK_HASH", "TX_HASH", 0, 0, DateTime.Now);
_poolConfig.Wallet.Adress.Returns("POOL_ADDRESS");
Expand Down

0 comments on commit 9e3e73a

Please sign in to comment.