From 88d00fe2f07b17c8867af186122b2645f16e8d76 Mon Sep 17 00:00:00 2001 From: **** <****@gmai.com> Date: Wed, 29 Dec 2021 14:00:11 +0800 Subject: [PATCH] upgrade gleec 2 --- .../org/bitcorej/chain/ChainStateProxy.java | 3 ++ .../chain/gleec2/GLEEC2NetParams.java | 27 ++++++++++++++ .../chain/gleec2/GLEEC2StateProvider.java | 37 +++++++++++++++++++ 3 files changed, 67 insertions(+) create mode 100644 core/src/main/java/org/bitcorej/chain/gleec2/GLEEC2NetParams.java create mode 100644 core/src/main/java/org/bitcorej/chain/gleec2/GLEEC2StateProvider.java diff --git a/core/src/main/java/org/bitcorej/chain/ChainStateProxy.java b/core/src/main/java/org/bitcorej/chain/ChainStateProxy.java index 2bbbac7..b1e006f 100644 --- a/core/src/main/java/org/bitcorej/chain/ChainStateProxy.java +++ b/core/src/main/java/org/bitcorej/chain/ChainStateProxy.java @@ -242,6 +242,9 @@ public class ChainStateProxy implements ChainState, UTXOState, USDTState, XMRSta GLEECStateProvider gleec = new GLEECStateProvider(Network.MAIN); services.put("GLEEC", gleec); services.put("GLEEC_MAIN", gleec); + GLEECStateProvider gleec2 = new GLEECStateProvider(Network.MAIN); + services.put("GLEEC2", gleec2); + services.put("GLEEC2_MAIN", gleec2); SPRKStateProvider sprk = new SPRKStateProvider(Network.MAIN); services.put("SPRK", sprk); services.put("SPRK_MAIN", sprk); diff --git a/core/src/main/java/org/bitcorej/chain/gleec2/GLEEC2NetParams.java b/core/src/main/java/org/bitcorej/chain/gleec2/GLEEC2NetParams.java new file mode 100644 index 0000000..1f2f095 --- /dev/null +++ b/core/src/main/java/org/bitcorej/chain/gleec2/GLEEC2NetParams.java @@ -0,0 +1,27 @@ +package org.bitcorej.chain.gleec2; + +import org.bitcoinj.params.AbstractBitcoinNetParams; +import org.bitcorej.chain.zcash.ZcashNetParams; + +public class GLEEC2NetParams extends AbstractBitcoinNetParams { + + public GLEEC2NetParams() { + super(); + addressHeader = 0x3c; + p2shHeader = 0x55; + acceptableAddressCodes = new int[] { addressHeader, p2shHeader }; + } + + private static GLEEC2NetParams instance; + public static synchronized GLEEC2NetParams get() { + if (instance == null) { + instance = new GLEEC2NetParams(); + } + return instance; + } + + @Override + public String getPaymentProtocolId() { + return "main"; + } +} diff --git a/core/src/main/java/org/bitcorej/chain/gleec2/GLEEC2StateProvider.java b/core/src/main/java/org/bitcorej/chain/gleec2/GLEEC2StateProvider.java new file mode 100644 index 0000000..7e42b75 --- /dev/null +++ b/core/src/main/java/org/bitcorej/chain/gleec2/GLEEC2StateProvider.java @@ -0,0 +1,37 @@ +package org.bitcorej.chain.gleec2; + +import org.bitcoinj.core.Base58; +import org.bitcoinj.script.Script; +import org.bitcoinj.script.ScriptBuilder; +import org.bitcorej.chain.zcash.ZcashStateProvider; +import org.bitcorej.core.Network; +import org.bitcorej.utils.NumericUtil; + +import static org.bitcoinj.script.ScriptOpCodes.*; +import static org.bitcoinj.script.ScriptOpCodes.OP_CHECKSIG; + +public class GLEEC2StateProvider extends ZcashStateProvider { + + public GLEEC2StateProvider(Network network) { + super(network); + super.params = GLEEC2NetParams.get(); + super.consensusBranchId = 0x76b809bb; + } + + @Override + public String generateP2PKHScript(String address) { + byte[] versionAndDataBytes = Base58.decodeChecked(address); + byte[] bytes = new byte[versionAndDataBytes.length - 1]; + System.arraycopy(versionAndDataBytes, 1, bytes, 0, versionAndDataBytes.length - 1); + + System.out.println(NumericUtil.bytesToHex(bytes)); + Script script = new ScriptBuilder() + .op(OP_DUP) + .op(OP_HASH160) + .data(bytes) + .op(OP_EQUALVERIFY) + .op(OP_CHECKSIG) + .build(); + return NumericUtil.bytesToHex(script.getProgram()); + } +} \ No newline at end of file