Skip to content

Commit f21d7e4

Browse files
ashuralykHanssen0
authored andcommitted
feat: rewrite spore-sdk in ccc
1 parent 686a335 commit f21d7e4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+5828
-2244
lines changed

.changeset/dirty-knives-develop.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@ckb-ccc/spore": minor
3+
"@ckb-ccc/core": minor
4+
---
5+
6+
add spore package and some known scripts

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@ coverage
99
packages/*/dist*
1010

1111
.vscode
12+
.env.js
1213

1314
*.DS_Store

config/tsconfig.base.json

+7-2
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,10 @@
1818
"forceConsistentCasingInFileNames": true,
1919
"skipLibCheck": true
2020
},
21-
"include": ["src/**/*"]
22-
}
21+
"include": [
22+
"src/**/*"
23+
],
24+
"exclude": [
25+
"**/*test.ts"
26+
]
27+
}

env.example.js

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
process.env.PRIVATE_KEY =
2+
"0x0000000000000000000000000000000000000000000000000000000000000000";

jest.config.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
/** @type {import('ts-jest').JestConfigWithTsJest} */
22
module.exports = {
3-
preset: 'ts-jest',
4-
testEnvironment: 'node',
5-
};
3+
preset: "ts-jest",
4+
testEnvironment: "node",
5+
setupFiles: ["<rootDir>/.env.js"],
6+
moduleNameMapper: {
7+
"^(\\.\\.?\\/.+)\\.js$": "$1",
8+
},
9+
};

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
"@changesets/changelog-github": "^0.5.0",
2222
"@changesets/cli": "^2.27.7",
2323
"@types/jest": "^29.5.12",
24-
"jest": "^29.7.0",
25-
"ts-jest": "^29.1.4",
24+
"jest": "30.0.0-alpha.6",
25+
"ts-jest": "^29.2.5",
2626
"typedoc": "^0.26.6",
2727
"typedoc-material-theme": "^1.1.0",
2828
"typedoc-plugin-extras": "^3.1.0",

packages/ccc/tsconfig.base.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,6 @@
1818
"forceConsistentCasingInFileNames": true,
1919
"skipLibCheck": true
2020
},
21-
"include": ["src/**/*"]
21+
"include": ["src/**/*"],
22+
"exclude": ["**/*test.ts"]
2223
}

packages/ckb-ccc/tsconfig.base.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,6 @@
1818
"forceConsistentCasingInFileNames": true,
1919
"skipLibCheck": true
2020
},
21-
"include": ["src/**/*"]
21+
"include": ["src/**/*"],
22+
"exclude": ["**/*test.ts"]
2223
}

packages/connector-react/tsconfig.base.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,6 @@
1919
"forceConsistentCasingInFileNames": true,
2020
"skipLibCheck": true
2121
},
22-
"include": ["src/**/*"]
22+
"include": ["src/**/*"],
23+
"exclude": ["**/*test.ts"]
2324
}

packages/connector/tsconfig.base.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,6 @@
1818
"forceConsistentCasingInFileNames": true,
1919
"skipLibCheck": true
2020
},
21-
"include": ["src/**/*"]
21+
"include": ["src/**/*"],
22+
"exclude": ["**/*test.ts"]
2223
}

packages/core/src/bytes/index.ts

+15-14
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export type Bytes = Uint8Array;
88
/**
99
* @public
1010
*/
11-
export type BytesLike = string | Uint8Array | ArrayBuffer | number[];
11+
export type BytesLike = string | Uint8Array | ArrayBuffer | ArrayLike<number>;
1212

