From b3327b0310fc555f85706d86363bdfb0bb854d3f Mon Sep 17 00:00:00 2001 From: fjchen7 Date: Thu, 16 Jun 2022 08:44:01 +0000 Subject: [PATCH 1/4] chore: update CHANGELOG.md for release v2.0.1 --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f4222543f..c2620c3e2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +# 2.0.1 (2022-06-16) + +## 🚀 Features + +- feat: make mercury enum public (#566) +- feat: add more easy-use mercury tool methods (#565) # 2.0.0 (2022-06-14) 2.0.0 is a refactored ckb-java-sdk release and brings plenty of BREAKING CHANGES compared with `v1.0.*` and the earlier releases. From d5c6c2bfcee3d5b0f1c2672c19ea610e297bce35 Mon Sep 17 00:00:00 2001 From: fjchen7 Date: Thu, 23 Jun 2022 10:52:37 +0800 Subject: [PATCH 2/4] feat: enhance mercury builder (#570) --- .github/workflows/on-release.yml | 3 +- .../model/DaoDepositPayloadBuilder.java | 4 +- .../model/GetBalancePayloadBuilder.java | 5 +-- .../QueryTransactionsPayloadBuilder.java | 9 ++-- .../mercury/model/TransferPayloadBuilder.java | 12 ++--- .../org/nervos/ckb/system/SystemContract.java | 45 ------------------- .../ckb/system/type/SystemScriptCell.java | 14 ------ .../test/java/system/SystemContractTest.java | 19 -------- core/src/test/java/type/WitnessArgsTest.java | 26 +++++------ .../org/nervos/ckb/address/CodeHashType.java | 7 --- .../org/nervos/ckb/crypto/secp256k1/Sign.java | 14 +++++- .../java/org/nervos/ckb/utils/Assertions.java | 16 ------- .../java/org/nervos/ckb/utils/Numeric.java | 6 ++- .../java/org/nervos/ckb/utils/Strings.java | 15 ------- .../org/nervos/ckb/utils/StringsTest.java | 29 ------------ 15 files changed, 45 insertions(+), 179 deletions(-) delete mode 100644 ckb/src/main/java/org/nervos/ckb/system/SystemContract.java delete mode 100644 ckb/src/main/java/org/nervos/ckb/system/type/SystemScriptCell.java delete mode 100644 ckb/src/test/java/system/SystemContractTest.java delete mode 100644 utils/src/main/java/org/nervos/ckb/address/CodeHashType.java delete mode 100644 utils/src/main/java/org/nervos/ckb/utils/Assertions.java delete mode 100644 utils/src/main/java/org/nervos/ckb/utils/Strings.java delete mode 100644 utils/src/test/java/org/nervos/ckb/utils/StringsTest.java diff --git a/.github/workflows/on-release.yml b/.github/workflows/on-release.yml index 4da68154a..51f4e97a3 100644 --- a/.github/workflows/on-release.yml +++ b/.github/workflows/on-release.yml @@ -19,5 +19,6 @@ jobs: with: commit-message: 'chore: update CHANGELOG.md for release ${{ github.event.release.tag_name }}' branch: chore/update-CHANGELOG-for-release-${{ github.event.release.tag_name }} - base: develop + base: master + author: github-actions title: 'Update CHANGELOG for release ${{ github.event.release.tag_name }}' diff --git a/ckb-mercury-sdk/src/main/java/org/nervos/mercury/model/DaoDepositPayloadBuilder.java b/ckb-mercury-sdk/src/main/java/org/nervos/mercury/model/DaoDepositPayloadBuilder.java index 294d5356f..1423d38d2 100644 --- a/ckb-mercury-sdk/src/main/java/org/nervos/mercury/model/DaoDepositPayloadBuilder.java +++ b/ckb-mercury-sdk/src/main/java/org/nervos/mercury/model/DaoDepositPayloadBuilder.java @@ -9,12 +9,10 @@ public class DaoDepositPayloadBuilder extends DaoDepositPayload { public DaoDepositPayloadBuilder() { this.feeRate = FeeConstant.DEFAULT_FEE_RATE; + this.from = new ArrayList<>(); } public void addFrom(Item from) { - if (this.from == null) { - this.from = new ArrayList<>(); - } this.from.add(from); } diff --git a/ckb-mercury-sdk/src/main/java/org/nervos/mercury/model/GetBalancePayloadBuilder.java b/ckb-mercury-sdk/src/main/java/org/nervos/mercury/model/GetBalancePayloadBuilder.java index 21a4e6c09..7154dab7d 100644 --- a/ckb-mercury-sdk/src/main/java/org/nervos/mercury/model/GetBalancePayloadBuilder.java +++ b/ckb-mercury-sdk/src/main/java/org/nervos/mercury/model/GetBalancePayloadBuilder.java @@ -9,7 +9,7 @@ public class GetBalancePayloadBuilder extends GetBalancePayload { public GetBalancePayloadBuilder() { - this.assetInfos = new HashSet<>(2, 1); + this.assetInfos = new HashSet<>(); } public void item(Item item) { @@ -17,9 +17,6 @@ public void item(Item item) { } public void addAssetInfo(AssetInfo info) { - if (this.assetInfos == null) { - this.assetInfos = new HashSet<>(); - } this.assetInfos.add(info); } diff --git a/ckb-mercury-sdk/src/main/java/org/nervos/mercury/model/QueryTransactionsPayloadBuilder.java b/ckb-mercury-sdk/src/main/java/org/nervos/mercury/model/QueryTransactionsPayloadBuilder.java index 2236e85c9..856a9dc2c 100644 --- a/ckb-mercury-sdk/src/main/java/org/nervos/mercury/model/QueryTransactionsPayloadBuilder.java +++ b/ckb-mercury-sdk/src/main/java/org/nervos/mercury/model/QueryTransactionsPayloadBuilder.java @@ -1,9 +1,6 @@ package org.nervos.mercury.model; -import org.nervos.mercury.model.common.AssetInfo; -import org.nervos.mercury.model.common.ExtraFilter; -import org.nervos.mercury.model.common.PaginationRequest; -import org.nervos.mercury.model.common.Range; +import org.nervos.mercury.model.common.*; import org.nervos.mercury.model.req.item.Item; import org.nervos.mercury.model.req.payload.QueryTransactionsPayload; @@ -51,6 +48,10 @@ public void extra(ExtraFilter.Type extra) { this.extra = extra; } + public void structureType(StructureType structureType) { + this.structureType = structureType; + } + public QueryTransactionsPayload build() { return this; } diff --git a/ckb-mercury-sdk/src/main/java/org/nervos/mercury/model/TransferPayloadBuilder.java b/ckb-mercury-sdk/src/main/java/org/nervos/mercury/model/TransferPayloadBuilder.java index c680625c1..29699d286 100644 --- a/ckb-mercury-sdk/src/main/java/org/nervos/mercury/model/TransferPayloadBuilder.java +++ b/ckb-mercury-sdk/src/main/java/org/nervos/mercury/model/TransferPayloadBuilder.java @@ -4,6 +4,7 @@ import org.nervos.mercury.model.common.AssetInfo; import org.nervos.mercury.model.req.ToInfo; import org.nervos.mercury.model.req.item.Item; +import org.nervos.mercury.model.req.payload.CapacityProvider; import org.nervos.mercury.model.req.payload.TransferPayload; import org.nervos.mercury.model.req.since.SinceConfig; @@ -15,13 +16,11 @@ public class TransferPayloadBuilder extends TransferPayload { public TransferPayloadBuilder() { this.assetInfo = AssetInfo.newCkbAsset(); this.feeRate = FeeConstant.DEFAULT_FEE_RATE; + this.from = new ArrayList<>(); this.to = new ArrayList<>(); } public void addFrom(Item from) { - if (this.from == null) { - this.from = new ArrayList<>(); - } this.from.add(from); } @@ -38,6 +37,10 @@ public void addTo(String address, long amount) { addTo(address, BigInteger.valueOf(amount)); } + public void outputCapacityProvider(CapacityProvider outputCapacityProvider) { + this.outputCapacityProvider = outputCapacityProvider; + } + public void payFee(PayFee payFee) { this.payFee = payFee; } @@ -51,9 +54,6 @@ public void since(SinceConfig since) { } public TransferPayload build() { - assert !(this.from == null) : "from not null"; - assert !(this.to == null) : "items not null"; - return this; } } diff --git a/ckb/src/main/java/org/nervos/ckb/system/SystemContract.java b/ckb/src/main/java/org/nervos/ckb/system/SystemContract.java deleted file mode 100644 index 7ebcd87f5..000000000 --- a/ckb/src/main/java/org/nervos/ckb/system/SystemContract.java +++ /dev/null @@ -1,45 +0,0 @@ -package org.nervos.ckb.system; - -import org.nervos.ckb.service.Api; -import org.nervos.ckb.system.type.SystemScriptCell; -import org.nervos.ckb.type.Block; -import org.nervos.ckb.type.OutPoint; -import org.nervos.ckb.type.Transaction; - -import java.io.IOException; -import java.util.List; - -public class SystemContract { - - private static List getSystemCellTransactions(Api api) throws IOException { - Block block = api.getBlockByNumber(0); - if (block == null) { - throw new IOException("Genesis block not found"); - } - if (block.transactions == null || block.transactions.size() < 2) { - throw new IOException("Genesis block transactions system script not found"); - } - return block.transactions; - } - - public static SystemScriptCell getSystemSecpCell(Api api) throws IOException { - List transactions = getSystemCellTransactions(api); - return new SystemScriptCell( - transactions.get(0).outputs.get(1).type.computeHash(), - new OutPoint(transactions.get(1).hash, 0)); - } - - public static SystemScriptCell getSystemMultiSigCell(Api api) throws IOException { - List transactions = getSystemCellTransactions(api); - return new SystemScriptCell( - transactions.get(0).outputs.get(4).type.computeHash(), - new OutPoint(transactions.get(1).hash, 1)); - } - - public static SystemScriptCell getSystemNervosDaoCell(Api api) throws IOException { - List transactions = getSystemCellTransactions(api); - return new SystemScriptCell( - transactions.get(0).outputs.get(2).type.computeHash(), - new OutPoint(transactions.get(0).hash, 2)); - } -} diff --git a/ckb/src/main/java/org/nervos/ckb/system/type/SystemScriptCell.java b/ckb/src/main/java/org/nervos/ckb/system/type/SystemScriptCell.java deleted file mode 100644 index 587b31a8f..000000000 --- a/ckb/src/main/java/org/nervos/ckb/system/type/SystemScriptCell.java +++ /dev/null @@ -1,14 +0,0 @@ -package org.nervos.ckb.system.type; - -import org.nervos.ckb.type.OutPoint; - -public class SystemScriptCell { - - public byte[] cellHash; - public OutPoint outPoint; - - public SystemScriptCell(byte[] cellHash, OutPoint outPoint) { - this.cellHash = cellHash; - this.outPoint = outPoint; - } -} diff --git a/ckb/src/test/java/system/SystemContractTest.java b/ckb/src/test/java/system/SystemContractTest.java deleted file mode 100644 index 605d60cc5..000000000 --- a/ckb/src/test/java/system/SystemContractTest.java +++ /dev/null @@ -1,19 +0,0 @@ -package system; - -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Disabled; -import org.junit.jupiter.api.Test; -import org.nervos.ckb.service.Api; -import org.nervos.ckb.system.SystemContract; -import org.nervos.ckb.system.type.SystemScriptCell; - -@Disabled -public class SystemContractTest { - - @Test - public void testGetSystemContract() throws Exception { - SystemScriptCell systemScriptCell = - SystemContract.getSystemSecpCell(new Api("http://localhost:8114")); - Assertions.assertNotNull(systemScriptCell); - } -} diff --git a/core/src/test/java/type/WitnessArgsTest.java b/core/src/test/java/type/WitnessArgsTest.java index 930dc7291..89831c6c8 100644 --- a/core/src/test/java/type/WitnessArgsTest.java +++ b/core/src/test/java/type/WitnessArgsTest.java @@ -5,18 +5,18 @@ import org.nervos.ckb.type.WitnessArgs; import org.nervos.ckb.utils.Numeric; -class WitnessArgsTest { - @Test - public void testSerialization() { - WitnessArgs witnessArgs = new WitnessArgs(); - witnessArgs.setLock(new byte[65]); - byte[] argsBytes = Numeric.hexStringToByteArray("0x55000000100000005500000055000000410000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"); - Assertions.assertArrayEquals(argsBytes, witnessArgs.pack().toByteArray()); - Assertions.assertEquals(WitnessArgs.unpack(argsBytes), witnessArgs); +public class WitnessArgsTest { + @Test + public void testSerialization() { + WitnessArgs witnessArgs = new WitnessArgs(); + witnessArgs.setLock(new byte[65]); + byte[] argsBytes = Numeric.hexStringToByteArray("0x55000000100000005500000055000000410000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"); + Assertions.assertArrayEquals(argsBytes, witnessArgs.pack().toByteArray()); + Assertions.assertEquals(WitnessArgs.unpack(argsBytes), witnessArgs); - witnessArgs.setInputType(new byte[]{(byte) 0xab}); - witnessArgs.setOutputType(new byte[]{(byte) 0xcd, (byte) 0xef}); - argsBytes = Numeric.hexStringToByteArray("0x6000000010000000550000005a00000041000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000ab02000000cdef"); - Assertions.assertArrayEquals(argsBytes, witnessArgs.pack().toByteArray()); - } + witnessArgs.setInputType(new byte[]{(byte) 0xab}); + witnessArgs.setOutputType(new byte[]{(byte) 0xcd, (byte) 0xef}); + argsBytes = Numeric.hexStringToByteArray("0x6000000010000000550000005a00000041000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000ab02000000cdef"); + Assertions.assertArrayEquals(argsBytes, witnessArgs.pack().toByteArray()); + } } \ No newline at end of file diff --git a/utils/src/main/java/org/nervos/ckb/address/CodeHashType.java b/utils/src/main/java/org/nervos/ckb/address/CodeHashType.java deleted file mode 100644 index da8215bac..000000000 --- a/utils/src/main/java/org/nervos/ckb/address/CodeHashType.java +++ /dev/null @@ -1,7 +0,0 @@ -package org.nervos.ckb.address; - -public enum CodeHashType { - BLAKE160, - MULTISIG, - ANYONE_CAN_APY -} diff --git a/utils/src/main/java/org/nervos/ckb/crypto/secp256k1/Sign.java b/utils/src/main/java/org/nervos/ckb/crypto/secp256k1/Sign.java index edd79b4b9..b9d61a3e6 100644 --- a/utils/src/main/java/org/nervos/ckb/crypto/secp256k1/Sign.java +++ b/utils/src/main/java/org/nervos/ckb/crypto/secp256k1/Sign.java @@ -17,8 +17,6 @@ import java.math.BigInteger; import java.util.Arrays; -import static org.nervos.ckb.utils.Assertions.verifyPrecondition; - /* * Copyright 2019 Web3 Labs Ltd. * @@ -77,6 +75,18 @@ public static SignatureData signMessage(byte[] message, ECKeyPair keyPair, boole return new SignatureData(v, r, s); } + + /** + * Verify that the provided precondition holds true. + * + * @param assertionResult assertion value + * @param errorMessage error message if precondition failure + */ + private static void verifyPrecondition(boolean assertionResult, String errorMessage) { + if (!assertionResult) { + throw new RuntimeException(errorMessage); + } + } /** * Given the components of a signature and a selector value, recover and return the public key diff --git a/utils/src/main/java/org/nervos/ckb/utils/Assertions.java b/utils/src/main/java/org/nervos/ckb/utils/Assertions.java deleted file mode 100644 index 44531ba82..000000000 --- a/utils/src/main/java/org/nervos/ckb/utils/Assertions.java +++ /dev/null @@ -1,16 +0,0 @@ -package org.nervos.ckb.utils; - -/** Assertion utility functions. */ -public class Assertions { - /** - * Verify that the provided precondition holds true. - * - * @param assertionResult assertion value - * @param errorMessage error message if precondition failure - */ - public static void verifyPrecondition(boolean assertionResult, String errorMessage) { - if (!assertionResult) { - throw new RuntimeException(errorMessage); - } - } -} diff --git a/utils/src/main/java/org/nervos/ckb/utils/Numeric.java b/utils/src/main/java/org/nervos/ckb/utils/Numeric.java index 85753c66a..7f75ce555 100644 --- a/utils/src/main/java/org/nervos/ckb/utils/Numeric.java +++ b/utils/src/main/java/org/nervos/ckb/utils/Numeric.java @@ -116,7 +116,7 @@ private static String toHexStringZeroPadded(BigInteger value, int size, boolean } if (length < size) { - result = Strings.zeros(size - length) + result; + result = repeat('0', size - length) + result; } if (withPrefix) { @@ -126,6 +126,10 @@ private static String toHexStringZeroPadded(BigInteger value, int size, boolean } } + private static String repeat(char value, int n) { + return new String(new char[n]).replace("\0", String.valueOf(value)); + } + public static byte[] toBytesPadded(BigInteger value, int length) { byte[] result = new byte[length]; byte[] bytes = value.toByteArray(); diff --git a/utils/src/main/java/org/nervos/ckb/utils/Strings.java b/utils/src/main/java/org/nervos/ckb/utils/Strings.java deleted file mode 100644 index 5c3faf7fe..000000000 --- a/utils/src/main/java/org/nervos/ckb/utils/Strings.java +++ /dev/null @@ -1,15 +0,0 @@ -package org.nervos.ckb.utils; - -public class Strings { - public static String zeros(int n) { - return repeat('0', n); - } - - public static String repeat(char value, int n) { - return new String(new char[n]).replace("\0", String.valueOf(value)); - } - - public static boolean isEmpty(String s) { - return s == null || s.length() == 0; - } -} diff --git a/utils/src/test/java/org/nervos/ckb/utils/StringsTest.java b/utils/src/test/java/org/nervos/ckb/utils/StringsTest.java deleted file mode 100644 index aae7f3a58..000000000 --- a/utils/src/test/java/org/nervos/ckb/utils/StringsTest.java +++ /dev/null @@ -1,29 +0,0 @@ -package org.nervos.ckb.utils; - -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; - -import static org.nervos.ckb.utils.Strings.*; - -public class StringsTest { - - @Test - public void testRepeat() { - Assertions.assertEquals(repeat('0', 0), ""); - Assertions.assertEquals(repeat('1', 3), "111"); - } - - @Test - public void testZeros() { - Assertions.assertEquals(zeros(0), ""); - Assertions.assertEquals(zeros(3), "000"); - } - - @SuppressWarnings("ConstantConditions") - @Test - public void testEmptyString() { - Assertions.assertTrue(isEmpty(null)); - Assertions.assertTrue(isEmpty("")); - Assertions.assertFalse(isEmpty("hello world")); - } -} From 014f1ff4018b3056023c4df92b4d3509d4e057f5 Mon Sep 17 00:00:00 2001 From: fjchen7 Date: Fri, 24 Jun 2022 10:09:49 +0800 Subject: [PATCH 3/4] chore: release 2.0.2 (#571) --- .github/workflows/cd.yml | 2 +- .github/workflows/on-release.yml | 6 +++--- build.gradle | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index 433103629..806be6861 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -3,7 +3,7 @@ name: Continuous delivery in GitHub and Maven Central Repository on: push: tags: - - 'v*' + - 'rc/v*' jobs: create_release_draft: diff --git a/.github/workflows/on-release.yml b/.github/workflows/on-release.yml index 51f4e97a3..66e80cb30 100644 --- a/.github/workflows/on-release.yml +++ b/.github/workflows/on-release.yml @@ -17,8 +17,8 @@ jobs: - name: Commit and create Pull Request uses: peter-evans/create-pull-request@v3 with: - commit-message: 'chore: update CHANGELOG.md for release ${{ github.event.release.tag_name }}' - branch: chore/update-CHANGELOG-for-release-${{ github.event.release.tag_name }} - base: master + commit-message: 'chore: release ${{ github.event.release.tag_name }}' + branch: chore/release-${{ github.event.release.tag_name }} + base: develop author: github-actions title: 'Update CHANGELOG for release ${{ github.event.release.tag_name }}' diff --git a/build.gradle b/build.gradle index 980005097..49ee868bf 100644 --- a/build.gradle +++ b/build.gradle @@ -42,7 +42,7 @@ allprojects { targetCompatibility = 1.8 group 'org.nervos.ckb' - version '2.0.1' + version '2.0.2' apply plugin: 'java' repositories { @@ -97,7 +97,7 @@ configure(subprojects.findAll { it.name != 'tests' }) { publications { mavenJava(MavenPublication) { groupId 'org.nervos.ckb' - version '2.0.1' + version '2.0.2' from components.java } } From 256053223df0cf44bbd15d04577a7825bcbfe6ba Mon Sep 17 00:00:00 2001 From: fjchen7 Date: Fri, 24 Jun 2022 10:22:43 +0800 Subject: [PATCH 4/4] chore: update CHANGELOG.md for release v2.0.2 --- CHANGELOG.md | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c2620c3e2..a743d8464 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,9 +1,16 @@ +# 2.0.2 (2022-06-24) + +## 🚀 Features + +- feat: enhance mercury builder (#570) + # 2.0.1 (2022-06-16) -## 🚀 Features - -- feat: make mercury enum public (#566) +## 🚀 Features + +- feat: make mercury enum public (#566) - feat: add more easy-use mercury tool methods (#565) + # 2.0.0 (2022-06-14) 2.0.0 is a refactored ckb-java-sdk release and brings plenty of BREAKING CHANGES compared with `v1.0.*` and the earlier releases.