ConstructMessage() public static method

public static ConstructMessage ( string command, byte payload ) : BitSharp.Network.Message
command string
payload byte
return BitSharp.Network.Message
Example #1
0
        public async Task SendVersion(IPEndPoint localEndPoint, IPEndPoint remoteEndPoint, UInt64 nodeId, UInt32 startBlockHeight)
        {
            var versionPayload = Messaging.ConstructVersionPayload(localEndPoint, remoteEndPoint, nodeId, startBlockHeight);
            var versionMessage = Messaging.ConstructMessage("version", NetworkEncoder.EncodeVersionPayload(versionPayload, withRelay: false));

            await SendMessageAsync(versionMessage);
        }
Example #2
0
        public async Task SendGetBlocks(ImmutableArray <UInt256> blockLocatorHashes, UInt256 hashStop)
        {
            var getBlocksPayload = Messaging.ConstructGetBlocksPayload(blockLocatorHashes, hashStop);
            var getBlocksMessage = Messaging.ConstructMessage("getblocks", NetworkEncoder.EncodeGetBlocksPayload(getBlocksPayload));

            await SendMessageAsync(getBlocksMessage);
        }
Example #3
0
        public async Task SendBlock(Block block)
        {
            await Task.Yield();

            var sendBlockMessage = Messaging.ConstructMessage("block", DataEncoder.EncodeBlock(block));

            await SendMessageAsync(sendBlockMessage);
        }
Example #4
0
        public async Task SendTransaction(EncodedTx transaction)
        {
            await Task.Yield();

            var sendTxMessage = Messaging.ConstructMessage("tx", transaction.TxBytes.ToArray());

            await SendMessageAsync(sendTxMessage);
        }
Example #5
0
        public async Task SendGetData(ImmutableArray <InventoryVector> invVectors)
        {
            await Task.Yield();

            var getDataPayload = Messaging.ConstructInventoryPayload(invVectors);
            var getDataMessage = Messaging.ConstructMessage("getdata", NetworkEncoder.EncodeInventoryPayload(getDataPayload));

            await SendMessageAsync(getDataMessage);
        }
Example #6
0
        public async Task SendInventory(ImmutableArray <InventoryVector> invVectors)
        {
            await Task.Yield();

            var invPayload = Messaging.ConstructInventoryPayload(invVectors);
            var invMessage = Messaging.ConstructMessage("inv", NetworkEncoder.EncodeInventoryPayload(invPayload));

            await SendMessageAsync(invMessage);
        }
Example #7
0
        private void OnPing(Peer peer, ImmutableArray <byte> payload)
        {
            if (this.Type == ChainType.Regtest)
            {
                // don't pong back until:
                // - all blocks requested from the comparison tool have been downloaded and processed
                // - current header inventory has been sent to the comparison tool
                while (comparisonHeadersSentEvent.WaitOne(1000) &&
                       this.requestedComparisonBlocks.Count > 0 && comparisonBlockAddedEvent.WaitOne(1000))
                {
                }
            }

            peer.Sender.SendMessageAsync(Messaging.ConstructMessage("pong", payload.ToArray())).Wait();
        }
Example #8
0
        public async Task SendHeaders(ImmutableArray <BlockHeader> blockHeaders)
        {
            await Task.Yield();

            using (var payloadStream = new MemoryStream())
                using (var payloadWriter = new BinaryWriter(payloadStream))
                {
                    payloadWriter.WriteVarInt((UInt64)blockHeaders.Length);
                    foreach (var blockHeader in blockHeaders)
                    {
                        DataEncoder.EncodeBlockHeader(payloadWriter, blockHeader);
                        payloadWriter.WriteVarInt(0);
                    }

                    await SendMessageAsync(Messaging.ConstructMessage("headers", payloadStream.ToArray()));
                }
        }
Example #9
0
 public async Task SendMessageAsync(string command)
 {
     await SendMessageAsync(Messaging.ConstructMessage(command, payload: new byte[0]));
 }