Skip to content

Commit

Permalink
Merge pull request #685 from nervosnetwork/develop
Browse files Browse the repository at this point in the history
Prepare release
  • Loading branch information
eval-exec authored Nov 26, 2024
2 parents 989726a + 53825e5 commit 1b06acb
Show file tree
Hide file tree
Showing 24 changed files with 547 additions and 138 deletions.
12 changes: 6 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ buildscript {
ext.okhttpVersion = '4.10.0'
ext.loggingOkhttpVersion = '4.10.0'
ext.slf4jVersion = '2.0.0'
ext.guavaVersion = '31.1-jre'
ext.junitVersion = '5.9.0'
ext.kotestVersion = '5.6.1'
ext.kotlinVersion = "1.8.21"
ext.mockkVersion = "1.13.5"
ext.guavaVersion = '32.1.1-jre'
ext.junitVersion = '5.10.0'
ext.kotestVersion = '5.6.2'
ext.kotlinVersion = "1.9.10"
ext.mockkVersion = "1.13.7"

repositories {
mavenCentral()
Expand All @@ -23,7 +23,7 @@ buildscript {
}

plugins {
id 'com.github.johnrengelman.shadow' version '6.1.0'
id 'com.github.johnrengelman.shadow' version '8.1.1'
id 'java'
}

Expand Down
6 changes: 3 additions & 3 deletions ckb-indexer/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ dependencies {

implementation "com.google.code.gson:gson:$gsonVersion"

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

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

test {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ public class Filter {
public List<Integer> outputDataLenRange;
public List<Long> outputCapacityRange;
public List<Integer> blockRange;
public List<Integer> scriptLenRange;
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ public SearchKeyBuilder filterBlockRange(int inclusive, int exclusive) {
return this;
}

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

private ScriptSearchMode _scriptSearchMode;

public SearchKeyBuilder scriptSearchMode(ScriptSearchMode scriptSearchMode) {
Expand Down
6 changes: 3 additions & 3 deletions ckb-mercury-sdk/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ dependencies {
implementation "com.google.code.gson:gson:$gsonVersion"

testImplementation project(":ckb")
testImplementation("org.junit.jupiter:junit-jupiter-api:5.9.0")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.9.0")
testImplementation("org.junit.jupiter:junit-jupiter-api:5.10.0")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.10.0")
// Enable use of the JUnitPlatform Runner within the IDE
testImplementation("org.junit.platform:junit-platform-runner:1.9.0")
testImplementation("org.junit.platform:junit-platform-runner:1.10.0")
}

test {
Expand Down
46 changes: 42 additions & 4 deletions ckb/src/main/java/org/nervos/ckb/CkbRpcApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,55 @@
import org.nervos.indexer.model.SearchKey;
import org.nervos.indexer.model.resp.*;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.io.IOException;
import java.util.List;

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;
default TransactionWithStatus getTransaction(@Nonnull byte[] transactionHash) throws IOException {
return getTransaction(transactionHash, null);
}

TransactionWithStatus getTransaction(@Nonnull byte[] transactionHash, @Nullable Boolean onlyCommitted) 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;
default TransactionWithStatus getTransactionStatus(@Nonnull byte[] transactionHash) throws IOException {
return getTransactionStatus(transactionHash, null);
}

TransactionWithStatus getTransactionStatus(@Nonnull byte[] transactionHash, @Nullable Boolean onlyCommitted) throws IOException;

default PackedTransactionWithStatus getPackedTransaction(@Nonnull byte[] transactionHash) throws IOException {
return getPackedTransaction(transactionHash, null);
}

PackedTransactionWithStatus getPackedTransaction(@Nonnull byte[] transactionHash, @Nullable Boolean onlyCommitted) 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 @@ -44,19 +66,25 @@ 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;

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

List<byte[]> verifyTransactionProof(TransactionProof transactionProof) throws IOException;

TransactionAndWitnessProof getTransactionAndWitnessProof(List<byte[]> txHashes, byte[] blockHash) throws IOException;

List<byte[]> verifyTransactionAndWitnessProof(TransactionAndWitnessProof proof) throws IOException;

Block getForkBlock(byte[] blockHash) throws IOException;

PackedBlockWithCycles getPackedForkBlock(byte[] blockHash) throws IOException;

Consensus getConsensus() throws IOException;
Expand All @@ -78,6 +106,16 @@ public interface CkbRpcApi {
byte[] sendTransaction(Transaction transaction, OutputsValidator outputsValidator)
throws IOException;

byte[] sendTestTransaction(Transaction transaction) throws IOException;

byte[] sendTestTransaction(Transaction transaction, OutputsValidator outputsValidator)
throws IOException;

byte[] testTxPoolAccept(Transaction transaction) throws IOException;

byte[] testTxPoolAccept(Transaction transaction, OutputsValidator outputsValidator)
throws IOException;

NodeInfo localNodeInfo() throws IOException;

List<PeerNodeInfo> getPeers() throws IOException;
Expand Down Expand Up @@ -129,5 +167,5 @@ long calculateDaoMaximumWithdraw(OutPoint outPoint, byte[] withdrawBlockHash)
* @return Returns the fee_rate statistics of confirmed blocks on the chain.
* @throws IOException if error there is an error
*/
FeeRateStatics getFeeRateStatics(Integer target) throws IOException;
FeeRateStatistics getFeeRateStatistics(Integer target) throws IOException;
}
78 changes: 65 additions & 13 deletions ckb/src/main/java/org/nervos/ckb/service/Api.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package org.nervos.ckb.service;

import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.Lists;
import com.google.gson.reflect.TypeToken;
import org.jetbrains.annotations.NotNull;
import org.nervos.ckb.CkbRpcApi;
import org.nervos.ckb.type.*;
import org.nervos.ckb.utils.Convert;
Expand All @@ -9,13 +12,14 @@
import org.nervos.indexer.model.resp.*;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

public class Api implements CkbRpcApi {

private RpcService rpcService;
private final RpcService rpcService;

public Api(String nodeUrl) {
this(nodeUrl, false);
Expand All @@ -29,6 +33,20 @@ public Api(RpcService rpcService) {
this.rpcService = rpcService;
}

// Remove trailing nulls for better backward compatibility.
@VisibleForTesting
public static List<Object> noTrailingNullParams(Object... ps) {
ArrayList<Object> params = Lists.newArrayList(ps);
for (int i = params.size() - 1; i >= 0; i--) {
if (params.get(i) == null) {
params.remove(i);
} else {
break;
}
}
return params;
}

@Override
public Block getBlock(byte[] blockHash) throws IOException {
return rpcService.post("get_block", Collections.singletonList(blockHash), Block.class);
Expand Down Expand Up @@ -95,19 +113,19 @@ public PackedBlockWithCycles getPackedBlockByNumber(long blockNumber, boolean wi
}

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

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

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

@Override
Expand Down Expand Up @@ -215,7 +233,7 @@ public List<byte[]> verifyTransactionProof(TransactionProof transactionProof) th
public TransactionAndWitnessProof getTransactionAndWitnessProof(List<byte[]> txHashes, byte[] blockHash) throws IOException {
return rpcService.post(
"get_transaction_and_witness_proof",
blockHash == null ? Collections.singletonList(txHashes): Arrays.asList(txHashes, blockHash),
blockHash == null ? Collections.singletonList(txHashes) : Arrays.asList(txHashes, blockHash),
TransactionAndWitnessProof.class);
}

Expand Down Expand Up @@ -248,7 +266,7 @@ public Consensus getConsensus() throws IOException {

@Override
public long getBlockMedianTime(byte[] blockHash) throws IOException {
return rpcService.post("get_block_median_time", Arrays.asList(blockHash), Long.class);
return rpcService.post("get_block_median_time", Collections.singletonList(blockHash), Long.class);
}

/** Stats RPC */
Expand Down Expand Up @@ -279,6 +297,40 @@ public RawTxPoolVerbose getRawTxPoolVerbose() throws IOException {
"get_raw_tx_pool", Collections.singletonList(true), RawTxPoolVerbose.class);
}

@Override
public byte[] sendTestTransaction(Transaction transaction) throws IOException {
return rpcService.post(
"send_test_transaction",
Arrays.asList(Convert.parseTransaction(transaction), OutputsValidator.PASSTHROUGH),
byte[].class);
}

@Override
public byte[] sendTestTransaction(Transaction transaction, OutputsValidator outputsValidator)
throws IOException {
return rpcService.post(
"send_test_transaction",
Arrays.asList(Convert.parseTransaction(transaction), outputsValidator),
byte[].class);
}

@Override
public byte[] testTxPoolAccept(Transaction transaction) throws IOException {
return rpcService.post(
"test_tx_pool_accept",
Arrays.asList(Convert.parseTransaction(transaction), OutputsValidator.PASSTHROUGH),
byte[].class);
}

@Override
public byte[] testTxPoolAccept(Transaction transaction, OutputsValidator outputsValidator)
throws IOException {
return rpcService.post(
"test_tx_pool_accept",
Arrays.asList(Convert.parseTransaction(transaction), outputsValidator),
byte[].class);
}

@Override
public byte[] sendTransaction(Transaction transaction) throws IOException {
return rpcService.post(
Expand Down Expand Up @@ -410,7 +462,7 @@ public TxsWithCells getTransactionsGrouped(
@Override
public CellCapacityResponse getCellsCapacity(SearchKey searchKey) throws IOException {
return this.rpcService.post("get_cells_capacity",
Arrays.asList(searchKey),
Collections.singletonList(searchKey),
CellCapacityResponse.class);
}

Expand All @@ -437,10 +489,10 @@ public List<RpcResponse> batchRPC(List<List> requests) throws IOException {
}

@Override
public FeeRateStatics getFeeRateStatics(Integer target) throws IOException {
public FeeRateStatistics getFeeRateStatistics(Integer target) throws IOException {
return rpcService.post(
"get_fee_rate_statics",
"get_fee_rate_statistics",
target == null ? Collections.emptyList() : Collections.singletonList(target),
FeeRateStatics.class);
FeeRateStatistics.class);
}
}
Loading

0 comments on commit 1b06acb

Please sign in to comment.