Skip to content

Commit

Permalink
Merge pull request #7 from vkynchev/develop-vkynchev
Browse files Browse the repository at this point in the history
Add txFee to pool config to substract from block reward + more...
  • Loading branch information
vagabondan authored Aug 17, 2017
2 parents ac7f40d + 3bce7d5 commit 6515fe7
Show file tree
Hide file tree
Showing 17 changed files with 71 additions and 28 deletions.
2 changes: 1 addition & 1 deletion src/CoiniumServ/Algorithms/AlgorithmRegistry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public class AlgorithmRegistry : IRegistry
public const string X15 = "x15";
public const string X17 = "x17";

// todo: add hefty1, qubit support
// todo: add hefty1 support

private readonly IApplicationContext _applicationContext;

Expand Down
2 changes: 1 addition & 1 deletion src/CoiniumServ/Blocks/BlockProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ private void QueryBlock(IPersistedBlock block)
}

// set the reward of the block to miners.
block.Reward = (decimal) poolOutput.Amount;
block.Reward = (decimal)poolOutput.Amount - (decimal)_poolConfig.Wallet.TxFee;

// find the block status
switch (poolOutput.Category)
Expand Down
2 changes: 1 addition & 1 deletion src/CoiniumServ/Jobs/Manager/JobManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public void Initialize(UInt32 instanceId)
_minerManager.MinerAuthenticated += OnMinerAuthenticated;

// create the timers as disabled.
_reBroadcastTimer = new Timer(IdleJobTimer, null,Timeout.Infinite, Timeout.Infinite);
_reBroadcastTimer = new Timer(IdleJobTimer, null, Timeout.Infinite, Timeout.Infinite);
_blockPollerTimer = new Timer(BlockPoller, null, Timeout.Infinite, Timeout.Infinite);

CreateAndBroadcastNewJob(true); // broadcast a new job initially - which will also setup the timers.
Expand Down
2 changes: 1 addition & 1 deletion src/CoiniumServ/Mining/MetaConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public MetaConfig(dynamic config)
{
// load the config data.
MOTD = string.IsNullOrEmpty(config.motd)
? "Welcome to CoiniumServ pool, enjoy your stay! - http://www.coinumserv.com"
? "Enjoy your stay!"
: config.motd;

TxMessage = string.IsNullOrEmpty(config.txMessage) ? "http://www.coiniumserv.com/" : config.txMessage;
Expand Down
5 changes: 5 additions & 0 deletions src/CoiniumServ/Payments/Config/IPaymentConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ public interface IPaymentConfig:IConfig
/// interval in seconds that payment-processor will be running.
/// </summary>
Int32 Interval { get; }

/// <summary>
/// interval in seconds that payment-processor's block checks will be running.
/// </summary>
Int32 CheckInterval { get; }

/// <summary>
/// minimum amount of coins before a miner is eligable for getting a payment.
Expand Down
5 changes: 5 additions & 0 deletions src/CoiniumServ/Payments/Config/IWalletConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,10 @@ public interface IWalletConfig:IConfig
/// Address that generated coins will arrive.
/// </summary>
string Adress { get; }

/// <summary>
/// Transaction fee to substract from block value
/// </summary>
double TxFee { get; }
}
}
2 changes: 2 additions & 0 deletions src/CoiniumServ/Payments/Config/PaymentConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public class PaymentConfig:IPaymentConfig
public bool Valid { get; private set; }
public bool Enabled { get; private set; }
public int Interval { get; private set; }
public int CheckInterval { get; private set; }
public double Minimum { get; private set; }

public PaymentConfig(dynamic config)
Expand All @@ -46,6 +47,7 @@ public PaymentConfig(dynamic config)
// load the config data.
Enabled = config.enabled;
Interval = config.interval == 0 ? 60 : config.interval;
CheckInterval = config.checkInterval == 0 ? 60 : config.checkInterval;
Minimum = config.minimum == 0 ? 0.01 : config.minimum;

