@alephium/web3 0.4.0 → 0.5.0-rc.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 +5 -3
- package/dist/src/api/api-alephium.js +1 -1
- package/dist/src/api/types.d.ts +1 -0
- package/dist/src/api/types.js +9 -1
- package/dist/src/constants.d.ts +1 -0
- package/dist/src/constants.js +2 -1
- package/dist/src/contract/contract.d.ts +90 -49
- package/dist/src/contract/contract.js +297 -77
- package/dist/src/contract/ralph.js +12 -3
- package/dist/src/signer/tx-builder.js +2 -2
- package/dist/src/signer/types.d.ts +2 -4
- package/dist/src/utils/utils.d.ts +1 -0
- package/dist/src/utils/utils.js +3 -1
- package/package.json +3 -3
- package/src/api/api-alephium.ts +5 -3
- package/src/api/types.ts +8 -0
- package/src/constants.ts +1 -0
- package/src/contract/contract.ts +472 -143
- package/src/contract/ralph.ts +13 -3
- package/src/signer/tx-builder.ts +2 -2
- package/src/signer/types.ts +14 -6
- package/src/utils/utils.ts +4 -1
|
@@ -425,7 +425,8 @@ export interface ContractState {
|
|
|
425
425
|
codeHash: string;
|
|
426
426
|
/** @format 32-byte-hash */
|
|
427
427
|
initialStateHash?: string;
|
|
428
|
-
|
|
428
|
+
immFields: Val[];
|
|
429
|
+
mutFields: Val[];
|
|
429
430
|
asset: AssetState;
|
|
430
431
|
}
|
|
431
432
|
export interface DebugMessage {
|
|
@@ -663,7 +664,8 @@ export interface TestContract {
|
|
|
663
664
|
address?: string;
|
|
664
665
|
/** @format contract */
|
|
665
666
|
bytecode: string;
|
|
666
|
-
|
|
667
|
+
initialImmFields?: Val[];
|
|
668
|
+
initialMutFields?: Val[];
|
|
667
669
|
initialAsset?: AssetState;
|
|
668
670
|
/** @format int32 */
|
|
669
671
|
methodIndex?: number;
|
|
@@ -908,7 +910,7 @@ export declare class HttpClient<SecurityDataType = unknown> {
|
|
|
908
910
|
}
|
|
909
911
|
/**
|
|
910
912
|
* @title Alephium API
|
|
911
|
-
* @version 1.
|
|
913
|
+
* @version 1.7.0
|
|
912
914
|
* @baseUrl ../
|
|
913
915
|
*/
|
|
914
916
|
export declare class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDataType> {
|
package/dist/src/api/types.d.ts
CHANGED
|
@@ -21,3 +21,4 @@ export declare function toApiVal(v: Val, tpe: string): node.Val;
|
|
|
21
21
|
export declare function fromApiVals(vals: node.Val[], names: string[], types: string[]): NamedVals;
|
|
22
22
|
export declare function fromApiArray(vals: node.Val[], types: string[]): Val[];
|
|
23
23
|
export declare function fromApiVal(v: node.Val, tpe: string): Val;
|
|
24
|
+
export declare function typeLength(tpe: string): number;
|
package/dist/src/api/types.js
CHANGED
|
@@ -17,7 +17,7 @@ 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.fromApiVal = exports.fromApiArray = exports.fromApiVals = exports.toApiVal = exports.toApiArray = exports.toApiAddress = exports.toApiByteVec = exports.fromApiNumber256 = exports.toApiNumber256Optional = exports.toApiNumber256 = exports.toApiBoolean = exports.fromApiTokens = exports.fromApiToken = exports.toApiTokens = exports.toApiToken = void 0;
|
|
20
|
+
exports.typeLength = exports.fromApiVal = exports.fromApiArray = exports.fromApiVals = exports.toApiVal = exports.toApiArray = exports.toApiAddress = exports.toApiByteVec = exports.fromApiNumber256 = exports.toApiNumber256Optional = exports.toApiNumber256 = exports.toApiBoolean = exports.fromApiTokens = exports.fromApiToken = exports.toApiTokens = exports.toApiToken = void 0;
|
|
21
21
|
const utils_1 = require("../utils");
|
|
22
22
|
utils_1.assertType;
|
|
23
23
|
function toApiToken(token) {
|
|
@@ -233,3 +233,11 @@ function foldVals(vals, dims) {
|
|
|
233
233
|
return result;
|
|
234
234
|
}
|
|
235
235
|
}
|
|
236
|
+
function typeLength(tpe) {
|
|
237
|
+
if (tpe === 'U256' || tpe === 'I256' || tpe === 'Bool' || tpe === 'ByteVec' || tpe === 'Address') {
|
|
238
|
+
return 1;
|
|
239
|
+
}
|
|
240
|
+
const [, dims] = decodeArrayType(tpe);
|
|
241
|
+
return dims.reduce((a, b) => a * b);
|
|
242
|
+
}
|
|
243
|
+
exports.typeLength = typeLength;
|
package/dist/src/constants.d.ts
CHANGED
package/dist/src/constants.js
CHANGED
|
@@ -17,7 +17,8 @@ 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.ALPH_TOKEN_ID = exports.MIN_UTXO_SET_AMOUNT = exports.TOTAL_NUMBER_OF_GROUPS = void 0;
|
|
20
|
+
exports.ONE_ALPH = exports.ALPH_TOKEN_ID = exports.MIN_UTXO_SET_AMOUNT = exports.TOTAL_NUMBER_OF_GROUPS = void 0;
|
|
21
21
|
exports.TOTAL_NUMBER_OF_GROUPS = 4;
|
|
22
22
|
exports.MIN_UTXO_SET_AMOUNT = BigInt(1000000000000);
|
|
23
23
|
exports.ALPH_TOKEN_ID = ''.padStart(64, '0');
|
|
24
|
+
exports.ONE_ALPH = 10n ** 18n;
|
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
import { NamedVals, node, Number256, Token
|
|
2
|
-
import { SignDeployContractTxParams, SignExecuteScriptTxParams, SignerProvider,
|
|
1
|
+
import { NamedVals, node, Number256, Token } from '../api';
|
|
2
|
+
import { SignDeployContractTxParams, SignDeployContractTxResult, SignExecuteScriptTxParams, SignerProvider, Address } from '../signer';
|
|
3
|
+
import { SubscribeOptions, Optional } from '../utils';
|
|
4
|
+
import { EventSubscription } from './events';
|
|
3
5
|
export declare type FieldsSig = node.FieldsSig;
|
|
4
6
|
export declare type EventSig = node.EventSig;
|
|
5
7
|
export declare type FunctionSig = node.FunctionSig;
|
|
6
8
|
export declare type Fields = NamedVals;
|
|
7
9
|
export declare type Arguments = NamedVals;
|
|
10
|
+
export declare type HexString = string;
|
|
8
11
|
declare enum SourceKind {
|
|
9
12
|
Contract = 0,
|
|
10
13
|
Script = 1,
|
|
@@ -108,28 +111,28 @@ export declare class Contract extends Artifact {
|
|
|
108
111
|
static fromJson(artifact: any, bytecodeDebugPatch?: string, codeHashDebug?: string): Contract;
|
|
109
112
|
static fromCompileResult(result: node.CompileContractResult): Contract;
|
|
110
113
|
static fromArtifactFile(path: string, bytecodeDebugPatch: string, codeHashDebug: string): Promise<Contract>;
|
|
111
|
-
fetchState(address: string, group: number): Promise<ContractState>;
|
|
112
114
|
toString(): string;
|
|
113
|
-
toState(fields:
|
|
115
|
+
toState<T extends Fields>(fields: T, asset: Asset, address?: string): ContractState<T>;
|
|
114
116
|
static randomAddress(): string;
|
|
115
|
-
|
|
116
|
-
private _test;
|
|
117
|
-
testPublicMethod(funcName: string, params: TestContractParams, printDebugMessages?: boolean): Promise<TestContractResult>;
|
|
118
|
-
testPrivateMethod(funcName: string, params: TestContractParams, printDebugMessages?: boolean): Promise<TestContractResult>;
|
|
117
|
+
printDebugMessages(funcName: string, messages: DebugMessage[]): void;
|
|
119
118
|
toApiFields(fields?: Fields): node.Val[];
|
|
120
119
|
toApiArgs(funcName: string, args?: Arguments): node.Val[];
|
|
121
120
|
getMethodIndex(funcName: string): number;
|
|
122
121
|
toApiContractStates(states?: ContractState[]): node.ContractState[] | undefined;
|
|
123
|
-
|
|
124
|
-
fromApiContractState(state: node.ContractState): ContractState
|
|
122
|
+
toApiTestContractParams(funcName: string, params: TestContractParams): node.TestContract;
|
|
123
|
+
fromApiContractState(state: node.ContractState): ContractState<Fields>;
|
|
125
124
|
static fromApiContractState(state: node.ContractState): ContractState;
|
|
125
|
+
static ContractCreatedEventIndex: number;
|
|
126
126
|
static ContractCreatedEvent: EventSig;
|
|
127
|
+
static ContractDestroyedEventIndex: number;
|
|
127
128
|
static ContractDestroyedEvent: EventSig;
|
|
128
|
-
static fromApiEvent(event: node.ContractEventByTxId, codeHash: string | undefined):
|
|
129
|
-
|
|
130
|
-
txParamsForDeployment(signer: SignerProvider, params:
|
|
131
|
-
deploy(signer: SignerProvider, params: Omit<BuildDeployContractTx, 'signerAddress'>): Promise<SignDeployContractTxResult>;
|
|
129
|
+
static fromApiEvent(event: node.ContractEventByTxId, codeHash: string | undefined, txId: string): ContractEvent;
|
|
130
|
+
fromApiTestContractResult(methodName: string, result: node.TestContractResult, txId: string): TestContractResult<unknown>;
|
|
131
|
+
txParamsForDeployment<P extends Fields>(signer: SignerProvider, params: DeployContractParams<P>): Promise<SignDeployContractTxParams>;
|
|
132
132
|
buildByteCodeToDeploy(initialFields: Fields): string;
|
|
133
|
+
static fromApiEvents(events: node.ContractEventByTxId[], addressToCodeHash: Map<string, string>, txId: string): ContractEvent[];
|
|
134
|
+
toApiCallContract<T extends Arguments>(params: CallContractParams<T>, groupIndex: number, contractAddress: string, methodIndex: number): node.CallContract;
|
|
135
|
+
fromApiCallContractResult(result: node.CallContractResult, txId: string, methodIndex: number): CallContractResult<unknown>;
|
|
133
136
|
}
|
|
134
137
|
export declare class Script extends Artifact {
|
|
135
138
|
readonly bytecodeTemplate: string;
|
|
@@ -140,8 +143,7 @@ export declare class Script extends Artifact {
|
|
|
140
143
|
static fromJson(artifact: any, bytecodeDebugPatch?: string): Script;
|
|
141
144
|
static fromArtifactFile(path: string, bytecodeDebugPatch: string): Promise<Script>;
|
|
142
145
|
toString(): string;
|
|
143
|
-
txParamsForExecution(signer: SignerProvider, params:
|
|
144
|
-
execute(signer: SignerProvider, params: Omit<BuildExecuteScriptTx, 'signerAddress'>): Promise<SignExecuteScriptTxResult>;
|
|
146
|
+
txParamsForExecution<P extends Fields>(signer: SignerProvider, params: ExecuteScriptParams<P>): Promise<SignExecuteScriptTxParams>;
|
|
145
147
|
buildByteCodeToDeploy(initialFields: Fields): string;
|
|
146
148
|
}
|
|
147
149
|
export interface Asset {
|
|
@@ -152,47 +154,45 @@ export interface InputAsset {
|
|
|
152
154
|
address: string;
|
|
153
155
|
asset: Asset;
|
|
154
156
|
}
|
|
155
|
-
export interface ContractState {
|
|
157
|
+
export interface ContractState<T extends Fields = Fields> {
|
|
156
158
|
address: string;
|
|
157
159
|
contractId: string;
|
|
158
160
|
bytecode: string;
|
|
159
161
|
initialStateHash?: string;
|
|
160
162
|
codeHash: string;
|
|
161
|
-
fields:
|
|
163
|
+
fields: T;
|
|
162
164
|
fieldsSig: FieldsSig;
|
|
163
165
|
asset: Asset;
|
|
164
166
|
}
|
|
165
|
-
export
|
|
167
|
+
export declare function toApiVals(fields: Fields, names: string[], types: string[]): node.Val[];
|
|
168
|
+
export interface TestContractParams<F extends Fields = Fields, A extends Arguments = Arguments> {
|
|
166
169
|
group?: number;
|
|
167
170
|
address?: string;
|
|
168
|
-
|
|
171
|
+
blockHash?: string;
|
|
172
|
+
txId?: string;
|
|
173
|
+
initialFields: F;
|
|
169
174
|
initialAsset?: Asset;
|
|
170
|
-
|
|
171
|
-
testArgs?: Arguments;
|
|
175
|
+
testArgs: A;
|
|
172
176
|
existingContracts?: ContractState[];
|
|
173
177
|
inputAssets?: InputAsset[];
|
|
174
178
|
}
|
|
175
|
-
export interface ContractEvent {
|
|
176
|
-
blockHash: string;
|
|
179
|
+
export interface ContractEvent<T extends Fields = Fields> {
|
|
177
180
|
txId: string;
|
|
178
|
-
name: string;
|
|
179
|
-
fields: Fields;
|
|
180
|
-
}
|
|
181
|
-
export interface ContractEventByTxId {
|
|
182
181
|
blockHash: string;
|
|
183
182
|
contractAddress: string;
|
|
183
|
+
eventIndex: number;
|
|
184
184
|
name: string;
|
|
185
|
-
fields:
|
|
185
|
+
fields: T;
|
|
186
186
|
}
|
|
187
187
|
export declare type DebugMessage = node.DebugMessage;
|
|
188
|
-
export interface TestContractResult {
|
|
188
|
+
export interface TestContractResult<R> {
|
|
189
189
|
contractId: string;
|
|
190
190
|
contractAddress: string;
|
|
191
|
-
returns:
|
|
191
|
+
returns: R;
|
|
192
192
|
gasUsed: number;
|
|
193
193
|
contracts: ContractState[];
|
|
194
194
|
txOutputs: Output[];
|
|
195
|
-
events:
|
|
195
|
+
events: ContractEvent[];
|
|
196
196
|
debugMessages: DebugMessage[];
|
|
197
197
|
}
|
|
198
198
|
export declare type Output = AssetOutput | ContractOutput;
|
|
@@ -208,35 +208,76 @@ export interface ContractOutput {
|
|
|
208
208
|
alphAmount: Number256;
|
|
209
209
|
tokens?: Token[];
|
|
210
210
|
}
|
|
211
|
-
export
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
unsignedTx: string;
|
|
215
|
-
txId: string;
|
|
216
|
-
contractAddress: string;
|
|
217
|
-
contractId: string;
|
|
218
|
-
}
|
|
219
|
-
export interface BuildDeployContractTx {
|
|
220
|
-
signerAddress: string;
|
|
221
|
-
initialFields?: Fields;
|
|
211
|
+
export declare function randomTxId(): string;
|
|
212
|
+
export interface DeployContractParams<P extends Fields = Fields> {
|
|
213
|
+
initialFields: P;
|
|
222
214
|
initialAttoAlphAmount?: Number256;
|
|
223
215
|
initialTokenAmounts?: Token[];
|
|
224
216
|
issueTokenAmount?: Number256;
|
|
225
217
|
gasAmount?: number;
|
|
226
218
|
gasPrice?: Number256;
|
|
227
219
|
}
|
|
228
|
-
export
|
|
229
|
-
|
|
230
|
-
|
|
220
|
+
export declare type DeployContractResult<T> = SignDeployContractTxResult & {
|
|
221
|
+
instance: T;
|
|
222
|
+
};
|
|
223
|
+
export declare abstract class ContractFactory<I, F extends Fields = Fields> {
|
|
224
|
+
readonly contract: Contract;
|
|
225
|
+
constructor(contract: Contract);
|
|
226
|
+
abstract at(address: string): I;
|
|
227
|
+
deploy(signer: SignerProvider, deployParams: DeployContractParams<F>): Promise<DeployContractResult<I>>;
|
|
228
|
+
stateForTest(initFields: F, asset?: Asset, address?: string): ContractState<F>;
|
|
229
|
+
}
|
|
230
|
+
export interface ExecuteScriptParams<P extends Fields = Fields> {
|
|
231
|
+
initialFields: P;
|
|
231
232
|
attoAlphAmount?: Number256;
|
|
232
233
|
tokens?: Token[];
|
|
233
234
|
gasAmount?: number;
|
|
234
235
|
gasPrice?: Number256;
|
|
235
236
|
}
|
|
236
|
-
export interface
|
|
237
|
-
|
|
238
|
-
toGroup: number;
|
|
237
|
+
export interface ExecuteScriptResult {
|
|
238
|
+
groupIndex: number;
|
|
239
239
|
unsignedTx: string;
|
|
240
240
|
txId: string;
|
|
241
|
+
signature: string;
|
|
242
|
+
gasAmount: number;
|
|
243
|
+
gasPrice: Number256;
|
|
244
|
+
}
|
|
245
|
+
export interface CallContractParams<T extends Arguments = Arguments> {
|
|
246
|
+
args: T;
|
|
247
|
+
worldStateBlockHash?: string;
|
|
248
|
+
txId?: string;
|
|
249
|
+
existingContracts?: string[];
|
|
250
|
+
inputAssets?: node.TestInputAsset[];
|
|
251
|
+
}
|
|
252
|
+
export interface CallContractResult<R> {
|
|
253
|
+
returns: R;
|
|
254
|
+
gasUsed: number;
|
|
255
|
+
contracts: ContractState[];
|
|
256
|
+
txInputs: string[];
|
|
257
|
+
txOutputs: Output[];
|
|
258
|
+
events: ContractEvent[];
|
|
259
|
+
}
|
|
260
|
+
export declare type ContractCreatedEvent = ContractEvent<{
|
|
261
|
+
address: HexString;
|
|
262
|
+
}>;
|
|
263
|
+
export declare type ContractDestroyedEvent = ContractEvent<{
|
|
264
|
+
address: HexString;
|
|
265
|
+
}>;
|
|
266
|
+
export declare function decodeContractCreatedEvent(event: node.ContractEvent): Omit<ContractCreatedEvent, 'contractAddress'>;
|
|
267
|
+
export declare function decodeContractDestroyedEvent(event: node.ContractEvent): Omit<ContractDestroyedEvent, 'contractAddress'>;
|
|
268
|
+
export declare function subscribeEventsFromContract<T extends Fields, M extends ContractEvent<T>>(options: SubscribeOptions<M>, address: string, eventIndex: number, decodeFunc: (event: node.ContractEvent) => M, fromCount?: number): EventSubscription;
|
|
269
|
+
export declare function testMethod<I, F extends Fields, A extends Arguments, R>(contract: ContractFactory<I, F>, methodName: string, params: Optional<TestContractParams<F, A>, 'testArgs' | 'initialFields'>): Promise<TestContractResult<R>>;
|
|
270
|
+
export declare abstract class ContractInstance {
|
|
271
|
+
readonly address: Address;
|
|
272
|
+
readonly contractId: string;
|
|
273
|
+
readonly groupIndex: number;
|
|
274
|
+
constructor(address: Address);
|
|
241
275
|
}
|
|
276
|
+
export declare function fetchContractState<F extends Fields, I extends ContractInstance>(contract: ContractFactory<I, F>, instance: ContractInstance): Promise<ContractState<F>>;
|
|
277
|
+
export declare function subscribeContractCreatedEvent(instance: ContractInstance, options: SubscribeOptions<ContractCreatedEvent>, fromCount?: number): EventSubscription;
|
|
278
|
+
export declare function subscribeContractDestroyedEvent(instance: ContractInstance, options: SubscribeOptions<ContractDestroyedEvent>, fromCount?: number): EventSubscription;
|
|
279
|
+
export declare function decodeEvent<F extends Fields, M extends ContractEvent<F>>(contract: Contract, instance: ContractInstance, event: node.ContractEvent, targetEventIndex: number): M;
|
|
280
|
+
export declare function subscribeContractEvent<F extends Fields, M extends ContractEvent<F>>(contract: Contract, instance: ContractInstance, options: SubscribeOptions<M>, eventName: string, fromCount?: number): EventSubscription;
|
|
281
|
+
export declare function subscribeAllEvents(contract: Contract, instance: ContractInstance, options: SubscribeOptions<ContractEvent<any>>, fromCount?: number): EventSubscription;
|
|
282
|
+
export declare function callMethod<I, F extends Fields, A extends Arguments, R>(contract: ContractFactory<I, F>, instance: ContractInstance, methodName: string, params: Optional<CallContractParams<A>, 'args'>): Promise<CallContractResult<R>>;
|
|
242
283
|
export {};
|