Skip to content

Commit

Permalink
chore: refactor RPC data structure (#539)
Browse files Browse the repository at this point in the history
  • Loading branch information
fjchen7 authored Apr 7, 2022
1 parent 5469050 commit 1ada026
Show file tree
Hide file tree
Showing 188 changed files with 1,974 additions and 2,633 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# 1.0.0 (2022-03-17)

## Breaking Changes

- feat: Replace Record Id with Outpoint (#534)
# 0.101.3 (2022-01-21)

## 🚀 Features
Expand Down
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ buildscript {

ext.bouncycastleVersion = '1.65'
ext.rxjavaVersion = '2.2.21'
ext.gsonVersion = '2.8.6'
ext.gsonVersion = '2.9.0'
ext.okhttpVersion = '4.9.1'
ext.loggingOkhttpVersion = '4.9.1'
ext.slf4jVersion = '1.7.30'
Expand Down Expand Up @@ -43,7 +43,7 @@ allprojects {
targetCompatibility = 1.8

group 'org.nervos.ckb'
version '0.101.3'
version '1.0.0'
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.101.3'
version '1.0.0'
from components.java
}
}
Expand Down
86 changes: 37 additions & 49 deletions ckb-api/src/main/java/org/nervos/api/DefaultCkbApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import org.nervos.ckb.type.PeerNodeInfo;
import org.nervos.ckb.type.RawTxPool;
import org.nervos.ckb.type.RawTxPoolVerbose;
import org.nervos.ckb.type.Script;
import org.nervos.ckb.type.SyncState;
import org.nervos.ckb.type.TransactionProof;
import org.nervos.ckb.type.TxPoolInfo;
Expand All @@ -32,6 +31,7 @@
import org.nervos.ckb.type.transaction.TransactionWithStatus;
import org.nervos.indexer.CkbIndexerApi;
import org.nervos.indexer.DefaultIndexerApi;
import org.nervos.indexer.model.Order;
import org.nervos.indexer.model.SearchKey;
import org.nervos.indexer.model.resp.CellCapacityResponse;
import org.nervos.indexer.model.resp.CellsResponse;
Expand Down Expand Up @@ -98,11 +98,11 @@ public TipResponse getTip() throws IOException {
}

@Override
public CellsResponse getCells(SearchKey searchKey, String order, String limit, String afterCursor)
public CellsResponse getCells(SearchKey searchKey, Order order, int limit, byte[] afterCursor)
throws IOException {

if (this.mercuryApi != null) {
return this.mercuryApi.getCells(searchKey, order, limit, afterCursor);
// return this.mercuryApi.getCells(searchKey, order, limit, afterCursor);
}

if (this.ckbIndexerApi != null) {
Expand All @@ -114,10 +114,10 @@ public CellsResponse getCells(SearchKey searchKey, String order, String limit, S

@Override
public TransactionResponse getTransactions(
SearchKey searchKey, String order, String limit, String afterCursor) throws IOException {
SearchKey searchKey, Order order, int limit, byte[] afterCursor) throws IOException {

if (this.mercuryApi != null) {
return this.mercuryApi.getTransactions(searchKey, order, limit, afterCursor);
// return this.mercuryApi.getTransactions(searchKey, order, limit, afterCursor);
}

if (this.ckbIndexerApi != null) {
Expand All @@ -140,27 +140,27 @@ public CellCapacityResponse getCellsCapacity(SearchKey searchKey) throws IOExcep
}

@Override
public Block getBlock(String blockHash) throws IOException {
public Block getBlock(byte[] blockHash) throws IOException {
return this.ckbApi.getBlock(blockHash);
}

@Override
public Block getBlockByNumber(String blockNumber) throws IOException {
public Block getBlockByNumber(int blockNumber) throws IOException {
return this.ckbApi.getBlockByNumber(blockNumber);
}

@Override
public TransactionWithStatus getTransaction(String transactionHash) throws IOException {
public TransactionWithStatus getTransaction(byte[] transactionHash) throws IOException {
return this.ckbApi.getTransaction(transactionHash);
}

@Override
public String getBlockHash(String blockNumber) throws IOException {
public byte[] getBlockHash(int blockNumber) throws IOException {
return this.ckbApi.getBlockHash(blockNumber);
}

@Override
public BlockEconomicState getBlockEconomicState(String blockHash) throws IOException {
public BlockEconomicState getBlockEconomicState(byte[] blockHash) throws IOException {
return this.ckbApi.getBlockEconomicState(blockHash);
}

Expand All @@ -185,38 +185,38 @@ public Epoch getCurrentEpoch() throws IOException {
}

@Override
public Epoch getEpochByNumber(String epochNumber) throws IOException {
public Epoch getEpochByNumber(int epochNumber) throws IOException {
return this.ckbApi.getEpochByNumber(epochNumber);
}

@Override
public Header getHeader(String blockHash) throws IOException {
public Header getHeader(byte[] blockHash) throws IOException {
return this.ckbApi.getHeader(blockHash);
}

@Override
public Header getHeaderByNumber(String blockNumber) throws IOException {
public Header getHeaderByNumber(int blockNumber) throws IOException {
return this.ckbApi.getHeaderByNumber(blockNumber);
}

@Override
public TransactionProof getTransactionProof(List<String> txHashes) throws IOException {
public TransactionProof getTransactionProof(List<byte[]> txHashes) throws IOException {
return this.ckbApi.getTransactionProof(txHashes);
}

@Override
public TransactionProof getTransactionProof(List<String> txHashes, String blockHash)
public TransactionProof getTransactionProof(List<byte[]> txHashes, byte[] blockHash)
throws IOException {
return this.ckbApi.getTransactionProof(txHashes, blockHash);
}

@Override
public List<String> verifyTransactionProof(TransactionProof transactionProof) throws IOException {
public List<byte[]> verifyTransactionProof(TransactionProof transactionProof) throws IOException {
return this.ckbApi.verifyTransactionProof(transactionProof);
}

@Override
public Block getForkBlock(String blockHash) throws IOException {
public Block getForkBlock(byte[] blockHash) throws IOException {
return this.ckbApi.getForkBlock(blockHash);
}

Expand All @@ -226,7 +226,7 @@ public Consensus getConsensus() throws IOException {
}

@Override
public String getBlockMedianTime(String blockHash) throws IOException {
public Long getBlockMedianTime(byte[] blockHash) throws IOException {
return this.ckbApi.getBlockMedianTime(blockHash);
}

Expand All @@ -241,8 +241,8 @@ public TxPoolInfo txPoolInfo() throws IOException {
}

@Override
public String clearTxPool() throws IOException {
return this.ckbApi.clearTxPool();
public void clearTxPool() throws IOException {
this.ckbApi.clearTxPool();
}

@Override
Expand All @@ -256,12 +256,12 @@ public RawTxPoolVerbose getRawTxPoolVerbose() throws IOException {
}

@Override
public String sendTransaction(Transaction transaction) throws IOException {
public byte[] sendTransaction(Transaction transaction) throws IOException {
return this.ckbApi.sendTransaction(transaction);
}

@Override
public String sendTransaction(Transaction transaction, OutputsValidator outputsValidator)
public byte[] sendTransaction(Transaction transaction, OutputsValidator outputsValidator)
throws IOException {
return this.ckbApi.sendTransaction(transaction, outputsValidator);
}
Expand All @@ -282,23 +282,23 @@ public SyncState syncState() throws IOException {
}

@Override
public String setNetworkActive(Boolean state) throws IOException {
return this.ckbApi.setNetworkActive(state);
public void setNetworkActive(Boolean state) throws IOException {
this.ckbApi.setNetworkActive(state);
}

@Override
public String addNode(String peerId, String address) throws IOException {
return this.ckbApi.addNode(peerId, address);
public void addNode(String peerId, String address) throws IOException {
this.ckbApi.addNode(peerId, address);
}

@Override
public String removeNode(String peerId) throws IOException {
return this.ckbApi.removeNode(peerId);
public void removeNode(String peerId) throws IOException {
this.ckbApi.removeNode(peerId);
}

@Override
public String setBan(BannedAddress bannedAddress) throws IOException {
return this.ckbApi.setBan(bannedAddress);
public void setBan(BannedAddress bannedAddress) throws IOException {
this.ckbApi.setBan(bannedAddress);
}

@Override
Expand All @@ -307,13 +307,13 @@ public List<BannedResultAddress> getBannedAddresses() throws IOException {
}

@Override
public String clearBannedAddresses() throws IOException {
return this.ckbApi.clearBannedAddresses();
public void clearBannedAddresses() throws IOException {
this.ckbApi.clearBannedAddresses();
}

@Override
public String pingPeers() throws IOException {
return this.ckbApi.pingPeers();
public void pingPeers() throws IOException {
this.ckbApi.pingPeers();
}

@Override
Expand All @@ -322,19 +322,7 @@ public Cycles dryRunTransaction(Transaction transaction) throws IOException {
}

@Override
@Deprecated
public String computeTransactionHash(Transaction transaction) throws IOException {
return this.ckbApi.computeTransactionHash(transaction);
}

@Override
@Deprecated
public String computeScriptHash(Script script) throws IOException {
return this.ckbApi.computeScriptHash(script);
}

@Override
public String calculateDaoMaximumWithdraw(OutPoint outPoint, String withdrawBlockHash)
public BigInteger calculateDaoMaximumWithdraw(OutPoint outPoint, String withdrawBlockHash)
throws IOException {
return this.ckbApi.calculateDaoMaximumWithdraw(outPoint, withdrawBlockHash);
}
Expand Down Expand Up @@ -368,7 +356,7 @@ public TransactionCompletionResponse buildSimpleTransferTransaction(SimpleTransf
}

@Override
public GetTransactionInfoResponse getTransactionInfo(String txHash) throws IOException {
public GetTransactionInfoResponse getTransactionInfo(byte[] txHash) throws IOException {
return this.mercuryApi.getTransactionInfo(txHash);
}

Expand All @@ -378,7 +366,7 @@ public BlockInfoResponse getBlockInfo(GetBlockInfoPayload payload) throws IOExce
}

@Override
public List<String> registerAddresses(List<String> normalAddresses) throws IOException {
public List<byte[]> registerAddresses(List<String> normalAddresses) throws IOException {
return this.mercuryApi.registerAddresses(normalAddresses);
}

Expand Down
5 changes: 3 additions & 2 deletions ckb-api/src/test/java/constant/AddressWithKeyHolder.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.HashMap;
import java.util.Map;
import org.nervos.ckb.utils.Numeric;

public class AddressWithKeyHolder {

Expand Down Expand Up @@ -105,8 +106,8 @@ public static String queryTransactionAddress() {
return QUERY_TRANSACTION_ADDRESS;
}

public static String testPubKey0() {
return TEST_PUBKEY0;
public static byte[] testPubKey0() {
return Numeric.hexStringToByteArray(TEST_PUBKEY0);
}

public static String testPubKey1() {
Expand Down
2 changes: 1 addition & 1 deletion ckb-api/src/test/java/constant/ApiFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

public class ApiFactory {

private static String MERCURY_URL = "http://127.0.0.1:8116";
private static String MERCURY_URL = "http://mercury-testnet.ckbapp.dev/";

private static String CKB_URL = "https://mercury-testnet.ckbapp.dev";

Expand Down
7 changes: 5 additions & 2 deletions ckb-api/src/test/java/constant/UdtHolder.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package constant;

import org.nervos.ckb.utils.Numeric;

/** @author zjh @Created Date: 2021/7/23 @Description: @Modify by: */
public class UdtHolder {
public static final String UDT_HASH =
"0xf21e7350fa9518ed3cbb008e0e8c941d7e01a12181931d5608aa366ee22228bd";
public static final byte[] UDT_HASH =
Numeric.hexStringToByteArray(
"0xf21e7350fa9518ed3cbb008e0e8c941d7e01a12181931d5608aa366ee22228bd");
}
Loading

0 comments on commit 1ada026

Please sign in to comment.