Skip to content

Commit

Permalink
Merge pull request #385 from nervosnetwork/rc/v0.39.1
Browse files Browse the repository at this point in the history
Rc/v0.39.1
  • Loading branch information
duanyytop authored Jan 30, 2021
2 parents 87b3ae9 + 627a2ec commit 75fa275
Show file tree
Hide file tree
Showing 22 changed files with 869 additions and 69 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.39.1](https://github.com/nervosnetwork/ckb-sdk-java/compare/v0.39.0...v0.39.1) (2021-01-30)

### Feature

* Add sudt example with ckb-indexer([176bfa1](https://github.com/nervosnetwork/ckb-sdk-java/commit/176bfa13855925b9c140d88cbf061aa31b1e650c))
* Add acp example with ckb-indexer([c4a2502](https://github.com/nervosnetwork/ckb-sdk-java/commit/c4a2502e2233906edaeaa0554a0de29600c8c6ca))

### Bugfix

* Fix WitnessArgs serialization size([bb73a39](https://github.com/nervosnetwork/ckb-sdk-java/commit/bb73a3947ad1ce3822845cdba8cd7b681397d8b2))

# [v0.39.0](https://github.com/nervosnetwork/ckb-sdk-java/compare/v0.38.1...v0.39.0) (2021-01-12)

### Feature
Expand Down
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,20 @@ You can reference detail example in `example/MultiKeySingleSigTxExample.java`.

[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.

#### SUDT Issue and 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.
>
[SUDTExample](https://github.com/nervosnetwork/ckb-sdk-java/tree/develop/example/src/main/java/org/nervos/ckb/SUDTExample.java) provides `issue` and `transfer` methods to issue Simple UDT and transfer Simple UDT to other address.

#### ACP Create and 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.
>
[ACPTransactionExample](https://github.com/nervosnetwork/ckb-sdk-java/tree/develop/example/src/main/java/org/nervos/ckb/ACPTransactionExample.java) provides `create` and `transfer` methods to create an ACP cell with SUDT and transfer CKB and SUDT to the ACP address.

#### Address

You can generate ckb address through this SDK as below:
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.39.0'
version '0.39.1'
apply plugin: 'java'

repositories {
Expand Down Expand Up @@ -112,7 +112,7 @@ configure(subprojects.findAll { it.name != 'tests' }) {
publications {
mavenJava(MavenPublication) {
groupId 'org.nervos.ckb'
version '0.39.0'
version '0.39.1'
from components.java
}
}
Expand Down
1 change: 1 addition & 0 deletions ckb/src/main/java/org/nervos/ckb/type/Witness.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.nervos.ckb.type;

/** Copyright © 2019 Nervos Foundation. All rights reserved. */
// The Witness class here corresponds to the WitnessArgs of CKB
public class Witness {

public static final String SIGNATURE_PLACEHOLDER =
Expand Down
20 changes: 14 additions & 6 deletions ckb/src/main/java/org/nervos/ckb/utils/Serializer.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,22 +95,30 @@ public static Fixed<Byte32> serializeByte32(List<String> bytes) {

public static Table serializeWitnessArgs(Witness witness) {
return new Table(
new Option(Strings.isEmpty(witness.lock) ? new Empty() : new Bytes(witness.lock)),
new Option(Strings.isEmpty(witness.inputType) ? new Empty() : new Bytes(witness.inputType)),
new Option(
Strings.isEmpty(witness.outputType) ? new Empty() : new Bytes(witness.outputType)));
Strings.isEmpty(witness.lock) || "0x".equals(witness.lock)
? new Empty()
: new Bytes(witness.lock)),
new Option(
Strings.isEmpty(witness.inputType) || "0x".equals(witness.inputType)
? new Empty()
: new Bytes(witness.inputType)),
new Option(
Strings.isEmpty(witness.outputType) || "0x".equals(witness.outputType)
? new Empty()
: new Bytes(witness.outputType)));
}

public static Dynamic<Type> serializeWitnesses(List witnesses) {
List witnessList = new ArrayList<>();
List<Type> witnessList = new ArrayList<>();
for (Object witness : witnesses) {
if (witness.getClass() == Witness.class) {
witnessList.add(serializeWitnessArgs((Witness) witness));
witnessList.add(new Bytes(serializeWitnessArgs((Witness) witness).toBytes()));
} else {
witnessList.add(new Bytes((String) witness));
}
}
return new Dynamic<Type>(witnessList);
return new Dynamic<>(witnessList);
}

public static Table serializeRawTransaction(Transaction transaction) {
Expand Down
247 changes: 215 additions & 32 deletions ckb/src/test/java/utils/CalculatorTest.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
package utils;

import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
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.Witness;
import org.nervos.ckb.type.cell.CellDep;
import org.nervos.ckb.type.cell.CellInput;
import org.nervos.ckb.type.cell.CellOutput;
Expand All @@ -20,31 +18,10 @@
/** Copyright © 2019 Nervos Foundation. All rights reserved. */
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
public class CalculatorTest {
private Transaction tx;

@BeforeAll
void init() {
List<CellOutput> cellOutputs = new ArrayList<>();
cellOutputs.add(
new CellOutput(
"0x174876e800",
new Script(
"0x68d5438ac952d2f584abf879527946a537e82c7f3c1cbf6d8ebf9767437d8e88",
"0x59a27ef3ba84f061517d13f42cf44ed020610061",
Script.TYPE),
new Script(
"0xece45e0979030e2f8909f76258631c42333b1e906fd9701ec3600a464a90b8f6",
"0x",
Script.DATA)));
cellOutputs.add(
new CellOutput(
"0x59e1416a5000",
new Script(
"0x68d5438ac952d2f584abf879527946a537e82c7f3c1cbf6d8ebf9767437d8e88",
"0x59a27ef3ba84f061517d13f42cf44ed020610061",
Script.TYPE)));

tx =
@Test
void testCalculateTransactionSize() {
Transaction tx =
new Transaction(
"0x0",
Arrays.asList(
Expand All @@ -65,20 +42,226 @@ void init() {
"0x31f695263423a4b05045dd25ce6692bb55d7bba2965d8be16b036e138e72cc65",
"0x1"),
"0x0")),
cellOutputs,
Arrays.asList(
new CellOutput(
"0x174876e800",
new Script(
"0x68d5438ac952d2f584abf879527946a537e82c7f3c1cbf6d8ebf9767437d8e88",
"0x59a27ef3ba84f061517d13f42cf44ed020610061",
Script.TYPE),
new Script(
"0xece45e0979030e2f8909f76258631c42333b1e906fd9701ec3600a464a90b8f6",
"0x",
Script.DATA)),
new CellOutput(
"0x59e1416a5000",
new Script(
"0x68d5438ac952d2f584abf879527946a537e82c7f3c1cbf6d8ebf9767437d8e88",
"0x59a27ef3ba84f061517d13f42cf44ed020610061",
Script.TYPE))),
Arrays.asList("0x1234", "0x"),
Collections.singletonList(
"0x82df73581bcd08cb9aa270128d15e79996229ce8ea9e4f985b49fbf36762c5c37936caf3ea3784ee326f60b8992924fcf496f9503c907982525a3436f01ab32900"));
}

@Test
void testCalculateTransactionSize() {
Assertions.assertEquals(Calculator.calculateTransactionSize(tx), 536);
}

@Test
public void testCalculateTransactionFee() {
Transaction tx =
new Transaction(
"0x0",
Arrays.asList(
new CellDep(
new OutPoint(
"0xc12386705b5cbb312b693874f3edf45c43a274482e27b8df0fd80c8d3f5feb8b",
"0x0"),
CellDep.DEP_GROUP),
new CellDep(
new OutPoint(
"0x0fb4945d52baf91e0dee2a686cdd9d84cad95b566a1d7409b970ee0a0f364f60",
"0x2"),
CellDep.CODE)),
Collections.emptyList(),
Collections.singletonList(
new CellInput(
new OutPoint(
"0x31f695263423a4b05045dd25ce6692bb55d7bba2965d8be16b036e138e72cc65",
"0x1"),
"0x0")),
Arrays.asList(
new CellOutput(
"0x174876e800",
new Script(
"0x68d5438ac952d2f584abf879527946a537e82c7f3c1cbf6d8ebf9767437d8e88",
"0x59a27ef3ba84f061517d13f42cf44ed020610061",
Script.TYPE),
new Script(
"0xece45e0979030e2f8909f76258631c42333b1e906fd9701ec3600a464a90b8f6",
"0x",
Script.DATA)),
new CellOutput(
"0x59e1416a5000",
new Script(
"0x68d5438ac952d2f584abf879527946a537e82c7f3c1cbf6d8ebf9767437d8e88",
"0x59a27ef3ba84f061517d13f42cf44ed020610061",
Script.TYPE))),
Arrays.asList("0x1234", "0x"),
Collections.singletonList(
"0x82df73581bcd08cb9aa270128d15e79996229ce8ea9e4f985b49fbf36762c5c37936caf3ea3784ee326f60b8992924fcf496f9503c907982525a3436f01ab32900"));
Assertions.assertEquals(
Calculator.calculateTransactionFee(tx, BigInteger.valueOf(900)), BigInteger.valueOf(483));
}

@Test
void testCalculateTransactionSize1V1() {
Transaction tx =
new Transaction(
"0x0",
Collections.singletonList(
new CellDep(
new OutPoint(
"0xc12386705b5cbb312b693874f3edf45c43a274482e27b8df0fd80c8d3f5feb8b",
"0x0"),
CellDep.DEP_GROUP)),
Collections.emptyList(),
Collections.singletonList(
new CellInput(
new OutPoint(
"0x31f695263423a4b05045dd25ce6692bb55d7bba2965d8be16b036e138e72cc65",
"0x1"),
"0x0")),
Collections.singletonList(
new CellOutput(
"0x174876e800",
new Script(
"0x68d5438ac952d2f584abf879527946a537e82c7f3c1cbf6d8ebf9767437d8e88",
"0x59a27ef3ba84f061517d13f42cf44ed020610061",
Script.TYPE))),
Collections.singletonList("0x"),
Collections.singletonList(
new Witness(
"0x0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000")));
Assertions.assertEquals(Calculator.calculateTransactionSize(tx), 355);
}

@Test
void testCalculateTransactionSize1V2() {
Transaction tx =
new Transaction(
"0x0",
Collections.singletonList(
new CellDep(
new OutPoint(
"0xc12386705b5cbb312b693874f3edf45c43a274482e27b8df0fd80c8d3f5feb8b",
"0x0"),
CellDep.DEP_GROUP)),
Collections.emptyList(),
Collections.singletonList(
new CellInput(
new OutPoint(
"0x31f695263423a4b05045dd25ce6692bb55d7bba2965d8be16b036e138e72cc65",
"0x1"),
"0x0")),
Arrays.asList(
new CellOutput(
"0x174876e800",
new Script(
"0x68d5438ac952d2f584abf879527946a537e82c7f3c1cbf6d8ebf9767437d8e88",
"0x59a27ef3ba84f061517d13f42cf44ed020610061",
Script.TYPE)),
new CellOutput(
"0x174876e800",
new Script(
"0x68d5438ac952d2f584abf879527946a537e82c7f3c1cbf6d8ebf9767437d8e88",
"0x59a27ef3ba84f061517d13f42cf44ed020610061",
Script.TYPE))),
Arrays.asList("0x", "0x"),
Collections.singletonList(
new Witness(
"0x0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000")));
Assertions.assertEquals(Calculator.calculateTransactionSize(tx), 464);
}

@Test
void testCalculateTransactionSize2V1() {
Transaction tx =
new Transaction(
"0x0",
Collections.singletonList(
new CellDep(
new OutPoint(
"0xc12386705b5cbb312b693874f3edf45c43a274482e27b8df0fd80c8d3f5feb8b",
"0x0"),
CellDep.DEP_GROUP)),
Collections.emptyList(),
Arrays.asList(
new CellInput(
new OutPoint(
"0x31f695263423a4b05045dd25ce6692bb55d7bba2965d8be16b036e138e72cc65",
"0x1"),
"0x0"),
new CellInput(
new OutPoint(
"0x31f695263423a4b05045dd25ce6692bb55d7bba2965d8be16b036e138e72cc65",
"0x1"),
"0x0")),
Collections.singletonList(
new CellOutput(
"0x174876e800",
new Script(
"0x68d5438ac952d2f584abf879527946a537e82c7f3c1cbf6d8ebf9767437d8e88",
"0x59a27ef3ba84f061517d13f42cf44ed020610061",
Script.TYPE))),
Collections.singletonList("0x"),
Arrays.asList(
new Witness(
"0x0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"),
"0x"));
Assertions.assertEquals(Calculator.calculateTransactionSize(tx), 407);
}

@Test
void testCalculateTransactionSize2V2() {
Transaction tx =
new Transaction(
"0x0",
Collections.singletonList(
new CellDep(
new OutPoint(
"0xc12386705b5cbb312b693874f3edf45c43a274482e27b8df0fd80c8d3f5feb8b",
"0x0"),
CellDep.DEP_GROUP)),
Collections.emptyList(),
Arrays.asList(
new CellInput(
new OutPoint(
"0x31f695263423a4b05045dd25ce6692bb55d7bba2965d8be16b036e138e72cc65",
"0x1"),
"0x0"),
new CellInput(
new OutPoint(
"0x31f695263423a4b05045dd25ce6692bb55d7bba2965d8be16b036e138e72cc65",
"0x1"),
"0x0")),
Arrays.asList(
new CellOutput(
"0x174876e800",
new Script(
"0x68d5438ac952d2f584abf879527946a537e82c7f3c1cbf6d8ebf9767437d8e88",
"0x59a27ef3ba84f061517d13f42cf44ed020610061",
Script.TYPE)),
new CellOutput(
"0x174876e800",
new Script(
"0x68d5438ac952d2f584abf879527946a537e82c7f3c1cbf6d8ebf9767437d8e88",
"0x59a27ef3ba84f061517d13f42cf44ed020610061",
Script.TYPE))),
Arrays.asList("0x", "0x"),
Arrays.asList(
new Witness(
"0x0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"),
new Witness(
"0x0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000")));
Assertions.assertEquals(Calculator.calculateTransactionSize(tx), 601);
}
}
Loading

0 comments on commit 75fa275

Please sign in to comment.