Esempio n. 1
0
        private decimal CheckForLowerThreshold(decimal stakeSplitThreshold)
        {
            Log.Debug("Call of method: decimal ProcessWallet.CheckForLowerThreshold(decimal stakeSplitThreshold).");
            Log.Verbose("Parameter stakeSplitThreshold: {stakeSplitThreshold}.", stakeSplitThreshold);
            //If every staking input is not older than StakePatient/2 days lower the thereshold
            List <ListUnspentResponse> stakeInputs = AccessWallet.ListUnspent(0, int.MaxValue, new List <string> {
                Settings.Stake.DedicatedStakingAddress
            });

            if (stakeInputs.Count <= 0)
            {
                return(stakeSplitThreshold);
            }

            decimal             newStakeSplitThreshold = stakeSplitThreshold;
            ListUnspentResponse oldestInput            = stakeInputs.OrderByDescending(s => s.Confirmations).First();
            double waitDays = Settings.Stake.StakingPatience / 2D;

            DateTime blockdate = TransactionHelper.BaseDate.AddSeconds(AccessWallet.GetTransaction(oldestInput.TxId).BlockTime);

            if (blockdate > DateTime.UtcNow.AddDays(-waitDays))
            {
                newStakeSplitThreshold = oldestInput.Amount >= stakeSplitThreshold?Math.Ceiling(oldestInput.Amount * 0.8M) : Math.Ceiling(oldestInput.Amount);
            }

            decimal ret = Math.Min(stakeSplitThreshold, newStakeSplitThreshold);

            Log.Verbose("Returnvalue of ProcessWallet.CheckForLowerThreshold(decimal stakeSplitThreshold): {ret}.", ret);
            return(ret);
        }
Esempio n. 2
0
        private void CreateNewInputs(decimal stakeSplitThreshold)
        {
            Log.Debug("Call of method: void ProcessWallet.CreateNewInputs(decimal stakeSplitThreshold).");
            Log.Verbose("Parameter stakeSplitThreshold: {stakeSplitThreshold}.", stakeSplitThreshold);
            if (!Settings.Stake.EditStakes)
            {
                Log.Information("Edit stakes deactivated. No new stake input will be created.");
                return;
            }

            ListUnspentResponse addressInput = AccessWallet.ListUnspent(1, int.MaxValue, new List <string> {
                Settings.Stake.DedicatedCollectingAddress
            })
                                               .OrderByDescending(i => i.Amount)
                                               .FirstOrDefault();

            if (!(addressInput?.Amount >= stakeSplitThreshold))
            {
                Log.Information("No need to create a new stake input.");
                return;
            }

            Log.Information("Create a new stake input.");
            var inputs  = new List <CreateRawTransactionInput>();
            var outputs = new Dictionary <string, decimal>();

            inputs.Add(new CreateRawTransactionInput {
                TxId = addressInput.TxId, Vout = addressInput.Vout
            });
            outputs.Add(Settings.Stake.DedicatedStakingAddress, addressInput.Amount);
            Send(inputs, outputs);
        }
Esempio n. 3
0
        private void ManageLowInputs(decimal stakeSplitThreshold)
        {
            Log.Debug("Call of method: void ProcessWallet.ManageLowInputs(decimal stakeSplitThreshold).");
            Log.Verbose("Parameter stakeSplitThreshold: {stakeSplitThreshold}.", stakeSplitThreshold);
            if (!Settings.Stake.EditStakes)
            {
                Log.Information("Edit stakes deactivated. No stake input will be altered.");
                return;
            }

            var found     = true;
            int maxInputs = TransactionHelper.GetMaxPossibleInputCountForFreeTransaction(2);

            Log.Verbose("Allowed inputs: {maxInputs}.", maxInputs);
            int maxOutputs = TransactionHelper.GetMaxPossibleOutputCountForFreeTransaction(2);

            Log.Verbose("Allowed outputs: {maxInputs}.", maxOutputs);

            if (maxInputs < 2 || maxOutputs < 2)
            {
                Log.Warning("Unable to create a zero fee transaction.");
                //Impossible to make zero fee transaction.
                return;
            }

            while (found)
            {
                found = false;

                ListUnspentResponse addressInput = AccessWallet.ListUnspent(1, int.MaxValue, new List <string> {
                    Settings.Stake.DedicatedCollectingAddress
                })
                                                   .OrderByDescending(i => i.Amount)
                                                   .FirstOrDefault();
                if (!(addressInput?.Amount > 0))
                {
                    continue;
                }

                List <ListUnspentResponse> lowInputs = AccessWallet.ListUnspent(1, int.MaxValue, new List <string> {
                    Settings.Stake.DedicatedStakingAddress
                });
                //Low confirmations first. This will prevent the threshold update logic to be confused and this are the inputs that stake less.
                ListUnspentResponse lowInput = lowInputs.OrderBy(i => i.Confirmations).FirstOrDefault(i => i.Amount < stakeSplitThreshold);
                if (lowInput == null)
                {
                    Log.Information("No need to alter a stake input.");
                    continue;
                }

                Log.Information("Alter a stake input to match stake split threshold.");
                decimal mergedAmount = lowInput.Amount + addressInput.Amount;
                var     inputs       = new List <CreateRawTransactionInput>();
                var     outputs      = new Dictionary <string, decimal>();
                inputs.Add(new CreateRawTransactionInput {
                    TxId = addressInput.TxId, Vout = addressInput.Vout
                });
                inputs.Add(new CreateRawTransactionInput {
                    TxId = lowInput.TxId, Vout = lowInput.Vout
                });
                if (mergedAmount > stakeSplitThreshold)
                {
                    outputs.Add(Settings.Stake.DedicatedStakingAddress, stakeSplitThreshold);
                    outputs.Add(Settings.Stake.DedicatedCollectingAddress, mergedAmount - stakeSplitThreshold);
                }
                else
                {
                    outputs.Add(Settings.Stake.DedicatedStakingAddress, mergedAmount);
                }

                string transaction = Send(inputs, outputs);
                found = true;
                WaitTillAllConfirmed(new List <string> {
                    transaction
                });
            }
        }