@ckb-ccc/core 0.0.2-alpha.2 → 0.0.2-alpha.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.prettierignore +12 -0
- package/dist/address/address.advanced.d.ts +29 -3
- package/dist/address/address.advanced.d.ts.map +1 -1
- package/dist/address/address.advanced.js +69 -22
- package/dist/address/advanced.d.ts +1 -28
- package/dist/address/advanced.d.ts.map +1 -1
- package/dist/address/advanced.js +3 -61
- package/dist/address/index.d.ts +10 -13
- package/dist/address/index.d.ts.map +1 -1
- package/dist/address/index.js +18 -18
- package/dist/advancedBarrel.d.ts +1 -0
- package/dist/advancedBarrel.d.ts.map +1 -1
- package/dist/advancedBarrel.js +1 -0
- package/dist/barrel.d.ts +4 -2
- package/dist/barrel.d.ts.map +1 -1
- package/dist/barrel.js +4 -2
- package/dist/bytes/index.d.ts +7 -0
- package/dist/bytes/index.d.ts.map +1 -0
- package/dist/bytes/index.js +41 -0
- package/dist/ckb/advanced.d.ts +3 -2
- package/dist/ckb/advanced.d.ts.map +1 -1
- package/dist/ckb/advanced.js +16 -2
- package/dist/ckb/index.d.ts +2 -3
- package/dist/ckb/index.d.ts.map +1 -1
- package/dist/ckb/index.js +2 -3
- package/dist/ckb/molecule.advanced/generated.d.ts.map +1 -0
- package/dist/ckb/{types/molecule.advanced → molecule.advanced}/generated.js +378 -97
- package/dist/ckb/molecule.advanced/index.d.ts +6 -0
- package/dist/ckb/molecule.advanced/index.d.ts.map +1 -0
- package/dist/ckb/{types/molecule.advanced → molecule.advanced}/index.js +8 -0
- package/dist/ckb/{types/script.advanced.d.ts → script.advanced.d.ts} +1 -0
- package/dist/ckb/script.advanced.d.ts.map +1 -0
- package/dist/ckb/{types/script.advanced.js → script.advanced.js} +2 -1
- package/dist/ckb/script.d.ts +29 -0
- package/dist/ckb/script.d.ts.map +1 -0
- package/dist/ckb/script.js +91 -0
- package/dist/ckb/{types/transaction.advanced.d.ts → transaction.advanced.d.ts} +1 -0
- package/dist/ckb/transaction.advanced.d.ts.map +1 -0
- package/dist/ckb/{types/transaction.advanced.js → transaction.advanced.js} +2 -1
- package/dist/ckb/transaction.d.ts +142 -0
- package/dist/ckb/transaction.d.ts.map +1 -0
- package/dist/ckb/transaction.js +262 -0
- package/dist/client/client.d.ts +4 -4
- package/dist/client/client.d.ts.map +1 -1
- package/dist/client/clientPublicMainnet.advanced.d.ts +2 -2
- package/dist/client/clientPublicMainnet.advanced.d.ts.map +1 -1
- package/dist/client/clientPublicMainnet.d.ts +2 -2
- package/dist/client/clientPublicMainnet.d.ts.map +1 -1
- package/dist/client/clientPublicTestnet.advanced.d.ts +2 -2
- package/dist/client/clientPublicTestnet.advanced.d.ts.map +1 -1
- package/dist/client/clientPublicTestnet.d.ts +2 -2
- package/dist/client/clientPublicTestnet.d.ts.map +1 -1
- package/dist/client/jsonRpc/advanced.d.ts +36 -36
- package/dist/client/jsonRpc/advanced.d.ts.map +1 -1
- package/dist/client/jsonRpc/advanced.js +11 -11
- package/dist/client/jsonRpc/index.d.ts.map +1 -1
- package/dist/client/jsonRpc/index.js +0 -1
- package/dist/fixedPoint/index.d.ts +7 -0
- package/dist/fixedPoint/index.d.ts.map +1 -0
- package/dist/{fixedPoint.js → fixedPoint/index.js} +9 -12
- package/dist/{ckb/hasher.advanced.d.ts → hasher/advanced.d.ts} +1 -1
- package/dist/hasher/advanced.d.ts.map +1 -0
- package/dist/{ckb/hasher.d.ts → hasher/index.d.ts} +3 -2
- package/dist/hasher/index.d.ts.map +1 -0
- package/dist/{ckb/hasher.js → hasher/index.js} +4 -4
- package/dist/hex/index.d.ts +5 -0
- package/dist/hex/index.d.ts.map +1 -0
- package/dist/hex/index.js +9 -0
- package/dist/num/index.d.ts +13 -0
- package/dist/num/index.d.ts.map +1 -0
- package/dist/num/index.js +47 -0
- package/dist/signer/helpers.d.ts +3 -3
- package/dist/signer/helpers.d.ts.map +1 -1
- package/dist/signer/helpers.js +7 -4
- package/dist/signer/index.d.ts +2 -0
- package/dist/signer/index.d.ts.map +1 -1
- package/dist/signer/index.js +2 -0
- package/dist/signer/signer.d.ts +12 -3
- package/dist/signer/signer.d.ts.map +1 -1
- package/dist/signer/signer.js +13 -2
- package/dist/signer/signerReadonly.d.ts +8 -0
- package/dist/signer/signerReadonly.d.ts.map +1 -0
- package/dist/signer/signerReadonly.js +13 -0
- package/dist/{ckb/viewerCkbScript.d.ts → signer/signerReadonlyCkbScript.d.ts} +6 -5
- package/dist/signer/signerReadonlyCkbScript.d.ts.map +1 -0
- package/dist/{ckb/viewerCkbScript.js → signer/signerReadonlyCkbScript.js} +7 -4
- package/dist/utils/index.d.ts +7 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +10 -0
- package/package.json +5 -3
- package/src/address/address.advanced.ts +76 -19
- package/src/address/advanced.ts +1 -59
- package/src/address/index.ts +46 -28
- package/src/advancedBarrel.ts +1 -0
- package/src/barrel.ts +4 -2
- package/src/bytes/index.ts +46 -0
- package/src/ckb/advanced.ts +3 -2
- package/src/ckb/index.ts +2 -3
- package/src/ckb/{types/molecule.advanced → molecule.advanced}/generated.d.ts +18 -7
- package/src/ckb/{types/molecule.advanced → molecule.advanced}/generated.js +551 -123
- package/src/ckb/molecule.advanced/index.ts +11 -0
- package/src/ckb/{types/script.advanced.ts → script.advanced.ts} +1 -0
- package/src/ckb/script.ts +94 -0
- package/src/ckb/{types/transaction.advanced.ts → transaction.advanced.ts} +1 -0
- package/src/ckb/transaction.ts +357 -0
- package/src/client/client.ts +4 -4
- package/src/client/clientPublicMainnet.advanced.ts +2 -2
- package/src/client/clientPublicMainnet.ts +2 -2
- package/src/client/clientPublicTestnet.advanced.ts +2 -2
- package/src/client/clientPublicTestnet.ts +2 -2
- package/src/client/clientTypes.ts +1 -1
- package/src/client/jsonRpc/advanced.ts +25 -25
- package/src/client/jsonRpc/index.ts +1 -3
- package/src/fixedPoint/index.ts +30 -0
- package/src/{ckb/hasher.ts → hasher/index.ts} +5 -5
- package/src/hex/index.ts +9 -0
- package/src/index.ts +1 -1
- package/src/num/index.ts +53 -0
- package/src/signer/helpers.ts +9 -6
- package/src/signer/index.ts +3 -1
- package/src/signer/signer.ts +23 -3
- package/src/signer/signerReadonly.ts +13 -0
- package/src/{ckb/viewerCkbScript.ts → signer/signerReadonlyCkbScript.ts} +8 -4
- package/src/utils/index.ts +28 -0
- package/dist/bytes.d.ts +0 -15
- package/dist/bytes.d.ts.map +0 -1
- package/dist/bytes.js +0 -114
- package/dist/ckb/hasher.advanced.d.ts.map +0 -1
- package/dist/ckb/hasher.d.ts.map +0 -1
- package/dist/ckb/types/advanced.d.ts +0 -4
- package/dist/ckb/types/advanced.d.ts.map +0 -1
- package/dist/ckb/types/advanced.js +0 -32
- package/dist/ckb/types/index.d.ts +0 -3
- package/dist/ckb/types/index.d.ts.map +0 -1
- package/dist/ckb/types/index.js +0 -18
- package/dist/ckb/types/molecule.advanced/generated.d.ts.map +0 -1
- package/dist/ckb/types/molecule.advanced/index.d.ts +0 -2
- package/dist/ckb/types/molecule.advanced/index.d.ts.map +0 -1
- package/dist/ckb/types/script.advanced.d.ts.map +0 -1
- package/dist/ckb/types/script.d.ts +0 -26
- package/dist/ckb/types/script.d.ts.map +0 -1
- package/dist/ckb/types/script.js +0 -75
- package/dist/ckb/types/transaction.advanced.d.ts.map +0 -1
- package/dist/ckb/types/transaction.d.ts +0 -127
- package/dist/ckb/types/transaction.d.ts.map +0 -1
- package/dist/ckb/types/transaction.js +0 -266
- package/dist/ckb/viewerCkbScript.d.ts.map +0 -1
- package/dist/fixedPoint.d.ts +0 -9
- package/dist/fixedPoint.d.ts.map +0 -1
- package/dist/primitive.d.ts +0 -5
- package/dist/primitive.d.ts.map +0 -1
- package/dist/primitive.js +0 -2
- package/dist/viewer.d.ts +0 -12
- package/dist/viewer.d.ts.map +0 -1
- package/dist/viewer.js +0 -19
- package/src/bytes.ts +0 -127
- package/src/ckb/types/advanced.ts +0 -3
- package/src/ckb/types/index.ts +0 -2
- package/src/ckb/types/molecule.advanced/index.ts +0 -1
- package/src/ckb/types/script.ts +0 -70
- package/src/ckb/types/transaction.ts +0 -366
- package/src/fixedPoint.ts +0 -53
- package/src/primitive.ts +0 -8
- package/src/viewer.ts +0 -22
- /package/dist/ckb/{types/molecule.advanced → molecule.advanced}/generated.d.ts +0 -0
- /package/dist/{ckb/hasher.advanced.js → hasher/advanced.js} +0 -0
- /package/src/ckb/{types/molecule.advanced → molecule.advanced}/blockchain.mol +0 -0
- /package/src/{ckb/hasher.advanced.ts → hasher/advanced.ts} +0 -0
|
@@ -1,366 +0,0 @@
|
|
|
1
|
-
import { HashType, Script } from "./script";
|
|
2
|
-
import {
|
|
3
|
-
toBytes,
|
|
4
|
-
toBytesFromNumber,
|
|
5
|
-
toHex,
|
|
6
|
-
toHexFromHex,
|
|
7
|
-
toNumber,
|
|
8
|
-
toNumberFromBytes,
|
|
9
|
-
} from "../../bytes";
|
|
10
|
-
import { BytesLike, Hex, NumberLike } from "../../primitive";
|
|
11
|
-
import type { TransactionSkeletonType } from "@ckb-lumos/helpers";
|
|
12
|
-
import { DeepReadonly } from "ts-essentials";
|
|
13
|
-
import * as mol from "./molecule.advanced";
|
|
14
|
-
import { DEP_TYPE_TO_NUM, NUM_TO_DEP_TYPE } from "./transaction.advanced";
|
|
15
|
-
import { Hasher, ckbHash } from "../hasher";
|
|
16
|
-
|
|
17
|
-
export type DepType = "depGroup" | "code";
|
|
18
|
-
|
|
19
|
-
export function encodeDepType(depType: DepType): Uint8Array {
|
|
20
|
-
return toBytes([DEP_TYPE_TO_NUM[depType]]);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export function decodeDepType(bytes: BytesLike): DepType {
|
|
24
|
-
return NUM_TO_DEP_TYPE[toBytes(bytes)[0]];
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export class OutPoint {
|
|
28
|
-
constructor(
|
|
29
|
-
public txHash: Hex,
|
|
30
|
-
public index: string,
|
|
31
|
-
) {}
|
|
32
|
-
|
|
33
|
-
static from({
|
|
34
|
-
txHash,
|
|
35
|
-
index,
|
|
36
|
-
}: {
|
|
37
|
-
txHash: BytesLike;
|
|
38
|
-
index: NumberLike;
|
|
39
|
-
}): OutPoint {
|
|
40
|
-
return new OutPoint(toHex(txHash), toNumber(index));
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
static _toMolData(outPoint: DeepReadonly<OutPoint>) {
|
|
44
|
-
return {
|
|
45
|
-
txHash: toBytes(outPoint.txHash),
|
|
46
|
-
index: toBytesFromNumber(outPoint.index, 4),
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
static encode(outPoint: DeepReadonly<OutPoint>): Uint8Array {
|
|
51
|
-
return toBytes(mol.SerializeOutPoint(OutPoint._toMolData(outPoint)));
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
static decode(bytes: BytesLike | mol.OutPoint): OutPoint {
|
|
55
|
-
const view =
|
|
56
|
-
bytes instanceof mol.OutPoint ? bytes : new mol.OutPoint(toBytes(bytes));
|
|
57
|
-
return {
|
|
58
|
-
txHash: toHex(view.getTxHash().raw()),
|
|
59
|
-
index: toNumberFromBytes(view.getIndex().raw()),
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
export class CellOutput {
|
|
65
|
-
constructor(
|
|
66
|
-
public capacity: string,
|
|
67
|
-
public lock: Script,
|
|
68
|
-
public type?: Script,
|
|
69
|
-
) {}
|
|
70
|
-
|
|
71
|
-
static from({
|
|
72
|
-
capacity,
|
|
73
|
-
lock,
|
|
74
|
-
type,
|
|
75
|
-
}: {
|
|
76
|
-
capacity: NumberLike;
|
|
77
|
-
lock: Parameters<typeof Script.from>[0];
|
|
78
|
-
type?: Parameters<typeof Script.from>[0];
|
|
79
|
-
}): CellOutput {
|
|
80
|
-
return new CellOutput(
|
|
81
|
-
toNumber(capacity),
|
|
82
|
-
Script.from(lock),
|
|
83
|
-
type ? Script.from(type) : undefined,
|
|
84
|
-
);
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
static _toMolData(cellOutput: DeepReadonly<CellOutput>) {
|
|
88
|
-
return {
|
|
89
|
-
capacity: toBytesFromNumber(cellOutput.capacity, 8),
|
|
90
|
-
lock: Script._toMolData(cellOutput.lock),
|
|
91
|
-
type: cellOutput.type ? Script._toMolData(cellOutput.type) : undefined,
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
static encode(cellOutput: DeepReadonly<CellOutput>): Uint8Array {
|
|
96
|
-
return toBytes(mol.SerializeCellOutput(CellOutput._toMolData(cellOutput)));
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
static decode(bytes: BytesLike | mol.CellOutput): CellOutput {
|
|
100
|
-
const view =
|
|
101
|
-
bytes instanceof mol.CellOutput
|
|
102
|
-
? bytes
|
|
103
|
-
: new mol.CellOutput(toBytes(bytes));
|
|
104
|
-
const type = view.getType();
|
|
105
|
-
return {
|
|
106
|
-
capacity: toNumberFromBytes(view.getCapacity().raw()),
|
|
107
|
-
lock: Script.decode(view.getLock()),
|
|
108
|
-
type: type.hasValue() ? Script.decode(type.value()) : undefined,
|
|
109
|
-
};
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
export class CellInput {
|
|
114
|
-
constructor(
|
|
115
|
-
public previousOutput: OutPoint,
|
|
116
|
-
public since: string,
|
|
117
|
-
public cellOutput?: CellOutput,
|
|
118
|
-
public outputData?: Hex,
|
|
119
|
-
) {}
|
|
120
|
-
|
|
121
|
-
static from({
|
|
122
|
-
previousOutput,
|
|
123
|
-
since,
|
|
124
|
-
cellOutput,
|
|
125
|
-
outputData,
|
|
126
|
-
}: {
|
|
127
|
-
previousOutput: Parameters<typeof OutPoint.from>[0];
|
|
128
|
-
since: NumberLike;
|
|
129
|
-
cellOutput?: Parameters<typeof CellOutput.from>[0];
|
|
130
|
-
outputData?: BytesLike;
|
|
131
|
-
}): CellInput {
|
|
132
|
-
return new CellInput(
|
|
133
|
-
OutPoint.from(previousOutput),
|
|
134
|
-
toNumber(since),
|
|
135
|
-
cellOutput ? CellOutput.from(cellOutput) : undefined,
|
|
136
|
-
outputData ? toHex(outputData) : undefined,
|
|
137
|
-
);
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
static _toMolData(cellInput: DeepReadonly<CellInput>) {
|
|
141
|
-
return {
|
|
142
|
-
previousOutput: OutPoint._toMolData(cellInput.previousOutput),
|
|
143
|
-
since: toBytesFromNumber(cellInput.since, 8),
|
|
144
|
-
};
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
static encode(cellInput: DeepReadonly<CellInput>): Uint8Array {
|
|
148
|
-
return toBytes(mol.SerializeCellInput(CellInput._toMolData(cellInput)));
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
static decode(bytes: BytesLike | mol.CellInput): CellInput {
|
|
152
|
-
const view =
|
|
153
|
-
bytes instanceof mol.CellInput
|
|
154
|
-
? bytes
|
|
155
|
-
: new mol.CellInput(toBytes(bytes));
|
|
156
|
-
return {
|
|
157
|
-
previousOutput: OutPoint.decode(view.getPreviousOutput()),
|
|
158
|
-
since: toNumberFromBytes(view.getSince().raw()),
|
|
159
|
-
};
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
export class CellDep {
|
|
164
|
-
constructor(
|
|
165
|
-
public outPoint: OutPoint,
|
|
166
|
-
public depType: DepType,
|
|
167
|
-
) {}
|
|
168
|
-
|
|
169
|
-
static from({
|
|
170
|
-
outPoint,
|
|
171
|
-
depType,
|
|
172
|
-
}: {
|
|
173
|
-
outPoint: Parameters<typeof OutPoint.from>[0];
|
|
174
|
-
depType: DepType;
|
|
175
|
-
}): CellDep {
|
|
176
|
-
return new CellDep(OutPoint.from(outPoint), depType);
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
static _toMolData(cellDep: DeepReadonly<CellDep>) {
|
|
180
|
-
return {
|
|
181
|
-
outPoint: OutPoint._toMolData(cellDep.outPoint),
|
|
182
|
-
depType: encodeDepType(cellDep.depType),
|
|
183
|
-
};
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
static encode(cellDep: DeepReadonly<CellDep>): Uint8Array {
|
|
187
|
-
return toBytes(mol.SerializeCellDep(CellDep._toMolData(cellDep)));
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
static decode(bytes: BytesLike | mol.CellDep): CellDep {
|
|
191
|
-
const view =
|
|
192
|
-
bytes instanceof mol.CellDep ? bytes : new mol.CellDep(toBytes(bytes));
|
|
193
|
-
return {
|
|
194
|
-
outPoint: OutPoint.decode(view.getOutPoint()),
|
|
195
|
-
depType: decodeDepType([view.getDepType()]),
|
|
196
|
-
};
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
export class WitnessArgs {
|
|
201
|
-
constructor(
|
|
202
|
-
public lock?: Hex,
|
|
203
|
-
public inputType?: Hex,
|
|
204
|
-
public outputType?: Hex,
|
|
205
|
-
) {}
|
|
206
|
-
|
|
207
|
-
static from({
|
|
208
|
-
lock,
|
|
209
|
-
inputType,
|
|
210
|
-
outputType,
|
|
211
|
-
}: {
|
|
212
|
-
lock?: BytesLike;
|
|
213
|
-
inputType?: BytesLike;
|
|
214
|
-
outputType?: BytesLike;
|
|
215
|
-
}): WitnessArgs {
|
|
216
|
-
return new WitnessArgs(
|
|
217
|
-
lock ? toHex(lock) : undefined,
|
|
218
|
-
inputType ? toHex(inputType) : undefined,
|
|
219
|
-
outputType ? toHex(outputType) : undefined,
|
|
220
|
-
);
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
static _toMolData(witnessArgs: DeepReadonly<WitnessArgs>) {
|
|
224
|
-
return {
|
|
225
|
-
lock: witnessArgs.lock ? toBytes(witnessArgs.lock) : undefined,
|
|
226
|
-
inputType: witnessArgs.inputType
|
|
227
|
-
? toBytes(witnessArgs.inputType)
|
|
228
|
-
: undefined,
|
|
229
|
-
outputType: witnessArgs.outputType
|
|
230
|
-
? toBytes(witnessArgs.outputType)
|
|
231
|
-
: undefined,
|
|
232
|
-
};
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
static encode(witnessArgs: DeepReadonly<WitnessArgs>): Uint8Array {
|
|
236
|
-
return toBytes(
|
|
237
|
-
mol.SerializeWitnessArgs(WitnessArgs._toMolData(witnessArgs)),
|
|
238
|
-
);
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
static decode(bytes: BytesLike | mol.WitnessArgs): WitnessArgs {
|
|
242
|
-
const view =
|
|
243
|
-
bytes instanceof mol.WitnessArgs
|
|
244
|
-
? bytes
|
|
245
|
-
: new mol.WitnessArgs(toBytes(bytes));
|
|
246
|
-
const lock = view.getLock();
|
|
247
|
-
const inputType = view.getInputType();
|
|
248
|
-
const outputType = view.getOutputType();
|
|
249
|
-
return {
|
|
250
|
-
lock: lock.hasValue() ? toHex(lock.value().raw()) : undefined,
|
|
251
|
-
inputType: inputType.hasValue()
|
|
252
|
-
? toHex(inputType.value().raw())
|
|
253
|
-
: undefined,
|
|
254
|
-
outputType: outputType.hasValue()
|
|
255
|
-
? toHex(outputType.value().raw())
|
|
256
|
-
: undefined,
|
|
257
|
-
};
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
export class Transaction {
|
|
262
|
-
constructor(
|
|
263
|
-
public version: string,
|
|
264
|
-
public cellDeps: CellDep[],
|
|
265
|
-
public headerDeps: Hex[],
|
|
266
|
-
public inputs: CellInput[],
|
|
267
|
-
public outputs: CellOutput[],
|
|
268
|
-
public outputsData: Hex[],
|
|
269
|
-
public witnesses: Hex[],
|
|
270
|
-
) {}
|
|
271
|
-
|
|
272
|
-
static default(): Transaction {
|
|
273
|
-
return new Transaction("0", [], [], [], [], [], []);
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
private static fromLumosOutPoint(outPoint: {
|
|
277
|
-
index: string;
|
|
278
|
-
txHash: string;
|
|
279
|
-
}) {
|
|
280
|
-
return {
|
|
281
|
-
...outPoint,
|
|
282
|
-
txHash: toHexFromHex(outPoint.txHash),
|
|
283
|
-
};
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
private static fromLumosScript(script: {
|
|
287
|
-
codeHash: string;
|
|
288
|
-
hashType: HashType;
|
|
289
|
-
args: string;
|
|
290
|
-
}) {
|
|
291
|
-
return {
|
|
292
|
-
codeHash: toHexFromHex(script.codeHash),
|
|
293
|
-
args: toHexFromHex(script.args),
|
|
294
|
-
hashType: script.hashType,
|
|
295
|
-
};
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
private static fromLumosOutput(output: {
|
|
299
|
-
lock: Parameters<typeof Transaction.fromLumosScript>[0];
|
|
300
|
-
type?: Parameters<typeof Transaction.fromLumosScript>[0];
|
|
301
|
-
capacity: string;
|
|
302
|
-
}) {
|
|
303
|
-
return {
|
|
304
|
-
lock: Transaction.fromLumosScript(output.lock),
|
|
305
|
-
type: output.type ? Transaction.fromLumosScript(output.type) : undefined,
|
|
306
|
-
capacity: toNumber(output.capacity),
|
|
307
|
-
};
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
static fromLumosSkeleton(skeleton: TransactionSkeletonType): Transaction {
|
|
311
|
-
return new Transaction(
|
|
312
|
-
"0",
|
|
313
|
-
skeleton.cellDeps.toArray().map((cellDep) =>
|
|
314
|
-
CellDep.from({
|
|
315
|
-
...cellDep,
|
|
316
|
-
outPoint: Transaction.fromLumosOutPoint(cellDep.outPoint),
|
|
317
|
-
}),
|
|
318
|
-
),
|
|
319
|
-
skeleton.headerDeps.toArray().map(toHex),
|
|
320
|
-
skeleton.inputs.toArray().map((input, i) => {
|
|
321
|
-
if (!input.outPoint) {
|
|
322
|
-
throw new Error("outPoint is required in input");
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
return CellInput.from({
|
|
326
|
-
previousOutput: Transaction.fromLumosOutPoint(input.outPoint),
|
|
327
|
-
since: skeleton.inputSinces.get(i, "0x00"),
|
|
328
|
-
cellOutput: Transaction.fromLumosOutput(input.cellOutput),
|
|
329
|
-
outputData: toHexFromHex(input.data),
|
|
330
|
-
});
|
|
331
|
-
}),
|
|
332
|
-
skeleton.outputs
|
|
333
|
-
.toArray()
|
|
334
|
-
.map((output) =>
|
|
335
|
-
CellOutput.from(Transaction.fromLumosOutput(output.cellOutput)),
|
|
336
|
-
),
|
|
337
|
-
skeleton.outputs.toArray().map((output) => toHex(output.data)),
|
|
338
|
-
skeleton.witnesses.toArray().map(toHex),
|
|
339
|
-
);
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
static encodeRaw(
|
|
343
|
-
transaction: Readonly<Omit<Transaction, "witnesses">>,
|
|
344
|
-
): Uint8Array {
|
|
345
|
-
return toBytes(
|
|
346
|
-
mol.SerializeRawTransaction({
|
|
347
|
-
version: toBytesFromNumber(transaction.version, 4),
|
|
348
|
-
cellDeps: transaction.cellDeps.map(CellDep._toMolData),
|
|
349
|
-
headerDeps: transaction.headerDeps.map(toBytes),
|
|
350
|
-
inputs: transaction.inputs.map(CellInput._toMolData),
|
|
351
|
-
outputs: transaction.outputs.map(CellOutput._toMolData),
|
|
352
|
-
outputsData: transaction.outputsData.map(toBytes),
|
|
353
|
-
}),
|
|
354
|
-
);
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
static hashRaw(transaction: Omit<Transaction, "witnesses">) {
|
|
358
|
-
return ckbHash(Transaction.encodeRaw(transaction));
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
static hashWitnessToHasher(witness: Hex, hasher: Hasher) {
|
|
362
|
-
const raw = toBytes(witness);
|
|
363
|
-
hasher.update(toBytesFromNumber(raw.length, 8))
|
|
364
|
-
hasher.update(raw);
|
|
365
|
-
}
|
|
366
|
-
}
|
package/src/fixedPoint.ts
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
export function composeFixedPoint(
|
|
2
|
-
val: undefined | null,
|
|
3
|
-
decimals?: number,
|
|
4
|
-
): null;
|
|
5
|
-
export function composeFixedPoint(val: bigint, decimals?: number): string;
|
|
6
|
-
export function composeFixedPoint(
|
|
7
|
-
val: bigint | undefined | null,
|
|
8
|
-
decimals?: number,
|
|
9
|
-
): string | null;
|
|
10
|
-
export function composeFixedPoint(
|
|
11
|
-
val: bigint | undefined | null,
|
|
12
|
-
decimals = 8,
|
|
13
|
-
): string | null {
|
|
14
|
-
if (val == null) {
|
|
15
|
-
return null;
|
|
16
|
-
}
|
|
17
|
-
const str = val.toString();
|
|
18
|
-
const l = str.length <= decimals ? "0" : str.slice(0, -decimals);
|
|
19
|
-
const r = str.slice(-decimals).padStart(decimals, "0").replace(/0*$/, "");
|
|
20
|
-
if (r === "") {
|
|
21
|
-
return l;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
return `${l}.${r}`;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export function parseFixedPoint(ori: undefined | null, decimals?: number): null;
|
|
28
|
-
export function parseFixedPoint(
|
|
29
|
-
ori: string | number,
|
|
30
|
-
decimals?: number,
|
|
31
|
-
): bigint;
|
|
32
|
-
export function parseFixedPoint(
|
|
33
|
-
ori: string | number | undefined | null,
|
|
34
|
-
decimals?: number,
|
|
35
|
-
): bigint | null;
|
|
36
|
-
export function parseFixedPoint(
|
|
37
|
-
ori: string | number | undefined | null,
|
|
38
|
-
decimals = 8,
|
|
39
|
-
): bigint | null {
|
|
40
|
-
if (ori == null) {
|
|
41
|
-
return null;
|
|
42
|
-
}
|
|
43
|
-
const [l, r] = ori.toString().split(".");
|
|
44
|
-
const lVal = BigInt(l.padEnd(l.length + decimals, "0"));
|
|
45
|
-
if (r === undefined) {
|
|
46
|
-
return lVal;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
return lVal + BigInt(r.slice(0, decimals).padEnd(decimals, "0"));
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export const Zero = 0n;
|
|
53
|
-
export const One = parseFixedPoint("1");
|
package/src/primitive.ts
DELETED
package/src/viewer.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { Address } from "./address";
|
|
2
|
-
import { Client } from "./client";
|
|
3
|
-
|
|
4
|
-
export abstract class Viewer {
|
|
5
|
-
constructor(public readonly client: Client) {}
|
|
6
|
-
|
|
7
|
-
abstract getInternalAddress(): Promise<string>;
|
|
8
|
-
|
|
9
|
-
abstract getAddressObjs(): Promise<Address[]>;
|
|
10
|
-
async getRecommendedAddressObj(_preference?: unknown): Promise<Address> {
|
|
11
|
-
return (await this.getAddressObjs())[0];
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
async getRecommendedAddress(preference?: unknown): Promise<string> {
|
|
15
|
-
return Address.toString(await this.getRecommendedAddressObj(preference));
|
|
16
|
-
}
|
|
17
|
-
async getAddresses(): Promise<string[]> {
|
|
18
|
-
return this.getAddressObjs().then((addresses) =>
|
|
19
|
-
addresses.map((address) => Address.toString(address)),
|
|
20
|
-
);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|