Exemplo n.º 1
0
        //private static void DoStorageFulllog(int doBlockIndex)
        //{
        //    DateTime start = DateTime.Now;

        //    var client = new MongoClient(mongodbConnStr);
        //    var database = client.GetDatabase(mongodbDatabase);
        //    var collection = database.GetCollection<BsonDocument>("block");

        //    var findBson = BsonDocument.Parse("{index:" + doBlockIndex + "}");
        //    var query = collection.Find(findBson).ToList();
        //    if (query.Count > 0)
        //    {
        //        BsonDocument queryB = query[0].AsBsonDocument;

        //        foreach (BsonValue bv in queryB["tx"].AsBsonArray)
        //        {
        //            //获取数据库Tx数据
        //            string doTxid = (string)bv["txid"];

        //            JObject postData = new JObject();
        //            postData.Add("jsonrpc", "2.0");
        //            postData.Add("method", "getfullloginfo");
        //            postData.Add("params", new JArray() { doTxid });
        //            postData.Add("id", 1);
        //            string postDataStr = Newtonsoft.Json.JsonConvert.SerializeObject(postData);
        //            //获取Cli Notify数据
        //            string resFulllog = chh.Post(NeoCliJsonRPCUrl, postDataStr,Encoding.UTF8);
        //            if (JObject.Parse(resFulllog)["result"] != null)
        //            {
        //                resFulllog = JObject.Parse(resFulllog)["result"].ToString();
        //            }
        //            else { resFulllog = null; }
        //            if (resFulllog != null)
        //            {
        //                if (!IsDataExist("fulllog", "txid", doTxid))
        //                {
        //                    string fulllog7z = resFulllog;
        //                    JObject j = new JObject
        //                    {
        //                        { "txid", doTxid },
        //                        { "fulllog7z", fulllog7z }
        //                    };
        //                    MongoInsertOne("fulllog", j);
        //                }
        //            }
        //        }

        //        DateTime end = DateTime.Now;
        //        var doTime = (end - start).TotalMilliseconds;
        //        Console.ForegroundColor = ConsoleColor.Magenta;
        //        Console.WriteLine("StorageFulllogData On Block " + doBlockIndex + " in " + doTime + "ms");
        //        Console.ForegroundColor = ConsoleColor.White;

        //        //更新最新处理区块索引
        //        SetSystemCounter("fulllog", doBlockIndex);
        //    }

        //    client = null;
        //}

        //private static void DoStorageUTXO(int doBlockIndex)
        //{
        //    DateTime start = DateTime.Now;

        //    var client = new MongoClient(mongodbConnStr);
        //    var database = client.GetDatabase(mongodbDatabase);
        //    var collection = database.GetCollection<BsonDocument>("block");

        //    var findBson = BsonDocument.Parse("{index:" + doBlockIndex + "}");
        //    var query = collection.Find(findBson).ToList();
        //    if (query.Count > 0)
        //    {
        //        BsonDocument queryB = query[0].AsBsonDocument;

        //        foreach (BsonValue bv in queryB["tx"].AsBsonArray)
        //        {
        //            //获取数据库Tx数据
        //            string doTxid = (string)bv["txid"];
        //            collection = database.GetCollection<BsonDocument>("tx");
        //            var queryTx = collection.Find(BsonDocument.Parse("{txid:'" + doTxid + "'}")).ToList()[0];

        //            BsonArray vinBA = queryTx["vin"].AsBsonArray;
        //            BsonArray voutBA = queryTx["vout"].AsBsonArray;

        //            var collUTXO = database.GetCollection<UTXO>("utxo");
        //            //先处理UTXO生成
        //            if (voutBA.Count > 0)
        //            {
        //                foreach (BsonValue voutBV in voutBA)
        //                {
        //                    UTXO utxo = new UTXO();

        //                    string Addr = voutBV["address"].AsString;
        //                    bool isUTXOexist = IsDataExist("utxo", "Addr", Addr);
        //                    BsonDocument findB = BsonDocument.Parse("{Addr:'" + Addr + "'}");
        //                    if (isUTXOexist)//已有UTXO记录则更新
        //                    {
        //                        //获取已有UTXO记录
        //                        utxo = collUTXO.Find(findB).ToList()[0];
        //                    }
        //                    else
        //                    {
        //                        utxo.Addr = Addr;
        //                    }
        //                    //更新最后区块索引
        //                    utxo.LastBlockindex = doBlockIndex;
        //                    //添加本vout数据
        //                    UTXOrecord utxoR = new UTXOrecord
        //                    {
        //                        GetTx = doTxid,
        //                        N = voutBV["n"].AsInt32,
        //                        Asset = voutBV["asset"].AsString,
        //                        Value = decimal.Parse(voutBV["value"].AsString)
        //                    };
        //                    //检查当前UTXO记录是否已被记录过
        //                    bool isUTXOexist_R = false;
        //                    if (utxo.UTXOrecord != null)
        //                    {
        //                        foreach (var r in utxo.UTXOrecord)
        //                        {
        //                            if (r.GetTx == utxoR.GetTx && r.N == utxoR.N)
        //                            {
        //                                isUTXOexist_R = true;
        //                                break;
        //                            }
        //                        }
        //                    }
        //                    else { utxo.UTXOrecord = new List<UTXOrecord>(); }
        //                    //只有不重复才会添加本vout数据并更新或插入
        //                    if (!isUTXOexist_R)
        //                    {
        //                        utxo.UTXOrecord.Add(utxoR);

        //                        if (isUTXOexist)
        //                        {
        //                            //已存在则更新
        //                            collUTXO.ReplaceOne(findB, utxo);
        //                        }
        //                        else
        //                        {
        //                            //不存在则插入
        //                            collUTXO.InsertOne(utxo);
        //                        }
        //                    }
        //                }
        //            }

        //            //处理UTXO使用
        //            if (vinBA.Count > 0)
        //            {
        //                foreach (BsonValue vinBV in vinBA)
        //                {
        //                    string vinTxid = vinBV["txid"].AsString;
        //                    int vinN = vinBV["vout"].AsInt32;

        //                    BsonDocument queryUTXOaddr = database.GetCollection<BsonDocument>("tx").Find(BsonDocument.Parse("{txid:'" + vinTxid + "'}")).ToList()[0];
        //                    BsonArray queryUTXOaddr_vout = queryUTXOaddr["vout"].AsBsonArray;
        //                    string Addr = string.Empty;
        //                    foreach (BsonValue voutBV in queryUTXOaddr_vout)
        //                    {
        //                        if (voutBV["n"] == vinN)
        //                        {
        //                            Addr = voutBV["address"].AsString;
        //                            break;
        //                        }
        //                    }

        //                    BsonDocument findB = BsonDocument.Parse("{Addr:'" + Addr + "'}");
        //                    UTXO utxo = database.GetCollection<UTXO>("utxo").Find(findB).ToList()[0];
        //                    bool isUseExist = false;//判断是否已被写过use
        //                    foreach (var r in utxo.UTXOrecord)
        //                    {
        //                        if (r.GetTx == vinTxid && r.N == vinN)
        //                        {
        //                            if (r.UseTx != null)
        //                            {
        //                                isUseExist = true;
        //                                break;
        //                            }

        //                            r.UseTx = queryTx["txid"].AsString;
        //                            break;
        //                        }
        //                    }
        //                    //只有不重复才写入
        //                    if (!isUseExist)
        //                    {
        //                        database.GetCollection<UTXO>("utxo").ReplaceOne(findB, utxo);
        //                    }
        //                }
        //            }
        //        }

        //        //更新utxo已处理块高度
        //        SetSystemCounter("utxo", doBlockIndex);

        //        DateTime end = DateTime.Now;
        //        var doTime = (end - start).TotalMilliseconds;
        //        Console.ForegroundColor = ConsoleColor.Yellow;
        //        Console.WriteLine("StorageUTXOData On Block " + doBlockIndex + " in " + doTime + "ms");
        //        Console.ForegroundColor = ConsoleColor.White;

        //        client = null;
        //    }
        //}

        private static string GetNeoCliData(string method, object[] paras)
        {
            Uri rpcEndpoint      = new Uri(NeoCliJsonRPCUrl);
            JsonRpcWebClient rpc = new JsonRpcWebClient(rpcEndpoint);

            var     response = rpc.InvokeAsync <JObject>(method, paras);
            JObject resJ     = JObject.Parse(Newtonsoft.Json.JsonConvert.SerializeObject(response.Result));
            var     resStr   = Newtonsoft.Json.JsonConvert.SerializeObject(resJ["result"]);

            return(resStr);
        }
Exemplo n.º 2
0
        public static async Task <JsonRpcResponse <ReturnType> > RPCCall <ReturnType>(IcxMethods method, RequestParams param = null)
        {
            Uri rpcEndpoint      = new Uri("https://wallet.icon.foundation/api/v3");
            JsonRpcWebClient rpc = new JsonRpcWebClient(rpcEndpoint);

            // you can use Json.Net JValue if the service returns a value or
            // JObject if it returns an object or you can provide your own
            // custom class type to be used when deserializing the rpc result
            var response = rpc.InvokeAsync <ReturnType>(method.ToString(), param);

            return(response.Result);
        }
Exemplo n.º 3
0
        public static async Task CallTestService()
        {
            Uri rpcEndpoint      = new Uri("http://gurujsonrpc.appspot.com/guru");
            JsonRpcWebClient rpc = new JsonRpcWebClient(rpcEndpoint);

            // you can use Json.Net JValue if the service returns a value or
            // JObject if it returns an object or you can provide your own
            // custom class type to be used when deserializing the rpc result
            var response = await rpc.InvokeAsync <JValue>("guru.test", new string[]
            {
                "World"
            });

            System.Console.WriteLine("RPC Reply: {0}", response.Result);
        }