Exemple #1
0
        public Task <List <Tuple <string, int> > > GetTransactionToAccount()
        {
            return(Task.Run(() =>
            {
                if (ServerList.Count == 0)
                {
                    return null;
                }
                TxInresults = new Dictionary <byte[], int>(new ByteArrayComparer());
                int bizantine = ServerList.Count / 3;
                List <Thread> threads = new List <Thread>();
                for (int i = 0; i < 2 * bizantine + 1; i++)
                {
                    Thread t = new Thread(GetTransactionToAccountThread);
                    t.Start(i);
                    threads.Add(t);
                }
                foreach (Thread t in threads)
                {
                    t.Join();
                }
                if (TxInresults.Keys.Count == 0)
                {
                    return null;
                }
                byte[] value = TxInresults.Keys.First();
                int occurence = TxInresults[value];
                foreach (byte[] b in TxInresults.Keys)
                {
                    if (TxInresults[b] > occurence)
                    {
                        value = b;
                        occurence = TxInresults[b];
                    }
                }
                Console.WriteLine("Occurence:" + TxInresults[value]);

                string Txs = Encoding.UTF8.GetString(value);
                Txs = Txs.Substring(1, Txs.Length - 2);
                List <string> list = Txs.Split(',').ToList();
                List <Tuple <string, int> > txOuts = new List <Tuple <string, int> >();
                foreach (string str in list)
                {
                    string tx = str.Substring(1, str.Length - 2);
                    Tx transaction = Tx.DeserializeSignedTx(Convert.FromBase64String(tx));
                    if (transaction != null)
                    {
                        foreach (TxOut txOut in transaction.TxOuts)
                        {
                            if (txOut.address.Equals(Convert.ToBase64String(this.Account.address)))
                            {
                                txOuts.Add(new Tuple <string, int>(Convert.ToBase64String(transaction.FromAddress), txOut.value));
                            }
                        }
                    }
                }
                return txOuts;
            }));
        }
Exemple #2
0
        //129.78.10.53,7822
        //129.78.10.53,7722
        //129.78.10.53,7622
        //129.78.10.53,7522
        //"{'method':'RpcNode.BootstrapTable','params':[null],'id':0}";
        //"{'method':'RpcNode.GetTableAccount','params':[null],'id':0}"
        public static void Call(string method, Object[] parameters, TcpClient client)
        {
            JsonObj json = new JsonObj(method, parameters, 0);
            dynamic recvJson;

            using (NetworkStream networkStream = client.GetStream())
            {
                String jsonData = JsonConvert.SerializeObject(json);
                Byte[] jsonByte = Encoding.UTF8.GetBytes(jsonData);
                networkStream.Write(jsonByte, 0, jsonByte.Length);
                String recv         = "";
                int    bufferLength = -1;
                Byte[] buffer       = new Byte[40000];
                do
                {
                    bufferLength = networkStream.Read(buffer, 0, buffer.Length);
                    recv        += Encoding.UTF8.GetString(buffer);
                    if (recv.IndexOf("\n") != -1)
                    {
                        break;
                    }
                } while (bufferLength != 0);
                recv     = recv.Substring(0, recv.IndexOf("\n"));
                recvJson = JObject.Parse(recv);
                Console.WriteLine(recvJson);
            }
            string result = recvJson.GetValue("result");

            //Console.WriteLine(result);
            byte[] b = Convert.FromBase64String(result);


            string Txs = Encoding.UTF8.GetString(b);

            Console.WriteLine(Txs);
            Txs = Txs.Substring(1, Txs.Length - 2);
            List <string> list = Txs.Split(',').ToList();

            foreach (string str in list)
            {
                Console.WriteLine();

                string tx = str.Substring(1, str.Length - 2);
                //Console.WriteLine("Signed Transaction Hash: "+tx);

                Tx transaction = Tx.DeserializeSignedTx(Convert.FromBase64String(tx));
                Console.WriteLine("From address: " + Convert.ToBase64String(transaction.FromAddress));
                Console.WriteLine("TxOuts:");

                foreach (TxOut txOut in transaction.TxOuts)
                {
                    Console.WriteLine("To address: " + txOut.address + "\nValue: " + txOut.value);
                }
            }
        }