예제 #1
0
        public override async Task <GetBalanceReply> GetBalance(GetBalanceRequest request, ServerCallContext context)
        {
            try
            {
                var client = LyraRestClient.Create(_config["network"], Environment.OSVersion.ToString(), "LyraBroker", "1.0");
                var wallet = new TransitWallet(request.PrivateKey, client);

                var result = await wallet.ReceiveAsync();

                if (result == Lyra.Core.Blocks.APIResultCodes.Success)
                {
                    var blances = await wallet.GetBalanceAsync();

                    if (blances != null)
                    {
                        var msg = new GetBalanceReply {
                            AccountId = wallet.AccountId
                        };
                        foreach (var kvp in blances)
                        {
                            msg.Balances.Add(new LyraBalance {
                                Ticker = kvp.Key, Balance = kvp.Value / 100000000
                            });
                        }
                        return(msg);
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.LogWarning("In OpenWallet: " + ex.ToString());
            }

            return(new GetBalanceReply());
        }
        public async Task <BalanceInfo> GetBalance(string privateKey)
        {
            try
            {
                var client = LyraRestClient.Create(_config["network"], Environment.OSVersion.ToString(), "LyraBroker", "1.0");
                var wallet = new TransitWallet(privateKey, client);

                var result = await wallet.ReceiveAsync();

                if (result == Lyra.Core.Blocks.APIResultCodes.Success)
                {
                    var blances = await wallet.GetBalanceAsync();

                    if (blances != null)
                    {
                        var msg = new BalanceInfo
                        {
                            AccountId = wallet.AccountId
                        };
                        var list = new List <LyraBalance>();
                        foreach (var kvp in blances)
                        {
                            list.Add(new LyraBalance {
                                Ticker = kvp.Key, Balance = kvp.Value / 100000000
                            });
                        }
                        msg.Balances = list.ToArray();
                        return(msg);
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.LogWarning("In OpenWallet: " + ex.ToString());
            }

            return(new BalanceInfo());
        }