Valid = true;
Expand Down
2 changes: 2 additions & 0 deletions src/CoiniumServ/Payments/Config/WalletConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,15 @@ namespace CoiniumServ.Payments.Config
public class WalletConfig:IWalletConfig
{
public string Adress { get; private set; }
public double TxFee { get; private set; }
public bool Valid { get; private set; }

public WalletConfig(dynamic config)
{
try
{
Adress = config.address;
TxFee = config.txfee;

Valid = true;
}
Expand Down
26 changes: 24 additions & 2 deletions src/CoiniumServ/Payments/PaymentManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,14 @@ namespace CoiniumServ.Payments
public class PaymentManager:IPaymentManager
{
private readonly Timer _timer;

private readonly Timer _timerCheck;

private readonly IPoolConfig _poolConfig;

private readonly IList<IPaymentLabor> _labors;

private readonly IList<IPaymentLabor> _laborsCheck;

private readonly ILogger _logger;

Expand All @@ -50,10 +54,13 @@ public PaymentManager(IPoolConfig poolConfig, IBlockProcessor blockProcessor, I
_poolConfig = poolConfig;
_labors = new List<IPaymentLabor>
{
blockProcessor,
blockAccounter,
blockAccounter,
paymentProcessor
};
_laborsCheck = new List<IPaymentLabor>
{
blockProcessor
};

_logger = Log.ForContext<PaymentManager>().ForContext("Component", poolConfig.Coin.Name);

Expand All @@ -62,6 +69,7 @@ public PaymentManager(IPoolConfig poolConfig, IBlockProcessor blockProcessor, I

// setup the timer to run payment laberos
_timer = new Timer(Run, null, _poolConfig.Payments.Interval * 1000, Timeout.Infinite);
_timerCheck = new Timer(RunCheck, null, _poolConfig.Payments.CheckInterval * 1000, Timeout.Infinite);
}

private void Run(object state)
Expand All @@ -77,5 +85,19 @@ private void Run(object state)

_timer.Change(_poolConfig.Payments.Interval * 1000, Timeout.Infinite); // reset the timer.
}

private void RunCheck(object state)
{
// loop through each payment labors and execute them.
foreach (var labor in _laborsCheck)
{
if (!labor.Active) // make sure labor is active
continue;

labor.Run(); // run the labor.
}

_timerCheck.Change(_poolConfig.Payments.CheckInterval * 1000, Timeout.Infinite); // reset the timer.
}
}
}
6 changes: 4 additions & 2 deletions src/CoiniumServ/Payments/PaymentProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,15 @@ private IList<ITransaction> ExecutePayments(IEnumerable<KeyValuePair<string, Lis
var filtered = paymentsToExecute.Where(
x => x.Value.Sum(y => y.Payment.Amount) >= (decimal)_poolConfig.Payments.Minimum)
.ToDictionary(x => x.Key, x => x.Value);

if (filtered.Count <= 0) // make sure we have payments to execute even after our filter.
return executed;

// coin daemon expects us to handle outputs in <wallet_address,amount> format, create the data structure so.
var outputs = filtered.ToDictionary(x => x.Key, x => x.Value.Sum(y => y.Payment.Amount));


_logger.Debug("Payment Outputs: {0}", outputs);

// send the payments all-together.
var txHash = _daemonClient.SendMany(_poolAccount, outputs);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public override void Up()
.WithColumn("AccountId").AsInt32().ForeignKey("Account", "Id")
.WithColumn("PaymentId").AsInt32().ForeignKey("Payment", "Id")
.WithColumn("Amount").AsDecimal().NotNullable()
.WithColumn("Currency").AsString(4).NotNullable()
.WithColumn("Currency").AsString(5).NotNullable()
.WithColumn("TxHash").AsString(64).NotNullable()
.WithColumn("CreatedAt").AsDateTime().NotNullable();
}
Expand Down
6 changes: 3 additions & 3 deletions src/CoiniumServ/Persistance/Providers/Redis/RedisClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ public class RedisClient
/// <param name="port">Redis server port</param>
public RedisClient(string host, int port, string password = "", string extraopts = "")
{
// create the connection
CM = ConnectionMultiplexer.Connect(host
// create the connection
CM = ConnectionMultiplexer.Connect(host
+ ((port == 0) ? "" : ":" + port)
+ (string.IsNullOrEmpty(password) ? "" : (",password="+password))
+ (string.IsNullOrEmpty(extraopts) ? "" : (","+extraopts)) );
+ (string.IsNullOrEmpty(extraopts) ? "" : (","+extraopts)));
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ private void Initialize()

Client = new RedisClient(_config.Host, _config.Port, _config.Password, "version=2.6");

// select the database
// select the database
Client.Select(_config.DatabaseId);

/*
Expand Down
28 changes: 15 additions & 13 deletions src/CoiniumServ/Utils/ConsoleWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,14 @@ class ConsoleWindow
public static void PrintBanner()
{
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine(@"-------------------------------------------------------------------");
Console.WriteLine(@" .__ .__ ");
Console.WriteLine(@" ____ ____ |__| ____ |__|__ __ _____ ______ ______________ __");
Console.WriteLine(@"_/ ___\/ _ \| |/ \| | | \/ \ / ___// __ \_ __ \ \/ /");
Console.WriteLine(@"\ \__( <_> ) | | \ | | / Y Y \\___ \\ ___/| | \/\ / ");
Console.WriteLine(@" \___ >____/|__|___| /__|____/|__|_| /____ >\___ >__| \_/ ");
Console.WriteLine(@" \/ \/ \/ \/ \/ ");
Console.WriteLine(@"-------------------------------------------------------------------");
Console.WriteLine();
}

Expand All @@ -56,19 +58,19 @@ public static void PrintBanner()
/// </summary>
public static void PrintLicense()
{
Console.ForegroundColor = ConsoleColor.Magenta;
Console.WriteLine("Copyright (C) 2013 - 2017, Coinium project - https://github.com/CoiniumServ/CoiniumServ");
Console.WriteLine();
Console.ForegroundColor = ConsoleColor.DarkYellow;
Console.WriteLine("CoiniumServ comes with ABSOLUTELY NO WARRANTY.");
Console.WriteLine();
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("You can contribute the development of the project by donating;");
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine(" BTC : 18qqrtR4xHujLKf9oqiCsjmwmH5vGpch4D");
Console.WriteLine(" LTC : LMXfRb3w8cMUBfqZb6RUkFTPaT6vbRozPa");
Console.WriteLine(" DOGE: DM8FW8REMHj3P4xtcMWDn33ccjikCWJnQr");
Console.WriteLine(" RDD : Rb9kcLs96VDHTmiXVjcWC2RBsfCJ73UQyr");
//Console.ForegroundColor = ConsoleColor.Magenta;
//Console.WriteLine("Copyright (C) 2013 - 2017, Coinium project - https://github.com/CoiniumServ/CoiniumServ");
//Console.WriteLine();
//Console.ForegroundColor = ConsoleColor.DarkYellow;
//Console.WriteLine("CoiniumServ comes with ABSOLUTELY NO WARRANTY.");
//Console.WriteLine();
//Console.ForegroundColor = ConsoleColor.Green;
//Console.WriteLine("You can contribute the development of the project by donating;");
//Console.ForegroundColor = ConsoleColor.Yellow;
//Console.WriteLine(" BTC : 18qqrtR4xHujLKf9oqiCsjmwmH5vGpch4D");
//Console.WriteLine(" LTC : LMXfRb3w8cMUBfqZb6RUkFTPaT6vbRozPa");
//Console.WriteLine(" DOGE: DM8FW8REMHj3P4xtcMWDn33ccjikCWJnQr");
//Console.WriteLine(" RDD : Rb9kcLs96VDHTmiXVjcWC2RBsfCJ73UQyr");
Console.WriteLine();
Console.ResetColor();
}
Expand Down
1 change: 1 addition & 0 deletions src/CoiniumServ/config/pools/default-example.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"payments": {
"enabled": true,
"interval": 60,
"checkInterval": 60,
"minimum": 0.01
},
"miner": {
Expand Down
6 changes: 4 additions & 2 deletions src/CoiniumServ/config/pools/pool.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
"password": "password"
},
"wallet": {
"address": "n3Mvrshbf4fMoHzWZkDVbhhx4BLZCcU9oY"
"address": "n3Mvrshbf4fMoHzWZkDVbhhx4BLZCcU9oY",
"txfee": 0.001
},
"rewards": [
{
"myxWybbhUkGzGF7yaf2QVNx3hh3HWTya5t": 1
"n3Mvrshbf4fMoHzWZkDVbhhx4BLZCcU9oY": 0.1,
"myxWybbhUkGzGF7yaf2QVNx3hh3HWTya5t": 0.9
}
],
"stratum": {
Expand Down
Binary file not shown.

0 comments on commit 6515fe7

Please sign in to comment.