コード例 #1
0
 public void deserialize_block_headers()
 {
     var bitcoinSerializer = new BitcoinSerializer(NetworkParameters.ProdNet());
     using (var bais = new MemoryStream(Hex.Decode("f9beb4d9686561" +
             "646572730000000000520000005d4fab8101010000006fe28c0ab6f1b372c1a6a246ae6" +
             "3f74f931e8365e15a089c68d6190000000000982051fd1e4ba744bbbe680e1fee14677b" +
             "a1a3c3540bf7b1cdb606e857233e0e61bc6649ffff001d01e3629900")))
     {
         var headerMessage = (HeadersMessage)bitcoinSerializer.Deserialize(bais);
         var block = headerMessage.BlockHeaders.FirstOrDefault();
         block.Should().NotBeNull();
         block.HashAsString.Should().Be("00000000839a8e6886ab5951d76f411475428afc90947ee320161bbf18eb6048");
         block.Transactions.Should().BeEmpty();
     }
 }
コード例 #2
0
 public void TestAddr()
 {
     var bs = new BitcoinSerializer(NetworkParameters.ProdNet());
     // the actual data from https://en.bitcoin.it/wiki/Protocol_specification#addr
     using (var bais = new MemoryStream(Hex.Decode("f9beb4d96164647200000000000000001f000000" +
                                                   "ed52399b01e215104d010000000000000000000000000000000000ffff0a000001208d")))
     {
         var a = (AddressMessage)bs.Deserialize(bais);
         Assert.AreEqual(1, a.Addresses.Count);
         var pa = a.Addresses[0];
         Assert.AreEqual(8333, pa.Port);
         Assert.AreEqual("10.0.0.1", pa.IpAddress.ToString());
     }
 }
コード例 #3
0
        public void TestVerack()
        {
            var bitcoinSerializer = new BitcoinSerializer(NetworkParameters.ProdNet());

            using (var memoryStream = new MemoryStream(Hex.Decode(ConstantVersionAck)))
            {
                var message = bitcoinSerializer.Deserialize(memoryStream) as VersionAckMessage;
                message.Should().NotBeNull();

            }
        }
コード例 #4
0
        public void TestVersion()
        {
            var bs = new BitcoinSerializer(NetworkParameters.ProdNet());
            // the actual data from https://en.bitcoin.it/wiki/Protocol_specification#version
            using (var bais = new MemoryStream(Hex.Decode("f9 be b4 d9 76 65 72 73 69 6f 6e 00 00 00 00 00" +
                                                          "64 00 00 00 35 8d 49 32 62 ea 00 00 01 00 00 00" +
                                                          "00 00 00 00 11 b2 d0 50 00 00 00 00 01 00 00 00" +
                                                          "00 00 00 00 00 00 00 00 00 00 00 00 00 00 ff ff" +
                                                          "00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00" +
                                                          "00 00 00 00 00 00 00 00 ff ff 00 00 00 00 00 00" +
                                                          "3b 2e b3 5d 8c e6 17 65 0f 2f 53 61 74 6f 73 68" +
                                                          "69 3a 30 2e 37 2e 32 2f c0 3e 03 00")))
            {
                var vm = (VersionMessage)bs.Deserialize(bais);
                Assert.AreEqual(60002, vm.ClientVersion);
                Assert.AreEqual(1355854353, vm.Time);
                Assert.AreEqual(1952535343, vm.BestHeight);

            }
        }
コード例 #5
0
        public void TestAddress_Something()
        {
            var bitcoinSerializer = new BitcoinSerializer(NetworkParameters.ProdNet());

            using (var bais = new MemoryStream(_addrMessage))
            {
                var addressMessage = (AddressMessage)bitcoinSerializer.Deserialize(bais);
                addressMessage.Addresses.Count.Should().Be(1);
                var peerAddress = addressMessage.Addresses.FirstOrDefault();
                peerAddress.Should().NotBeNull();
                peerAddress.Port.Should().Be(8333);
            }
        }