Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
8a3143f
chore: 🤖 Update deprecated gradle functions to new ones
Dec 27, 2022
5b4ac47
test: 💍 Disable unittest since test indexer point to ckb module
Dec 27, 2022
72edda4
Merge pull request #619 from liuck8080/chore/fix_auto_cd_problems
quake Jan 3, 2023
c281e32
feat: 🎸 enable with_cycles of get_block and get_block_by_number
Jan 13, 2023
85e6305
refactor: 💡 Rename BlockResponse to BlockWithCycles
Feb 1, 2023
75d9d3c
Merge pull request #623 from liuck8080/feat/get_block_with_cycles
quake Feb 1, 2023
312a258
fix: 🐛 Pack uint32(-1) into 0xffffffff instead of 0xff000000
Feb 2, 2023
81bf4f9
feat: 🎸 add get packed version getblock and gettransaction
Feb 2, 2023
02ee274
feat: 🎸 Support packed header RPC
Feb 2, 2023
2f36ad1
feat: 🎸 support packed get_fork_block
Feb 2, 2023
d3de6a5
test: 💍 Add test about not data for RPC call
Feb 2, 2023
4c5c5c8
feat: 🎸 Add get_transaction with verbosity=1
Feb 2, 2023
83bb037
refactor: 💡 getTransactionVerbosity1 => getTransactionStatus
Feb 6, 2023
07a984a
Merge pull request #624 from liuck8080/feat/packed-rpcs
Feb 6, 2023
39e1010
feat: 🎸 support indexer search mode
Mar 12, 2023
5ea7d04
Merge pull request #627 from liuck8080/feat/support_exact_index_search
quake Mar 14, 2023
eb762b5
docs: ✏️ Update CHANGELOG.md to prepare new release
Mar 22, 2023
35c68e1
Merge pull request #630 from liuck8080/develop
Mar 22, 2023
b8a55db
chore: 🤖 change version to 2.1.1
Mar 23, 2023
91e07ce
Merge pull request #632 from liuck8080/develop
quake Mar 23, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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