@alephium/web3 1.12.0-beta.0 → 1.12.0-danube.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/address/address.d.ts +1 -0
- package/dist/src/address/address.js +45 -22
- package/dist/src/api/api-alephium.d.ts +78 -124
- package/dist/src/api/api-alephium.js +0 -50
- package/dist/src/api/node-provider.d.ts +0 -2
- package/dist/src/api/node-provider.js +0 -1
- package/dist/src/codec/instr-codec.d.ts +26 -10
- package/dist/src/codec/instr-codec.js +38 -18
- package/dist/src/contract/contract.d.ts +11 -6
- package/dist/src/contract/contract.js +35 -21
- package/dist/src/contract/deployment.d.ts +2 -0
- package/dist/src/signer/signer.d.ts +13 -13
- package/dist/src/signer/signer.js +84 -9
- package/dist/src/signer/tx-builder.d.ts +4 -10
- package/dist/src/signer/tx-builder.js +41 -67
- package/dist/src/signer/types.d.ts +14 -27
- package/dist/src/signer/types.js +0 -3
- package/dist/src/utils/sign.js +2 -2
- package/package.json +1 -1
- package/src/address/address.ts +50 -19
- package/src/api/api-alephium.ts +92 -172
- package/src/api/node-provider.ts +0 -3
- package/src/codec/instr-codec.ts +45 -21
- package/src/contract/contract.ts +45 -29
- package/src/contract/deployment.ts +2 -0
- package/src/signer/signer.ts +118 -24
- package/src/signer/tx-builder.ts +60 -99
- package/src/signer/types.ts +31 -39
- package/src/utils/sign.ts +2 -2
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.I256Add = exports.BoolToByteVec = exports.BoolNeq = exports.BoolEq = exports.BoolOr = exports.BoolAnd = exports.BoolNot = exports.Pop = exports.StoreLocal = exports.LoadLocal = exports.AddressConst = exports.BytesConst = exports.U256Const = exports.I256Const = exports.U256Const5 = exports.U256Const4 = exports.U256Const3 = exports.U256Const2 = exports.U256Const1 = exports.U256Const0 = exports.I256ConstN1 = exports.I256Const5 = exports.I256Const4 = exports.I256Const3 = exports.I256Const2 = exports.I256Const1 = exports.I256Const0 = exports.ConstFalse = exports.ConstTrue = exports.Return = exports.CallExternal = exports.CallLocal = exports.CallExternalBySelectorCode = exports.MethodSelectorCode = exports.CreateMapEntryCode = exports.LoadImmFieldCode = exports.StoreMutFieldCode = exports.LoadMutFieldCode = exports.DEBUGCode = exports.IfFalseCode = exports.IfTrueCode = exports.JumpCode = exports.StoreLocalCode = exports.LoadLocalCode = exports.AddressConstCode = exports.BytesConstCode = exports.U256ConstCode = exports.I256ConstCode = exports.CallExternalCode = exports.CallLocalCode = void 0;
|
|
4
|
-
exports.Sha3 = exports.Sha256 = exports.Keccak256 = exports.Blake2b = exports.Assert = exports.IfFalse = exports.IfTrue = exports.Jump = exports.IsContractAddress = exports.IsAssetAddress = exports.AddressToByteVec = exports.AddressNeq = exports.AddressEq = exports.ByteVecConcat = exports.ByteVecSize = exports.ByteVecNeq = exports.ByteVecEq = exports.U256ToByteVec = exports.U256ToI256 = exports.I256ToByteVec = exports.I256ToU256 = exports.
|
|
4
|
+
exports.Sha3 = exports.Sha256 = exports.Keccak256 = exports.Blake2b = exports.Assert = exports.IfFalse = exports.IfTrue = exports.Jump = exports.IsContractAddress = exports.IsAssetAddress = exports.AddressToByteVec = exports.AddressNeq = exports.AddressEq = exports.ByteVecConcat = exports.ByteVecSize = exports.ByteVecNeq = exports.ByteVecEq = exports.U256ToByteVec = exports.U256ToI256 = exports.I256ToByteVec = exports.I256ToU256 = exports.NumericSHR = exports.NumericSHL = exports.NumericXor = exports.NumericBitOr = exports.NumericBitAnd = exports.U256ModMul = exports.U256ModSub = exports.U256ModAdd = exports.U256Ge = exports.U256Gt = exports.U256Le = exports.U256Lt = exports.U256Neq = exports.U256Eq = exports.U256Mod = exports.U256Div = exports.U256Mul = exports.U256Sub = exports.U256Add = exports.I256Ge = exports.I256Gt = exports.I256Le = exports.I256Lt = exports.I256Neq = exports.I256Eq = exports.I256Mod = exports.I256Div = exports.I256Mul = exports.I256Sub = void 0;
|
|
5
5
|
exports.U256Exp = exports.I256Exp = exports.TxGasFee = exports.TxGasAmount = exports.TxGasPrice = exports.DEBUG = exports.BlockHash = exports.Swap = exports.AssertWithErrorCode = exports.Dup = exports.StoreLocalByIndex = exports.LoadLocalByIndex = exports.ContractIdToAddress = exports.Log9 = exports.Log8 = exports.Log7 = exports.Log6 = exports.EthEcRecover = exports.U256From32Byte = exports.U256From16Byte = exports.U256From8Byte = exports.U256From4Byte = exports.U256From2Byte = exports.U256From1Byte = exports.U256To32Byte = exports.U256To16Byte = exports.U256To8Byte = exports.U256To4Byte = exports.U256To2Byte = exports.U256To1Byte = exports.Zeros = exports.Encode = exports.ByteVecToAddress = exports.ByteVecSlice = exports.Log5 = exports.Log4 = exports.Log3 = exports.Log2 = exports.Log1 = exports.VerifyRelativeLocktime = exports.VerifyAbsoluteLocktime = exports.TxInputsSize = exports.TxInputAddressAt = exports.TxId = exports.BlockTarget = exports.BlockTimeStamp = exports.NetworkId = exports.VerifyED25519 = exports.VerifySecP256K1 = exports.VerifyTxSignature = void 0;
|
|
6
|
-
exports.
|
|
7
|
-
exports.toI256 = exports.toU256 = exports.instrsCodec = exports.instrCodec = exports.InstrCodec = exports.CallExternalBySelector = exports.MethodSelector = exports.CreateMapEntry = exports.MinimalContractDeposit = exports.PayGasFee = exports.LoadImmFieldByIndex = exports.LoadImmField = exports.ALPHTokenId = exports.SubContractIdOf = exports.SubContractId = exports.NullContractAddress = exports.CopyCreateSubContractAndTransferToken = void 0;
|
|
6
|
+
exports.CreateContractAndTransferToken = exports.ContractExists = exports.StoreMutFieldByIndex = exports.LoadMutFieldByIndex = exports.CopyCreateSubContractWithToken = exports.CopyCreateSubContract = exports.CreateSubContractWithToken = exports.CreateSubContract = exports.LockApprovedAssets = exports.BurnToken = exports.CopyCreateContractWithToken = exports.MigrateWithFields = exports.MigrateSimple = exports.ContractCodeHash = exports.ContractInitialStateHash = exports.CallerCodeHash = exports.CallerInitialStateHash = exports.IsCalledFromTxScript = exports.CallerAddress = exports.CallerContractId = exports.SelfAddress = exports.SelfContractId = exports.DestroySelf = exports.CopyCreateContract = exports.CreateContractWithToken = exports.CreateContract = exports.TransferTokenToSelf = exports.TransferTokenFromSelf = exports.TransferToken = exports.TransferAlphToSelf = exports.TransferAlphFromSelf = exports.TransferAlph = exports.IsPaying = exports.TokenRemaining = exports.AlphRemaining = exports.ApproveToken = exports.ApproveAlph = exports.StoreMutField = exports.LoadMutField = exports.GetSegregatedWebAuthnSignature = exports.VerifySignature = exports.GroupOfAddress = exports.BoolToString = exports.I256ToString = exports.U256ToString = exports.AddModN = exports.MulModN = exports.GetSegregatedSignature = exports.VerifyBIP340Schnorr = exports.U256ModExp = void 0;
|
|
7
|
+
exports.toI256 = exports.toU256 = exports.instrsCodec = exports.instrCodec = exports.InstrCodec = exports.ExternalCallerAddress = exports.ExternalCallerContractId = exports.CallExternalBySelector = exports.MethodSelector = exports.CreateMapEntry = exports.MinimalContractDeposit = exports.PayGasFee = exports.LoadImmFieldByIndex = exports.LoadImmField = exports.ALPHTokenId = exports.SubContractIdOf = exports.SubContractId = exports.NullContractAddress = exports.CopyCreateSubContractAndTransferToken = exports.CreateSubContractAndTransferToken = exports.CopyCreateContractAndTransferToken = void 0;
|
|
8
8
|
/*
|
|
9
9
|
Copyright 2018 - 2022 The Alephium Authors
|
|
10
10
|
This file is part of the alephium project.
|
|
@@ -127,11 +127,11 @@ exports.U256Ge = { name: 'U256Ge', code: 0x34 };
|
|
|
127
127
|
exports.U256ModAdd = { name: 'U256ModAdd', code: 0x35 };
|
|
128
128
|
exports.U256ModSub = { name: 'U256ModSub', code: 0x36 };
|
|
129
129
|
exports.U256ModMul = { name: 'U256ModMul', code: 0x37 };
|
|
130
|
-
exports.
|
|
131
|
-
exports.
|
|
132
|
-
exports.
|
|
133
|
-
exports.
|
|
134
|
-
exports.
|
|
130
|
+
exports.NumericBitAnd = { name: 'NumericBitAnd', code: 0x38 };
|
|
131
|
+
exports.NumericBitOr = { name: 'NumericBitOr', code: 0x39 };
|
|
132
|
+
exports.NumericXor = { name: 'NumericXor', code: 0x3a };
|
|
133
|
+
exports.NumericSHL = { name: 'NumericSHL', code: 0x3b };
|
|
134
|
+
exports.NumericSHR = { name: 'NumericSHR', code: 0x3c };
|
|
135
135
|
exports.I256ToU256 = { name: 'I256ToU256', code: 0x3d };
|
|
136
136
|
exports.I256ToByteVec = { name: 'I256ToByteVec', code: 0x3e };
|
|
137
137
|
exports.U256ToI256 = { name: 'U256ToI256', code: 0x3f };
|
|
@@ -224,6 +224,8 @@ exports.U256ToString = { name: 'U256ToString', code: 0x89 };
|
|
|
224
224
|
exports.I256ToString = { name: 'I256ToString', code: 0x8a };
|
|
225
225
|
exports.BoolToString = { name: 'BoolToString', code: 0x8b };
|
|
226
226
|
exports.GroupOfAddress = { name: 'GroupOfAddress', code: 0x8c };
|
|
227
|
+
exports.VerifySignature = { name: 'VerifySignature', code: 0x8d };
|
|
228
|
+
exports.GetSegregatedWebAuthnSignature = { name: 'GetSegregatedWebAuthnSignature', code: 0x8e };
|
|
227
229
|
const LoadMutField = (index) => {
|
|
228
230
|
return { name: 'LoadMutField', code: 0xa0, index };
|
|
229
231
|
};
|
|
@@ -298,6 +300,8 @@ const CallExternalBySelector = (selector) => {
|
|
|
298
300
|
return { name: 'CallExternalBySelector', code: 0xd4, selector };
|
|
299
301
|
};
|
|
300
302
|
exports.CallExternalBySelector = CallExternalBySelector;
|
|
303
|
+
exports.ExternalCallerContractId = { name: 'ExternalCallerContractId', code: 0xd5 };
|
|
304
|
+
exports.ExternalCallerAddress = { name: 'ExternalCallerAddress', code: 0xd6 };
|
|
301
305
|
class InstrCodec extends codec_1.Codec {
|
|
302
306
|
encode(instr) {
|
|
303
307
|
switch (instr.name) {
|
|
@@ -413,15 +417,15 @@ class InstrCodec extends codec_1.Codec {
|
|
|
413
417
|
return new Uint8Array([0x36]);
|
|
414
418
|
case 'U256ModMul':
|
|
415
419
|
return new Uint8Array([0x37]);
|
|
416
|
-
case '
|
|
420
|
+
case 'NumericBitAnd':
|
|
417
421
|
return new Uint8Array([0x38]);
|
|
418
|
-
case '
|
|
422
|
+
case 'NumericBitOr':
|
|
419
423
|
return new Uint8Array([0x39]);
|
|
420
|
-
case '
|
|
424
|
+
case 'NumericXor':
|
|
421
425
|
return new Uint8Array([0x3a]);
|
|
422
|
-
case '
|
|
426
|
+
case 'NumericSHL':
|
|
423
427
|
return new Uint8Array([0x3b]);
|
|
424
|
-
case '
|
|
428
|
+
case 'NumericSHR':
|
|
425
429
|
return new Uint8Array([0x3c]);
|
|
426
430
|
case 'I256ToU256':
|
|
427
431
|
return new Uint8Array([0x3d]);
|
|
@@ -583,6 +587,10 @@ class InstrCodec extends codec_1.Codec {
|
|
|
583
587
|
return new Uint8Array([0x8b]);
|
|
584
588
|
case 'GroupOfAddress':
|
|
585
589
|
return new Uint8Array([0x8c]);
|
|
590
|
+
case 'VerifySignature':
|
|
591
|
+
return new Uint8Array([0x8d]);
|
|
592
|
+
case 'GetSegregatedWebAuthnSignature':
|
|
593
|
+
return new Uint8Array([0x8e]);
|
|
586
594
|
case 'LoadMutField':
|
|
587
595
|
return new Uint8Array([0xa0, ...codec_1.byteCodec.encode(instr.index)]);
|
|
588
596
|
case 'StoreMutField':
|
|
@@ -689,6 +697,10 @@ class InstrCodec extends codec_1.Codec {
|
|
|
689
697
|
return new Uint8Array([0xd3, ...int_as_4bytes_codec_1.intAs4BytesCodec.encode(instr.selector)]);
|
|
690
698
|
case 'CallExternalBySelector':
|
|
691
699
|
return new Uint8Array([0xd4, ...int_as_4bytes_codec_1.intAs4BytesCodec.encode(instr.selector)]);
|
|
700
|
+
case 'ExternalCallerContractId':
|
|
701
|
+
return new Uint8Array([0xd5]);
|
|
702
|
+
case 'ExternalCallerAddress':
|
|
703
|
+
return new Uint8Array([0xd6]);
|
|
692
704
|
}
|
|
693
705
|
}
|
|
694
706
|
_decode(input) {
|
|
@@ -807,15 +819,15 @@ class InstrCodec extends codec_1.Codec {
|
|
|
807
819
|
case 0x37:
|
|
808
820
|
return exports.U256ModMul;
|
|
809
821
|
case 0x38:
|
|
810
|
-
return exports.
|
|
822
|
+
return exports.NumericBitAnd;
|
|
811
823
|
case 0x39:
|
|
812
|
-
return exports.
|
|
824
|
+
return exports.NumericBitOr;
|
|
813
825
|
case 0x3a:
|
|
814
|
-
return exports.
|
|
826
|
+
return exports.NumericXor;
|
|
815
827
|
case 0x3b:
|
|
816
|
-
return exports.
|
|
828
|
+
return exports.NumericSHL;
|
|
817
829
|
case 0x3c:
|
|
818
|
-
return exports.
|
|
830
|
+
return exports.NumericSHR;
|
|
819
831
|
case 0x3d:
|
|
820
832
|
return exports.I256ToU256;
|
|
821
833
|
case 0x3e:
|
|
@@ -976,6 +988,10 @@ class InstrCodec extends codec_1.Codec {
|
|
|
976
988
|
return exports.BoolToString;
|
|
977
989
|
case 0x8c:
|
|
978
990
|
return exports.GroupOfAddress;
|
|
991
|
+
case 0x8d:
|
|
992
|
+
return exports.VerifySignature;
|
|
993
|
+
case 0x8e:
|
|
994
|
+
return exports.GetSegregatedWebAuthnSignature;
|
|
979
995
|
case 0xa0:
|
|
980
996
|
return (0, exports.LoadMutField)(codec_1.byteCodec._decode(input));
|
|
981
997
|
case 0xa1:
|
|
@@ -1082,6 +1098,10 @@ class InstrCodec extends codec_1.Codec {
|
|
|
1082
1098
|
return (0, exports.MethodSelector)(int_as_4bytes_codec_1.intAs4BytesCodec._decode(input));
|
|
1083
1099
|
case 0xd4:
|
|
1084
1100
|
return (0, exports.CallExternalBySelector)(int_as_4bytes_codec_1.intAs4BytesCodec._decode(input));
|
|
1101
|
+
case 0xd5:
|
|
1102
|
+
return exports.ExternalCallerContractId;
|
|
1103
|
+
case 0xd6:
|
|
1104
|
+
return exports.ExternalCallerAddress;
|
|
1085
1105
|
default:
|
|
1086
1106
|
throw new Error(`Unknown instr code: ${code}`);
|
|
1087
1107
|
}
|
|
@@ -3,6 +3,7 @@ import { SignDeployContractTxParams, SignDeployContractTxResult, SignExecuteScri
|
|
|
3
3
|
import { Optional, HexString } from '../utils';
|
|
4
4
|
import { EventSubscribeOptions, EventSubscription } from './events';
|
|
5
5
|
import { contract, Method } from '../codec';
|
|
6
|
+
import { SimulationResult } from '../api/api-alephium';
|
|
6
7
|
export type FieldsSig = node.FieldsSig;
|
|
7
8
|
export type MapsSig = node.MapsSig;
|
|
8
9
|
export type EventSig = node.EventSig;
|
|
@@ -100,7 +101,7 @@ export declare class Script extends Artifact {
|
|
|
100
101
|
static fromJson(artifact: any, bytecodeDebugPatch?: string, structs?: Struct[]): Script;
|
|
101
102
|
static fromArtifactFile(path: string, bytecodeDebugPatch: string, structs?: Struct[]): Promise<Script>;
|
|
102
103
|
toString(): string;
|
|
103
|
-
txParamsForExecution<P extends Fields>(
|
|
104
|
+
txParamsForExecution<P extends Fields>(params: ExecuteScriptParams<P>): Promise<SignExecuteScriptTxParams>;
|
|
104
105
|
buildByteCodeToDeploy(initialFields: Fields): string;
|
|
105
106
|
}
|
|
106
107
|
export declare function fromApiFields(immFields: node.Val[], mutFields: node.Val[], fieldsSig: FieldsSig, structs: Struct[]): NamedVals;
|
|
@@ -131,7 +132,7 @@ export interface ContractStateWithMaps<T extends Fields = Fields, M extends Reco
|
|
|
131
132
|
export type TestContractParamsWithoutMaps<F extends Fields = Fields, A extends Arguments = Arguments> = Omit<TestContractParams<F, A>, 'initialMaps'>;
|
|
132
133
|
export interface TestContractParams<F extends Fields = Fields, A extends Arguments = Arguments, M extends Record<string, Map<Val, Val>> = Record<string, Map<Val, Val>>> {
|
|
133
134
|
group?: number;
|
|
134
|
-
|
|
135
|
+
contractAddress?: string;
|
|
135
136
|
callerContractAddress?: string;
|
|
136
137
|
blockHash?: string;
|
|
137
138
|
blockTimeStamp?: number;
|
|
@@ -139,9 +140,10 @@ export interface TestContractParams<F extends Fields = Fields, A extends Argumen
|
|
|
139
140
|
initialFields: F;
|
|
140
141
|
initialMaps?: M;
|
|
141
142
|
initialAsset?: Asset;
|
|
142
|
-
|
|
143
|
+
args: A;
|
|
143
144
|
existingContracts?: ContractStateWithMaps[];
|
|
144
145
|
inputAssets?: InputAsset[];
|
|
146
|
+
dustAmount?: Number256;
|
|
145
147
|
}
|
|
146
148
|
export interface ContractEvent<T extends Fields = Fields> {
|
|
147
149
|
txId: string;
|
|
@@ -187,6 +189,7 @@ export interface DeployContractParams<P extends Fields = Fields> {
|
|
|
187
189
|
gasAmount?: number;
|
|
188
190
|
gasPrice?: Number256;
|
|
189
191
|
exposePrivateFunctions?: boolean;
|
|
192
|
+
group?: number;
|
|
190
193
|
}
|
|
191
194
|
export type DeployContractResult<T extends ContractInstance> = Omit<SignDeployContractTxResult, 'contractId' | 'contractAddress' | 'groupIndex'> & {
|
|
192
195
|
contractInstance: T;
|
|
@@ -203,11 +206,12 @@ export declare class ExecutableScript<P extends Fields = Fields, R extends Val |
|
|
|
203
206
|
readonly script: Script;
|
|
204
207
|
readonly getContractByCodeHash: (codeHash: string) => Contract;
|
|
205
208
|
constructor(script: Script, getContractByCodeHash: (codeHash: string) => Contract);
|
|
206
|
-
execute(
|
|
209
|
+
execute(params: ExecuteScriptParams<P>): Promise<ExecuteScriptResult>;
|
|
207
210
|
call(params: CallScriptParams<P>): Promise<CallScriptResult<R>>;
|
|
208
211
|
}
|
|
209
212
|
export interface ExecuteScriptParams<P extends Fields = Fields> {
|
|
210
213
|
initialFields: P;
|
|
214
|
+
signer: SignerProvider;
|
|
211
215
|
attoAlphAmount?: Number256;
|
|
212
216
|
tokens?: Token[];
|
|
213
217
|
gasAmount?: number;
|
|
@@ -220,6 +224,7 @@ export interface ExecuteScriptResult {
|
|
|
220
224
|
signature: string;
|
|
221
225
|
gasAmount: number;
|
|
222
226
|
gasPrice: Number256;
|
|
227
|
+
simulationResult: SimulationResult;
|
|
223
228
|
}
|
|
224
229
|
export interface CallScriptParams<P extends Fields = Fields> {
|
|
225
230
|
initialFields: P;
|
|
@@ -273,11 +278,11 @@ export declare function subscribeEventsFromContract<T extends Fields, M extends
|
|
|
273
278
|
export declare function addStdIdToFields<F extends Fields>(contract: Contract, fields: F): F | (F & {
|
|
274
279
|
__stdInterfaceId: HexString;
|
|
275
280
|
});
|
|
276
|
-
export declare function extractMapsFromApiResult(selfAddress: string, params: Optional<TestContractParams, '
|
|
281
|
+
export declare function extractMapsFromApiResult(selfAddress: string, params: Optional<TestContractParams, 'args' | 'initialFields'>, group: number, apiResult: node.TestContractResult, getContractByCodeHash: (codeHash: string) => Contract): {
|
|
277
282
|
address: string;
|
|
278
283
|
maps: Record<string, Map<Val, Val>>;
|
|
279
284
|
}[];
|
|
280
|
-
export declare function testMethod<I extends ContractInstance, F extends Fields, A extends Arguments, R, M extends Record<string, Map<Val, Val>> = Record<string, Map<Val, Val>>>(factory: ContractFactory<I, F>, methodName: string, params: Optional<TestContractParams<F, A, M>, '
|
|
285
|
+
export declare function testMethod<I extends ContractInstance, F extends Fields, A extends Arguments, R, M extends Record<string, Map<Val, Val>> = Record<string, Map<Val, Val>>>(factory: ContractFactory<I, F>, methodName: string, params: Optional<TestContractParams<F, A, M>, 'args' | 'initialFields'>, getContractByCodeHash: (codeHash: string) => Contract): Promise<TestContractResult<R, M>>;
|
|
281
286
|
export declare function getDebugMessagesFromTx(txId: HexString, provider?: NodeProvider): Promise<{
|
|
282
287
|
contractAddress: string;
|
|
283
288
|
message: string;
|
|
@@ -309,16 +309,17 @@ class Contract extends Artifact {
|
|
|
309
309
|
blockHash: params.blockHash,
|
|
310
310
|
blockTimeStamp: params.blockTimeStamp,
|
|
311
311
|
txId: params.txId,
|
|
312
|
-
address: params.
|
|
312
|
+
address: params.contractAddress,
|
|
313
313
|
callerContractAddress: params.callerContractAddress,
|
|
314
314
|
bytecode: this.isInlineFunc(methodIndex) ? this.getByteCodeForTesting() : this.bytecodeDebug,
|
|
315
315
|
initialImmFields: immFields,
|
|
316
316
|
initialMutFields: mutFields,
|
|
317
317
|
initialAsset: typeof params.initialAsset !== 'undefined' ? toApiAsset(params.initialAsset) : undefined,
|
|
318
318
|
methodIndex,
|
|
319
|
-
args: this.toApiArgs(funcName, params.
|
|
319
|
+
args: this.toApiArgs(funcName, params.args),
|
|
320
320
|
existingContracts: this.toApiContractStates(params.existingContracts),
|
|
321
|
-
inputAssets: toApiInputAssets(params.inputAssets)
|
|
321
|
+
inputAssets: toApiInputAssets(params.inputAssets),
|
|
322
|
+
dustAmount: params.dustAmount?.toString()
|
|
322
323
|
};
|
|
323
324
|
}
|
|
324
325
|
fromApiContractState(state) {
|
|
@@ -387,15 +388,13 @@ class Contract extends Artifact {
|
|
|
387
388
|
const initialFields = params.initialFields ?? {};
|
|
388
389
|
const bytecode = this.buildByteCodeToDeploy(addStdIdToFields(this, initialFields), isDevnet, params.exposePrivateFunctions ?? false);
|
|
389
390
|
const selectedAccount = await signer.getSelectedAccount();
|
|
390
|
-
|
|
391
|
-
if ((0, address_1.isGrouplessAddressWithoutGroupIndex)(selectedAccount.address)) {
|
|
391
|
+
if (selectedAccount.keyType === 'gl-secp256k1') {
|
|
392
392
|
if (group === undefined) {
|
|
393
393
|
throw new Error('Groupless address requires explicit group number for contract deployment');
|
|
394
394
|
}
|
|
395
|
-
signerAddress = `${selectedAccount.address}:${group}`;
|
|
396
395
|
}
|
|
397
396
|
const signerParams = {
|
|
398
|
-
signerAddress,
|
|
397
|
+
signerAddress: selectedAccount.address,
|
|
399
398
|
signerKeyType: selectedAccount.keyType,
|
|
400
399
|
bytecode: bytecode,
|
|
401
400
|
initialAttoAlphAmount: params?.initialAttoAlphAmount,
|
|
@@ -403,7 +402,8 @@ class Contract extends Artifact {
|
|
|
403
402
|
issueTokenTo: params?.issueTokenTo,
|
|
404
403
|
initialTokenAmounts: params?.initialTokenAmounts,
|
|
405
404
|
gasAmount: params?.gasAmount,
|
|
406
|
-
gasPrice: params?.gasPrice
|
|
405
|
+
gasPrice: params?.gasPrice,
|
|
406
|
+
group: group
|
|
407
407
|
};
|
|
408
408
|
return signerParams;
|
|
409
409
|
}
|
|
@@ -519,8 +519,8 @@ class Script extends Artifact {
|
|
|
519
519
|
};
|
|
520
520
|
return JSON.stringify(object, null, 2);
|
|
521
521
|
}
|
|
522
|
-
async txParamsForExecution(
|
|
523
|
-
const selectedAccount = await signer.getSelectedAccount();
|
|
522
|
+
async txParamsForExecution(params) {
|
|
523
|
+
const selectedAccount = await params.signer.getSelectedAccount();
|
|
524
524
|
const signerParams = {
|
|
525
525
|
signerAddress: selectedAccount.address,
|
|
526
526
|
signerKeyType: selectedAccount.keyType,
|
|
@@ -691,10 +691,18 @@ class ContractFactory {
|
|
|
691
691
|
initialFields: addStdIdToFields(this.contract, deployParams.initialFields)
|
|
692
692
|
}, group);
|
|
693
693
|
const result = await signer.signAndSubmitDeployContractTx(signerParams);
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
694
|
+
if ('transferTxs' in result) {
|
|
695
|
+
return {
|
|
696
|
+
...result.tx,
|
|
697
|
+
contractInstance: this.at(result.tx.contractAddress)
|
|
698
|
+
};
|
|
699
|
+
}
|
|
700
|
+
else {
|
|
701
|
+
return {
|
|
702
|
+
...result,
|
|
703
|
+
contractInstance: this.at(result.contractAddress)
|
|
704
|
+
};
|
|
705
|
+
}
|
|
698
706
|
}
|
|
699
707
|
async deployTemplate(signer) {
|
|
700
708
|
return this.deploy(signer, {
|
|
@@ -722,9 +730,15 @@ class ExecutableScript {
|
|
|
722
730
|
this.script = script;
|
|
723
731
|
this.getContractByCodeHash = getContractByCodeHash;
|
|
724
732
|
}
|
|
725
|
-
async execute(
|
|
726
|
-
const signerParams = await this.script.txParamsForExecution(
|
|
727
|
-
|
|
733
|
+
async execute(params) {
|
|
734
|
+
const signerParams = await this.script.txParamsForExecution(params);
|
|
735
|
+
const result = await params.signer.signAndSubmitExecuteScriptTx(signerParams);
|
|
736
|
+
if ('transferTxs' in result) {
|
|
737
|
+
return result.tx;
|
|
738
|
+
}
|
|
739
|
+
else {
|
|
740
|
+
return result;
|
|
741
|
+
}
|
|
728
742
|
}
|
|
729
743
|
async call(params) {
|
|
730
744
|
const mainFunc = this.script.functions.find((f) => f.name === 'main');
|
|
@@ -971,16 +985,16 @@ exports.extractMapsFromApiResult = extractMapsFromApiResult;
|
|
|
971
985
|
async function testMethod(factory, methodName, params, getContractByCodeHash) {
|
|
972
986
|
const txId = params?.txId ?? randomTxId();
|
|
973
987
|
const selfContract = factory.contract;
|
|
974
|
-
const selfAddress = params.
|
|
988
|
+
const selfAddress = params.contractAddress ?? (0, address_1.addressFromContractId)((0, utils_1.binToHex)(crypto.getRandomValues(new Uint8Array(32))));
|
|
975
989
|
const selfContractId = (0, utils_1.binToHex)((0, address_1.contractIdFromAddress)(selfAddress));
|
|
976
990
|
const group = params.group ?? 0;
|
|
977
991
|
const existingContracts = getTestExistingContracts(selfContract, selfContractId, group, params, getContractByCodeHash);
|
|
978
992
|
const apiParams = selfContract.toApiTestContractParams(methodName, {
|
|
979
993
|
...params,
|
|
980
|
-
|
|
994
|
+
contractAddress: selfAddress,
|
|
981
995
|
txId: txId,
|
|
982
996
|
initialFields: addStdIdToFields(selfContract, params.initialFields ?? {}),
|
|
983
|
-
|
|
997
|
+
args: params.args === undefined ? {} : params.args,
|
|
984
998
|
existingContracts
|
|
985
999
|
});
|
|
986
1000
|
const apiResult = await (0, global_1.getCurrentNodeProvider)().contracts.postContractsTestContract(apiParams);
|
|
@@ -1258,7 +1272,7 @@ async function signExecuteMethod(contract, instance, methodName, params) {
|
|
|
1258
1272
|
gasAmount: params.gasAmount,
|
|
1259
1273
|
gasPrice: params.gasPrice
|
|
1260
1274
|
};
|
|
1261
|
-
const result = await signer.signAndSubmitExecuteScriptTx(signerParams);
|
|
1275
|
+
const result = (await signer.signAndSubmitExecuteScriptTx(signerParams));
|
|
1262
1276
|
if ((0, debug_1.isContractDebugMessageEnabled)() && isDevnet) {
|
|
1263
1277
|
await printDebugMessagesFromTx(result.txId, signer.nodeProvider);
|
|
1264
1278
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { SimulationResult } from '../api/api-alephium';
|
|
1
2
|
import { ContractInstance } from './contract';
|
|
2
3
|
export interface ExecutionResult {
|
|
3
4
|
txId: string;
|
|
@@ -16,4 +17,5 @@ export interface DeployContractExecutionResult<I extends ContractInstance = Cont
|
|
|
16
17
|
}
|
|
17
18
|
export interface RunScriptResult extends ExecutionResult {
|
|
18
19
|
groupIndex: number;
|
|
20
|
+
simulationResult: SimulationResult;
|
|
19
21
|
}
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { ExplorerProvider, NodeProvider } from '../api';
|
|
2
2
|
import { node } from '../api';
|
|
3
|
-
import { Account, EnableOptionsBase, Destination, SignDeployContractTxParams, SignDeployContractTxResult, SignExecuteScriptTxParams, SignExecuteScriptTxResult, SignMessageParams, SignMessageResult, SignTransferTxParams, SignTransferTxResult, SignUnsignedTxParams, SignUnsignedTxResult, SubmissionResult, SubmitTransactionParams, KeyType, MessageHasher, SignChainedTxParams, SignChainedTxResult } from './types';
|
|
3
|
+
import { Account, EnableOptionsBase, Destination, SignDeployContractTxParams, SignDeployContractTxResult, SignExecuteScriptTxParams, SignExecuteScriptTxResult, SignMessageParams, SignMessageResult, SignTransferTxParams, SignTransferTxResult, SignUnsignedTxParams, SignUnsignedTxResult, SubmissionResult, SubmitTransactionParams, KeyType, MessageHasher, SignChainedTxParams, SignChainedTxResult, BuildTxResult, SignTxResult } from './types';
|
|
4
4
|
export declare abstract class SignerProvider {
|
|
5
5
|
abstract get nodeProvider(): NodeProvider | undefined;
|
|
6
6
|
abstract get explorerProvider(): ExplorerProvider | undefined;
|
|
7
7
|
protected abstract unsafeGetSelectedAccount(): Promise<Account>;
|
|
8
8
|
getSelectedAccount(): Promise<Account>;
|
|
9
9
|
static validateAccount(account: Account): void;
|
|
10
|
-
abstract signAndSubmitTransferTx(params: SignTransferTxParams): Promise<SignTransferTxResult
|
|
11
|
-
abstract signAndSubmitDeployContractTx(params: SignDeployContractTxParams): Promise<SignDeployContractTxResult
|
|
12
|
-
abstract signAndSubmitExecuteScriptTx(params: SignExecuteScriptTxParams): Promise<SignExecuteScriptTxResult
|
|
10
|
+
abstract signAndSubmitTransferTx(params: SignTransferTxParams): Promise<SignTxResult<SignTransferTxResult>>;
|
|
11
|
+
abstract signAndSubmitDeployContractTx(params: SignDeployContractTxParams): Promise<SignTxResult<SignDeployContractTxResult>>;
|
|
12
|
+
abstract signAndSubmitExecuteScriptTx(params: SignExecuteScriptTxParams): Promise<SignTxResult<SignExecuteScriptTxResult>>;
|
|
13
13
|
abstract signAndSubmitUnsignedTx(params: SignUnsignedTxParams): Promise<SignUnsignedTxResult>;
|
|
14
14
|
abstract signAndSubmitChainedTx(params: SignChainedTxParams[]): Promise<SignChainedTxResult[]>;
|
|
15
15
|
abstract signUnsignedTx(params: SignUnsignedTxParams): Promise<SignUnsignedTxResult>;
|
|
@@ -23,18 +23,18 @@ export declare abstract class InteractiveSignerProvider<EnableOptions extends En
|
|
|
23
23
|
export declare abstract class SignerProviderSimple extends SignerProvider {
|
|
24
24
|
abstract get nodeProvider(): NodeProvider;
|
|
25
25
|
submitTransaction(params: SubmitTransactionParams): Promise<SubmissionResult>;
|
|
26
|
-
signAndSubmitTransferTx(params: SignTransferTxParams): Promise<SignTransferTxResult
|
|
27
|
-
signAndSubmitDeployContractTx(params: SignDeployContractTxParams): Promise<SignDeployContractTxResult
|
|
28
|
-
signAndSubmitExecuteScriptTx(params: SignExecuteScriptTxParams): Promise<SignExecuteScriptTxResult
|
|
26
|
+
signAndSubmitTransferTx(params: SignTransferTxParams): Promise<SignTxResult<SignTransferTxResult>>;
|
|
27
|
+
signAndSubmitDeployContractTx(params: SignDeployContractTxParams): Promise<SignTxResult<SignDeployContractTxResult>>;
|
|
28
|
+
signAndSubmitExecuteScriptTx(params: SignExecuteScriptTxParams): Promise<SignTxResult<SignExecuteScriptTxResult>>;
|
|
29
29
|
signAndSubmitUnsignedTx(params: SignUnsignedTxParams): Promise<SignUnsignedTxResult>;
|
|
30
30
|
signAndSubmitChainedTx(params: SignChainedTxParams[]): Promise<SignChainedTxResult[]>;
|
|
31
31
|
protected abstract getPublicKey(address: string): Promise<string>;
|
|
32
|
-
signTransferTx(params: SignTransferTxParams): Promise<SignTransferTxResult
|
|
33
|
-
buildTransferTx(params: SignTransferTxParams): Promise<
|
|
34
|
-
signDeployContractTx(params: SignDeployContractTxParams): Promise<SignDeployContractTxResult
|
|
35
|
-
buildDeployContractTx(params: SignDeployContractTxParams): Promise<
|
|
36
|
-
signExecuteScriptTx(params: SignExecuteScriptTxParams): Promise<SignExecuteScriptTxResult
|
|
37
|
-
buildExecuteScriptTx(params: SignExecuteScriptTxParams): Promise<
|
|
32
|
+
signTransferTx(params: SignTransferTxParams): Promise<SignTxResult<SignTransferTxResult>>;
|
|
33
|
+
buildTransferTx(params: SignTransferTxParams): Promise<BuildTxResult<SignTransferTxResult>>;
|
|
34
|
+
signDeployContractTx(params: SignDeployContractTxParams): Promise<SignTxResult<SignDeployContractTxResult>>;
|
|
35
|
+
buildDeployContractTx(params: SignDeployContractTxParams): Promise<BuildTxResult<SignDeployContractTxResult>>;
|
|
36
|
+
signExecuteScriptTx(params: SignExecuteScriptTxParams): Promise<SignTxResult<SignExecuteScriptTxResult>>;
|
|
37
|
+
buildExecuteScriptTx(params: SignExecuteScriptTxParams): Promise<BuildTxResult<SignExecuteScriptTxResult>>;
|
|
38
38
|
signChainedTx(params: SignChainedTxParams[]): Promise<SignChainedTxResult[]>;
|
|
39
39
|
buildChainedTx(params: SignChainedTxParams[]): Promise<Omit<SignChainedTxResult, 'signature'>[]>;
|
|
40
40
|
signUnsignedTx(params: SignUnsignedTxParams): Promise<SignUnsignedTxResult>;
|
|
@@ -81,17 +81,41 @@ class SignerProviderSimple extends SignerProvider {
|
|
|
81
81
|
}
|
|
82
82
|
async signAndSubmitTransferTx(params) {
|
|
83
83
|
const signResult = await this.signTransferTx(params);
|
|
84
|
-
|
|
84
|
+
if ('transferTxs' in signResult) {
|
|
85
|
+
for (const r of signResult.transferTxs) {
|
|
86
|
+
await this.submitTransaction(r);
|
|
87
|
+
}
|
|
88
|
+
await this.submitTransaction(signResult.tx);
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
await this.submitTransaction(signResult);
|
|
92
|
+
}
|
|
85
93
|
return signResult;
|
|
86
94
|
}
|
|
87
95
|
async signAndSubmitDeployContractTx(params) {
|
|
88
96
|
const signResult = await this.signDeployContractTx(params);
|
|
89
|
-
|
|
97
|
+
if ('transferTxs' in signResult) {
|
|
98
|
+
for (const r of signResult.transferTxs) {
|
|
99
|
+
await this.submitTransaction(r);
|
|
100
|
+
}
|
|
101
|
+
await this.submitTransaction(signResult.tx);
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
await this.submitTransaction(signResult);
|
|
105
|
+
}
|
|
90
106
|
return signResult;
|
|
91
107
|
}
|
|
92
108
|
async signAndSubmitExecuteScriptTx(params) {
|
|
93
109
|
const signResult = await this.signExecuteScriptTx(params);
|
|
94
|
-
|
|
110
|
+
if ('transferTxs' in signResult) {
|
|
111
|
+
for (const r of signResult.transferTxs) {
|
|
112
|
+
await this.submitTransaction(r);
|
|
113
|
+
}
|
|
114
|
+
await this.submitTransaction(signResult.tx);
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
await this.submitTransaction(signResult);
|
|
118
|
+
}
|
|
95
119
|
return signResult;
|
|
96
120
|
}
|
|
97
121
|
async signAndSubmitUnsignedTx(params) {
|
|
@@ -108,24 +132,75 @@ class SignerProviderSimple extends SignerProvider {
|
|
|
108
132
|
}
|
|
109
133
|
async signTransferTx(params) {
|
|
110
134
|
const response = await this.buildTransferTx(params);
|
|
111
|
-
|
|
112
|
-
|
|
135
|
+
if ('transferTxs' in response) {
|
|
136
|
+
const transferTxs = [];
|
|
137
|
+
for (let i = 0; i < response.transferTxs.length; i++) {
|
|
138
|
+
const txSignature = await this.signRaw(params.signerAddress, response.transferTxs[i].txId);
|
|
139
|
+
transferTxs.push({
|
|
140
|
+
...response.transferTxs[i],
|
|
141
|
+
signature: txSignature
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
const signature = await this.signRaw(params.signerAddress, response.tx.txId);
|
|
145
|
+
return {
|
|
146
|
+
transferTxs,
|
|
147
|
+
tx: { ...response.tx, signature }
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
const signature = await this.signRaw(params.signerAddress, response.txId);
|
|
152
|
+
return { signature, ...response };
|
|
153
|
+
}
|
|
113
154
|
}
|
|
114
155
|
async buildTransferTx(params) {
|
|
115
156
|
return tx_builder_1.TransactionBuilder.from(this.nodeProvider).buildTransferTx(params, await this.getPublicKey(params.signerAddress));
|
|
116
157
|
}
|
|
117
158
|
async signDeployContractTx(params) {
|
|
118
159
|
const response = await this.buildDeployContractTx(params);
|
|
119
|
-
|
|
120
|
-
|
|
160
|
+
if ('transferTxs' in response) {
|
|
161
|
+
const transferTxs = [];
|
|
162
|
+
for (let i = 0; i < response.transferTxs.length; i++) {
|
|
163
|
+
const txSignature = await this.signRaw(params.signerAddress, response.transferTxs[i].txId);
|
|
164
|
+
transferTxs.push({
|
|
165
|
+
...response.transferTxs[i],
|
|
166
|
+
signature: txSignature
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
const signature = await this.signRaw(params.signerAddress, response.tx.txId);
|
|
170
|
+
return {
|
|
171
|
+
transferTxs,
|
|
172
|
+
tx: { ...response.tx, signature }
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
else {
|
|
176
|
+
const signature = await this.signRaw(params.signerAddress, response.txId);
|
|
177
|
+
return { signature, ...response };
|
|
178
|
+
}
|
|
121
179
|
}
|
|
122
180
|
async buildDeployContractTx(params) {
|
|
123
181
|
return tx_builder_1.TransactionBuilder.from(this.nodeProvider).buildDeployContractTx(params, await this.getPublicKey(params.signerAddress));
|
|
124
182
|
}
|
|
125
183
|
async signExecuteScriptTx(params) {
|
|
126
184
|
const response = await this.buildExecuteScriptTx(params);
|
|
127
|
-
|
|
128
|
-
|
|
185
|
+
if ('transferTxs' in response) {
|
|
186
|
+
const transferTxs = [];
|
|
187
|
+
for (let i = 0; i < response.transferTxs.length; i++) {
|
|
188
|
+
const txSignature = await this.signRaw(params.signerAddress, response.transferTxs[i].txId);
|
|
189
|
+
transferTxs.push({
|
|
190
|
+
...response.transferTxs[i],
|
|
191
|
+
signature: txSignature
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
const signature = await this.signRaw(params.signerAddress, response.tx.txId);
|
|
195
|
+
return {
|
|
196
|
+
transferTxs,
|
|
197
|
+
tx: { ...response.tx, signature }
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
else {
|
|
201
|
+
const signature = await this.signRaw(params.signerAddress, response.txId);
|
|
202
|
+
return { signature, ...response };
|
|
203
|
+
}
|
|
129
204
|
}
|
|
130
205
|
async buildExecuteScriptTx(params) {
|
|
131
206
|
return tx_builder_1.TransactionBuilder.from(this.nodeProvider).buildExecuteScriptTx(params, await this.getPublicKey(params.signerAddress));
|
|
@@ -1,22 +1,16 @@
|
|
|
1
1
|
import { NodeProvider } from '../api';
|
|
2
|
-
import { SignChainedTxParams, SignChainedTxResult, SignDeployContractTxParams, SignDeployContractTxResult, SignExecuteScriptTxParams, SignExecuteScriptTxResult, SignTransferTxParams, SignTransferTxResult, SignUnsignedTxParams, SignUnsignedTxResult,
|
|
2
|
+
import { SignChainedTxParams, SignChainedTxResult, SignDeployContractTxParams, SignDeployContractTxResult, SignExecuteScriptTxParams, SignExecuteScriptTxResult, SignTransferTxParams, SignTransferTxResult, SignUnsignedTxParams, SignUnsignedTxResult, BuildTxResult } from './types';
|
|
3
3
|
export declare abstract class TransactionBuilder {
|
|
4
4
|
abstract get nodeProvider(): NodeProvider;
|
|
5
5
|
static from(nodeProvider: NodeProvider): TransactionBuilder;
|
|
6
6
|
static from(baseUrl: string, apiKey?: string, customFetch?: typeof fetch): TransactionBuilder;
|
|
7
7
|
private static validatePublicKey;
|
|
8
|
-
buildTransferTx(params: SignTransferTxParams, publicKey: string): Promise<
|
|
9
|
-
buildDeployContractTx(params: SignDeployContractTxParams, publicKey: string): Promise<
|
|
10
|
-
buildExecuteScriptTx(params: SignExecuteScriptTxParams, publicKey: string): Promise<
|
|
8
|
+
buildTransferTx(params: SignTransferTxParams, publicKey: string): Promise<BuildTxResult<SignTransferTxResult>>;
|
|
9
|
+
buildDeployContractTx(params: SignDeployContractTxParams, publicKey: string): Promise<BuildTxResult<SignDeployContractTxResult>>;
|
|
10
|
+
buildExecuteScriptTx(params: SignExecuteScriptTxParams, publicKey: string): Promise<BuildTxResult<SignExecuteScriptTxResult>>;
|
|
11
11
|
buildChainedTx(params: SignChainedTxParams[], publicKeys: string[]): Promise<Omit<SignChainedTxResult, 'signature'>[]>;
|
|
12
|
-
buildGrouplessTransferTx(params: SignGrouplessTransferTxParams): Promise<Omit<SignChainedTxResult, 'signature'>[]>;
|
|
13
|
-
buildGrouplessDeployContractTx(params: SignGrouplessDeployContractTxParams): Promise<Omit<SignChainedTxResult, 'signature'>[]>;
|
|
14
|
-
buildGrouplessExecuteScriptTx(params: SignGrouplessExecuteScriptTxParams): Promise<Omit<SignChainedTxResult, 'signature'>[]>;
|
|
15
12
|
static buildUnsignedTx(params: SignUnsignedTxParams): Omit<SignUnsignedTxResult, 'signature'>;
|
|
16
13
|
private buildTransferTxParams;
|
|
17
|
-
private buildGrouplessTransferTxParams;
|
|
18
|
-
private buildGrouplessDeployContractTxParams;
|
|
19
|
-
private buildGrouplessExecuteScriptTxParams;
|
|
20
14
|
private buildDeployContractTxParams;
|
|
21
15
|
private buildExecuteScriptTxParams;
|
|
22
16
|
private convertTransferTxResult;
|