diff --git a/core/src/main/java/org/bitcoinj/core/NetworkParameters.java b/core/src/main/java/org/bitcoinj/core/NetworkParameters.java index d97dd568c..3a23ae26b 100644 --- a/core/src/main/java/org/bitcoinj/core/NetworkParameters.java +++ b/core/src/main/java/org/bitcoinj/core/NetworkParameters.java @@ -678,7 +678,7 @@ public static enum ProtocolVersion { COINJOIN_PROTX_HASH(70226), DMN_TYPE(70227), SMNLE_VERSIONED(70228), - CURRENT(70228); + CURRENT(70227); private final int bitcoinProtocol; diff --git a/core/src/main/java/org/bitcoinj/evolution/CoinbaseTx.java b/core/src/main/java/org/bitcoinj/evolution/CoinbaseTx.java index 1ce6d2631..4e349be83 100644 --- a/core/src/main/java/org/bitcoinj/evolution/CoinbaseTx.java +++ b/core/src/main/java/org/bitcoinj/evolution/CoinbaseTx.java @@ -2,18 +2,25 @@ import org.bitcoinj.core.*; +import org.bitcoinj.crypto.BLSSignature; import org.json.JSONObject; import java.io.IOException; import java.io.OutputStream; +import java.math.BigInteger; public class CoinbaseTx extends SpecialTxPayload { - public static final int CURRENT_VERSION = 2; + public static final int CB_V19_VERSION = 2; + public static final int CB_V20_VERSION = 3; + public static final int CURRENT_VERSION = CB_V19_VERSION; private static final int PAYLOAD_SIZE = 2 + 4 + 32 + 32; long height; Sha256Hash merkleRootMasternodeList; Sha256Hash merkleRootQuorums; //v2 + long bestCLHeightDiff; + BLSSignature bestCLSignature; + Coin assetLockedAmount; public CoinbaseTx(long height, Sha256Hash merkleRootMasternodeList, Sha256Hash merkleRootQuorums) { super(CURRENT_VERSION); @@ -32,8 +39,15 @@ protected void parse() throws ProtocolException { super.parse(); height = readUint32(); merkleRootMasternodeList = readHash(); - if(version >= 2) + if(version >= CB_V19_VERSION) { merkleRootQuorums = readHash(); + if (version >= CB_V20_VERSION) { + bestCLHeightDiff = readVarInt(); + bestCLSignature = new BLSSignature(params, payload, cursor); + cursor += bestCLSignature.getMessageSize(); + assetLockedAmount = Coin.valueOf(readInt64()); + } + } length = cursor - offset; } @@ -42,8 +56,14 @@ protected void bitcoinSerializeToStream(OutputStream stream) throws IOException super.bitcoinSerializeToStream(stream); Utils.uint32ToByteStreamLE(height, stream); stream.write(merkleRootMasternodeList.getReversedBytes()); - if(version >= 2) + if(version >= CB_V19_VERSION) { stream.write(merkleRootQuorums.getReversedBytes()); + if (version >= CB_V20_VERSION) { + stream.write(new VarInt(bestCLHeightDiff).encode()); + bestCLSignature.bitcoinSerialize(stream); + Utils.uint64ToByteStreamLE(BigInteger.valueOf(assetLockedAmount.getValue()), stream); + } + } } public int getCurrentVersion() { @@ -71,6 +91,13 @@ public JSONObject toJson() { result.append("height", height); result.append("merkleRootMNList", merkleRootMasternodeList); result.append("merkleRootQuorums", merkleRootQuorums); + if (version >= CB_V19_VERSION) { + result.append("merkleRootQuorums", merkleRootQuorums); + if (version >= CB_V20_VERSION) { + result.append("bestCLHeightDiff", bestCLHeightDiff); + result.append("bestCLSignature", bestCLSignature.toString()); + } + } return result; } diff --git a/core/src/main/java/org/bitcoinj/evolution/SimplifiedMasternodeListDiff.java b/core/src/main/java/org/bitcoinj/evolution/SimplifiedMasternodeListDiff.java index 3cb0ceb73..bd300b2e8 100644 --- a/core/src/main/java/org/bitcoinj/evolution/SimplifiedMasternodeListDiff.java +++ b/core/src/main/java/org/bitcoinj/evolution/SimplifiedMasternodeListDiff.java @@ -4,6 +4,7 @@ import com.google.common.collect.Sets; import org.bitcoinj.core.*; import org.bitcoinj.crypto.BLSScheme; +import org.bitcoinj.crypto.LazyECPoint; import org.bitcoinj.quorums.FinalCommitment; import org.bitcoinj.store.BlockStore; import org.bitcoinj.utils.Pair; @@ -78,7 +79,7 @@ protected void parse() throws ProtocolException { if (protocolVersion >= NetworkParameters.ProtocolVersion.BLS_SCHEME.getBitcoinProtocolVersion()) { version = (short) readUint16(); } else { - version = CURRENT_VERSION; + version = LEGACY_BLS_VERSION; } int size = (int)readVarInt(); @@ -89,9 +90,12 @@ protected void parse() throws ProtocolException { size = (int)readVarInt(); mnList = new ArrayList(size); + int protocolVersionSMLE = version == BASIC_BLS_VERSION ? + NetworkParameters.ProtocolVersion.DMN_TYPE.getBitcoinProtocolVersion() : + NetworkParameters.ProtocolVersion.BLS_LEGACY.getBitcoinProtocolVersion(); for(int i = 0; i < size; ++i) { - SimplifiedMasternodeListEntry mn = new SimplifiedMasternodeListEntry(params, payload, cursor, protocolVersion); + SimplifiedMasternodeListEntry mn = new SimplifiedMasternodeListEntry(params, payload, cursor, protocolVersionSMLE); cursor += mn.getMessageSize(); mnList.add(mn); } diff --git a/core/src/main/java/org/bitcoinj/evolution/SimplifiedMasternodeListEntry.java b/core/src/main/java/org/bitcoinj/evolution/SimplifiedMasternodeListEntry.java index e8ca5c0cc..c154ac2a1 100644 --- a/core/src/main/java/org/bitcoinj/evolution/SimplifiedMasternodeListEntry.java +++ b/core/src/main/java/org/bitcoinj/evolution/SimplifiedMasternodeListEntry.java @@ -86,8 +86,8 @@ public SimplifiedMasternodeListEntry(NetworkParameters params, SimplifiedMastern @Override protected void parse() throws ProtocolException { - if (protocolVersion >= NetworkParameters.ProtocolVersion.SMNLE_VERSIONED.getBitcoinProtocolVersion()) { - version = (short) readUint16(); + if (protocolVersion >= NetworkParameters.ProtocolVersion.BLS_SCHEME.getBitcoinProtocolVersion()) { + version = BASIC_BLS_VERSION; } else { version = LEGACY_BLS_VERSION; }