@alephium/web3 1.9.0 → 1.10.0
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 +25 -6
- package/dist/src/api/api-alephium.js +33 -4
- package/dist/src/api/api-explorer.d.ts +810 -819
- package/dist/src/api/api-explorer.js +350 -360
- package/dist/src/codec/unlock-script-codec.d.ts +1 -0
- package/dist/src/codec/unlock-script-codec.js +2 -1
- package/dist/src/contract/contract.d.ts +5 -1
- package/dist/src/contract/contract.js +44 -8
- package/dist/src/contract/events.d.ts +1 -0
- package/dist/src/contract/events.js +14 -3
- package/dist/src/exchange/exchange.d.ts +13 -2
- package/dist/src/exchange/exchange.js +52 -14
- package/dist/src/exchange/index.d.ts +1 -1
- package/dist/src/exchange/index.js +3 -2
- package/dist/src/signer/types.d.ts +1 -0
- package/package.json +3 -3
- package/src/api/api-alephium.ts +49 -9
- package/src/api/api-explorer.ts +990 -1000
- package/src/codec/unlock-script-codec.ts +2 -0
- package/src/contract/contract.ts +46 -7
- package/src/contract/events.ts +15 -3
- package/src/exchange/exchange.ts +69 -17
- package/src/exchange/index.ts +10 -1
- package/src/signer/tx-builder.ts +2 -2
- package/src/signer/types.ts +1 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.unlockScriptCodec = void 0;
|
|
3
|
+
exports.encodedSameAsPrevious = exports.unlockScriptCodec = void 0;
|
|
4
4
|
/*
|
|
5
5
|
Copyright 2018 - 2022 The Alephium Authors
|
|
6
6
|
This file is part of the alephium project.
|
|
@@ -47,3 +47,4 @@ exports.unlockScriptCodec = new codec_1.EnumCodec('unlock script', {
|
|
|
47
47
|
P2SH: p2shCodec,
|
|
48
48
|
SameAsPrevious: sameAsPreviousCodec
|
|
49
49
|
});
|
|
50
|
+
exports.encodedSameAsPrevious = exports.unlockScriptCodec.encode({ kind: 'SameAsPrevious', value: 'SameAsPrevious' });
|
|
@@ -50,15 +50,18 @@ export declare class Contract extends Artifact {
|
|
|
50
50
|
readonly codeHashDebug: string;
|
|
51
51
|
readonly decodedContract: contract.Contract;
|
|
52
52
|
private bytecodeForTesting;
|
|
53
|
+
private decodedTestingContract;
|
|
53
54
|
private codeHashForTesting;
|
|
54
55
|
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[], mapsSig?: MapsSig, stdInterfaceId?: HexString);
|
|
56
|
+
isInlineFunc(index: number): boolean;
|
|
55
57
|
getByteCodeForTesting(): string;
|
|
58
|
+
getDecodedTestingContract(): contract.Contract;
|
|
56
59
|
hasCodeHash(hash: string): boolean;
|
|
57
60
|
getDecodedMethod(methodIndex: number): Method;
|
|
58
61
|
publicFunctions(): FunctionSig[];
|
|
59
62
|
usingPreapprovedAssetsFunctions(): FunctionSig[];
|
|
60
63
|
usingAssetsInContractFunctions(): FunctionSig[];
|
|
61
|
-
isMethodUsePreapprovedAssets(methodIndex: number): boolean;
|
|
64
|
+
isMethodUsePreapprovedAssets(isDevnet: boolean, methodIndex: number): boolean;
|
|
62
65
|
static fromJson(artifact: any, bytecodeDebugPatch?: string, codeHashDebug?: string, structs?: Struct[]): Contract;
|
|
63
66
|
static fromCompileResult(result: node.CompileContractResult, structs?: Struct[]): Contract;
|
|
64
67
|
static fromArtifactFile(path: string, bytecodeDebugPatch: string, codeHashDebug: string, structs?: Struct[]): Promise<Contract>;
|
|
@@ -314,4 +317,5 @@ export declare function multicallMethods<I extends ContractInstance, F extends F
|
|
|
314
317
|
export declare function getContractEventsCurrentCount(contractAddress: Address): Promise<number>;
|
|
315
318
|
export declare const getContractIdFromUnsignedTx: (nodeProvider: NodeProvider, unsignedTx: string) => Promise<HexString>;
|
|
316
319
|
export declare const getTokenIdFromUnsignedTx: (nodeProvider: NodeProvider, unsignedTx: string) => Promise<HexString>;
|
|
320
|
+
export declare function getContractCodeByCodeHash(nodeProvider: NodeProvider, codeHash: HexString): Promise<HexString | undefined>;
|
|
317
321
|
export {};
|
|
@@ -40,7 +40,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
40
40
|
return result;
|
|
41
41
|
};
|
|
42
42
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
43
|
-
exports.getTokenIdFromUnsignedTx = exports.getContractIdFromUnsignedTx = exports.getContractEventsCurrentCount = exports.multicallMethods = exports.signExecuteMethod = exports.callMethod = exports.subscribeContractEvents = exports.subscribeContractEvent = exports.decodeEvent = exports.subscribeContractDestroyedEvent = exports.subscribeContractCreatedEvent = exports.fetchContractState = exports.ContractInstance = exports.getMapItem = exports.RalphMap = exports.printDebugMessagesFromTx = exports.getDebugMessagesFromTx = exports.testMethod = exports.extractMapsFromApiResult = exports.addStdIdToFields = exports.subscribeEventsFromContract = exports.decodeContractDestroyedEvent = exports.decodeContractCreatedEvent = exports.DestroyContractEventAddresses = exports.CreateContractEventAddresses = exports.ExecutableScript = exports.ContractFactory = exports.randomTxId = exports.fromApiEventFields = exports.fromApiArray = exports.getDefaultValue = exports.fromApiFields = exports.Script = exports.Contract = exports.Artifact = exports.Struct = exports.DEFAULT_COMPILER_OPTIONS = exports.DEFAULT_NODE_COMPILER_OPTIONS = exports.StdIdFieldName = void 0;
|
|
43
|
+
exports.getContractCodeByCodeHash = exports.getTokenIdFromUnsignedTx = exports.getContractIdFromUnsignedTx = exports.getContractEventsCurrentCount = exports.multicallMethods = exports.signExecuteMethod = exports.callMethod = exports.subscribeContractEvents = exports.subscribeContractEvent = exports.decodeEvent = exports.subscribeContractDestroyedEvent = exports.subscribeContractCreatedEvent = exports.fetchContractState = exports.ContractInstance = exports.getMapItem = exports.RalphMap = exports.printDebugMessagesFromTx = exports.getDebugMessagesFromTx = exports.testMethod = exports.extractMapsFromApiResult = exports.addStdIdToFields = exports.subscribeEventsFromContract = exports.decodeContractDestroyedEvent = exports.decodeContractCreatedEvent = exports.DestroyContractEventAddresses = exports.CreateContractEventAddresses = exports.ExecutableScript = exports.ContractFactory = exports.randomTxId = exports.fromApiEventFields = exports.fromApiArray = exports.getDefaultValue = exports.fromApiFields = exports.Script = exports.Contract = exports.Artifact = exports.Struct = exports.DEFAULT_COMPILER_OPTIONS = exports.DEFAULT_NODE_COMPILER_OPTIONS = exports.StdIdFieldName = void 0;
|
|
44
44
|
const fs_1 = require("fs");
|
|
45
45
|
const api_1 = require("../api");
|
|
46
46
|
const ralph = __importStar(require("./ralph"));
|
|
@@ -133,12 +133,21 @@ class Contract extends Artifact {
|
|
|
133
133
|
this.codeHashDebug = codeHashDebug;
|
|
134
134
|
this.decodedContract = codec_1.contract.contractCodec.decodeContract((0, utils_1.hexToBinUnsafe)(this.bytecode));
|
|
135
135
|
this.bytecodeForTesting = undefined;
|
|
136
|
+
this.decodedTestingContract = undefined;
|
|
136
137
|
this.codeHashForTesting = undefined;
|
|
137
138
|
}
|
|
139
|
+
isInlineFunc(index) {
|
|
140
|
+
if (index >= this.functions.length) {
|
|
141
|
+
throw new Error(`Invalid function index ${index}, function size: ${this.functions.length}`);
|
|
142
|
+
}
|
|
143
|
+
const inlineFuncFromIndex = this.decodedContract.methods.length;
|
|
144
|
+
return index >= inlineFuncFromIndex;
|
|
145
|
+
}
|
|
138
146
|
getByteCodeForTesting() {
|
|
139
147
|
if (this.bytecodeForTesting !== undefined)
|
|
140
148
|
return this.bytecodeForTesting;
|
|
141
|
-
|
|
149
|
+
const hasInlineFunction = this.functions.length > this.decodedContract.methods.length;
|
|
150
|
+
if (!hasInlineFunction && this.publicFunctions().length == this.functions.length) {
|
|
142
151
|
this.bytecodeForTesting = this.bytecodeDebug;
|
|
143
152
|
this.codeHashForTesting = this.codeHashDebug;
|
|
144
153
|
return this.bytecodeForTesting;
|
|
@@ -154,6 +163,13 @@ class Contract extends Artifact {
|
|
|
154
163
|
this.codeHashForTesting = (0, utils_1.binToHex)(codeHashForTesting);
|
|
155
164
|
return this.bytecodeForTesting;
|
|
156
165
|
}
|
|
166
|
+
getDecodedTestingContract() {
|
|
167
|
+
if (this.decodedTestingContract !== undefined)
|
|
168
|
+
return this.decodedTestingContract;
|
|
169
|
+
const bytecodeForTesting = (0, utils_1.hexToBinUnsafe)(this.getByteCodeForTesting());
|
|
170
|
+
this.decodedTestingContract = codec_1.contract.contractCodec.decodeContract(bytecodeForTesting);
|
|
171
|
+
return this.decodedTestingContract;
|
|
172
|
+
}
|
|
157
173
|
hasCodeHash(hash) {
|
|
158
174
|
return this.codeHash === hash || this.codeHashDebug === hash || this.codeHashForTesting === hash;
|
|
159
175
|
}
|
|
@@ -169,8 +185,11 @@ class Contract extends Artifact {
|
|
|
169
185
|
usingAssetsInContractFunctions() {
|
|
170
186
|
return this.functions.filter((_, index) => this.getDecodedMethod(index).useContractAssets);
|
|
171
187
|
}
|
|
172
|
-
isMethodUsePreapprovedAssets(methodIndex) {
|
|
173
|
-
|
|
188
|
+
isMethodUsePreapprovedAssets(isDevnet, methodIndex) {
|
|
189
|
+
if (!isDevnet || !this.isInlineFunc(methodIndex))
|
|
190
|
+
return this.getDecodedMethod(methodIndex).usePreapprovedAssets;
|
|
191
|
+
const contract = this.getDecodedTestingContract();
|
|
192
|
+
return contract.methods[`${methodIndex}`].usePreapprovedAssets;
|
|
174
193
|
}
|
|
175
194
|
// TODO: safely parse json
|
|
176
195
|
static fromJson(artifact, bytecodeDebugPatch = '', codeHashDebug = '', structs = []) {
|
|
@@ -284,6 +303,7 @@ class Contract extends Artifact {
|
|
|
284
303
|
: ralph.flattenFields(params.initialFields, this.fieldsSig.names, this.fieldsSig.types, this.fieldsSig.isMutable, this.structs);
|
|
285
304
|
const immFields = allFields.filter((f) => !f.isMutable).map((f) => (0, api_1.toApiVal)(f.value, f.type));
|
|
286
305
|
const mutFields = allFields.filter((f) => f.isMutable).map((f) => (0, api_1.toApiVal)(f.value, f.type));
|
|
306
|
+
const methodIndex = this.getMethodIndex(funcName);
|
|
287
307
|
return {
|
|
288
308
|
group: params.group,
|
|
289
309
|
blockHash: params.blockHash,
|
|
@@ -291,11 +311,11 @@ class Contract extends Artifact {
|
|
|
291
311
|
txId: params.txId,
|
|
292
312
|
address: params.address,
|
|
293
313
|
callerAddress: params.callerAddress,
|
|
294
|
-
bytecode: this.bytecodeDebug,
|
|
314
|
+
bytecode: this.isInlineFunc(methodIndex) ? this.getByteCodeForTesting() : this.bytecodeDebug,
|
|
295
315
|
initialImmFields: immFields,
|
|
296
316
|
initialMutFields: mutFields,
|
|
297
317
|
initialAsset: typeof params.initialAsset !== 'undefined' ? toApiAsset(params.initialAsset) : undefined,
|
|
298
|
-
methodIndex
|
|
318
|
+
methodIndex,
|
|
299
319
|
args: this.toApiArgs(funcName, params.testArgs),
|
|
300
320
|
existingContracts: this.toApiContractStates(params.existingContracts),
|
|
301
321
|
inputAssets: toApiInputAssets(params.inputAssets)
|
|
@@ -1190,7 +1210,8 @@ exports.callMethod = callMethod;
|
|
|
1190
1210
|
async function signExecuteMethod(contract, instance, methodName, params) {
|
|
1191
1211
|
const methodIndex = contract.contract.getMethodIndex(methodName);
|
|
1192
1212
|
const functionSig = contract.contract.functions[methodIndex];
|
|
1193
|
-
const
|
|
1213
|
+
const isDevnet = await contract.contract.isDevnet(params.signer);
|
|
1214
|
+
const methodUsePreapprovedAssets = contract.contract.isMethodUsePreapprovedAssets(isDevnet, methodIndex);
|
|
1194
1215
|
const bytecodeTemplate = getBytecodeTemplate(methodIndex, methodUsePreapprovedAssets, functionSig, contract.contract.structs, params.attoAlphAmount, params.tokens);
|
|
1195
1216
|
const fieldsSig = toFieldsSig(contract.contract.name, functionSig);
|
|
1196
1217
|
const bytecode = ralph.buildScriptByteCode(bytecodeTemplate, { __contract__: instance.contractId, ...params.args }, fieldsSig, contract.contract.structs);
|
|
@@ -1206,7 +1227,7 @@ async function signExecuteMethod(contract, instance, methodName, params) {
|
|
|
1206
1227
|
gasPrice: params.gasPrice
|
|
1207
1228
|
};
|
|
1208
1229
|
const result = await signer.signAndSubmitExecuteScriptTx(signerParams);
|
|
1209
|
-
if ((0, debug_1.isContractDebugMessageEnabled)() &&
|
|
1230
|
+
if ((0, debug_1.isContractDebugMessageEnabled)() && isDevnet) {
|
|
1210
1231
|
await printDebugMessagesFromTx(result.txId, signer.nodeProvider);
|
|
1211
1232
|
}
|
|
1212
1233
|
return result;
|
|
@@ -1418,3 +1439,18 @@ const getContractIdFromUnsignedTx = async (nodeProvider, unsignedTx) => {
|
|
|
1418
1439
|
exports.getContractIdFromUnsignedTx = getContractIdFromUnsignedTx;
|
|
1419
1440
|
// This function only works in the simple case where a single non-subcontract is created in the tx
|
|
1420
1441
|
exports.getTokenIdFromUnsignedTx = exports.getContractIdFromUnsignedTx;
|
|
1442
|
+
async function getContractCodeByCodeHash(nodeProvider, codeHash) {
|
|
1443
|
+
if ((0, utils_1.isHexString)(codeHash) && codeHash.length === 64) {
|
|
1444
|
+
try {
|
|
1445
|
+
return await nodeProvider.contracts.getContractsCodehashCode(codeHash);
|
|
1446
|
+
}
|
|
1447
|
+
catch (error) {
|
|
1448
|
+
if (error instanceof Error && error.message.includes('not found')) {
|
|
1449
|
+
return undefined;
|
|
1450
|
+
}
|
|
1451
|
+
throw new error_1.TraceableError(`Failed to get contract by code hash ${codeHash}`, error);
|
|
1452
|
+
}
|
|
1453
|
+
}
|
|
1454
|
+
throw new Error(`Invalid code hash: ${codeHash}`);
|
|
1455
|
+
}
|
|
1456
|
+
exports.getContractCodeByCodeHash = getContractCodeByCodeHash;
|
|
@@ -9,6 +9,7 @@ export declare class EventSubscription extends Subscription<node.ContractEvent>
|
|
|
9
9
|
private onEventCountChanged?;
|
|
10
10
|
constructor(options: EventSubscribeOptions<node.ContractEvent>, contractAddress: string, fromCount?: number);
|
|
11
11
|
currentEventCount(): number;
|
|
12
|
+
private getEvents;
|
|
12
13
|
polling(): Promise<void>;
|
|
13
14
|
}
|
|
14
15
|
export declare function subscribeToEvents(options: EventSubscribeOptions<node.ContractEvent>, contractAddress: string, fromCount?: number): EventSubscription;
|
|
@@ -53,11 +53,22 @@ class EventSubscription extends utils_1.Subscription {
|
|
|
53
53
|
currentEventCount() {
|
|
54
54
|
return this.fromCount;
|
|
55
55
|
}
|
|
56
|
+
async getEvents(start) {
|
|
57
|
+
try {
|
|
58
|
+
return await web3
|
|
59
|
+
.getCurrentNodeProvider()
|
|
60
|
+
.events.getEventsContractContractaddress(this.contractAddress, { start });
|
|
61
|
+
}
|
|
62
|
+
catch (error) {
|
|
63
|
+
if (error instanceof Error && error.message.includes(`Contract events of ${this.contractAddress} not found`)) {
|
|
64
|
+
return { events: [], nextStart: start };
|
|
65
|
+
}
|
|
66
|
+
throw error;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
56
69
|
async polling() {
|
|
57
70
|
try {
|
|
58
|
-
const events = await
|
|
59
|
-
start: this.fromCount
|
|
60
|
-
});
|
|
71
|
+
const events = await this.getEvents(this.fromCount);
|
|
61
72
|
if (this.fromCount === events.nextStart) {
|
|
62
73
|
return;
|
|
63
74
|
}
|
|
@@ -1,10 +1,21 @@
|
|
|
1
|
+
import { HexString } from '../utils';
|
|
1
2
|
import { Transaction } from '../api/api-alephium';
|
|
2
3
|
import { Address } from '../signer';
|
|
3
4
|
export declare function validateExchangeAddress(address: string): void;
|
|
4
5
|
export declare function isALPHTransferTx(tx: Transaction): boolean;
|
|
5
|
-
export
|
|
6
|
+
export interface BaseDepositInfo {
|
|
6
7
|
targetAddress: Address;
|
|
7
8
|
depositAmount: bigint;
|
|
8
|
-
}
|
|
9
|
+
}
|
|
10
|
+
export declare function getALPHDepositInfo(tx: Transaction): BaseDepositInfo[];
|
|
11
|
+
export interface TokenDepositInfo extends BaseDepositInfo {
|
|
12
|
+
tokenId: HexString;
|
|
13
|
+
}
|
|
14
|
+
export interface DepositInfo {
|
|
15
|
+
alph: BaseDepositInfo[];
|
|
16
|
+
tokens: TokenDepositInfo[];
|
|
17
|
+
}
|
|
18
|
+
export declare function getDepositInfo(tx: Transaction): DepositInfo;
|
|
9
19
|
export declare function getSenderAddress(tx: Transaction): Address;
|
|
10
20
|
export declare function getAddressFromUnlockScript(unlockScript: string): Address;
|
|
21
|
+
export declare function isTransferTx(tx: Transaction): boolean;
|
|
@@ -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.getAddressFromUnlockScript = exports.getSenderAddress = exports.getALPHDepositInfo = exports.isALPHTransferTx = exports.validateExchangeAddress = void 0;
|
|
20
|
+
exports.isTransferTx = exports.getAddressFromUnlockScript = exports.getSenderAddress = exports.getDepositInfo = exports.getALPHDepositInfo = exports.isALPHTransferTx = exports.validateExchangeAddress = void 0;
|
|
21
21
|
const address_1 = require("../address");
|
|
22
22
|
const utils_1 = require("../utils");
|
|
23
23
|
const unlock_script_codec_1 = require("../codec/unlock-script-codec");
|
|
@@ -41,19 +41,9 @@ function isALPHTransferTx(tx) {
|
|
|
41
41
|
}
|
|
42
42
|
exports.isALPHTransferTx = isALPHTransferTx;
|
|
43
43
|
function getALPHDepositInfo(tx) {
|
|
44
|
-
if (!isALPHTransferTx(tx))
|
|
44
|
+
if (!isALPHTransferTx(tx))
|
|
45
45
|
return [];
|
|
46
|
-
|
|
47
|
-
const inputAddresses = [];
|
|
48
|
-
for (const input of tx.unsigned.inputs) {
|
|
49
|
-
try {
|
|
50
|
-
const address = getAddressFromUnlockScript(input.unlockScript);
|
|
51
|
-
if (!inputAddresses.includes(address)) {
|
|
52
|
-
inputAddresses.push(address);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
catch (_) { }
|
|
56
|
-
}
|
|
46
|
+
const inputAddresses = getInputAddresses(tx);
|
|
57
47
|
const result = new Map();
|
|
58
48
|
tx.unsigned.fixedOutputs.forEach((o) => {
|
|
59
49
|
if (!inputAddresses.includes(o.address)) {
|
|
@@ -69,7 +59,54 @@ function getALPHDepositInfo(tx) {
|
|
|
69
59
|
return Array.from(result.entries()).map(([key, value]) => ({ targetAddress: key, depositAmount: value }));
|
|
70
60
|
}
|
|
71
61
|
exports.getALPHDepositInfo = getALPHDepositInfo;
|
|
72
|
-
|
|
62
|
+
function getInputAddresses(tx) {
|
|
63
|
+
const inputAddresses = [];
|
|
64
|
+
for (const input of tx.unsigned.inputs) {
|
|
65
|
+
try {
|
|
66
|
+
if (input.unlockScript === (0, utils_1.binToHex)(unlock_script_codec_1.encodedSameAsPrevious))
|
|
67
|
+
continue;
|
|
68
|
+
const address = getAddressFromUnlockScript(input.unlockScript);
|
|
69
|
+
if (!inputAddresses.includes(address)) {
|
|
70
|
+
inputAddresses.push(address);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
catch (error) {
|
|
74
|
+
throw new error_1.TraceableError(`Failed to decode address from unlock script`, error);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return inputAddresses;
|
|
78
|
+
}
|
|
79
|
+
function getDepositInfo(tx) {
|
|
80
|
+
if (!isTransferTx(tx))
|
|
81
|
+
return { alph: [], tokens: [] };
|
|
82
|
+
const inputAddresses = getInputAddresses(tx);
|
|
83
|
+
const alphDepositInfos = new Map();
|
|
84
|
+
const tokenDepositInfos = new Map();
|
|
85
|
+
tx.unsigned.fixedOutputs.forEach((o) => {
|
|
86
|
+
if (!inputAddresses.includes(o.address)) {
|
|
87
|
+
const alphAmount = alphDepositInfos.get(o.address) ?? 0n;
|
|
88
|
+
alphDepositInfos.set(o.address, alphAmount + BigInt(o.attoAlphAmount));
|
|
89
|
+
o.tokens.forEach((token) => {
|
|
90
|
+
const depositPerToken = tokenDepositInfos.get(token.id) ?? new Map();
|
|
91
|
+
const currentAmount = depositPerToken.get(o.address) ?? 0n;
|
|
92
|
+
depositPerToken.set(o.address, currentAmount + BigInt(token.amount));
|
|
93
|
+
tokenDepositInfos.set(token.id, depositPerToken);
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
return {
|
|
98
|
+
alph: Array.from(alphDepositInfos.entries()).map(([key, value]) => ({ targetAddress: key, depositAmount: value })),
|
|
99
|
+
tokens: Array.from(tokenDepositInfos.entries()).flatMap(([tokenId, depositPerToken]) => {
|
|
100
|
+
return Array.from(depositPerToken.entries()).map(([targetAddress, depositAmount]) => ({
|
|
101
|
+
tokenId,
|
|
102
|
+
targetAddress,
|
|
103
|
+
depositAmount
|
|
104
|
+
}));
|
|
105
|
+
})
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
exports.getDepositInfo = getDepositInfo;
|
|
109
|
+
// we assume that the tx is a simple transfer tx, i.e. isALPHTransferTx(tx) || isTokenTransferTx(tx)
|
|
73
110
|
function getSenderAddress(tx) {
|
|
74
111
|
return getAddressFromUnlockScript(tx.unsigned.inputs[0].unlockScript);
|
|
75
112
|
}
|
|
@@ -124,3 +161,4 @@ function isTransferTx(tx) {
|
|
|
124
161
|
}
|
|
125
162
|
return true;
|
|
126
163
|
}
|
|
164
|
+
exports.isTransferTx = isTransferTx;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { validateExchangeAddress,
|
|
1
|
+
export { validateExchangeAddress, getSenderAddress, isALPHTransferTx, getALPHDepositInfo, BaseDepositInfo, TokenDepositInfo, DepositInfo, getDepositInfo } from './exchange';
|
|
@@ -17,9 +17,10 @@ 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.
|
|
20
|
+
exports.getDepositInfo = exports.getALPHDepositInfo = exports.isALPHTransferTx = exports.getSenderAddress = exports.validateExchangeAddress = void 0;
|
|
21
21
|
var exchange_1 = require("./exchange");
|
|
22
22
|
Object.defineProperty(exports, "validateExchangeAddress", { enumerable: true, get: function () { return exchange_1.validateExchangeAddress; } });
|
|
23
|
-
Object.defineProperty(exports, "isALPHTransferTx", { enumerable: true, get: function () { return exchange_1.isALPHTransferTx; } });
|
|
24
23
|
Object.defineProperty(exports, "getSenderAddress", { enumerable: true, get: function () { return exchange_1.getSenderAddress; } });
|
|
24
|
+
Object.defineProperty(exports, "isALPHTransferTx", { enumerable: true, get: function () { return exchange_1.isALPHTransferTx; } });
|
|
25
25
|
Object.defineProperty(exports, "getALPHDepositInfo", { enumerable: true, get: function () { return exchange_1.getALPHDepositInfo; } });
|
|
26
|
+
Object.defineProperty(exports, "getDepositInfo", { enumerable: true, get: function () { return exchange_1.getDepositInfo; } });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alephium/web3",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.10.0",
|
|
4
4
|
"description": "A JS/TS library to interact with the Alephium platform",
|
|
5
5
|
"license": "GPL",
|
|
6
6
|
"main": "dist/src/index.js",
|
|
@@ -33,8 +33,8 @@
|
|
|
33
33
|
},
|
|
34
34
|
"author": "Alephium dev <dev@alephium.org>",
|
|
35
35
|
"config": {
|
|
36
|
-
"alephium_version": "3.
|
|
37
|
-
"explorer_backend_version": "2.2
|
|
36
|
+
"alephium_version": "3.10.0",
|
|
37
|
+
"explorer_backend_version": "2.3.2"
|
|
38
38
|
},
|
|
39
39
|
"type": "commonjs",
|
|
40
40
|
"dependencies": {
|
package/src/api/api-alephium.ts
CHANGED
|
@@ -308,6 +308,7 @@ export interface BuildExecuteScriptTxResult {
|
|
|
308
308
|
gasPrice: string
|
|
309
309
|
/** @format 32-byte-hash */
|
|
310
310
|
txId: string
|
|
311
|
+
simulatedOutputs: Output[]
|
|
311
312
|
}
|
|
312
313
|
|
|
313
314
|
/** BuildInfo */
|
|
@@ -366,6 +367,8 @@ export interface BuildSweepAddressTransactions {
|
|
|
366
367
|
gasPrice?: string
|
|
367
368
|
/** @format block-hash */
|
|
368
369
|
targetBlockHash?: string
|
|
370
|
+
/** @format int32 */
|
|
371
|
+
utxosLimit?: number
|
|
369
372
|
}
|
|
370
373
|
|
|
371
374
|
/** BuildSweepAddressTransactionsResult */
|
|
@@ -1406,11 +1409,6 @@ export interface WalletCreationResult {
|
|
|
1406
1409
|
mnemonic: string
|
|
1407
1410
|
}
|
|
1408
1411
|
|
|
1409
|
-
/** WalletDeletion */
|
|
1410
|
-
export interface WalletDeletion {
|
|
1411
|
-
password: string
|
|
1412
|
-
}
|
|
1413
|
-
|
|
1414
1412
|
/** WalletRestore */
|
|
1415
1413
|
export interface WalletRestore {
|
|
1416
1414
|
password: string
|
|
@@ -1651,7 +1649,7 @@ export class HttpClient<SecurityDataType = unknown> {
|
|
|
1651
1649
|
|
|
1652
1650
|
/**
|
|
1653
1651
|
* @title Alephium API
|
|
1654
|
-
* @version 3.
|
|
1652
|
+
* @version 3.10.0
|
|
1655
1653
|
* @baseUrl ../
|
|
1656
1654
|
*/
|
|
1657
1655
|
export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDataType> {
|
|
@@ -1738,12 +1736,17 @@ export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDa
|
|
|
1738
1736
|
* @summary Delete your wallet file (can be recovered with your mnemonic)
|
|
1739
1737
|
* @request DELETE:/wallets/{wallet_name}
|
|
1740
1738
|
*/
|
|
1741
|
-
deleteWalletsWalletName: (
|
|
1739
|
+
deleteWalletsWalletName: (
|
|
1740
|
+
walletName: string,
|
|
1741
|
+
query: {
|
|
1742
|
+
password: string
|
|
1743
|
+
},
|
|
1744
|
+
params: RequestParams = {}
|
|
1745
|
+
) =>
|
|
1742
1746
|
this.request<void, BadRequest | Unauthorized | NotFound | InternalServerError | ServiceUnavailable>({
|
|
1743
1747
|
path: `/wallets/${walletName}`,
|
|
1744
1748
|
method: 'DELETE',
|
|
1745
|
-
|
|
1746
|
-
type: ContentType.Json,
|
|
1749
|
+
query: query,
|
|
1747
1750
|
...params
|
|
1748
1751
|
}).then(convertHttpResponse),
|
|
1749
1752
|
|
|
@@ -2593,6 +2596,27 @@ export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDa
|
|
|
2593
2596
|
...params
|
|
2594
2597
|
}).then(convertHttpResponse),
|
|
2595
2598
|
|
|
2599
|
+
/**
|
|
2600
|
+
* No description
|
|
2601
|
+
*
|
|
2602
|
+
* @tags Transactions
|
|
2603
|
+
* @name PostTransactionsBuildTransferFromOneToManyGroups
|
|
2604
|
+
* @summary Build unsigned transfer transactions from an address of one group to addresses of many groups. Each target group requires a dedicated transaction or more in case large number of outputs needed to be split.
|
|
2605
|
+
* @request POST:/transactions/build-transfer-from-one-to-many-groups
|
|
2606
|
+
*/
|
|
2607
|
+
postTransactionsBuildTransferFromOneToManyGroups: (data: BuildTransferTx, params: RequestParams = {}) =>
|
|
2608
|
+
this.request<
|
|
2609
|
+
BuildTransferTxResult[],
|
|
2610
|
+
BadRequest | Unauthorized | NotFound | InternalServerError | ServiceUnavailable
|
|
2611
|
+
>({
|
|
2612
|
+
path: `/transactions/build-transfer-from-one-to-many-groups`,
|
|
2613
|
+
method: 'POST',
|
|
2614
|
+
body: data,
|
|
2615
|
+
type: ContentType.Json,
|
|
2616
|
+
format: 'json',
|
|
2617
|
+
...params
|
|
2618
|
+
}).then(convertHttpResponse),
|
|
2619
|
+
|
|
2596
2620
|
/**
|
|
2597
2621
|
* No description
|
|
2598
2622
|
*
|
|
@@ -3019,6 +3043,22 @@ export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDa
|
|
|
3019
3043
|
...params
|
|
3020
3044
|
}).then(convertHttpResponse),
|
|
3021
3045
|
|
|
3046
|
+
/**
|
|
3047
|
+
* No description
|
|
3048
|
+
*
|
|
3049
|
+
* @tags Contracts
|
|
3050
|
+
* @name GetContractsCodehashCode
|
|
3051
|
+
* @summary Get contract code by code hash
|
|
3052
|
+
* @request GET:/contracts/{codeHash}/code
|
|
3053
|
+
*/
|
|
3054
|
+
getContractsCodehashCode: (codeHash: string, params: RequestParams = {}) =>
|
|
3055
|
+
this.request<string, BadRequest | Unauthorized | NotFound | InternalServerError | ServiceUnavailable>({
|
|
3056
|
+
path: `/contracts/${codeHash}/code`,
|
|
3057
|
+
method: 'GET',
|
|
3058
|
+
format: 'json',
|
|
3059
|
+
...params
|
|
3060
|
+
}).then(convertHttpResponse),
|
|
3061
|
+
|
|
3022
3062
|
/**
|
|
3023
3063
|
* No description
|
|
3024
3064
|
*
|