Skip to content

Commit

Permalink
fix: incompatible types in indexer and rpc (ckb-js#385)
Browse files Browse the repository at this point in the history
* chore(release): publish v0.19.0-alpha.0

* fix base export

* fix api.d.ts

* use base types in rpc

* add test cases

* add ref for hardforkFeatures

* update migration guide

Co-authored-by: homura <homura.dev@gmail.com>
  • Loading branch information
zhangyouxin and homura authored Aug 17, 2022
1 parent 5c9cdb1 commit b8e4d10
Show file tree
Hide file tree
Showing 41 changed files with 359 additions and 616 deletions.
4 changes: 2 additions & 2 deletions examples/cardano-lock-namiwallet/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"private": true,
"name": "@lumos-examples/cardano-lock-namiwallet",
"version": "0.18.0",
"version": "0.19.0-alpha.0",
"description": "",
"main": "index.js",
"scripts": {
Expand All @@ -12,7 +12,7 @@
"author": "",
"license": "MIT",
"dependencies": {
"@ckb-lumos/lumos": "0.18.0",
"@ckb-lumos/lumos": "0.19.0-alpha.0",
"@emurgo/cardano-message-signing-asmjs": "^1.0.1",
"@emurgo/cardano-serialization-lib-asmjs": "^10.0.4",
"@types/react": "^17.0.34",
Expand Down
4 changes: 2 additions & 2 deletions examples/omni-lock-metamask/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"private": true,
"name": "@lumos-examples/omni-lock-metamask",
"version": "0.18.0",
"version": "0.19.0-alpha.0",
"description": "",
"main": "index.js",
"scripts": {
Expand All @@ -12,7 +12,7 @@
"author": "",
"license": "MIT",
"dependencies": {
"@ckb-lumos/lumos": "0.18.0",
"@ckb-lumos/lumos": "0.19.0-alpha.0",
"@types/react": "^17.0.34",
"@types/react-dom": "^17.0.11",
"react": "^17.0.2",
Expand Down
4 changes: 2 additions & 2 deletions examples/omni-lock-secp256k1-blake160/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"private": true,
"name": "@lumos-examples/omni-lock-own-signature",
"version": "0.18.0",
"version": "0.19.0-alpha.0",
"description": "",
"main": "index.js",
"scripts": {
Expand All @@ -12,7 +12,7 @@
"author": "",
"license": "MIT",
"dependencies": {
"@ckb-lumos/lumos": "0.18.0",
"@ckb-lumos/lumos": "0.19.0-alpha.0",
"@types/react": "^17.0.34",
"@types/react-dom": "^17.0.11",
"react": "^17.0.2",
Expand Down
4 changes: 2 additions & 2 deletions examples/pw-lock-metamask/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"private": true,
"name": "@lumos-examples/pw-lock-metamask",
"version": "0.18.0",
"version": "0.19.0-alpha.0",
"description": "",
"main": "index.js",
"scripts": {
Expand All @@ -12,7 +12,7 @@
"author": "",
"license": "MIT",
"dependencies": {
"@ckb-lumos/lumos": "0.18.0",
"@ckb-lumos/lumos": "0.19.0-alpha.0",
"@types/react": "^17.0.34",
"@types/react-dom": "^17.0.11",
"keccak": "^3.0.1",
Expand Down
4 changes: 2 additions & 2 deletions examples/secp256k1-transfer/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"private": true,
"name": "@lumos-examples/secp256k1-transfer",
"version": "0.18.0",
"version": "0.19.0-alpha.0",
"description": "",
"main": "index.js",
"scripts": {
Expand All @@ -11,7 +11,7 @@
"author": "",
"license": "MIT",
"dependencies": {
"@ckb-lumos/lumos": "0.18.0",
"@ckb-lumos/lumos": "0.19.0-alpha.0",
"@types/react": "^17.0.34",
"@types/react-dom": "^17.0.11",
"react": "^17.0.2",
Expand Down
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
],
"npmClient": "yarn",
"useWorkspaces": true,
"version": "0.18.0",
"version": "0.19.0-alpha.0",
"command": {
"publish": {
"access": "public"
Expand Down
20 changes: 10 additions & 10 deletions packages/base/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import * as utils from "./src/utils";
import * as helpers from "./src/helpers";
import * as since from "./src/since";
import * as values from "./src/values";
import * as logger from "./src/logger";
import * as blockchain from "./src/blockchain";
import * as utils from "./lib/utils";
import * as helpers from "./lib/helpers";
import * as since from "./lib/since";
import * as values from "./lib/values";
import * as logger from "./lib/logger";
import * as blockchain from "./lib/blockchain";

export * from "./src/primitive";
export * from "./src/api";
export * from "./src/indexer";
export * from "./lib/primitive";
export * from "./lib/api";
export * from "./lib/indexer";

export { utils, helpers, since, values, logger, blockchain };
export { SinceValidationInfo } from "./src/since";
export { SinceValidationInfo } from "./lib/since";

export interface Tip {
blockNumber: string;
Expand Down
8 changes: 4 additions & 4 deletions packages/base/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ckb-lumos/base",
"version": "0.18.0",
"version": "0.19.0-alpha.0",
"description": "Base data structures and utilities used in lumos",
"author": "Xuejie Xiao <xxuejie@gmail.com>",
"homepage": "https://github.com/nervosnetwork/lumos#readme",
Expand Down Expand Up @@ -49,9 +49,9 @@
]
},
"dependencies": {
"@ckb-lumos/bi": "0.18.0",
"@ckb-lumos/codec": "0.18.0",
"@ckb-lumos/toolkit": "0.18.0",
"@ckb-lumos/bi": "^0.19.0-alpha.0",
"@ckb-lumos/codec": "^0.19.0-alpha.0",
"@ckb-lumos/toolkit": "^0.19.0-alpha.0",
"@types/lodash.isequal": "^4.5.5",
"blake2b": "^2.1.3",
"js-xxhash": "^1.0.4",
Expand Down
21 changes: 13 additions & 8 deletions packages/base/src/api.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,15 @@ export interface Block {
proposals: HexString[];
}

export interface LiveCell {
data: {
content: HexString;
hash: Hash;
};
output: Output;
}
export interface CellWithStatus {
cell: {
data: {
content: HexString;
hash: Hash;
};
output: Output;
} | null;
cell: LiveCell | null;
status: "live" | "unknown";
}

Expand Down Expand Up @@ -159,6 +160,8 @@ export interface ProposalWindow {
export interface Consensus {
id: string;
genesisHash: Hash;
// added this field by: https://github.com/nervosnetwork/ckb/pull/2879
hardforkFeatures: Array<{ rfc: string; epochNumber: string | undefined }>;
daoTypeHash?: Hash;
secp256k1Blake160SighashAllTypeHash?: Hash;
secp256k1Blake160MultisigAllTypeHash?: Hash;
Expand Down Expand Up @@ -211,6 +214,8 @@ export interface PeerSyncState {
lastCommonHeaderHash?: HexString;
lastCommonHeaderNumber?: HexNumber;
unknownHeaderListSize?: HexNumber;
canFetchCount?: HexNumber;
inflightCount?: HexNumber;
}

export interface RemoteNodeProtocol {
Expand All @@ -222,7 +227,7 @@ export interface RemoteNode {
version: string;
nodeId: string;
addresses: NodeAddress[];
isOutbount: boolean;
isOutbound: boolean;
connectedDuration: HexNumber;
lastPingDuration?: HexNumber;
syncState?: PeerSyncState;
Expand Down
2 changes: 1 addition & 1 deletion packages/bi/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ckb-lumos/bi",
"version": "0.18.0",
"version": "0.19.0-alpha.0",
"description": "Bigint support in lumos",
"author": "",
"homepage": "https://github.com/nervosnetwork/lumos#readme",
Expand Down
12 changes: 6 additions & 6 deletions packages/ckb-indexer/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ckb-lumos/ckb-indexer",
"version": "0.18.0",
"version": "0.19.0-alpha.0",
"description": "CKB Indexer",
"author": "Xuejie Xiao <xxuejie@gmail.com>",
"homepage": "https://github.com/nervosnetwork/lumos#readme",
Expand All @@ -19,15 +19,15 @@
"src"
],
"dependencies": {
"@ckb-lumos/base": "0.18.0",
"@ckb-lumos/bi": "0.18.0",
"@ckb-lumos/rpc": "0.18.0",
"@ckb-lumos/toolkit": "0.18.0",
"@ckb-lumos/base": "^0.19.0-alpha.0",
"@ckb-lumos/bi": "^0.19.0-alpha.0",
"@ckb-lumos/rpc": "^0.19.0-alpha.0",
"@ckb-lumos/toolkit": "^0.19.0-alpha.0",
"cross-fetch": "^3.1.5",
"events": "^3.3.0"
},
"devDependencies": {
"@ckb-lumos/testkit": "0.18.0",
"@ckb-lumos/testkit": "^0.19.0-alpha.0",
"@types/request": "^2.48.8",
"@types/sinon": "^10.0.6",
"find-process": "^1.4.7",
Expand Down
19 changes: 18 additions & 1 deletion packages/ckb-indexer/src/paramsFormatter.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,26 @@
import { Script } from "@ckb-lumos/base";
import type * as RPCType from "./rpcType";
import { SearchKey, SearchFilter } from "./type";

const toScript = (data: Script): RPCType.Script => ({
code_hash: data.codeHash,
hash_type: data.hashType,
args: data.args,
});
export { toScript };

const toSearchFilter = (data: SearchFilter): RPCType.SearchFilter => {
return {
script: data.script ? toScript(data.script) : data.script,
output_data_len_range: data.outputDataLenRange,
output_capacity_range: data.outputCapacityRange,
block_range: data.blockRange,
};
};

const toSearchKey = (data: SearchKey): RPCType.SearchKey => ({
script: toScript(data.script),
script_type: data.scriptType,
filter: data.filter ? toSearchFilter(data.filter) : data.filter,
});

export { toScript, toSearchKey, toSearchFilter };
25 changes: 24 additions & 1 deletion packages/ckb-indexer/src/resultFormatter.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { OutPoint, Script } from "@ckb-lumos/base";
import type * as IndexerType from "./indexerType";
import type * as RPCType from "./rpcType";
import { SearchFilter, SearchKey } from "./type";

const toTip = (tip: RPCType.Tip): IndexerType.Tip => ({
blockHash: tip.block_hash,
Expand All @@ -21,4 +22,26 @@ const toCellOutPut = (data: RPCType.CellOutput): IndexerType.CellOutput => ({
type: data.type ? toScript(data.type) : undefined,
});

export { toTip, toScript, toOutPoint, toCellOutPut };
const toSearchFilter = (data: RPCType.SearchFilter): SearchFilter => {
return {
script: data.script ? toScript(data.script) : data.script,
outputDataLenRange: data.output_data_len_range,
outputCapacityRange: data.output_capacity_range,
blockRange: data.block_range,
};
};

const toSearchKey = (data: RPCType.SearchKey): SearchKey => ({
script: toScript(data.script),
scriptType: data.script_type,
filter: data.filter ? toSearchFilter(data.filter) : data.filter,
});

export {
toTip,
toScript,
toOutPoint,
toCellOutPut,
toSearchKey,
toSearchFilter,
};
5 changes: 3 additions & 2 deletions packages/ckb-indexer/src/rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
SearchKey,
} from "./type";
import fetch from "cross-fetch";
import { toSearchKey } from "./paramsFormatter";

export class RPC {
private uri: string;
Expand All @@ -27,7 +28,7 @@ export class RPC {
limit: HexString,
cursor?: string
): Promise<GetLiveCellsResult> {
const params = [searchKey, order, limit, cursor];
const params = [toSearchKey(searchKey), order, limit, cursor];
return utils.deepCamel(await request(this.uri, "get_cells", params));
}
async getTransactions(
Expand All @@ -36,7 +37,7 @@ export class RPC {
limit: HexString,
cursor?: string
): Promise<IndexerTransactionList> {
const params = [searchKey, order, limit, cursor];
const params = [toSearchKey(searchKey), order, limit, cursor];
return utils.deepCamel(await request(this.uri, "get_transactions", params));
}
async getIndexerInfo(): Promise<string> {
Expand Down
17 changes: 16 additions & 1 deletion packages/ckb-indexer/src/rpcType.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { HexString, HexNumber, Hash } from "@ckb-lumos/base";
import { HexString, HexNumber, Hash, Hexadecimal } from "@ckb-lumos/base";

export type Tip = {
block_hash: HexNumber;
Expand All @@ -18,3 +18,18 @@ export type CellOutput = {
lock: Script;
type?: Script;
};

export type HexadecimalRange = [Hexadecimal, Hexadecimal];
export type ScriptType = "type" | "lock";

export interface SearchFilter {
script?: Script;
output_data_len_range?: HexadecimalRange; //empty
output_capacity_range?: HexadecimalRange; //empty
block_range?: HexadecimalRange; //fromBlock-toBlock
}
export interface SearchKey {
script: Script;
script_type: ScriptType;
filter?: SearchFilter;
}
Loading

0 comments on commit b8e4d10

Please sign in to comment.