Skip to content

Commit

Permalink
Merge pull request #631 from nervosnetwork/develop
Browse files Browse the repository at this point in the history
Chore: release to version 2.1.1
  • Loading branch information
quake authored Apr 12, 2023
2 parents c9fb5cc + 91e07ce commit 0c1256e
Show file tree
Hide file tree
Showing 23 changed files with 640 additions and 42 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# 2.1.1 (2023-03-23)
- feat: support with_cycles for get_block and get_block_by_number rpc (#623)
- feat: support packed rpcs (#624)
- feat: support indexer exact search mod (#627)

## 🚀 Features
# 2.1.0 (2022-12-26)

## 🚀 Features
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ allprojects {
targetCompatibility = 1.8

group 'org.nervos.ckb'
version '2.1.0'
version '2.1.1'
apply plugin: 'java'

repositories {
Expand Down Expand Up @@ -97,7 +97,7 @@ configure(subprojects.findAll { it.name != 'tests' }) {
publications {
mavenJava(MavenPublication) {
groupId 'org.nervos.ckb'
version '2.1.0'
version '2.1.1'
from components.java
}
}
Expand Down
7 changes: 4 additions & 3 deletions ckb-indexer/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ description 'SDK for CKB indexer'

dependencies {
compile project(":core")
testCompile("org.junit.jupiter:junit-jupiter-api:5.9.0")
testRuntime("org.junit.jupiter:junit-jupiter-engine:5.9.0")

testImplementation 'org.junit.jupiter:junit-jupiter-api:5.9.0'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.9.0'

// Enable use of the JUnitPlatform Runner within the IDE
testCompile("org.junit.platform:junit-platform-runner:1.9.0")
testImplementation("org.junit.platform:junit-platform-runner:1.9.0")
}

test {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.nervos.indexer.model;

import com.google.gson.annotations.SerializedName;

public enum ScriptSearchMode {
// search script with prefix
@SerializedName("prefix")
Prefix,
// search script with exact match
@SerializedName("exact")
Exact,
;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@
public class SearchKey {
public Script script;
public ScriptType scriptType;
/**
* Script search mode, optional default is prefix, means search script with prefix
*/
public ScriptSearchMode scriptSearchMode;
public Filter filter;
/**
* bool, optional default is true, if with_data is set to false, the field of returning cell.output_data is null in the result
*/
public Boolean withData;
public boolean groupByTransaction;
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,45 +13,68 @@ public class SearchKeyBuilder {

private Filter filter;

public void script(Script script) {
public SearchKeyBuilder script(Script script) {
this.script = script;
return this;
}

public void scriptType(ScriptType scriptType) {
public SearchKeyBuilder scriptType(ScriptType scriptType) {
this.scriptType = scriptType;
return this;
}

public void filterScript(Script script) {
public SearchKeyBuilder filterScript(Script script) {
initFilter();
this.filter.script = script;
return this;
}

public void filterOutputDataLenRange(int inclusive, int exclusive) {
public SearchKeyBuilder filterOutputDataLenRange(int inclusive, int exclusive) {
initFilter();
this.filter.outputDataLenRange = new ArrayList<>(2);
this.filter.outputDataLenRange.add(inclusive);
this.filter.outputDataLenRange.add(exclusive);
return this;
}

public void filterOutputCapacityRange(long inclusive, long exclusive) {
public SearchKeyBuilder filterOutputCapacityRange(long inclusive, long exclusive) {
initFilter();
this.filter.outputCapacityRange = new ArrayList<>(2);
this.filter.outputCapacityRange.add(inclusive);
this.filter.outputCapacityRange.add(exclusive);
return this;
}

public void filterBlockRange(int inclusive, int exclusive) {
public SearchKeyBuilder filterBlockRange(int inclusive, int exclusive) {
initFilter();
this.filter.blockRange = new ArrayList<>(2);
this.filter.blockRange.add(inclusive);
this.filter.blockRange.add(exclusive);
return this;
}

private ScriptSearchMode _scriptSearchMode;

public SearchKeyBuilder scriptSearchMode(ScriptSearchMode scriptSearchMode) {
this._scriptSearchMode = scriptSearchMode;
return this;
}

private Boolean _withData;

public SearchKeyBuilder withData(Boolean withData) {
this._withData = withData;
return this;
}

public SearchKey build() {
SearchKey searchKey = new SearchKey();
searchKey.script = this.script;
searchKey.scriptType = this.scriptType;
searchKey.filter = this.filter;
searchKey.scriptSearchMode = this._scriptSearchMode;
searchKey.withData = this._withData;
// searchKey.groupByTransaction controlled by api function

return searchKey;
}
Expand Down
3 changes: 3 additions & 0 deletions ckb-indexer/src/test/java/indexer/TipTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ void getTip() throws IOException {
Assertions.assertTrue(tip.blockNumber <= tip2.blockNumber);
}

// both testnet and mainnet indexer url point to the ckb module ones, so no get_tip exist, it's get_indexer_tip,
// so if you use a old standalone ckb-indexer, should Configuration.setIndexerUrl yourself.
@Disabled
@Test
void getTipStandAlone() throws IOException {
Configuration.getInstance().setIndexType(IndexerType.StandAlone);
Expand Down
8 changes: 4 additions & 4 deletions ckb-mercury-sdk/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ description 'SDK for CKB mercury'
dependencies {
compile project(":core")
compile project(":ckb-indexer")
testCompile project(":ckb")
testCompile("org.junit.jupiter:junit-jupiter-api:5.9.0")
testRuntime("org.junit.jupiter:junit-jupiter-engine:5.9.0")
testImplementation project(":ckb")
testImplementation("org.junit.jupiter:junit-jupiter-api:5.9.0")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.9.0")
// Enable use of the JUnitPlatform Runner within the IDE
testCompile("org.junit.platform:junit-platform-runner:1.9.0")
testImplementation("org.junit.platform:junit-platform-runner:1.9.0")
}

test {
Expand Down
16 changes: 16 additions & 0 deletions ckb/src/main/java/org/nervos/ckb/CkbRpcApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,29 @@

public interface CkbRpcApi {
Block getBlock(byte[] blockHash) throws IOException;
BlockWithCycles getBlock(byte[] blockHash, boolean with_cycles) throws IOException;
PackedBlockWithCycles getPackedBlock(byte[] blockHash, boolean with_cycles) throws IOException;

Block getBlockByNumber(long blockNumber) throws IOException;
BlockWithCycles getBlockByNumber(long blockNumber, boolean with_cycles) throws IOException;
PackedBlockWithCycles getPackedBlockByNumber(long blockNumber, boolean with_cycles) throws IOException;

TransactionWithStatus getTransaction(byte[] transactionHash) throws IOException;

/**
* get transaction with verbosity value is 1
* @param transactionHash the transaction hash
* @return the RPC does not return the transaction content and the field transaction must be null.
* @throws IOException
*/
TransactionWithStatus getTransactionStatus(byte[] transactionHash) throws IOException;
PackedTransactionWithStatus getPackedTransaction(byte[] transactionHash) throws IOException;
byte[] getBlockHash(long blockNumber) throws IOException;

BlockEconomicState getBlockEconomicState(byte[] blockHash) throws IOException;

Header getTipHeader() throws IOException;
PackedHeader getPackedTipHeader() throws IOException;

CellWithStatus getLiveCell(OutPoint outPoint, boolean withData) throws IOException;

Expand All @@ -31,8 +44,10 @@ public interface CkbRpcApi {
Epoch getEpochByNumber(long epochNumber) throws IOException;

Header getHeader(byte[] blockHash) throws IOException;
PackedHeader getPackedHeader(byte[] blockHash) throws IOException;

Header getHeaderByNumber(long blockNumber) throws IOException;
PackedHeader getPackedHeaderByNumber(long blockNumber) throws IOException;

TransactionProof getTransactionProof(List<byte[]> txHashes) throws IOException;

Expand All @@ -41,6 +56,7 @@ public interface CkbRpcApi {
List<byte[]> verifyTransactionProof(TransactionProof transactionProof) throws IOException;

Block getForkBlock(byte[] blockHash) throws IOException;
PackedBlockWithCycles getPackedForkBlock(byte[] blockHash) throws IOException;

Consensus getConsensus() throws IOException;

Expand Down
103 changes: 102 additions & 1 deletion ckb/src/main/java/org/nervos/ckb/service/Api.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,82 @@ public Block getBlock(byte[] blockHash) throws IOException {
return rpcService.post("get_block", Collections.singletonList(blockHash), Block.class);
}

@Override
public BlockWithCycles getBlock(byte[] blockHash, boolean with_cycles) throws IOException {
List params = Arrays.asList(blockHash, null, with_cycles);
if (with_cycles) {
return rpcService.post("get_block", params, BlockWithCycles.class);
} else {
Block block = rpcService.post("get_block", params, Block.class);
BlockWithCycles ret = new BlockWithCycles();
ret.block = block;
return ret;
}
}

@Override
public Block getBlockByNumber(long blockNumber) throws IOException {
return rpcService.post(
"get_block_by_number", Collections.singletonList(blockNumber), Block.class);
}

@Override
public BlockWithCycles getBlockByNumber(long blockNumber, boolean with_cycles) throws IOException {
List params = Arrays.asList(blockNumber, null, with_cycles);
if (with_cycles) {
return rpcService.post("get_block_by_number", params, BlockWithCycles.class);
} else {
Block block = rpcService.post("get_block_by_number", params, Block.class);
if (block == null) return null;
BlockWithCycles ret = new BlockWithCycles();
ret.block = block;
return ret;
}
}

@Override
public PackedBlockWithCycles getPackedBlock(byte[] blockHash, boolean with_cycles) throws IOException {
if (with_cycles) {
return rpcService.post("get_block", Arrays.asList(blockHash, 0, true), PackedBlockWithCycles.class);
} else {
String s = rpcService.post("get_block", Arrays.asList(blockHash, 0, false), String.class);
if (s == null) return null;
PackedBlockWithCycles ret = new PackedBlockWithCycles();
ret.block = s;
return ret;
}
}

@Override
public PackedBlockWithCycles getPackedBlockByNumber(long blockNumber, boolean with_cycles) throws IOException {
List params = Arrays.asList(blockNumber, 0, with_cycles);
if (with_cycles) {
return rpcService.post("get_block_by_number", params, PackedBlockWithCycles.class);
} else {
String s = rpcService.post("get_block_by_number", params, String.class);
if (s == null) return null;
PackedBlockWithCycles ret = new PackedBlockWithCycles();
ret.block = s;
return ret;
}
}

@Override
public TransactionWithStatus getTransaction(byte[] transactionHash) throws IOException {
return rpcService.post(
"get_transaction", Collections.singletonList(transactionHash), TransactionWithStatus.class);
}

@Override
public TransactionWithStatus getTransactionStatus(byte[] transactionHash) throws IOException {
return rpcService.post("get_transaction", Arrays.asList(transactionHash, 1), TransactionWithStatus.class);
}

@Override
public PackedTransactionWithStatus getPackedTransaction(byte[] transactionHash) throws IOException {
return rpcService.post("get_transaction", Arrays.asList(transactionHash, 0), PackedTransactionWithStatus.class);
}

@Override
public byte[] getBlockHash(long blockNumber) throws IOException {
return rpcService.post("get_block_hash", Collections.singletonList(blockNumber), byte[].class);
Expand All @@ -62,6 +126,15 @@ public Header getTipHeader() throws IOException {
return rpcService.post("get_tip_header", Collections.<String>emptyList(), Header.class);
}

@Override
public PackedHeader getPackedTipHeader() throws IOException {
String s = rpcService.post("get_tip_header", Collections.singletonList(0), String.class);
if (s == null) return null;
PackedHeader ret = new PackedHeader();
ret.header = s;
return ret;
}

@Override
public CellWithStatus getLiveCell(OutPoint outPoint, boolean withData) throws IOException {
return rpcService.post(
Expand Down Expand Up @@ -92,12 +165,31 @@ public Header getHeader(byte[] blockHash) throws IOException {
return rpcService.post("get_header", Collections.singletonList(blockHash), Header.class);
}

@Override
public PackedHeader getPackedHeader(byte[] blockHash) throws IOException {
String s = rpcService.post("get_header", Arrays.asList(blockHash, 0), String.class);
if (s == null) return null;
PackedHeader ret = new PackedHeader();
ret.header = s;
return ret;
}

@Override
public Header getHeaderByNumber(long blockNumber) throws IOException {
return rpcService.post(
"get_header_by_number", Collections.singletonList(blockNumber), Header.class);
}

@Override
public PackedHeader getPackedHeaderByNumber(long blockNumber) throws IOException {
String s = rpcService.post(
"get_header_by_number", Arrays.asList(blockNumber, 0), String.class);
if (s == null) return null;
PackedHeader ret = new PackedHeader();
ret.header = s;
return ret;
}

@Override
public TransactionProof getTransactionProof(List<byte[]> txHashes) throws IOException {
return rpcService.post(
Expand All @@ -124,6 +216,15 @@ public Block getForkBlock(byte[] blockHash) throws IOException {
return rpcService.post("get_fork_block", Collections.singletonList(blockHash), Block.class);
}

@Override
public PackedBlockWithCycles getPackedForkBlock(byte[] blockHash) throws IOException {
String s = rpcService.post("get_fork_block", Arrays.asList(blockHash, 0), String.class);
if (s == null) return null;
PackedBlockWithCycles ret = new PackedBlockWithCycles();
ret.block = s;
return ret;
}

@Override
public Consensus getConsensus() throws IOException {
return rpcService.post("get_consensus", Collections.emptyList(), Consensus.class);
Expand Down Expand Up @@ -261,7 +362,7 @@ public Cycles estimateCycles(Transaction transaction) throws IOException {

@Override
public TipResponse getIndexerTip() throws IOException {
return this.rpcService.post("get_indexer_tip", Arrays.asList(), TipResponse.class);
return this.rpcService.post("get_indexer_tip", Collections.emptyList(), TipResponse.class);
}

@Override
Expand Down
Loading

0 comments on commit 0c1256e

Please sign in to comment.