Skip to content

Commit

Permalink
Merge pull request #49 from nervosnetwork/rc/v0.10.0
Browse files Browse the repository at this point in the history
[ᚬmaster] Rc/v0.10.0
  • Loading branch information
duanyytop authored May 6, 2019
2 parents 1fbfca1 + 7d23d3d commit 1781834
Show file tree
Hide file tree
Showing 15 changed files with 104 additions and 90 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.10.0](https://github.com/nervosnetwork/ckb-sdk-java/compare/v0.9.0...v0.10.0) (2019-05-06)

### Bug Fixes

- Change capacity in RPC interface data type to string ([88723c3](https://github.com/nervosnetwork/ckb-sdk-java/pull/49/commits/88723c346a6c78468bdb4c1ac8f02aa29d2158df))
- Add valid since to cell input ([b4758e1](https://github.com/nervosnetwork/ckb-sdk-java/pull/49/commits/b4758e1fe34706a366cf66f30054ee96d1421e1c))

# [v0.9.0](https://github.com/nervosnetwork/ckb-sdk-java/compare/v0.8.0...v0.9.0) (2019-4-22)

### Features
Expand Down
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,12 @@ git clone https://github.com/nervosnetwork/ckb-sdk-java.git
gradle shadowJar // ./gradlew shadowJar
```
You will get `console-{version}-all.jar` from console module.


## License

The SDK is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).

## Changelog

See [CHANGELOG](CHANGELOG.md) for more information.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ buildscript {
ext.gsonVersion = '2.8.5'
ext.jacksonVersion = '2.8.5'
ext.okhttpVersion = '3.14.1'
ext.loggingOkhttpVersion = '3.14.0'
ext.loggingOkhttpVersion = '3.14.1'
ext.slf4jVersion = '1.7.26'

ext.junitVersion = '5.4.2'
Expand Down Expand Up @@ -34,7 +34,7 @@ allprojects {
targetCompatibility = 1.8

group 'org.nervos.ckb'
version '0.9.0'
version '0.10.0'

apply plugin: 'java'

Expand Down
6 changes: 3 additions & 3 deletions console/src/main/java/org/nervos/ckb/RpcRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class RpcRequest {
ckbService = CKBService.build(new HttpService(NODE_URL));
}

public static String getBlockHash(long blockNumber) throws IOException {
public static String getBlockHash(String blockNumber) throws IOException {
return ckbService.getBlockHash(blockNumber).send().getBlockHash();
}

Expand All @@ -52,7 +52,7 @@ public static NodeInfo localNodeInfo() throws IOException {
return ckbService.localNodeInfo().send().getNodeInfo();
}

public static List<CellOutputWithOutPoint> getCellsByLockHash(String lockHash, long fromBlockNumber, long toBlockNumber) throws IOException {
public static List<CellOutputWithOutPoint> getCellsByLockHash(String lockHash, String fromBlockNumber, String toBlockNumber) throws IOException {
return ckbService.getCellsByLockHash(lockHash, fromBlockNumber, toBlockNumber).send().getCells();
}

Expand All @@ -69,7 +69,7 @@ public static String sendTransaction(Transaction transaction) throws IOException


public static Block genesisBlock() throws IOException {
String blockHash = ckbService.getBlockHash(0).send().getBlockHash();
String blockHash = ckbService.getBlockHash("0").send().getBlockHash();
return ckbService.getBlock(blockHash).send().getBlock();
}

Expand Down
52 changes: 23 additions & 29 deletions core/src/main/java/org/nervos/ckb/methods/type/CellInput.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,44 +4,38 @@

import java.util.List;

/**
* Created by duanyytop on 2019-01-08.
* Copyright © 2018 Nervos Foundation. All rights reserved.
*/
/** Created by duanyytop on 2019-01-08. Copyright © 2018 Nervos Foundation. All rights reserved. */
public class CellInput {

/**
* previous_output : {"hash":"0x0000000000000000000000000000000000000000000000000000000000000000","index":4294967295}
* unlock : {"args":[],"binary":[1,0,0,0,0,0,0,0],"reference":null,"signed_args":[],"version":0}
*/
@JsonProperty("previous_output")
public PreviousOutput previousOutput;

@JsonProperty("previous_output")
public PreviousOutput previousOutput;
public List<String> args;
public List<String> args;

public CellInput(){}
@JsonProperty("valid_since")
public String validSince;

public CellInput(PreviousOutput previousOutput, List<String> args) {
this.previousOutput = previousOutput;
this.args = args;
}
public CellInput() {}

public static class PreviousOutput {
/**
* hash : 0x0000000000000000000000000000000000000000000000000000000000000000
* index : 4294967295
*/
public CellInput(PreviousOutput previousOutput, List<String> args, String validSince) {
this.previousOutput = previousOutput;
this.args = args;
this.validSince = validSince;
}

public String hash;
public long index;
public static class PreviousOutput {
/**
* hash : 0x0000000000000000000000000000000000000000000000000000000000000000 index : 4294967295
*/
public String hash;

public PreviousOutput(){}
public long index;

public PreviousOutput(String hash, long index) {
this.hash = hash;
this.index = index;
}
public PreviousOutput() {}

public PreviousOutput(String hash, long index) {
this.hash = hash;
this.index = index;
}

}
}
36 changes: 15 additions & 21 deletions core/src/main/java/org/nervos/ckb/methods/type/CellOutput.java
Original file line number Diff line number Diff line change
@@ -1,29 +1,23 @@
package org.nervos.ckb.methods.type;

/**
* Created by duanyytop on 2019-01-08.
* Copyright © 2018 Nervos Foundation. All rights reserved.
*/
/** Created by duanyytop on 2019-01-08. Copyright © 2018 Nervos Foundation. All rights reserved. */
public class CellOutput {

/**
* capacity : 50000
* type : null
* data : 0x
* lock : 0x321c1ca2887fb8eddaaa7e917399f71e63e03a1c83ff75ed12099a01115ea2ff
*/
/**
* capacity : 50000 type : null data : 0x lock :
* 0x321c1ca2887fb8eddaaa7e917399f71e63e03a1c83ff75ed12099a01115ea2ff
*/
public String capacity;

public long capacity;
public Script type;
public Script lock;
public String data;
public Script type;
public Script lock;
public String data;

public CellOutput(){}

public CellOutput(long capacity, String data, Script lock) {
this.capacity = capacity;
this.data = data;
this.lock = lock;
}
public CellOutput() {}

public CellOutput(String capacity, String data, Script lock) {
this.capacity = capacity;
this.data = data;
this.lock = lock;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,12 @@

import com.fasterxml.jackson.annotation.JsonProperty;

/**
* Created by duanyytop on 2018-12-21.
* Copyright © 2018 Nervos Foundation. All rights reserved.
*/
/** Created by duanyytop on 2018-12-21. Copyright © 2018 Nervos Foundation. All rights reserved. */
public class CellOutputWithOutPoint {

/**
* capacity : 50000
* lock : 0x321c1ca2887fb8eddaaa7e917399f71e63e03a1c83ff75ed12099a01115ea2ff
* out_point : {"hash":"0xbddb7c2559c2c3cdfc8f3cae2697ca75489521c352265cc9e60b4b2416ad5929","index":0}
*/

public int capacity;
public String lock;

@JsonProperty("out_point")
public OutPoint outPoint;
public int capacity;
public Script lock;

@JsonProperty("out_point")
public OutPoint outPoint;
}
8 changes: 4 additions & 4 deletions core/src/main/java/org/nervos/ckb/methods/type/Header.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ public class Header {
/**
* "difficulty": "0x100",
* "hash": "0x087c25e23e42f5d1e00e6984241b3711742d5e0eaf75d79a427276473e1de3f9",
* "number": 1,
* "number": "1",
* "parent_hash": "0x9b0bd5be9498a0b873d08e242fff306eec04fac7c59ce479b49ca92a8f649982",
* "seal": {
* "nonce": 16394887283531791882,
* "nonce": "16394887283531791882",
* "proof": "0xbd010000810200008a1300002e240000a9350000c4350000ea420000ca4d00005d5d0000766800004b6b000075730000"
* },
* "timestamp": 1545992487397,
Expand All @@ -27,12 +27,12 @@ public class Header {

public String difficulty;
public String hash;
public int number;
public String number;

@JsonProperty("parent_hash")
public String parentHash;

public long timestamp;
public String timestamp;

@JsonProperty("txs_commit")
public String txsCommit;
Expand Down
6 changes: 2 additions & 4 deletions core/src/main/java/org/nervos/ckb/methods/type/Script.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,19 @@ public class Script {

public static final String ALWAYS_SUCCESS_HASH = "0000000000000000000000000000000000000000000000000000000000000001";

public int version;
@JsonProperty("binary_hash")
public String binaryHash;
public List<String> args;

public Script(){}

public Script(int version, String binaryHash, List<String> args) {
this.version = version;
public Script(String binaryHash, List<String> args) {
this.binaryHash = binaryHash;
this.args = args;
}

public static Script alwaysSuccess() {
return new Script(0, ALWAYS_SUCCESS_HASH, Collections.emptyList());
return new Script(ALWAYS_SUCCESS_HASH, Collections.emptyList());
}

public String getTypeHash() {
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/org/nervos/ckb/service/CKBApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ public interface CKBApi {

Request<?, CkbTransaction> getTransaction(String transactionHash);

Request<?, CkbBlockHash> getBlockHash(long blockNumber);
Request<?, CkbBlockHash> getBlockHash(String blockNumber);

Request<?, CkbHeader> getTipHeader();

Request<?, CkbCells> getCellsByLockHash(String lockHash, long fromBlockNumber, long toBlockNumber);
Request<?, CkbCells> getCellsByLockHash(String lockHash, String fromBlockNumber, String toBlockNumber);

Request<?, CkbCell> getLiveCell(OutPoint outPoint);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public Request<?, CkbTransaction> getTransaction(String transactionHash) {


@Override
public Request<?, CkbBlockHash> getBlockHash(long blockNumber) {
public Request<?, CkbBlockHash> getBlockHash(String blockNumber) {
return new Request<>(
"get_block_hash",
Collections.singletonList(blockNumber),
Expand All @@ -61,7 +61,7 @@ public Request<?, CkbHeader> getTipHeader() {


@Override
public Request<?, CkbCells> getCellsByLockHash(String lockHash, long fromBlockNumber, long toBlockNumber) {
public Request<?, CkbCells> getCellsByLockHash(String lockHash, String fromBlockNumber, String toBlockNumber) {
return new Request<>(
"get_cells_by_lock_hash",
Arrays.asList(lockHash, fromBlockNumber, toBlockNumber),
Expand Down
14 changes: 7 additions & 7 deletions core/src/test/java/type/ScriptTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ public class ScriptTest {
private static final String ZERO_HASH =
"0000000000000000000000000000000000000000000000000000000000000000";

@Test
public void testEmptyScriptTypeHash() {
Script script = new Script(0, ZERO_HASH, Collections.emptyList());
Assertions.assertEquals(
"0x266cec97cbede2cfbce73666f08deed9560bdf7841a7a5a51b3a3f09da249e21", script.getTypeHash());
}
@Test
public void testEmptyScriptTypeHash() {
Script script = new Script(ZERO_HASH, Collections.emptyList());
Assertions.assertEquals("0x266cec97cbede2cfbce73666f08deed9560bdf7841a7a5a51b3a3f09da249e21", script.getTypeHash());
}


@Test
public void testScriptTypeHash() {
Script script = new Script(0, ZERO_HASH, Collections.singletonList("0x01"));
Script script = new Script(ZERO_HASH, Collections.singletonList("0x01"));
Assertions.assertEquals(
"0xdade0e507e27e2a5995cf39c8cf454b6e70fa80d03c1187db7a4cb2c9eab79da", script.getTypeHash());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ public static BigInteger signedMessageToKey(
public static BigInteger publicKeyFromPrivate(BigInteger privKey) {
ECPoint point = publicPointFromPrivate(privKey);

byte[] encoded = point.getEncoded(false);
byte[] encoded = point.getEncoded(true);
return new BigInteger(1, Arrays.copyOfRange(encoded, 1, encoded.length));
}

Expand Down
13 changes: 13 additions & 0 deletions utils/src/test/java/org/nervos/ckb/address/AddressTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.nervos.ckb.crypto.secp256k1.ECKeyPair;
import org.nervos.ckb.crypto.secp256k1.Sign;
import org.nervos.ckb.utils.Bech32;
import org.nervos.ckb.utils.Network;
import org.nervos.ckb.utils.Numeric;
Expand Down Expand Up @@ -58,4 +60,15 @@ public void testPublicKeyHashToAddressMainnet() {
"ckb1q9gry5zgxmpjnmtrp4kww5r39frh2sm89tdt2l6vqdd7em",
utils.generate("0x024a501efd328e062c8675f2365970728c859c592beeefd6be8ead3d901330bc01"));
}

@Test
public void testPrivateKeyHashToAddressTestnet() {
AddressUtils utils = new AddressUtils(Network.TESTNET);
String publicKey = Sign.publicKeyFromPrivate(Numeric.toBigInt("e79f3207ea4980b7fed79956d5934249ceac4751a4fae01a0f7c4a96884bc4e3"),
true).toString(16);
Assertions.assertEquals(
"ckt1q9gry5zgxmpjnmtrp4kww5r39frh2sm89tdt2l6v234ygf",
utils.generate(publicKey));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
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.utils.Numeric;

/** Created by duanyytop on 2019-02-01. Copyright © 2018 Nervos Foundation. All rights reserved. */
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
public class SignTest {

private ECKeyPair ecKeyPair;
Expand All @@ -20,6 +22,13 @@ public void init() {
"85a1feafb48eae47b88308f525b759d651986e5a4d80a5915cb5d28566d6c7c5");
}

@Test
public void compressedPublicKeyTest() {
String privateKey = "e79f3207ea4980b7fed79956d5934249ceac4751a4fae01a0f7c4a96884bc4e3";
String publicKey = Numeric.toHexStringNoPrefix(Sign.publicKeyFromPrivate(Numeric.toBigInt(privateKey), true));
Assertions.assertEquals("24a501efd328e062c8675f2365970728c859c592beeefd6be8ead3d901330bc01", publicKey);
}

@Test
public void signMessageTest() {
String signResult =
Expand Down

0 comments on commit 1781834

Please sign in to comment.