Skip to content

Commit

Permalink
Re-structured coin config options section.
Browse files Browse the repository at this point in the history
* Replaced acceptFirstOput with useDefaultAccount parameter.
* Moved blockTemplateModeRequired and txMessageSupported to main section.
Removed unused BlockTemplateOptions, GenTxOptions,
Fixed coin configs.
FindPoolAccount() on BlockProcessor.cs, PaymentProcessor.cs and ShareManager.cs now sets the pool account based on useDefaultAccount from coin-config.
Fixed back Transaction.cs:GetPoolOutput().
  • Loading branch information
bonesoul committed Sep 24, 2014
1 parent 2324a5a commit 9d3f791
Show file tree
Hide file tree
Showing 26 changed files with 110 additions and 254 deletions.
6 changes: 4 additions & 2 deletions 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, _poolConfig.Coin.Options.GenTx.AcceptFirstOutput);
var poolOutput = genTx.GetPoolOutput(_poolConfig.Wallet.Adress, _poolAccount);

// make sure we have a valid reference to poolOutput
if (poolOutput == null)
Expand Down Expand Up @@ -248,7 +248,9 @@ private void FindPoolAccount()
{
try
{
_poolAccount = _daemonClient.GetAccount(_poolConfig.Wallet.Adress);
_poolAccount = !_poolConfig.Coin.Options.UseDefaultAccount // if UseDefaultAccount is not set
? _daemonClient.GetAccount(_poolConfig.Wallet.Adress) // find the account of the our pool address.
: ""; // use the default account.
}
catch (RpcException e)
{
Expand Down
52 changes: 0 additions & 52 deletions src/CoiniumServ/Coin/Config/BlockTemplateOptions.cs

This file was deleted.

14 changes: 8 additions & 6 deletions src/CoiniumServ/Coin/Config/CoinOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,22 @@ public class CoinOptions:ICoinOptions
{
public bool IsProofOfStakeHybrid { get; set; }

public IBlockTemplateOptions BlockTemplate { get; private set; }

public IGenTxOptions GenTx { get; private set; }
public bool BlockTemplateModeRequired { get; private set; }

public bool UseDefaultAccount { get; private set; }

public bool TxMessageSupported { get; private set; }

public bool Valid { get; private set; }

public CoinOptions(dynamic config)
{
try
{
// if no value is set, use the default value as false.
IsProofOfStakeHybrid = config.isProofOfStakeHybrid is NullExceptionPreventer ? false : config.isProofOfStakeHybrid;
BlockTemplate = new BlockTemplateOptions(config.blockTemplate);
GenTx = new GenTxOptions(config.genTx);
BlockTemplateModeRequired = config.blockTemplateModeRequired is NullExceptionPreventer ? false : config.blockTemplateModeRequired;
UseDefaultAccount = config.useDefaultAccount is NullExceptionPreventer ? false : config.useDefaultAccount;
TxMessageSupported = config.txMessageSupported is NullExceptionPreventer ? false : config.txMessageSupported;
Valid = true;
}
catch (Exception e)
Expand Down
55 changes: 0 additions & 55 deletions src/CoiniumServ/Coin/Config/GenTxOptions.cs

This file was deleted.

32 changes: 0 additions & 32 deletions src/CoiniumServ/Coin/Config/IBlockTemplateOptions.cs

This file was deleted.

15 changes: 11 additions & 4 deletions src/CoiniumServ/Coin/Config/ICoinOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,20 @@ public interface ICoinOptions:IConfig
bool IsProofOfStakeHybrid { get; set; }

/// <summary>
/// Block template options
/// Is setting a mode required in getblocktemplate function?
/// <remarks>Required by peercoin variants</remarks>
/// </summary>
IBlockTemplateOptions BlockTemplate { get; }
bool BlockTemplateModeRequired { get; }

/// <summary>
/// Generation transaction options
/// Use the default account for coinbase transactions?
/// <remarks>Required by peercoin variants</remarks>
/// </summary>
IGenTxOptions GenTx { get; }
bool UseDefaultAccount { get; }

/// <summary>
/// Does the coin uses TxMessages.
/// </summary>
bool TxMessageSupported { get; }
}
}
37 changes: 0 additions & 37 deletions src/CoiniumServ/Coin/Config/IGenTxOptions.cs

This file was deleted.

55 changes: 51 additions & 4 deletions src/CoiniumServ/CoiniumServ.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,9 @@
<Compile Include="Blocks\IBlockProcessor.cs" />
<Compile Include="Coin\Address\Exceptions\AddressNotOwnedException.cs" />
<Compile Include="Coin\Config\BlockExplorerOptions.cs" />
<Compile Include="Coin\Config\BlockTemplateOptions.cs" />
<Compile Include="Coin\Config\CoinOptions.cs" />
<Compile Include="Coin\Config\GenTxOptions.cs" />
<Compile Include="Coin\Config\IBlockExplorerOptions.cs" />
<Compile Include="Coin\Config\IBlockTemplateOptions.cs" />
<Compile Include="Coin\Config\ICoinOptions.cs" />
<Compile Include="Coin\Config\IGenTxOptions.cs" />
<Compile Include="Coin\Helpers\Hashrate.cs" />
<Compile Include="Configuration\IJsonConfigReader.cs" />
<Compile Include="Daemon\Converters\DifficultyConverter.cs" />
Expand Down Expand Up @@ -939,6 +935,57 @@
</ItemGroup>
<ItemGroup>
<Content Include="Coinium.ico" />
<None Include="web\default\Content\img\coins\icon\21.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="web\default\Content\img\coins\icon\365.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="web\default\Content\img\coins\icon\ANC.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="web\default\Content\img\coins\icon\BTC.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="web\default\Content\img\coins\icon\BTCD.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="web\default\Content\img\coins\icon\CAP.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="web\default\Content\img\coins\icon\CLR.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="web\default\Content\img\coins\icon\CSC.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="web\default\Content\img\coins\icon\CTM.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="web\default\Content\img\coins\icon\DVC.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="web\default\Content\img\coins\icon\EMC.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="web\default\Content\img\coins\icon\EXE.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="web\default\Content\img\coins\icon\FLO.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="web\default\Content\img\coins\icon\FRC.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="web\default\Content\img\coins\icon\FRK.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="web\default\Content\img\coins\icon\FST.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="web\default\Content\img\coins\icon\TiPS.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="web\default\Content\img\coins\icon\PPC.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand Down
2 changes: 1 addition & 1 deletion src/CoiniumServ/Daemon/IDaemonClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace CoiniumServ.Daemon
{
public interface IDaemonClient
{
BlockTemplate GetBlockTemplate(bool capabilitiesSupported = true);
BlockTemplate GetBlockTemplate(bool modeRequired = false);

BlockTemplate GetBlockTemplate(string blockHex);

Expand Down
9 changes: 1 addition & 8 deletions src/CoiniumServ/Daemon/Responses/Transaction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,8 @@ 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, bool acceptFirstOutput = false)
public TransactionDetail GetPoolOutput(string poolAddress, string poolAccount)
{
if (Details == null) // make sure we have valid outputs.
return null;
Expand All @@ -70,8 +69,6 @@ public TransactionDetail GetPoolOutput(string poolAddress, string poolAccount, b
// 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.
// for peercoin variants, acceptFirstOutput parameter can make it work by just returning the very first output of the transaction.

// check for case 1.
if (Details.Any(x => x.Address == poolAddress))
Expand All @@ -80,10 +77,6 @@ public TransactionDetail GetPoolOutput(string poolAddress, string poolAccount, b
// 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;
}
Expand Down
4 changes: 2 additions & 2 deletions src/CoiniumServ/Jobs/Manager/JobManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ private void BlockPoller(object stats)

try
{
var blockTemplate = _daemonClient.GetBlockTemplate(_poolConfig.Coin.Options.BlockTemplate.ModeRequired);
var blockTemplate = _daemonClient.GetBlockTemplate(_poolConfig.Coin.Options.BlockTemplateModeRequired);

if (blockTemplate.Height == _jobTracker.Current.Height) // if network reports the same block-height with our current job.
return; // just return.
Expand Down Expand Up @@ -146,7 +146,7 @@ private IJob GetNewJob()
{
try
{
var blockTemplate = _daemonClient.GetBlockTemplate(_poolConfig.Coin.Options.BlockTemplate.ModeRequired);
var blockTemplate = _daemonClient.GetBlockTemplate(_poolConfig.Coin.Options.BlockTemplateModeRequired);

// TODO: convert generation transaction to ioc & DI based.
var generationTransaction = new GenerationTransaction(ExtraNonce, _daemonClient, blockTemplate, _poolConfig);
Expand Down

0 comments on commit 9d3f791

Please sign in to comment.