@alephium/web3 0.35.1 → 0.36.1
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/dist/alephium-web3.min.js +1 -1
- package/dist/alephium-web3.min.js.map +1 -1
- package/dist/src/api/api-alephium.d.ts +8 -1
- package/dist/src/api/api-alephium.js +1 -1
- package/dist/src/api/types.d.ts +7 -6
- package/dist/src/api/types.js +19 -100
- package/dist/src/contract/contract.d.ts +31 -11
- package/dist/src/contract/contract.js +167 -89
- package/dist/src/contract/ralph.d.ts +6 -5
- package/dist/src/contract/ralph.js +71 -83
- package/package.json +2 -2
- package/src/api/api-alephium.ts +9 -1
- package/src/api/types.ts +20 -103
- package/src/contract/contract.ts +218 -92
- package/src/contract/ralph.ts +98 -84
|
@@ -380,6 +380,7 @@ export interface CompileContractResult {
|
|
|
380
380
|
export interface CompileProjectResult {
|
|
381
381
|
contracts: CompileContractResult[];
|
|
382
382
|
scripts: CompileScriptResult[];
|
|
383
|
+
structs?: StructSig[];
|
|
383
384
|
}
|
|
384
385
|
export interface CompileScriptResult {
|
|
385
386
|
version: string;
|
|
@@ -696,6 +697,12 @@ export interface Source {
|
|
|
696
697
|
gasAmount?: number;
|
|
697
698
|
utxos?: OutputRef[];
|
|
698
699
|
}
|
|
700
|
+
export interface StructSig {
|
|
701
|
+
name: string;
|
|
702
|
+
fieldNames: string[];
|
|
703
|
+
fieldTypes: string[];
|
|
704
|
+
isMutable: boolean[];
|
|
705
|
+
}
|
|
699
706
|
export interface SubmitMultisig {
|
|
700
707
|
unsignedTx: string;
|
|
701
708
|
signatures: string[];
|
|
@@ -995,7 +1002,7 @@ export declare class HttpClient<SecurityDataType = unknown> {
|
|
|
995
1002
|
}
|
|
996
1003
|
/**
|
|
997
1004
|
* @title Alephium API
|
|
998
|
-
* @version 2.
|
|
1005
|
+
* @version 2.10.0
|
|
999
1006
|
* @baseUrl ../
|
|
1000
1007
|
*/
|
|
1001
1008
|
export declare class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDataType> {
|
package/dist/src/api/types.d.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import * as node from './api-alephium';
|
|
2
2
|
export type Number256 = bigint | string;
|
|
3
|
-
export type Val = Number256 | boolean | string | Val[];
|
|
3
|
+
export type Val = Number256 | boolean | string | Val[] | ValObject;
|
|
4
|
+
export interface ValObject extends Record<string, Val> {
|
|
5
|
+
}
|
|
4
6
|
export type NamedVals = Record<string, Val>;
|
|
7
|
+
export declare const PrimitiveTypes: string[];
|
|
5
8
|
export interface Token {
|
|
6
9
|
id: string;
|
|
7
10
|
amount: Number256;
|
|
@@ -18,11 +21,9 @@ export declare function toApiByteVec(v: Val): string;
|
|
|
18
21
|
export declare function toApiAddress(v: Val): string;
|
|
19
22
|
export declare function toApiArray(tpe: string, v: Val): node.Val;
|
|
20
23
|
export declare function toApiVal(v: Val, tpe: string): node.Val;
|
|
21
|
-
export declare function
|
|
22
|
-
export declare function
|
|
23
|
-
export declare function
|
|
24
|
-
export declare function getDefaultValue(tpe: string): Val;
|
|
25
|
-
export declare function typeLength(tpe: string): number;
|
|
24
|
+
export declare function fromApiPrimitiveVal(value: node.Val, tpe: string, systemEvent?: boolean): Val;
|
|
25
|
+
export declare function decodeArrayType(tpe: string): [string, number];
|
|
26
|
+
export declare function getDefaultPrimitiveValue(tpe: string): Val;
|
|
26
27
|
export interface ApiRequestArguments {
|
|
27
28
|
path: string;
|
|
28
29
|
method: string;
|
package/dist/src/api/types.js
CHANGED
|
@@ -17,10 +17,11 @@ You should have received a copy of the GNU Lesser General Public License
|
|
|
17
17
|
along with the library. If not, see <http://www.gnu.org/licenses/>.
|
|
18
18
|
*/
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.StdInterfaceIds = exports.request = exports.requestWithLog = exports.forwardRequests = exports.
|
|
20
|
+
exports.StdInterfaceIds = exports.request = exports.requestWithLog = exports.forwardRequests = exports.getDefaultPrimitiveValue = exports.decodeArrayType = exports.fromApiPrimitiveVal = exports.toApiVal = exports.toApiArray = exports.toApiAddress = exports.toApiByteVec = exports.fromApiNumber256 = exports.toApiNumber256Optional = exports.toApiNumber256 = exports.toApiBoolean = exports.fromApiTokens = exports.fromApiToken = exports.toApiTokens = exports.toApiToken = exports.PrimitiveTypes = void 0;
|
|
21
21
|
const constants_1 = require("../constants");
|
|
22
22
|
const debug_1 = require("../debug");
|
|
23
23
|
const utils_1 = require("../utils");
|
|
24
|
+
exports.PrimitiveTypes = ['U256', 'I256', 'Bool', 'ByteVec', 'Address'];
|
|
24
25
|
utils_1.assertType;
|
|
25
26
|
function toApiToken(token) {
|
|
26
27
|
return { id: token.id, amount: toApiNumber256(token.amount) };
|
|
@@ -145,88 +146,32 @@ function toApiVal(v, tpe) {
|
|
|
145
146
|
}
|
|
146
147
|
}
|
|
147
148
|
exports.toApiVal = toApiVal;
|
|
148
|
-
function
|
|
149
|
-
if (
|
|
150
|
-
|
|
149
|
+
function fromApiPrimitiveVal(value, tpe, systemEvent = false) {
|
|
150
|
+
if (tpe === 'Bool' && value.type === tpe) {
|
|
151
|
+
return value.value;
|
|
151
152
|
}
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
return [firstVal.value, valIndex + 1];
|
|
153
|
+
else if ((tpe === 'U256' || tpe === 'I256') && value.type === tpe) {
|
|
154
|
+
return fromApiNumber256(value.value);
|
|
155
155
|
}
|
|
156
|
-
else if ((tpe === '
|
|
157
|
-
return
|
|
158
|
-
}
|
|
159
|
-
else if ((tpe === 'ByteVec' || tpe === 'Address') && (firstVal.type === tpe || systemEvent)) {
|
|
160
|
-
return [firstVal.value, valIndex + 1];
|
|
156
|
+
else if ((tpe === 'ByteVec' || tpe === 'Address') && (value.type === tpe || systemEvent)) {
|
|
157
|
+
return value.value;
|
|
161
158
|
}
|
|
162
159
|
else {
|
|
163
|
-
|
|
164
|
-
const arraySize = dims.reduce((a, b) => a * b);
|
|
165
|
-
const nextIndex = valIndex + arraySize;
|
|
166
|
-
const valsToUse = vals.slice(valIndex, nextIndex);
|
|
167
|
-
if (valsToUse.length == arraySize && valsToUse.every((val) => val.type === baseType)) {
|
|
168
|
-
const localVals = valsToUse.map((val) => fromApiVal(val, baseType));
|
|
169
|
-
return [foldVals(localVals, dims), nextIndex];
|
|
170
|
-
}
|
|
171
|
-
else {
|
|
172
|
-
throw new Error(`Invalid array Val type: ${valsToUse}, ${tpe}`);
|
|
173
|
-
}
|
|
160
|
+
throw new Error(`Expected primitive type, got ${tpe}`);
|
|
174
161
|
}
|
|
175
162
|
}
|
|
176
|
-
|
|
177
|
-
let valIndex = 0;
|
|
178
|
-
const result = {};
|
|
179
|
-
types.forEach((currentType, index) => {
|
|
180
|
-
const currentName = names[`${index}`];
|
|
181
|
-
const [val, nextIndex] = _fromApiVal(vals, valIndex, currentType, systemEvent);
|
|
182
|
-
valIndex = nextIndex;
|
|
183
|
-
result[`${currentName}`] = val;
|
|
184
|
-
});
|
|
185
|
-
return result;
|
|
186
|
-
}
|
|
187
|
-
exports.fromApiVals = fromApiVals;
|
|
188
|
-
function fromApiArray(vals, types) {
|
|
189
|
-
let valIndex = 0;
|
|
190
|
-
const result = [];
|
|
191
|
-
for (const currentType of types) {
|
|
192
|
-
const [val, nextIndex] = _fromApiVal(vals, valIndex, currentType);
|
|
193
|
-
result.push(val);
|
|
194
|
-
valIndex = nextIndex;
|
|
195
|
-
}
|
|
196
|
-
return result;
|
|
197
|
-
}
|
|
198
|
-
exports.fromApiArray = fromApiArray;
|
|
199
|
-
function fromApiVal(v, tpe) {
|
|
200
|
-
if (v.type === 'Bool' && v.type === tpe) {
|
|
201
|
-
return v.value;
|
|
202
|
-
}
|
|
203
|
-
else if ((v.type === 'U256' || v.type === 'I256') && v.type === tpe) {
|
|
204
|
-
return fromApiNumber256(v.value);
|
|
205
|
-
}
|
|
206
|
-
else if ((v.type === 'ByteVec' || v.type === 'Address') && v.type === tpe) {
|
|
207
|
-
return v.value;
|
|
208
|
-
}
|
|
209
|
-
else {
|
|
210
|
-
throw new Error(`Invalid node.Val type: ${v}`);
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
exports.fromApiVal = fromApiVal;
|
|
163
|
+
exports.fromApiPrimitiveVal = fromApiPrimitiveVal;
|
|
214
164
|
function decodeArrayType(tpe) {
|
|
215
165
|
const semiColonIndex = tpe.lastIndexOf(';');
|
|
216
166
|
if (semiColonIndex === -1) {
|
|
217
|
-
throw new Error(`Invalid
|
|
218
|
-
}
|
|
219
|
-
const subType = tpe.slice(1, semiColonIndex);
|
|
220
|
-
const dim = parseInt(tpe.slice(semiColonIndex + 1, -1));
|
|
221
|
-
if (subType[0] == '[') {
|
|
222
|
-
const [baseType, subDim] = decodeArrayType(subType);
|
|
223
|
-
return [baseType, (subDim.unshift(dim), subDim)];
|
|
224
|
-
}
|
|
225
|
-
else {
|
|
226
|
-
return [subType, [dim]];
|
|
167
|
+
throw new Error(`Invalid array type: ${tpe}`);
|
|
227
168
|
}
|
|
169
|
+
const baseType = tpe.slice(1, semiColonIndex);
|
|
170
|
+
const size = parseInt(tpe.slice(semiColonIndex + 1, -1));
|
|
171
|
+
return [baseType, size];
|
|
228
172
|
}
|
|
229
|
-
|
|
173
|
+
exports.decodeArrayType = decodeArrayType;
|
|
174
|
+
function getDefaultPrimitiveValue(tpe) {
|
|
230
175
|
if (tpe === 'U256' || tpe === 'I256')
|
|
231
176
|
return 0n;
|
|
232
177
|
if (tpe === 'Bool')
|
|
@@ -235,35 +180,9 @@ function getDefaultValue(tpe) {
|
|
|
235
180
|
return '';
|
|
236
181
|
if (tpe === 'Address')
|
|
237
182
|
return constants_1.ZERO_ADDRESS;
|
|
238
|
-
|
|
239
|
-
const [baseType, dims] = decodeArrayType(tpe);
|
|
240
|
-
const defaultBaseValue = getDefaultValue(baseType);
|
|
241
|
-
return dims.reduceRight((acc, length) => Array(length).fill(acc), defaultBaseValue);
|
|
242
|
-
}
|
|
243
|
-
exports.getDefaultValue = getDefaultValue;
|
|
244
|
-
function foldVals(vals, dims) {
|
|
245
|
-
if (dims.length == 1) {
|
|
246
|
-
return vals;
|
|
247
|
-
}
|
|
248
|
-
else {
|
|
249
|
-
const result = [];
|
|
250
|
-
const chunkSize = vals.length / dims[0];
|
|
251
|
-
const chunkDims = dims.slice(1);
|
|
252
|
-
for (let i = 0; i < vals.length; i += chunkSize) {
|
|
253
|
-
const chunk = vals.slice(i, i + chunkSize);
|
|
254
|
-
result.push(foldVals(chunk, chunkDims));
|
|
255
|
-
}
|
|
256
|
-
return result;
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
function typeLength(tpe) {
|
|
260
|
-
if (tpe === 'U256' || tpe === 'I256' || tpe === 'Bool' || tpe === 'ByteVec' || tpe === 'Address') {
|
|
261
|
-
return 1;
|
|
262
|
-
}
|
|
263
|
-
const [, dims] = decodeArrayType(tpe);
|
|
264
|
-
return dims.reduce((a, b) => a * b);
|
|
183
|
+
throw Error(`Expected primitive type, got ${tpe}`);
|
|
265
184
|
}
|
|
266
|
-
exports.
|
|
185
|
+
exports.getDefaultPrimitiveValue = getDefaultPrimitiveValue;
|
|
267
186
|
async function call(args, handler) {
|
|
268
187
|
const debugModeEnabled = (0, debug_1.isDebugModeEnabled)();
|
|
269
188
|
const { path, method, params } = args;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { NamedVals, node, NodeProvider, Number256, Token } from '../api';
|
|
1
|
+
import { NamedVals, node, NodeProvider, Number256, Token, Val } from '../api';
|
|
2
2
|
import { SignDeployContractTxParams, SignDeployContractTxResult, SignExecuteScriptTxParams, SignerProvider, Address } from '../signer';
|
|
3
3
|
import { Optional } from '../utils';
|
|
4
4
|
import { EventSubscribeOptions, EventSubscription } from './events';
|
|
@@ -15,7 +15,8 @@ declare enum SourceKind {
|
|
|
15
15
|
Contract = 0,
|
|
16
16
|
Script = 1,
|
|
17
17
|
AbstractContract = 2,
|
|
18
|
-
Interface = 3
|
|
18
|
+
Interface = 3,
|
|
19
|
+
Struct = 4
|
|
19
20
|
}
|
|
20
21
|
export type CompilerOptions = node.CompilerOptions & {
|
|
21
22
|
errorOnWarnings: boolean;
|
|
@@ -63,10 +64,21 @@ export declare class ProjectArtifact {
|
|
|
63
64
|
needToReCompile(compilerOptions: node.CompilerOptions, sourceInfos: SourceInfo[], fullNodeVersion: string): boolean;
|
|
64
65
|
static from(rootPath: string): Promise<ProjectArtifact | undefined>;
|
|
65
66
|
}
|
|
67
|
+
export declare class Struct {
|
|
68
|
+
name: string;
|
|
69
|
+
fieldNames: string[];
|
|
70
|
+
fieldTypes: string[];
|
|
71
|
+
isMutable: boolean[];
|
|
72
|
+
constructor(name: string, fieldNames: string[], fieldTypes: string[], isMutable: boolean[]);
|
|
73
|
+
static fromJson(json: any): Struct;
|
|
74
|
+
static fromStructSig(sig: node.StructSig): Struct;
|
|
75
|
+
toJson(): any;
|
|
76
|
+
}
|
|
66
77
|
export declare class Project {
|
|
67
78
|
sourceInfos: SourceInfo[];
|
|
68
79
|
contracts: Map<string, Compiled<Contract>>;
|
|
69
80
|
scripts: Map<string, Compiled<Script>>;
|
|
81
|
+
structs: Struct[];
|
|
70
82
|
projectArtifact: ProjectArtifact;
|
|
71
83
|
readonly contractsRootDir: string;
|
|
72
84
|
readonly artifactsRootDir: string;
|
|
@@ -76,12 +88,15 @@ export declare class Project {
|
|
|
76
88
|
static readonly contractMatcher: TypedMatcher<SourceKind.Contract>;
|
|
77
89
|
static readonly interfaceMatcher: TypedMatcher<SourceKind.Interface>;
|
|
78
90
|
static readonly scriptMatcher: TypedMatcher<SourceKind.Script>;
|
|
91
|
+
static readonly structMatcher: TypedMatcher<SourceKind.Struct>;
|
|
79
92
|
static readonly matchers: TypedMatcher<SourceKind>[];
|
|
80
93
|
static buildProjectArtifact(fullNodeVersion: string, sourceInfos: SourceInfo[], contracts: Map<string, Compiled<Contract>>, scripts: Map<string, Compiled<Script>>, compilerOptions: node.CompilerOptions): ProjectArtifact;
|
|
81
94
|
private constructor();
|
|
82
95
|
static checkCompilerWarnings(warnings: string[], errorOnWarnings: boolean): void;
|
|
83
96
|
static contract(name: string): Contract;
|
|
84
97
|
static script(name: string): Script;
|
|
98
|
+
private static loadStructs;
|
|
99
|
+
private saveStructsToFile;
|
|
85
100
|
private saveArtifactsToFile;
|
|
86
101
|
contractByCodeHash(codeHash: string): Contract;
|
|
87
102
|
private static getCompileResult;
|
|
@@ -114,13 +129,14 @@ export declare class Contract extends Artifact {
|
|
|
114
129
|
readonly eventsSig: EventSig[];
|
|
115
130
|
readonly constants: Constant[];
|
|
116
131
|
readonly enums: Enum[];
|
|
132
|
+
readonly structs: Struct[];
|
|
117
133
|
readonly stdInterfaceId?: HexString;
|
|
118
134
|
readonly bytecodeDebug: string;
|
|
119
135
|
readonly codeHashDebug: string;
|
|
120
|
-
constructor(version: string, name: string, bytecode: string, bytecodeDebugPatch: string, codeHash: string, codeHashDebug: string, fieldsSig: FieldsSig, eventsSig: EventSig[], functions: FunctionSig[], constants: Constant[], enums: Enum[], stdInterfaceId?: HexString);
|
|
121
|
-
static fromJson(artifact: any, bytecodeDebugPatch?: string, codeHashDebug?: string): Contract;
|
|
122
|
-
static fromCompileResult(result: node.CompileContractResult): Contract;
|
|
123
|
-
static fromArtifactFile(path: string, bytecodeDebugPatch: string, codeHashDebug: string): Promise<Contract>;
|
|
136
|
+
constructor(version: string, name: string, bytecode: string, bytecodeDebugPatch: string, codeHash: string, codeHashDebug: string, fieldsSig: FieldsSig, eventsSig: EventSig[], functions: FunctionSig[], constants: Constant[], enums: Enum[], structs: Struct[], stdInterfaceId?: HexString);
|
|
137
|
+
static fromJson(artifact: any, bytecodeDebugPatch?: string, codeHashDebug?: string, structs?: Struct[]): Contract;
|
|
138
|
+
static fromCompileResult(result: node.CompileContractResult, structs?: Struct[]): Contract;
|
|
139
|
+
static fromArtifactFile(path: string, bytecodeDebugPatch: string, codeHashDebug: string, structs?: Struct[]): Promise<Contract>;
|
|
124
140
|
toString(): string;
|
|
125
141
|
getInitialFieldsWithDefaultValues(): Fields;
|
|
126
142
|
toState<T extends Fields>(fields: T, asset: Asset, address?: string): ContractState<T>;
|
|
@@ -149,14 +165,19 @@ export declare class Script extends Artifact {
|
|
|
149
165
|
readonly bytecodeTemplate: string;
|
|
150
166
|
readonly bytecodeDebugPatch: string;
|
|
151
167
|
readonly fieldsSig: FieldsSig;
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
static
|
|
155
|
-
static
|
|
168
|
+
readonly structs: Struct[];
|
|
169
|
+
constructor(version: string, name: string, bytecodeTemplate: string, bytecodeDebugPatch: string, fieldsSig: FieldsSig, functions: FunctionSig[], structs: Struct[]);
|
|
170
|
+
static fromCompileResult(result: node.CompileScriptResult, structs?: Struct[]): Script;
|
|
171
|
+
static fromJson(artifact: any, bytecodeDebugPatch?: string, structs?: Struct[]): Script;
|
|
172
|
+
static fromArtifactFile(path: string, bytecodeDebugPatch: string, structs?: Struct[]): Promise<Script>;
|
|
156
173
|
toString(): string;
|
|
157
174
|
txParamsForExecution<P extends Fields>(signer: SignerProvider, params: ExecuteScriptParams<P>): Promise<SignExecuteScriptTxParams>;
|
|
158
175
|
buildByteCodeToDeploy(initialFields: Fields): string;
|
|
159
176
|
}
|
|
177
|
+
export declare function fromApiFields(immFields: node.Val[], mutFields: node.Val[], fieldsSig: FieldsSig, structs: Struct[]): NamedVals;
|
|
178
|
+
export declare function getDefaultValue(fieldsSig: FieldsSig, structs: Struct[]): Fields;
|
|
179
|
+
export declare function fromApiArray(values: node.Val[], types: string[], structs: Struct[]): Val[];
|
|
180
|
+
export declare function fromApiEventFields(vals: node.Val[], eventSig: node.EventSig, systemEvent?: boolean): Fields;
|
|
160
181
|
export interface Asset {
|
|
161
182
|
alphAmount: Number256;
|
|
162
183
|
tokens?: Token[];
|
|
@@ -175,7 +196,6 @@ export interface ContractState<T extends Fields = Fields> {
|
|
|
175
196
|
fieldsSig: FieldsSig;
|
|
176
197
|
asset: Asset;
|
|
177
198
|
}
|
|
178
|
-
export declare function toApiVals(fields: Fields, names: string[], types: string[]): node.Val[];
|
|
179
199
|
export interface TestContractParams<F extends Fields = Fields, A extends Arguments = Arguments> {
|
|
180
200
|
group?: number;
|
|
181
201
|
address?: string;
|