private bool CheckStakingInfo(ref CoinControlStatusReport statusReport) { string errorMessage; StakingInfoRequest stakingInfoRequest = new StakingInfoRequest(); StakingInfoResponse stakingInfoResponse; if (!m_dataConnector.TryPost <StakingInfoResponse>( stakingInfoRequest, out stakingInfoResponse, out errorMessage)) { MessageService.Error(errorMessage); return(false); } if (!stakingInfoResponse.Enabled) { MessageService.Warning(string.Format("Staking is disabled!")); } statusReport.Staking = stakingInfoResponse.Staking; if (stakingInfoResponse.Staking) { statusReport.ExpectedTimeToEarnReward = TimeSpan.FromSeconds(stakingInfoResponse.ExpectedTimeInSeconds); } if (!string.IsNullOrEmpty(stakingInfoResponse.Errors)) { MessageService.Error(string.Format("Staking errors found: {0}", stakingInfoResponse.Errors)); } return(true); }
private bool CheckStakingRewards(ref CoinControlStatusReport statusReport) { string errorMessage; List <TransactionResponse> stakingTransactions; TransactionHelper helper = new TransactionHelper(m_dataConnector); if (!helper.TryGetStakingTransactions( m_config.AddressToCoinControl, 30, out stakingTransactions, out errorMessage)) { MessageService.Error(errorMessage); return(false); } if (stakingTransactions.Count < 1) { statusReport.RewardTotal = 0; return(true); } decimal rewardTotal = 0; foreach (TransactionResponse trans in stakingTransactions) { rewardTotal += trans.Amount; } statusReport.RewardTotal = rewardTotal; statusReport.OldestRewardDateTime = TransactionHelper.GetTransactionTime( stakingTransactions[stakingTransactions.Count - 1].Time).LocalDateTime.Date; return(true); }
private bool SetUnspentTransactionDateTime( List <UnspentResponse> unspentInNeedOfCoinControl, CoinControlStatusReport statusReport, out string errorMessage) { GetTransactionRequest transRequest = new GetTransactionRequest() { TransactionId = unspentInNeedOfCoinControl[0].TransactionId }; GetTransactionResponse transResponse; if (!m_dataConnector.TryPost(transRequest, out transResponse, out errorMessage)) { return(false); } statusReport.UnspentTransactionDateTime = TransactionHelper.GetTransactionTime(transResponse.Time); return(true); }
private void ProcessNext() { MessageService.Break(); MessageService.Info(string.Format("Address: {0}", m_config.AddressToCoinControl)); string errorMessage; if (!TryUnlockWalletForStakingOnly(out errorMessage)) { MessageService.Error(errorMessage); return; } List <UnspentResponse> unspentInNeedOfCoinControl; TransactionHelper helper = new TransactionHelper(m_dataConnector); if (!helper.TryGetUnspentInNeedOfCoinControl( m_config.AddressToCoinControl, out unspentInNeedOfCoinControl, out errorMessage)) { MessageService.Error(errorMessage); return; } CoinControlStatusReport statusReport = CreateStatusReport(unspentInNeedOfCoinControl); if (statusReport == null) { return; } statusReport.Report(MessageService); if (statusReport.Status == CoinControlStatus.Starting) { DoCoinControl(unspentInNeedOfCoinControl); } }
private CoinControlStatusReport CreateStatusReport(List <UnspentResponse> unspentInNeedOfCoinControl) { CoinControlStatusReport statusReport = new CoinControlStatusReport(); if (!CheckStakingRewards(ref statusReport)) { return(null); } string errorMessage; List <TransactionResponse> imatureTransactions; TransactionHelper helper = new TransactionHelper(m_dataConnector); if (!helper.TryGetImatureTransactions( m_config.AddressToCoinControl, 1, out imatureTransactions, out errorMessage)) { MessageService.Error(errorMessage); return(null); } if (imatureTransactions.Count > 0) { statusReport.SetStatus( CoinControlStatus.WaitingForStakeToMature, string.Format( "Waiting for stake to mature - {0} LINDA {1} confirmations {2}", imatureTransactions[0].Amount, imatureTransactions[0].Confirmations, imatureTransactions[0].TransactionId)); return(statusReport); } foreach (UnspentResponse unspent in unspentInNeedOfCoinControl) { if (unspent.Confirmations < m_config.RequiredConfirmations) { statusReport.SetStatus( CoinControlStatus.WaitingForUnspentConfirmations, string.Format( "Waiting for more confirmations - {0}/{1} {2} LINDA {3}", unspent.Confirmations, m_config.RequiredConfirmations, unspent.Amount, unspent.TransactionId)); return(statusReport); } } if (unspentInNeedOfCoinControl.Count > 1) { statusReport.SetStatus( CoinControlStatus.Starting, "Starting..."); return(statusReport); } if (!CheckStakingInfo(ref statusReport)) { return(null); } if (unspentInNeedOfCoinControl.Count == 1) { if (!SetUnspentTransactionDateTime( unspentInNeedOfCoinControl, statusReport, out errorMessage)) { MessageService.Error(errorMessage); return(null); } statusReport.SetStatus( CoinControlStatus.NotReadyOneUnspent, "Not ready - Only one unspent transaction"); return(statusReport); } statusReport.SetStatus( CoinControlStatus.NotReadyWaitingForPaymentToYourself, "Not ready - Waiting for a payment to yourself."); return(statusReport); }