Example #1
0
        // Note: This current implementation requires NeoScan running at port 4000
        public override Dictionary <string, List <UnspentEntry> > GetUnspent(UInt160 hash)
        {
            var url  = this.neoscanUrl + "/api/main_net/v1/get_balance/" + hash.ToAddress();
            var json = RequestUtils.GetWebRequest(url);

            var root     = LunarLabs.Parser.JSON.JSONReader.ReadFromString(json);
            var unspents = new Dictionary <string, List <UnspentEntry> >();

            root = root["balance"];

            foreach (var child in root.Children)
            {
                var symbol = child.GetString("asset");

                List <UnspentEntry> list = new List <UnspentEntry>();
                unspents[symbol] = list;

                var unspentNode = child.GetNode("unspent");
                foreach (var entry in unspentNode.Children)
                {
                    var txid = entry.GetString("txid");
                    var val  = entry.GetDecimal("value");
                    var temp = new UnspentEntry()
                    {
                        hash = new UInt256(LuxUtils.ReverseHex(txid).HexToBytes()), value = val, index = entry.GetUInt32("n")
                    };
                    list.Add(temp);
                }
            }

            return(unspents);
        }
Example #2
0
        public override Dictionary <string, List <UnspentEntry> > GetUnspent(UInt160 hash)
        {
            var result = new Dictionary <string, List <UnspentEntry> >();

            var account = Chain.GetAccount(hash);

            foreach (var entry in account.unspent)
            {
                var tx     = Chain.GetTransaction(entry.prevHash);
                var output = tx.outputs[entry.prevIndex];

                var unspent = new UnspentEntry()
                {
                    index = entry.prevIndex, hash = entry.prevHash, value = output.value
                };

                var symbol = NeoAPI.SymbolFromAssetID(output.assetID);

                List <UnspentEntry> list;

                if (result.ContainsKey(symbol))
                {
                    list = result[symbol];
                }
                else
                {
                    list           = new List <UnspentEntry>();
                    result[symbol] = list;
                }

                list.Add(unspent);
            }

            return(result);
        }
Example #3
0
        public override Dictionary <string, List <UnspentEntry> > GetUnspent(UInt160 hash)
        {
            try
            {
                var response = DoRequest("GetUnspent", hash.ToAddress());
                var result   = new Dictionary <string, List <UnspentEntry> >();

                foreach (var node in response.Children)
                {
                    var asset   = node.GetString("asset");
                    var entries = node.GetNode("unspents");

                    var list = new List <UnspentEntry>();
                    foreach (var child in entries.Children)
                    {
                        var entry = new UnspentEntry()
                        {
                            hash  = new UInt256(child.GetString("hash").HexToBytes()),
                            index = child.GetUInt32("index"),
                            value = child.GetDecimal("value")
                        };
                        list.Add(entry);
                    }

                    result[asset] = list;
                }
                return(result);
            }
            catch (EmulatorException e)
            {
                throw e;
            }
        }
Example #4
0
 public override List <UnspentEntry> GetClaimable(UInt160 hash, out decimal amount)
 {
     try
     {
         var response = DoRequest("GetClaimable", hash.ToAddress());
         var result   = new List <UnspentEntry>();
         amount = 0;
         foreach (var node in response.Children)
         {
             var entry = new UnspentEntry()
             {
                 hash  = new UInt256(node.GetString("hash").HexToBytes()),
                 index = node.GetUInt32("index"),
                 value = node.GetDecimal("value")
             };
             amount += entry.value;
             result.Add(entry);
         }
         return(result);
     }
     catch (EmulatorException e)
     {
         throw e;
     }
 }
Example #5
0
 public static Dictionary\\\>\ GetUnspent(Net net, string address)
 {
   var result = new Dictionary\\\>\();
   var neoscan = new NeoscanApi(net);
   var response = neoscan.GetBalance(address);
   foreach (var b in response.Balance)
   {
     var entry = b.Unspent.Select(u =\>\
       new UnspentEntry
       {
         index = u.N,
         txid = u.Txid,
         value = u.Value
       }
     );
     result.Add(b.Asset.ToUpper(), entry.ToList());
   }
   return result;
 }
Example #6
0
        public Dictionary <string, List <UnspentEntry> > GetUnspent(string address, UInt256 th)
        {
            JObject unspent =
                th.Equals(UInt256.Zero) ?
                ProcessGetUnspents(new JArray(address)) :
                ProcessGetUnspents(new JArray(address, true, th.ToString()));

            var result = new Dictionary <string, List <UnspentEntry> >();

            foreach (var node in (JArray)unspent["balance"])
            {
                var child = (JArray)node["unspent"];
                if (child != null)
                {
                    List <UnspentEntry> list;
                    string sym = node["asset_symbol"].AsString();
                    if (result.ContainsKey(sym))
                    {
                        list = result[sym];
                    }
                    else
                    {
                        list        = new List <UnspentEntry>();
                        result[sym] = list;
                    }

                    foreach (var utxo in child)
                    {
                        var input = new UnspentEntry()
                        {
                            txid  = utxo["txid"].AsString(),
                            index = (uint)utxo["n"].AsNumber(),
                            value = (decimal)utxo["value"].AsNumber()
                        };

                        list.Add(input);
                    }
                }
            }
            return(result);
        }
Example #7
0
        public static Dictionary <string, List <UnspentEntry> > GetUnspent(Net net, string address)
        {
            var apiEndpoint = getAPIEndpoint(net);
            var url         = apiEndpoint + "/v2/address/balance/" + address;
            var response    = RequestUtils.Request(RequestType.GET, url);

            var result = new Dictionary <string, List <UnspentEntry> >();

            foreach (var node in response.Children)
            {
                var child = node.GetNode("unspent");
                if (child != null)
                {
                    List <UnspentEntry> list;
                    if (result.ContainsKey(node.Name))
                    {
                        list = result[node.Name];
                    }
                    else
                    {
                        list = new List <UnspentEntry>();
                        result[node.Name] = list;
                    }

                    foreach (var data in child.Children)
                    {
                        var input = new UnspentEntry()
                        {
                            txid  = data.GetString("txid"),
                            index = data.GetUInt32("index"),
                            value = data.GetDecimal("value")
                        };

                        list.Add(input);
                    }
                }
            }
            return(result);
        }