Skip to content

Commit

Permalink
Merge pull request #229 from nervosnetwork/rc/v0.24.7
Browse files Browse the repository at this point in the history
[ᚬmaster] Rc/v0.24.7
  • Loading branch information
quake authored Nov 12, 2019
2 parents 14a0b89 + 5d53643 commit 266dcb3
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 20 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ allprojects {
targetCompatibility = 1.8

group 'org.nervos.ckb'
version '0.24.6'
version '0.24.7'

apply plugin: 'java'

Expand Down Expand Up @@ -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
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<CellInput> cellInputs = new ArrayList<>();
private List<CellOutput> cellOutputs = new ArrayList<>();
private List<String> 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();
Expand Down Expand Up @@ -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");
}
Expand All @@ -83,9 +79,10 @@ public Transaction buildTx() throws IOException {
}

List<CellDep> 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",
Expand Down
13 changes: 13 additions & 0 deletions ckb/src/main/java/org/nervos/ckb/type/Script.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
}
}
16 changes: 16 additions & 0 deletions ckb/src/main/java/org/nervos/ckb/type/cell/CellOutput.java
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ public Map<String, List<CellInput>> collectInputs(
throws IOException {
List<String> 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");
}
Expand Down

0 comments on commit 266dcb3

Please sign in to comment.