Ejemplo n.º 1
0
        /// <summary>
        /// Get the unspent coin references for a specific address.
        /// For now it only works using the NeoScan API.
        /// </summary>
        /// <param name="address"></param>
        /// <param name="restService"></param>
        /// <returns></returns>
        public static async Task <IEnumerable <Coin> > GetUnspent(string address,
                                                                  INeoscanService restService)
        {
            if (restService == null)
            {
                throw new NullReferenceException("REST client not configured");
            }
            var addressBalance = await restService.GetBalanceAsync(address);

            var coinList = new List <Coin>();

            if (addressBalance.Balance != null)
            {
                coinList.AddRange(from balanceEntry in addressBalance.Balance
                                  let child = balanceEntry?.Unspent
                                              where child?.Count > 0
                                              from unspent in balanceEntry?.Unspent
                                              select new Coin
                {
                    Output = new TransactionOutput
                    {
                        AssetId    = UInt256.Parse(balanceEntry?.AssetHash),
                        ScriptHash = address?.ToScriptHash(),
                        Value      = Fixed8.FromDecimal((decimal)unspent.Value),
                    },
                    Reference = new CoinReference
                    {
                        PrevHash  = UInt256.Parse(unspent.TxId),
                        PrevIndex = (ushort)unspent.N,
                    }
                });
            }
            return(coinList);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets nep5 tokens balance from Neoscan.
        /// </summary>
        /// <param name="address"></param>
        /// <param name="restService"></param>
        /// <returns></returns>
        //TODO change this to become neoscan independent
        public static async Task <List <Balance> > GetNep5Balances(string address,
                                                                   INeoscanService restService)
        {
            if (restService == null)
            {
                throw new NullReferenceException("REST client not configured");
            }
            var addressBalance = await restService.GetBalanceAsync(address);

            var nep5Balances = new List <Balance>();

            if (addressBalance.Balance != null)
            {
                foreach (var balanceEntry in addressBalance.Balance)
                {
                    if (balanceEntry.Amount > 0)
                    {
                        nep5Balances.Add(balanceEntry);
                    }
                }
            }

            return(nep5Balances);
        }