/// <summary> /// apiGetBlocks functions /// </summary> /// <param name="offset">смещение от конечно блока в цепочке</param> /// <param name="count">blocks' value</param> /// <returns>List[HashType] contains hashes(naems) of blocks</returns> public List <HashType> cmdGetBlocks(UInt64 offset = 0, UInt16 count = 20) { List <HashType> list = new List <HashType>(); if (i_connect()) { byte[] snd = new byte[sizeof(UInt64) + sizeof(UInt16)]; BitConverter.GetBytes(offset).CopyTo(snd, 0); BitConverter.GetBytes(count).CopyTo(snd, 8); ApiCmd c = new ApiCmd(ApiCommands.apiGetBlocks); c.sz = (uint)snd.Length; sock.Send(c.GetBytes()); sock.Send(snd); c.cmd = ApiCommands.apiTerminatingBlock; sock.Send(c.GetBytes()); byte[] recv = new byte[6]; sock.Receive(recv); c.SetFromBytes(recv); if (c.cmd == ApiCommands.apiSendBlocks) { recv = new byte[c.sz]; int rbyte = sock.Receive(recv); if (rbyte == c.sz) { for (int i = 0; i < rbyte / 64; i++) { HashType h = new HashType(); Array.Copy(recv, i * 64, h.data, 0, 64); list.Add(h); } } } } return(list); }
/// <summary> /// get counters of blockchain from node /// </summary> /// <param name="block_counter">blocks' value</param> /// <param name="tran_counter">transaction's value</param> /// <param name="bindata_counter">binary data's value</param> /// <remarks> corrent values returns only after reindex on the node </remarks> /// <returns>true - in succeful case </returns> public bool cmdGetCounters(ref ulong block_counter, ref ulong tran_counter, ref ulong bindata_counter) { if (i_connect()) { ApiCmd cmd = new ApiCmd(ApiCommands.apiGetCounters); //cmd.cmd = ApiCommands.apiGetCounters; sock.Send(cmd.GetBytes()); cmd.cmd = ApiCommands.apiTerminatingBlock; sock.Send(cmd.GetBytes()); byte[] recv = new byte[6]; sock.Receive(recv); cmd.SetFromBytes(recv); if (cmd.cmd == ApiCommands.apiSendCounters) { recv = new byte[cmd.sz]; if (sock.Receive(recv) == recv.Length && recv.Length > 0) { block_counter = BitConverter.ToUInt64(recv, 0); tran_counter = BitConverter.ToUInt64(recv, 8); bindata_counter = BitConverter.ToUInt64(recv, 16); return(true); } else { return(false); } } else { return(true); } } return(false); }