diff --git a/CHANGELOG.md b/CHANGELOG.md index e6c75ec6f..1aa71564b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,17 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +# [v0.24.7](https://github.com/nervosnetwork/ckb-sdk-java/compare/v0.24.6...v0.24.7) (2019-11-12) + +### Feature + +* Update cell output and script size calculating([b19d201](https://github.com/nervosnetwork/ckb-sdk-java/commit/b19d20145aeeb34ae940ac7cc919e56b6778ea21)) +* Update multisig transaction estimating fee([4a084fa](https://github.com/nervosnetwork/ckb-sdk-java/commit/4a084fac174c834a18a9abf84d6bbdcb02b68685)) + +### BugFix + +* Remove useless min capacity([2709d57](https://github.com/nervosnetwork/ckb-sdk-java/commit/2709d570c61db110b37103cca00b60b84caaaf10)) + # [v0.24.6](https://github.com/nervosnetwork/ckb-sdk-java/compare/v0.24.5...v0.24.6) (2019-11-09) ### BugFix diff --git a/build.gradle b/build.gradle index 459d1a459..26d3fad51 100644 --- a/build.gradle +++ b/build.gradle @@ -43,7 +43,7 @@ allprojects { targetCompatibility = 1.8 group 'org.nervos.ckb' - version '0.24.6' + version '0.24.7' apply plugin: 'java' @@ -113,7 +113,7 @@ configure(subprojects.findAll { it.name != 'tests' }) { publications { mavenJava(MavenPublication) { groupId 'org.nervos.ckb' - version '0.24.6' + version '0.24.7' from components.java } } diff --git a/ckb/src/main/java/org/nervos/ckb/transaction/Secp256k1SighashAllBuilder.java b/ckb/src/main/java/org/nervos/ckb/transaction/Secp256k1SighashAllBuilder.java index 73ce3819f..1578bab61 100644 --- a/ckb/src/main/java/org/nervos/ckb/transaction/Secp256k1SighashAllBuilder.java +++ b/ckb/src/main/java/org/nervos/ckb/transaction/Secp256k1SighashAllBuilder.java @@ -59,9 +59,6 @@ public void sign(ScriptGroup scriptGroup, String privateKey) throws IOException } String message = blake2b.doFinalString(); ECKeyPair ecKeyPair = ECKeyPair.createWithPrivateKey(privateKey, false); - ((Witness) groupWitnesses.get(0)).lock = - Numeric.toHexString( - Sign.signMessage(Numeric.hexStringToByteArray(message), ecKeyPair).getSignature()); Witness signedWitness = (Witness) groupWitnesses.get(0); signedWitness.lock = diff --git a/ckb/src/main/java/org/nervos/ckb/transaction/TransactionBuilder.java b/ckb/src/main/java/org/nervos/ckb/transaction/TransactionBuilder.java index 4f65bee8c..c029e4314 100644 --- a/ckb/src/main/java/org/nervos/ckb/transaction/TransactionBuilder.java +++ b/ckb/src/main/java/org/nervos/ckb/transaction/TransactionBuilder.java @@ -17,26 +17,25 @@ /** Copyright © 2019 Nervos Foundation. All rights reserved. */ public class TransactionBuilder { - private static final BigInteger MIN_CAPACITY = new BigInteger("6000000000"); - private SystemScriptCell systemSecpCell; private SystemScriptCell systemMultiSigCell; private List cellInputs = new ArrayList<>(); private List cellOutputs = new ArrayList<>(); private List cellOutputsData = new ArrayList<>(); private List witnesses = new ArrayList<>(); - private boolean containMultiSig = false; + private boolean isMultiSig = false; public TransactionBuilder(Api api) { this(api, false); } - public TransactionBuilder(Api api, boolean containMultiSig) { + public TransactionBuilder(Api api, boolean isMultiSig) { try { - this.containMultiSig = containMultiSig; - this.systemSecpCell = SystemContract.getSystemSecpCell(api); - if (containMultiSig) { + this.isMultiSig = isMultiSig; + if (isMultiSig) { this.systemMultiSigCell = SystemContract.getSystemMultiSigCell(api); + } else { + this.systemSecpCell = SystemContract.getSystemSecpCell(api); } } catch (Exception e) { e.printStackTrace(); @@ -72,9 +71,6 @@ public Transaction buildTx() throws IOException { for (CellOutput output : cellOutputs) { needCapacity = needCapacity.add(Numeric.toBigInt(output.capacity)); } - if (needCapacity.compareTo(MIN_CAPACITY) < 0) { - throw new IOException("Less than min capacity"); - } if (cellInputs.size() == 0) { throw new IOException("Cell inputs could not empty"); } @@ -83,9 +79,10 @@ public Transaction buildTx() throws IOException { } List cellDeps = new ArrayList<>(); - cellDeps.add(new CellDep(systemSecpCell.outPoint, CellDep.DEP_GROUP)); - if (containMultiSig) { + if (isMultiSig) { cellDeps.add(new CellDep(systemMultiSigCell.outPoint, CellDep.DEP_GROUP)); + } else { + cellDeps.add(new CellDep(systemSecpCell.outPoint, CellDep.DEP_GROUP)); } return new Transaction( "0", diff --git a/ckb/src/main/java/org/nervos/ckb/type/Script.java b/ckb/src/main/java/org/nervos/ckb/type/Script.java index 89275c0c7..b3bcb7ca2 100644 --- a/ckb/src/main/java/org/nervos/ckb/type/Script.java +++ b/ckb/src/main/java/org/nervos/ckb/type/Script.java @@ -3,7 +3,9 @@ import com.google.gson.annotations.SerializedName; import org.nervos.ckb.Encoder; import org.nervos.ckb.crypto.Blake2b; +import org.nervos.ckb.utils.Numeric; import org.nervos.ckb.utils.Serializer; +import org.nervos.ckb.utils.Strings; /** Copyright © 2019 Nervos Foundation. All rights reserved. */ public class Script { @@ -38,4 +40,15 @@ public String computeHash() { blake2b.update(Encoder.encode(Serializer.serializeScript(this))); return blake2b.doFinalString(); } + + public int occupiedCapacity() { + int byteSize = 1; + if (!Strings.isEmpty(codeHash)) { + byteSize += Numeric.hexStringToByteArray(codeHash).length / 2; + } + if (!Strings.isEmpty(args)) { + byteSize += Numeric.hexStringToByteArray(args).length / 2; + } + return byteSize; + } } diff --git a/ckb/src/main/java/org/nervos/ckb/type/cell/CellOutput.java b/ckb/src/main/java/org/nervos/ckb/type/cell/CellOutput.java index bb4dc1dc0..b529a9231 100644 --- a/ckb/src/main/java/org/nervos/ckb/type/cell/CellOutput.java +++ b/ckb/src/main/java/org/nervos/ckb/type/cell/CellOutput.java @@ -1,6 +1,8 @@ package org.nervos.ckb.type.cell; import org.nervos.ckb.type.Script; +import org.nervos.ckb.utils.Numeric; +import org.nervos.ckb.utils.Strings; /** Copyright © 2018 Nervos Foundation. All rights reserved. */ public class CellOutput { @@ -20,4 +22,18 @@ public CellOutput(String capacity, Script lock, Script type) { this.lock = lock; this.type = type; } + + public int occupiedCapacity(String data) { + int byteSize = 8; + if (!Strings.isEmpty(data)) { + byteSize += Numeric.hexStringToByteArray(data).length / 2; + } + if (lock != null) { + byteSize += lock.occupiedCapacity(); + } + if (type != null) { + byteSize += type.occupiedCapacity(); + } + return byteSize; + } } diff --git a/example/src/main/java/org/nervos/ckb/MultiSignTransactionExample.java b/example/src/main/java/org/nervos/ckb/MultiSignTransactionExample.java index 0a0ace5e1..982a7ff5f 100644 --- a/example/src/main/java/org/nervos/ckb/MultiSignTransactionExample.java +++ b/example/src/main/java/org/nervos/ckb/MultiSignTransactionExample.java @@ -120,7 +120,7 @@ public static Transaction generateTx( Collections.singletonList(configuration.address()), cellOutputs, feeRate, - configuration.serialize().length() + configuration.requireN * Sign.SIGN_LENGTH * 2); + configuration.serialize().length() + configuration.threshold * Sign.SIGN_LENGTH * 2); int startIndex = 0; for (CellsWithAddress cellsWithAddress : cellsWithAddresses) { txBuilder.addInputs(cellsWithAddress.inputs); diff --git a/example/src/main/java/org/nervos/ckb/transaction/CellCollector.java b/example/src/main/java/org/nervos/ckb/transaction/CellCollector.java index 31c965831..363300173 100644 --- a/example/src/main/java/org/nervos/ckb/transaction/CellCollector.java +++ b/example/src/main/java/org/nervos/ckb/transaction/CellCollector.java @@ -32,9 +32,9 @@ public Map> collectInputs( throws IOException { List cellOutputsData = new ArrayList<>(); for (int i = 0; i < cellOutputs.size() - 1; i++) { - int size = Serializer.serializeCellOutput(cellOutputs.get(i)).getLength(); + int size = cellOutputs.get(i).occupiedCapacity("0x"); if (BigInteger.valueOf(size).compareTo(Numeric.toBigInt(cellOutputs.get(i).capacity)) > 0) { - throw new IOException("Cell output serialize size must not be bigger than capacity"); + throw new IOException("Cell output byte size must not be bigger than capacity"); } cellOutputsData.add("0x"); }