mirror of
https://github.com/Qortal/altcoinj.git
synced 2025-02-13 10:45:51 +00:00
Add support for "sendheaders" message (BIP130) and use protocol version to 70012.
For now, we're ignoring this message as bitcoinj does not relay blocks.
This commit is contained in:
parent
ca033e3368
commit
70bef0a129
@ -71,6 +71,7 @@ public class BitcoinSerializer extends MessageSerializer {
|
|||||||
names.put(RejectMessage.class, "reject");
|
names.put(RejectMessage.class, "reject");
|
||||||
names.put(GetUTXOsMessage.class, "getutxos");
|
names.put(GetUTXOsMessage.class, "getutxos");
|
||||||
names.put(UTXOsMessage.class, "utxos");
|
names.put(UTXOsMessage.class, "utxos");
|
||||||
|
names.put(SendHeadersMessage.class, "sendheaders");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -229,6 +230,8 @@ public class BitcoinSerializer extends MessageSerializer {
|
|||||||
return new UTXOsMessage(params, payloadBytes);
|
return new UTXOsMessage(params, payloadBytes);
|
||||||
} else if (command.equals("getutxos")) {
|
} else if (command.equals("getutxos")) {
|
||||||
return new GetUTXOsMessage(params, payloadBytes);
|
return new GetUTXOsMessage(params, payloadBytes);
|
||||||
|
} else if (command.equals("sendheaders")) {
|
||||||
|
return new SendHeadersMessage(params, payloadBytes);
|
||||||
} else {
|
} else {
|
||||||
log.warn("No support for deserializing message with name {}", command);
|
log.warn("No support for deserializing message with name {}", command);
|
||||||
return new UnknownMessage(params, command, payloadBytes);
|
return new UnknownMessage(params, command, payloadBytes);
|
||||||
|
@ -527,7 +527,7 @@ public abstract class NetworkParameters {
|
|||||||
MINIMUM(70000),
|
MINIMUM(70000),
|
||||||
PONG(60001),
|
PONG(60001),
|
||||||
BLOOM_FILTER(70000),
|
BLOOM_FILTER(70000),
|
||||||
CURRENT(70002);
|
CURRENT(70012);
|
||||||
|
|
||||||
private final int bitcoinProtocol;
|
private final int bitcoinProtocol;
|
||||||
|
|
||||||
|
36
core/src/main/java/org/bitcoinj/core/SendHeadersMessage.java
Normal file
36
core/src/main/java/org/bitcoinj/core/SendHeadersMessage.java
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2017 Anton Kumaigorodski
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.bitcoinj.core;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* A new message, "sendheaders", which indicates that a node prefers to receive new block announcements via a "headers"
|
||||||
|
* message rather than an "inv".
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* See <a href="https://github.com/bitcoin/bips/blob/master/bip-0130.mediawiki">BIP 130</a>.
|
||||||
|
* </p>
|
||||||
|
*/
|
||||||
|
public class SendHeadersMessage extends EmptyMessage {
|
||||||
|
public SendHeadersMessage() {
|
||||||
|
}
|
||||||
|
|
||||||
|
// this is needed by the BitcoinSerializer
|
||||||
|
public SendHeadersMessage(NetworkParameters params, byte[] payload) {
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,44 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2017 Anton Kumaigorodski
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.bitcoinj.core;
|
||||||
|
|
||||||
|
import org.bitcoinj.params.RegTestParams;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
|
|
||||||
|
import static org.bitcoinj.core.Utils.HEX;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
public class SendHeadersMessageTest {
|
||||||
|
@Test
|
||||||
|
public void decodeAndEncode() throws Exception {
|
||||||
|
byte[] message = HEX
|
||||||
|
.decode("00000000fabfb5da73656e646865616465727300000000005df6e0e2fabfb5da70696e670000000000000000080000009a"
|
||||||
|
+ "65b9cc9840c9729e4502b200000000000000000000000000000d000000000000000000000000000000000000000000000000007ad82"
|
||||||
|
+ "872c28ac782102f5361746f7368693a302e31342e312fe41d000001fabfb5da76657261636b000000000000000000005df6e0e2fabf"
|
||||||
|
+ "b5da616c65727400000000000000a80000001bf9aaea60010000000000000000000000ffffff7f00000000ffffff7ffeffff7f01fff"
|
||||||
|
+ "fff7f00000000ffffff7f00ffffff7f002f555247454e543a20416c657274206b657920636f6d70726f6d697365642c207570677261"
|
||||||
|
+ "6465207265717569726564004630440220653febd6410f470f6bae11cad19c48413becb1ac2c17f908fd0fd53bdc3abd5202206d0e9"
|
||||||
|
+ "c96fe88d4a0f01ed9dedae2b6f9e00da94cad0fecaae66ecf689bf71b50000000000000000000000000000000000000000000000000");
|
||||||
|
|
||||||
|
ByteBuffer buffer = ByteBuffer.wrap(message);
|
||||||
|
RegTestParams params = org.bitcoinj.params.RegTestParams.get();
|
||||||
|
BitcoinSerializer serializer = new BitcoinSerializer(params, false);
|
||||||
|
assertTrue(serializer.deserialize(buffer) instanceof org.bitcoinj.core.SendHeadersMessage);
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user