From 49338d164a4d2347331bf8fb09fb927752195d1c Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Tue, 18 Feb 2020 21:19:58 +0000 Subject: [PATCH 1/9] chore(deps): bump logging-interceptor from 4.3.1 to 4.4.0 Bumps [logging-interceptor](https://github.com/square/okhttp) from 4.3.1 to 4.4.0. - [Release notes](https://github.com/square/okhttp/releases) - [Changelog](https://github.com/square/okhttp/blob/master/CHANGELOG.md) - [Commits](https://github.com/square/okhttp/compare/parent-4.3.1...parent-4.4.0) Signed-off-by: dependabot-preview[bot] --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index aa3e0fb5c..68ddef446 100644 --- a/build.gradle +++ b/build.gradle @@ -4,7 +4,7 @@ buildscript { ext.rxjavaVersion = '2.2.17' ext.gsonVersion = '2.8.6' ext.okhttpVersion = '4.3.1' - ext.loggingOkhttpVersion = '4.3.1' + ext.loggingOkhttpVersion = '4.4.0' ext.slf4jVersion = '1.7.30' ext.guavaVersion = '28.2-jre' From ed96de9ea1259c12dcc750767f668c0f20ebef4c Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Wed, 19 Feb 2020 01:24:15 +0000 Subject: [PATCH 2/9] chore(deps): bump okhttp from 4.3.1 to 4.4.0 Bumps [okhttp](https://github.com/square/okhttp) from 4.3.1 to 4.4.0. - [Release notes](https://github.com/square/okhttp/releases) - [Changelog](https://github.com/square/okhttp/blob/master/CHANGELOG.md) - [Commits](https://github.com/square/okhttp/compare/parent-4.3.1...parent-4.4.0) Signed-off-by: dependabot-preview[bot] --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 68ddef446..69b40265f 100644 --- a/build.gradle +++ b/build.gradle @@ -3,7 +3,7 @@ buildscript { ext.bouncycastleVersion = '1.64' ext.rxjavaVersion = '2.2.17' ext.gsonVersion = '2.8.6' - ext.okhttpVersion = '4.3.1' + ext.okhttpVersion = '4.4.0' ext.loggingOkhttpVersion = '4.4.0' ext.slf4jVersion = '1.7.30' ext.guavaVersion = '28.2-jre' From 607fe34f9cad5557c4424d938fa697b4134e88e4 Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Tue, 25 Feb 2020 21:20:01 +0000 Subject: [PATCH 3/9] chore(deps): bump rxjava from 2.2.17 to 2.2.18 Bumps [rxjava](https://github.com/ReactiveX/RxJava) from 2.2.17 to 2.2.18. - [Release notes](https://github.com/ReactiveX/RxJava/releases) - [Changelog](https://github.com/ReactiveX/RxJava/blob/v2.2.18/CHANGES.md) - [Commits](https://github.com/ReactiveX/RxJava/compare/v2.2.17...v2.2.18) Signed-off-by: dependabot-preview[bot] --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 69b40265f..c631c4234 100644 --- a/build.gradle +++ b/build.gradle @@ -1,7 +1,7 @@ buildscript { ext.bouncycastleVersion = '1.64' - ext.rxjavaVersion = '2.2.17' + ext.rxjavaVersion = '2.2.18' ext.gsonVersion = '2.8.6' ext.okhttpVersion = '4.4.0' ext.loggingOkhttpVersion = '4.4.0' From a858559abd8dee81d0969334b5d6487533545ca6 Mon Sep 17 00:00:00 2001 From: duanyytop Date: Thu, 27 Feb 2020 11:19:04 +0800 Subject: [PATCH 4/9] refactor: remove useless code --- .../main/java/org/nervos/ckb/MultiKeySingleSigTxExample.java | 4 ---- .../java/org/nervos/ckb/SendToMultiSigAddressTxExample.java | 5 ----- .../java/org/nervos/ckb/SingleKeySingleSigTxExample.java | 4 ---- .../java/org/nervos/ckb/SingleSigWithIndexerTxExample.java | 4 ---- .../main/java/org/nervos/ckb/transaction/CollectUtils.java | 4 ---- 5 files changed, 21 deletions(-) diff --git a/example/src/main/java/org/nervos/ckb/MultiKeySingleSigTxExample.java b/example/src/main/java/org/nervos/ckb/MultiKeySingleSigTxExample.java index 957dd9894..6b141933b 100644 --- a/example/src/main/java/org/nervos/ckb/MultiKeySingleSigTxExample.java +++ b/example/src/main/java/org/nervos/ckb/MultiKeySingleSigTxExample.java @@ -137,10 +137,6 @@ private static String sendCapacity( private static Transaction generateTx( String address, List receivers, String changeAddress) throws IOException { - BigInteger needCapacity = BigInteger.ZERO; - for (Receiver receiver : receivers) { - needCapacity = needCapacity.add(receiver.capacity); - } return generateTx(Collections.singletonList(address), receivers, changeAddress); } diff --git a/example/src/main/java/org/nervos/ckb/SendToMultiSigAddressTxExample.java b/example/src/main/java/org/nervos/ckb/SendToMultiSigAddressTxExample.java index a93d2f818..c88a7cb35 100644 --- a/example/src/main/java/org/nervos/ckb/SendToMultiSigAddressTxExample.java +++ b/example/src/main/java/org/nervos/ckb/SendToMultiSigAddressTxExample.java @@ -66,11 +66,6 @@ private static String getMultiSigBalance() { private static String sendCapacity(List receivers, String changeAddress) throws IOException { - BigInteger needCapacity = BigInteger.ZERO; - for (Receiver receiver : receivers) { - needCapacity = needCapacity.add(receiver.capacity); - } - TransactionBuilder txBuilder = new TransactionBuilder(api); CollectUtils txUtils = new CollectUtils(api); diff --git a/example/src/main/java/org/nervos/ckb/SingleKeySingleSigTxExample.java b/example/src/main/java/org/nervos/ckb/SingleKeySingleSigTxExample.java index 5416077a1..6c3ff5533 100644 --- a/example/src/main/java/org/nervos/ckb/SingleKeySingleSigTxExample.java +++ b/example/src/main/java/org/nervos/ckb/SingleKeySingleSigTxExample.java @@ -71,11 +71,7 @@ private static String getBalance(String address) { private static String sendCapacity(List receivers, String changeAddress) throws IOException { - BigInteger needCapacity = BigInteger.ZERO; List scriptGroupWithPrivateKeysList = new ArrayList<>(); - for (Receiver receiver : receivers) { - needCapacity = needCapacity.add(receiver.capacity); - } TransactionBuilder txBuilder = new TransactionBuilder(api); CollectUtils txUtils = new CollectUtils(api); diff --git a/example/src/main/java/org/nervos/ckb/SingleSigWithIndexerTxExample.java b/example/src/main/java/org/nervos/ckb/SingleSigWithIndexerTxExample.java index 21305084a..85529109d 100644 --- a/example/src/main/java/org/nervos/ckb/SingleSigWithIndexerTxExample.java +++ b/example/src/main/java/org/nervos/ckb/SingleSigWithIndexerTxExample.java @@ -83,11 +83,7 @@ private static BigInteger getBalance(String address) { private static String sendCapacity(List receivers, String changeAddress) throws IOException { - BigInteger needCapacity = BigInteger.ZERO; List scriptGroupWithPrivateKeysList = new ArrayList<>(); - for (Receiver receiver : receivers) { - needCapacity = needCapacity.add(receiver.capacity); - } TransactionBuilder txBuilder = new TransactionBuilder(api); CollectUtils txUtils = new CollectUtils(api); diff --git a/example/src/main/java/org/nervos/ckb/transaction/CollectUtils.java b/example/src/main/java/org/nervos/ckb/transaction/CollectUtils.java index b3da924d5..dcd203aed 100644 --- a/example/src/main/java/org/nervos/ckb/transaction/CollectUtils.java +++ b/example/src/main/java/org/nervos/ckb/transaction/CollectUtils.java @@ -79,10 +79,6 @@ public List generateOutputs(List receivers, String changeA new CellOutput( Numeric.toHexStringWithPrefix(receiver.capacity), addressParseResult.script)); } - BigInteger needCapacity = BigInteger.ZERO; - for (Receiver receiver : receivers) { - needCapacity = needCapacity.add(receiver.capacity); - } AddressParseResult addressParseResult = AddressParser.parse(changeAddress); cellOutputs.add(new CellOutput("0x0", addressParseResult.script)); return cellOutputs; From 004c6e30b571b805ec2905df0c909a1287c6917d Mon Sep 17 00:00:00 2001 From: duanyytop Date: Thu, 27 Feb 2020 14:28:17 +0800 Subject: [PATCH 5/9] refactor: update tx fee calculating --- .../nervos/ckb/transaction/CellCollector.java | 3 +-- .../java/org/nervos/ckb/utils/Calculator.java | 12 ++++++++--- ckb/src/test/java/utils/CalculatorTest.java | 21 +++++++++++-------- 3 files changed, 22 insertions(+), 14 deletions(-) diff --git a/ckb/src/main/java/org/nervos/ckb/transaction/CellCollector.java b/ckb/src/main/java/org/nervos/ckb/transaction/CellCollector.java index 94287b969..4ace112ff 100644 --- a/ckb/src/main/java/org/nervos/ckb/transaction/CellCollector.java +++ b/ckb/src/main/java/org/nervos/ckb/transaction/CellCollector.java @@ -130,8 +130,7 @@ public CollectResult collectInputs( } private BigInteger calculateTxFee(Transaction transaction, BigInteger feeRate) { - int txSize = Serializer.serializeTransaction(transaction).toBytes().length; - return Calculator.calculateTransactionFee(BigInteger.valueOf(txSize), feeRate); + return Calculator.calculateTransactionFee(transaction, feeRate); } private BigInteger calculateOutputSize(CellOutput cellOutput) { diff --git a/ckb/src/main/java/org/nervos/ckb/utils/Calculator.java b/ckb/src/main/java/org/nervos/ckb/utils/Calculator.java index 944042b8a..53c760d02 100644 --- a/ckb/src/main/java/org/nervos/ckb/utils/Calculator.java +++ b/ckb/src/main/java/org/nervos/ckb/utils/Calculator.java @@ -12,14 +12,15 @@ public class Calculator { private static final int SERIALIZED_TX_OFFSET_BYTE_SIZE = 4; private static final int MIN_CONFIRM_BLOCKS = 3; - public static int calculateSerializedSizeInBlock(Transaction transaction) { + public static int calculateTransactionSize(Transaction transaction) { Table serializedTx = Serializer.serializeTransaction(transaction); return serializedTx.getLength() + SERIALIZED_TX_OFFSET_BYTE_SIZE; } private static final BigInteger RADIO = BigInteger.valueOf(1000); - public static BigInteger calculateTransactionFee(BigInteger transactionSize, BigInteger feeRate) { + private static BigInteger calculateTransactionFee( + BigInteger transactionSize, BigInteger feeRate) { BigInteger base = transactionSize.multiply(feeRate); BigInteger fee = base.divide(RADIO); if (fee.multiply(RADIO).compareTo(base) < 0) { @@ -35,7 +36,12 @@ public static BigInteger calculateTransactionFee( } BigInteger feeRate = Numeric.toBigInt(api.estimateFeeRate(String.valueOf(expectedConfirmBlocks)).feeRate); - BigInteger txSize = BigInteger.valueOf(calculateSerializedSizeInBlock(transaction)); + BigInteger txSize = BigInteger.valueOf(calculateTransactionSize(transaction)); + return calculateTransactionFee(txSize, feeRate); + } + + public static BigInteger calculateTransactionFee(Transaction transaction, BigInteger feeRate) { + BigInteger txSize = BigInteger.valueOf(calculateTransactionSize(transaction)); return calculateTransactionFee(txSize, feeRate); } } diff --git a/ckb/src/test/java/utils/CalculatorTest.java b/ckb/src/test/java/utils/CalculatorTest.java index 4774af517..c73881e4c 100644 --- a/ckb/src/test/java/utils/CalculatorTest.java +++ b/ckb/src/test/java/utils/CalculatorTest.java @@ -6,7 +6,9 @@ import java.util.Collections; import java.util.List; import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; import org.nervos.ckb.type.OutPoint; import org.nervos.ckb.type.Script; import org.nervos.ckb.type.cell.CellDep; @@ -16,10 +18,12 @@ import org.nervos.ckb.utils.Calculator; /** Copyright © 2019 Nervos Foundation. All rights reserved. */ +@TestInstance(TestInstance.Lifecycle.PER_CLASS) public class CalculatorTest { + private Transaction tx; - @Test - void testCalculateTransactionSize() { + @BeforeAll + void init() { List cellOutputs = new ArrayList<>(); cellOutputs.add( new CellOutput( @@ -40,7 +44,7 @@ void testCalculateTransactionSize() { "0x59a27ef3ba84f061517d13f42cf44ed020610061", Script.TYPE))); - Transaction tx = + tx = new Transaction( "0x0", Arrays.asList( @@ -65,17 +69,16 @@ void testCalculateTransactionSize() { Arrays.asList("0x1234", "0x"), Collections.singletonList( "0x82df73581bcd08cb9aa270128d15e79996229ce8ea9e4f985b49fbf36762c5c37936caf3ea3784ee326f60b8992924fcf496f9503c907982525a3436f01ab32900")); + } - Assertions.assertEquals(Calculator.calculateSerializedSizeInBlock(tx), 536); + @Test + void testCalculateTransactionSize() { + Assertions.assertEquals(Calculator.calculateTransactionSize(tx), 536); } @Test public void testCalculateTransactionFee() { Assertions.assertEquals( - Calculator.calculateTransactionFee(BigInteger.valueOf(1035), BigInteger.valueOf(900)), - BigInteger.valueOf(932)); - Assertions.assertEquals( - Calculator.calculateTransactionFee(BigInteger.valueOf(900), BigInteger.valueOf(900)), - BigInteger.valueOf(810)); + Calculator.calculateTransactionFee(tx, BigInteger.valueOf(900)), BigInteger.valueOf(483)); } } From 4ef039d8bd44e7f6587a5d7410f13267a1115bee Mon Sep 17 00:00:00 2001 From: duanyytop Date: Fri, 28 Feb 2020 15:31:08 +0800 Subject: [PATCH 6/9] docs: update changelog for v0.29.0 --- CHANGELOG.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c7acd44e0..a69347677 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,13 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +# [v0.29.0](https://github.com/nervosnetwork/ckb-sdk-java/compare/v0.28.0...v0.29.0) (2020-2-29) + +### Refactor + +* Remove useless code ([a858559](https://github.com/nervosnetwork/ckb-sdk-java/commit/a858559abd8dee81d0969334b5d6487533545ca6)) +* Update transaction fee calculating ([004c6e3](https://github.com/nervosnetwork/ckb-sdk-java/commit/004c6e30b571b805ec2905df0c909a1287c6917d)) + # [v0.28.0](https://github.com/nervosnetwork/ckb-sdk-java/compare/v0.27.1...v0.28.0) (2020-2-7) Bump version to v0.28.0 From 3182d3cf3908e80cefdacf257eac0576e0fdc359 Mon Sep 17 00:00:00 2001 From: duanyytop Date: Fri, 28 Feb 2020 15:32:48 +0800 Subject: [PATCH 7/9] chore: bump to v0.29.0 --- build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index c631c4234..aca51b2f8 100644 --- a/build.gradle +++ b/build.gradle @@ -43,7 +43,7 @@ allprojects { targetCompatibility = 1.8 group 'org.nervos.ckb' - version '0.28.0' + version '0.29.0' apply plugin: 'java' @@ -113,7 +113,7 @@ configure(subprojects.findAll { it.name != 'tests' }) { publications { mavenJava(MavenPublication) { groupId 'org.nervos.ckb' - version '0.28.0' + version '0.29.0' from components.java } } From c089e77efd6e66e143391ada3c403d2a7e0d9b52 Mon Sep 17 00:00:00 2001 From: duanyytop Date: Fri, 28 Feb 2020 16:21:29 +0800 Subject: [PATCH 8/9] docs: update readme of transfer examples --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index e8df212c0..b01b62881 100644 --- a/README.md +++ b/README.md @@ -103,6 +103,9 @@ You can see more JSON-RPC requests from [RPC Document](https://github.com/nervos #### Single-sig Transfer +> Note: If you want to run transfer example, you should update example private key of sender whose balance is not zero. +> And if you want to use example default private key to run, you should make the example sender's balance is not zero or set the blake160 of default sender's public key to CKB dev chain node configuration file to be a miner. + [SingleKeySingleSigTxExample](https://github.com/nervosnetwork/ckb-sdk-java/tree/develop/example/src/main/java/org/nervos/ckb/SingleKeySingleSigTxExample.java) provides `sendCapacity` method with any amount inputs which belong to a private key. [MultiKeySingleSigTxExample](https://github.com/nervosnetwork/ckb-sdk-java/tree/develop/example/src/main/java/org/nervos/ckb/MultiKeySingleSigTxExample.java) provides `sendCapacity` method with any amount inputs which belong to any amount private keys. @@ -138,6 +141,9 @@ You can reference detail example in `example/MultiKeySingleSigTxExample.java`. #### Multi-sig Transfer +> Note: If you want to run transfer example, you should update example private key of sender whose balance is not zero. +> And if you want to use example default private key to run, you should make the example sender's balance is not zero or set the blake160 of default sender's public key to CKB dev chain node configuration file to be a miner. + [SendToMultiSigAddressTxExample](https://github.com/nervosnetwork/ckb-sdk-java/tree/develop/example/src/main/java/org/nervos/ckb/SendToMultiSigAddressTxExample.java) provides `sendCapacity` method which single-sig address sends capacity to 2/3 format multi-sig address. [MultiSignTransactionExample](https://github.com/nervosnetwork/ckb-sdk-java/tree/develop/example/src/main/java/org/nervos/ckb/MultiSignTransactionExample.java) provides `sendCapacity` method which 2/3 format multi-sig address sends capacity to single-sig address. From 0450fdf336cf13b0ac6ebb8622c67bd3dbd02d0c Mon Sep 17 00:00:00 2001 From: duanyytop Date: Fri, 28 Feb 2020 18:00:27 +0800 Subject: [PATCH 9/9] docs: update changelog date --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a69347677..b944a36a9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,7 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. -# [v0.29.0](https://github.com/nervosnetwork/ckb-sdk-java/compare/v0.28.0...v0.29.0) (2020-2-29) +# [v0.29.0](https://github.com/nervosnetwork/ckb-sdk-java/compare/v0.28.0...v0.29.0) (2020-2-28) ### Refactor