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); }
private void WaitTillAllConfirmed([NotNull] List <string> transactions) { Log.Debug("Call of method: string ProcessWallet.WaitTillAllConfirmed(List<string> transactions)."); Log.Verbose("Parameter transactions: {@transactions}.", transactions); List <string> waitingList = transactions.ToList(); while (waitingList.Count > 0) { Log.Information($"Waiting for {waitingList.Count} transactions to complete."); Task.Delay(TimeSpan.FromSeconds(10)).Wait(); //Some wallets do not allow Zero Fee transactions if the inputs have 0 or even 1 confirmation. //The wallets are not consistent in that, there are wallets that sometimes let the transaction happen //and sometimes the refuse. There seem to be no logic behind that behavior. waitingList = waitingList.Where(t => AccessWallet.GetTransaction(t).Confirmations < TransactionHelper.Confirms).ToList(); } Log.Information("All transactions complete."); }
private decimal CheckForHigherThreshold(decimal stakeSplitThreshold) { Log.Debug("Call of method: decimal ProcessWallet.CheckForHigherThreshold(decimal stakeSplitThreshold)."); Log.Verbose("Parameter stakeSplitThreshold: {stakeSplitThreshold}.", stakeSplitThreshold); decimal newStakeSplitThreshold = stakeSplitThreshold; List <ListUnspentResponse> stakeInputs = AccessWallet.ListUnspent(0, int.MaxValue, new List <string> { Settings.Stake.DedicatedStakingAddress }); if (stakeInputs.Count <= 0) { return(newStakeSplitThreshold); } List <ListUnspentResponse> oldestInputs = stakeInputs.OrderByDescending(s => s.Confirmations) .Where(s => TransactionHelper.BaseDate.AddSeconds(AccessWallet.GetTransaction(s.TxId).BlockTime) < DateTime.UtcNow.AddDays(-Settings.Stake.StakingPatience)) .ToList(); if (oldestInputs.Count > 0) { newStakeSplitThreshold = oldestInputs.Max(i => i.Amount); newStakeSplitThreshold = Math.Floor(newStakeSplitThreshold); if (newStakeSplitThreshold <= stakeSplitThreshold) { newStakeSplitThreshold = oldestInputs.Max(i => i.Amount) * 1.2M; newStakeSplitThreshold = Math.Ceiling(newStakeSplitThreshold); } newStakeSplitThreshold = Math.Max(newStakeSplitThreshold, stakeSplitThreshold); } Log.Verbose("Returnvalue of ProcessWallet.CheckForHigherThreshold(decimal stakeSplitThreshold): {newStakeSplitThreshold}.", newStakeSplitThreshold); return(newStakeSplitThreshold); }