public IAPIResult GetAccount([APIParameter("Address of account", "PDHcAHq1fZXuwDrtJGDhjemFnj2ZaFc7iu3qD4XjZG9eV")] string addressText) { if (!Address.IsValidAddress(addressText)) { return(new ErrorResult { error = "invalid address" }); } var result = new AccountResult(); var address = Address.FromText(addressText); result.address = address.Text; result.name = Nexus.LookUpAddress(address); var balanceList = new List <BalanceResult>(); foreach (var symbol in Nexus.Tokens) { foreach (var chainName in Nexus.Chains) { var chain = Nexus.FindChainByName(chainName); var balance = chain.GetTokenBalance(symbol, address); if (balance > 0) { var token = Nexus.GetTokenInfo(symbol); var balanceEntry = new BalanceResult { chain = chain.Name, amount = balance.ToString(), symbol = token.Symbol, decimals = (uint)token.Decimals, ids = new string[0] }; if (!token.IsFungible) { var ownerships = new OwnershipSheet(symbol); var idList = ownerships.Get(chain.Storage, address); if (idList != null && idList.Any()) { balanceEntry.ids = idList.Select(x => x.ToString()).ToArray(); } } balanceList.Add(balanceEntry); } } } result.balances = balanceList.ToArray(); return(result); }
public IAPIResult GetAccount([APIParameter("Address of account", "PDHcAHq1fZXuwDrtJGDhjemFnj2ZaFc7iu3qD4XjZG9eV")] string addressText) { if (!Address.IsValidAddress(addressText)) { return(new ErrorResult { error = "invalid address" }); } var result = new AccountResult(); var address = Address.FromText(addressText); result.address = address.Text; result.name = Nexus.LookUpAddress(address); var balanceList = new List <BalanceResult>(); foreach (var token in Nexus.Tokens) { foreach (var chain in Nexus.Chains) { var balance = chain.GetTokenBalance(token, address); if (balance > 0) { var balanceEntry = new BalanceResult { chain = chain.Name, amount = balance.ToString(), symbol = token.Symbol, decimals = (uint)token.Decimals, ids = new string[0] }; if (!token.IsFungible) { // TODO do we need to go this deep, arent there any higher level methods to achieve this already? var idList = chain.GetTokenOwnerships(token).Get(chain.Storage, address); if (idList != null && idList.Any()) { balanceEntry.ids = idList.Select(x => x.ToString()).ToArray(); } } balanceList.Add(balanceEntry); } } } result.balances = balanceList.ToArray(); return(result); }