Пример #1
0
        private async Task <bool> TaskSendPacketRemoteNode(string command)
        {
            if (!RemoteNodeStatus)
            {
                return(false);
            }
            try
            {
                using (var _remoteNodeStream = new NetworkStream(_remoteNodeClient.Client))
                {
                    using (var bufferedStream = new BufferedStream(_remoteNodeStream, ClassConnectorSetting.MaxNetworkPacketSize))
                    {
                        using (var packetObject = new ClassWalletConnectToRemoteNodeObjectSendPacket(command + "*"))
                        {
                            await bufferedStream.WriteAsync(packetObject.packetByte, 0, packetObject.packetByte.Length);

                            await bufferedStream.FlushAsync();
                        }
                    }
                }
            }
            catch
            {
                RemoteNodeStatus = false;
                return(false);
            }

            return(true);
        }
Пример #2
0
        /// <summary>
        ///     Send the right packet type to remote node.
        /// </summary>
        /// <returns></returns>
        public async Task <bool> SendPacketTypeRemoteNode(string walletId)
        {
            ClassWalletConnectToRemoteNodeObjectSendPacket packet;

            switch (_remoteNodeClientType)
            {
            case ClassWalletConnectToRemoteNodeObject.ObjectTransaction:
                packet = new ClassWalletConnectToRemoteNodeObjectSendPacket(
                    ClassRemoteNodeCommandForWallet.RemoteNodeSendPacketEnumeration.WalletAskHisNumberTransaction +
                    "|" + walletId + "*");
                break;

            case ClassWalletConnectToRemoteNodeObject.ObjectAskWalletAnonymityTransaction:
                packet = new ClassWalletConnectToRemoteNodeObjectSendPacket(
                    ClassRemoteNodeCommandForWallet.RemoteNodeSendPacketEnumeration.WalletAskHisAnonymityNumberTransaction +
                    "|" + walletId + "*");
                break;

            case ClassWalletConnectToRemoteNodeObject.ObjectSupply:
                packet = new ClassWalletConnectToRemoteNodeObjectSendPacket(
                    ClassRemoteNodeCommandForWallet.RemoteNodeSendPacketEnumeration.AskCoinMaxSupply + "|" +
                    walletId + "*");
                break;

            case ClassWalletConnectToRemoteNodeObject.ObjectCirculating:
                packet = new ClassWalletConnectToRemoteNodeObjectSendPacket(
                    ClassRemoteNodeCommandForWallet.RemoteNodeSendPacketEnumeration.AskCoinCirculating + "|" +
                    walletId + "*");
                break;

            case ClassWalletConnectToRemoteNodeObject.ObjectFee:
                packet = new ClassWalletConnectToRemoteNodeObjectSendPacket(
                    ClassRemoteNodeCommandForWallet.RemoteNodeSendPacketEnumeration.AskTotalFee + "|" + walletId + "*");
                break;

            case ClassWalletConnectToRemoteNodeObject.ObjectBlockMined:
                packet = new ClassWalletConnectToRemoteNodeObjectSendPacket(
                    ClassRemoteNodeCommandForWallet.RemoteNodeSendPacketEnumeration.AskTotalBlockMined + "|" +
                    walletId + "*");
                break;

            case ClassWalletConnectToRemoteNodeObject.ObjectDifficulty:
                packet = new ClassWalletConnectToRemoteNodeObjectSendPacket(
                    ClassRemoteNodeCommandForWallet.RemoteNodeSendPacketEnumeration.AskCurrentDifficulty + "|" +
                    walletId + "*");
                break;

            case ClassWalletConnectToRemoteNodeObject.ObjectRate:
                packet = new ClassWalletConnectToRemoteNodeObjectSendPacket(
                    ClassRemoteNodeCommandForWallet.RemoteNodeSendPacketEnumeration.AskCurrentRate + "|" +
                    walletId + "*");
                break;

            case ClassWalletConnectToRemoteNodeObject.ObjectPendingTransaction:
                packet = new ClassWalletConnectToRemoteNodeObjectSendPacket(
                    ClassRemoteNodeCommandForWallet.RemoteNodeSendPacketEnumeration.AskTotalPendingTransaction +
                    "|" + walletId + "*");
                break;

            case ClassWalletConnectToRemoteNodeObject.ObjectAskLastBlockFound:
                packet = new ClassWalletConnectToRemoteNodeObjectSendPacket(
                    ClassRemoteNodeCommandForWallet.RemoteNodeSendPacketEnumeration.AskLastBlockFoundTimestamp +
                    "|" + walletId + "*");
                break;

            case ClassWalletConnectToRemoteNodeObject.ObjectAskWalletTransaction:
                return(true);

            case ClassWalletConnectToRemoteNodeObject.ObjectAskBlock:
                return(true);

            default:
                return(false);
            }


            try
            {
                using (var _remoteNodeStream = new NetworkStream(_remoteNodeClient.Client))
                {
                    using (var bufferedStreamNetwork = new BufferedStream(_remoteNodeStream, ClassConnectorSetting.MaxNetworkPacketSize))
                    {
                        await bufferedStreamNetwork.WriteAsync(packet.packetByte, 0, packet.packetByte.Length);

                        await bufferedStreamNetwork.FlushAsync();
                    }
                }
            }
            catch (Exception error)
            {
                RemoteNodeStatus = false;
#if DEBUG
                Console.WriteLine("Error to send packet on remote node network: " + error.Message);
#endif
                return(false);
            }


            return(true);
        }