1313
/**
1414
* Concatenates multiple byte-like arrays into a single byte array.
@@ -98,22 +98,23 @@ export function bytesFrom(
9898
return new Uint8Array(bytes);
9999
}
100100

101-
if (Array.isArray(bytes)) {
102-
if (bytes.some((v) => v < 0 || 0xff < v)) {
103-
throw new Error(`Invalid bytes ${JSON.stringify(bytes)}`);
101+
if (typeof bytes === "string") {
102+
if (encoding !== undefined) {
103+
return Buffer.from(bytes, encoding);
104104
}
105-
return new Uint8Array(bytes);
106-
}
107105

108-
if (encoding !== undefined) {
109-
return Buffer.from(bytes, encoding);
106+
const str = bytes.startsWith("0x") ? bytes.slice(2) : bytes;
107+
const paddedStr = str.length % 2 === 0 ? str : `0${str}`;
108+
const data = Buffer.from(paddedStr, "hex");
109+
if (data.length * 2 !== paddedStr.length) {
110+
throw new Error(`Invalid bytes ${bytes}`);
111+
}
112+
return data;
110113
}
111114

112-
const str = bytes.startsWith("0x") ? bytes.slice(2) : bytes;
113-
const paddedStr = str.length % 2 === 0 ? str : `0${str}`;
114-
const data = Buffer.from(paddedStr, "hex");
115-
if (data.length * 2 !== paddedStr.length) {
116-
throw new Error(`Invalid bytes ${bytes}`);
115+
const bytesArr = Array.from(bytes);
116+
if (bytesArr.some((v) => v < 0 || 0xff < v)) {
117+
throw new Error(`Invalid bytes ${JSON.stringify(bytes)}`);
117118
}
118-
return data;
119+
return new Uint8Array(bytes);
119120
}

packages/core/src/client/client.ts

+6-61
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
import {
22
Cell,
33
CellDep,
4-
CellDepLike,
54
OutPoint,
65
OutPointLike,
7-
Script,
86
ScriptLike,
97
Transaction,
108
TransactionLike,
119
} from "../ckb/index.js";
1210
import { Zero } from "../fixedPoint/index.js";
1311
import { Hex, HexLike, hexFrom } from "../hex/index.js";
1412
import { Num, NumLike, numFrom, numMax } from "../num/index.js";
15-
import { apply, reduceAsync, sleep } from "../utils/index.js";
13+
import { reduceAsync, sleep } from "../utils/index.js";
1614
import { ClientCache } from "./cache/index.js";
1715
import { ClientCacheMemory } from "./cache/memory.js";
1816
import { ClientCollectableSearchKeyLike } from "./clientTypes.advanced.js";
1917
import {
18+
CellDepInfo,
19+
CellDepInfoLike,
2020
ClientBlock,
2121
ClientBlockHeader,
2222
ClientFindCellsResponse,
@@ -27,62 +27,11 @@ import {
2727
ClientIndexerSearchKeyTransactionLike,
2828
ClientTransactionResponse,
2929
ErrorClientWaitTransactionTimeout,
30+
KnownScript,
3031
OutputsValidator,
32+
ScriptInfo,
3133
} from "./clientTypes.js";
3234

33-
/**
34-
* @public
35-
*/
36-
export enum KnownScript {
37-
NervosDao = "NervosDao",
38-
Secp256k1Blake160 = "Secp256k1Blake160",
39-
Secp256k1Multisig = "Secp256k1Multisig",
40-
AnyoneCanPay = "AnyoneCanPay",
41-
TypeId = "TypeId",
42-
XUdt = "XUdt",
43-
JoyId = "JoyId",
44-
COTA = "COTA",
45-
PWLock = "PWLock",
46-
OmniLock = "OmniLock",
47-
NostrLock = "NostrLock",
48-
UniqueType = "UniqueType",
49-
50-
// ckb-proxy-locks https://github.com/ckb-ecofund/ckb-proxy-locks
51-
AlwaysSuccess = "AlwaysSuccess",
52-
InputTypeProxyLock = "InputTypeProxyLock",
53-
OutputTypeProxyLock = "OutputTypeProxyLock",
54-
LockProxyLock = "LockProxyLock",
55-
SingleUseLock = "SingleUseLock",
56-
TypeBurnLock = "TypeBurnLock",
57-
EasyToDiscoverType = "EasyToDiscoverType",
58-
TimeLock = "TimeLock",
59-
}
60-
61-
/**
62-
* @public
63-
*/
64-
export type CellDepInfoLike = {
65-
cellDep: CellDepLike;
66-
type?: ScriptLike | null;
67-
};
68-
69-
/**
70-
* @public
71-
*/
72-
export class CellDepInfo {
73-
constructor(
74-
public cellDep: CellDep,
75-
public type?: Script,
76-
) {}
77-
78-
static from(cellDepInfoLike: CellDepInfoLike): CellDepInfo {
79-
return new CellDepInfo(
80-
CellDep.from(cellDepInfoLike.cellDep),
81-
apply(Script.from, cellDepInfoLike.type),
82-
);
83-
}
84-
}
85-
8635
/**
8736
* @public
8837
*/
@@ -96,11 +45,7 @@ export abstract class Client {
9645
abstract get url(): string;
9746
abstract get addressPrefix(): string;
9847

99-
abstract getKnownScript(
100-
script: KnownScript,
101-
): Promise<
102-
Pick<Script, "codeHash" | "hashType"> & { cellDeps: CellDepInfo[] }
103-
>;
48+
abstract getKnownScript(script: KnownScript): Promise<ScriptInfo>;
10449

10550
abstract getFeeRateStatistics(
10651
blockRange?: NumLike,

0 commit comments

Comments
 (0)