Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: integrate ckb-js-toolkit #231

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ build:
yarn workspace @ckb-lumos/hd-cache build
yarn workspace @ckb-lumos/ckb-indexer build
yarn workspace @ckb-lumos/lumos build
yarn workspace @ckb-lumos/core build

build-release: build
yarn workspace @ckb-lumos/lumos build:umd
Expand All @@ -23,6 +24,7 @@ test:
yarn workspace @ckb-lumos/indexer test
yarn workspace @ckb-lumos/transaction-manager test
yarn workspace @ckb-lumos/rpc test
yarn workspace @ckb-lumos/core test

test-coverage:
yarn c8 --reporter=cobertura --reporter=html --clean -o coverage make test
Expand Down
4 changes: 4 additions & 0 deletions packages/core/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules/
build/
lib/
dist/
21 changes: 21 additions & 0 deletions packages/core/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2020 Xuejie Xiao

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
442 changes: 442 additions & 0 deletions packages/core/README.md

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions packages/core/images/toolkit.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
162 changes: 162 additions & 0 deletions packages/core/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
import JSBI from "jsbi";

export class Reader {
constructor(reader: string | ArrayBuffer | Reader);
static fromRawString(s: string): Reader;

length(): number;
indexAt(i: number): number;
toArrayBuffer(): ArrayBuffer;
serializeJson(): string;
}

export type RPCValue = any;
export type RPCSyncHandler = (...params: RPCValue[]) => RPCValue;
export type RPCHandler = (...params: RPCValue[]) => Promise<RPCValue>;

export class BatchRPCMethods {
send: RPCHandler;
}

export class BatchRPCProxy {
[method: string]: RPCSyncHandler;
}

export type BatchRPC = BatchRPCMethods & BatchRPCProxy;

export class RPCMethods {
batch: () => BatchRPC;
}

export class RPCProxy {
[method: string]: RPCHandler;
}

export class RPC {
/**
* To preserve compatibility, we still provide the default constructor
* but it cannot tell if you are calling the sync method batch, or other
* async methods. You will need to distinguish between them yourself.
*/
constructor(uri: string, options?: object);
[method: string]: RPCHandler | RPCSyncHandler;

static create(uri: string): RPCMethods & RPCProxy;
}

export function HexStringToBigInt(hexString: string): JSBI;
export function BigIntToHexString(i: JSBI): string;

export interface ValidatorOptions {
nestedValidation?: boolean;
debugPath?: string;
}
type ValidatorFunction = (value: object, options?: ValidatorOptions) => void;

export namespace validators {
const ValidateScript: ValidatorFunction;
const ValidateOutPoint: ValidatorFunction;
const ValidateCellInput: ValidatorFunction;
const ValidateCellOutput: ValidatorFunction;
const ValidateCellDep: ValidatorFunction;
const ValidateRawTransaction: ValidatorFunction;
const ValidateTransaction: ValidatorFunction;
const ValidateRawHeader: ValidatorFunction;
const ValidateHeader: ValidatorFunction;
const ValidateUncleBlock: ValidatorFunction;
const ValidateBlock: ValidatorFunction;
const ValidateCellbaseWitness: ValidatorFunction;
const ValidateWitnessArgs: ValidatorFunction;
}

export interface TransformerOptions {
validation?: boolean;
debugPath?: string;
}
type TransformerFunction = (
value: object,
options?: TransformerOptions
) => object;

export namespace transformers {
const TransformScript: TransformerFunction;
const TransformOutPoint: TransformerFunction;
const TransformCellInput: TransformerFunction;
const TransformCellOutput: TransformerFunction;
const TransformCellDep: TransformerFunction;
const TransformRawTransaction: TransformerFunction;
const TransformTransaction: TransformerFunction;
const TransformRawHeader: TransformerFunction;
const TransformHeader: TransformerFunction;
const TransformUncleBlock: TransformerFunction;
const TransformBlock: TransformerFunction;
const TransformCellbaseWitness: TransformerFunction;
const TransformWitnessArgs: TransformerFunction;
}

export interface NormalizerOptions {
debugPath?: string;
}
type NormalizerFunction = (
value: object,
options?: NormalizerOptions
) => object;

export namespace normalizers {
const NormalizeScript: NormalizerFunction;
const NormalizeOutPoint: NormalizerFunction;
const NormalizeCellInput: NormalizerFunction;
const NormalizeCellOutput: NormalizerFunction;
const NormalizeCellDep: NormalizerFunction;
const NormalizeRawTransaction: NormalizerFunction;
const NormalizeTransaction: NormalizerFunction;
const NormalizeRawHeader: NormalizerFunction;
const NormalizeHeader: NormalizerFunction;
const NormalizeUncleBlock: NormalizerFunction;
const NormalizeBlock: NormalizerFunction;
const NormalizeCellbaseWitness: NormalizerFunction;
const NormalizeWitnessArgs: NormalizerFunction;
}

export interface Cell {
cell_output: object;
out_point: object;
block_hash: string;
data?: string;
block_number?: string;
}

export interface CellCollectorResults {
[Symbol.asyncIterator](): AsyncIterator<Cell>;
}

export interface CellCollector {
collect(): CellCollectorResults;
}

export namespace cell_collectors {
interface RPCCollectorOptions {
skipCellWithContent?: boolean;
loadData?: boolean;
}

class RPCCollector implements CellCollector {
constructor(rpc: RPC, lockHash: string, options?: RPCCollectorOptions);

collect(): CellCollectorResults;
}
}

export type DepGroupUnpacker = (data: Reader) => Array<object>;
export interface TransactionDumperOptions {
validateTransaction?: boolean;
depGroupUnpacker?: DepGroupUnpacker;
}

export class TransactionDumper {
constructor(rpc: RPC, options?: TransactionDumperOptions);

dump(tx: object): Promise<string>;
}

export const VERSION: string;
1 change: 1 addition & 0 deletions packages/core/lib/ckb-js-toolkit.esm.js

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions packages/core/lib/ckb-js-toolkit.node.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions packages/core/lib/ckb-js-toolkit.node.js.map

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions packages/core/lib/ckb-js-toolkit.umd.js

Large diffs are not rendered by default.

Loading