예제 #1
0
        /// <summary>
        /// Get the history of withdrawals and statuses.
        /// </summary>
        /// <param name="maximumEntriesToReturn">The maximum number of entries to return.</param>
        /// <returns>A <see cref="WithdrawalModel"/> object containing a history of withdrawals and statuses.</returns>
        public List <WithdrawalModel> GetHistory(int maximumEntriesToReturn)
        {
            var result = new List <WithdrawalModel>();

            IWithdrawal[] withdrawals = this.federationWalletManager.GetWithdrawals().Take(maximumEntriesToReturn).ToArray();

            if (withdrawals.Length > 0)
            {
                ICrossChainTransfer[] transfers = this.crossChainTransferStore.GetAsync(withdrawals.Select(w => w.DepositId).ToArray()).GetAwaiter().GetResult().ToArray();

                for (int i = 0; i < withdrawals.Length; i++)
                {
                    ICrossChainTransfer transfer = transfers[i];
                    var model = new WithdrawalModel();
                    model.withdrawal = withdrawals[i];
                    string status = transfer?.Status.ToString();
                    switch (transfer?.Status)
                    {
                    case CrossChainTransferStatus.FullySigned:
                        if (this.mempoolManager.InfoAsync(model.withdrawal.Id).GetAwaiter().GetResult() != null)
                        {
                            status += "+InMempool";
                        }

                        model.SpendingOutputDetails = this.GetSpendingInfo(transfer.PartialTransaction);
                        break;

                    case CrossChainTransferStatus.Partial:
                        status += " (" + transfer.GetSignatureCount(this.network) + "/" + this.federationGatewaySettings.MultiSigM + ")";
                        model.SpendingOutputDetails = this.GetSpendingInfo(transfer.PartialTransaction);
                        break;
                    }

                    model.TransferStatus = status;
                    result.Add(model);
                }
            }

            return(result);
        }
        private string CollectStats()
        {
            StringBuilder benchLog = new StringBuilder();

            benchLog.AppendLine();
            benchLog.AppendLine("====== Federation Wallet ======");

            (Money ConfirmedAmount, Money UnConfirmedAmount)balances = this.federationWalletManager.GetWallet().GetSpendableAmount();
            bool isFederationActive = this.federationWalletManager.IsFederationActive();

            benchLog.AppendLine("Federation Wallet: ".PadRight(LoggingConfiguration.ColumnLength)
                                + " Confirmed balance: " + balances.ConfirmedAmount.ToString().PadRight(LoggingConfiguration.ColumnLength)
                                + " Unconfirmed balance: " + balances.UnConfirmedAmount.ToString().PadRight(LoggingConfiguration.ColumnLength)
                                + " Federation Status: " + (isFederationActive ? "Active" : "Inactive"));
            benchLog.AppendLine();

            var apiSettings = (ApiSettings)this.fullNode.Services.ServiceProvider.GetService(typeof(ApiSettings));

            if (!isFederationActive)
            {
                var warning =
                    "=============================================".PadLeft(10, '=')
                    + Environment.NewLine
                    + Environment.NewLine + "Federation node not enabled. You will not be able to sign transactions until you enable it."
                    + Environment.NewLine + $"If not done previously, please import your private key using "
                    + Environment.NewLine + $"{apiSettings.ApiUri}/api/FederationWallet/{FederationWalletRouteEndPoint.ImportKey}"
                    + Environment.NewLine + $"Then enable the wallet using "
                    + Environment.NewLine + $"{apiSettings.ApiUri}/api/FederationWallet/{FederationWalletRouteEndPoint.EnableFederation}"
                    + Environment.NewLine
                    + Environment.NewLine + $"============================================".PadLeft(10, '=')
                    + Environment.NewLine;
                benchLog.AppendLine(warning);
            }

            // Display recent withdrawals (if any).
            IWithdrawal[] withdrawals = this.federationWalletManager.GetWithdrawals().Take(5).ToArray();
            if (withdrawals.Length > 0)
            {
                benchLog.AppendLine("-- Recent Withdrawals --");
                ICrossChainTransfer[] transfers = this.crossChainTransferStore.GetAsync(withdrawals.Select(w => w.DepositId).ToArray()).GetAwaiter().GetResult().ToArray();
                for (int i = 0; i < withdrawals.Length; i++)
                {
                    ICrossChainTransfer transfer   = transfers[i];
                    IWithdrawal         withdrawal = withdrawals[i];
                    string line = withdrawal.GetInfo() + " Status=" + transfer?.Status;
                    switch (transfer?.Status)
                    {
                    case CrossChainTransferStatus.FullySigned:
                        if (this.mempoolManager.InfoAsync(withdrawal.Id).GetAwaiter().GetResult() != null)
                        {
                            line += "+InMempool";
                        }
                        break;

                    case CrossChainTransferStatus.Partial:
                        line += " (" + transfer.GetSignatureCount(this.network) + "/" + this.federationGatewaySettings.MultiSigM + ")";
                        break;
                    }

                    benchLog.AppendLine(line);
                }
                benchLog.AppendLine();
            }

            benchLog.AppendLine("====== NodeStore ======");
            this.AddBenchmarkLine(benchLog, new (string, int)[] {