@fuel-ts/account 0.0.0-rc-2238-20240514123903 → 0.0.0-rc-1356-20240514125020
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.
Potentially problematic release.
This version of @fuel-ts/account might be problematic. Click here for more details.
- package/dist/account.d.ts.map +1 -1
- package/dist/index.global.js +1140 -408
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +254 -234
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +145 -118
- package/dist/index.mjs.map +1 -1
- package/dist/predicate/predicate.d.ts.map +1 -1
- package/dist/providers/coin.d.ts +1 -0
- package/dist/providers/coin.d.ts.map +1 -1
- package/dist/providers/message.d.ts +1 -0
- package/dist/providers/message.d.ts.map +1 -1
- package/dist/providers/transaction-request/input.d.ts +2 -0
- package/dist/providers/transaction-request/input.d.ts.map +1 -1
- package/dist/providers/transaction-request/transaction-request.d.ts +1 -0
- package/dist/providers/transaction-request/transaction-request.d.ts.map +1 -1
- package/dist/providers/transaction-summary/call.d.ts +1 -1
- package/dist/providers/transaction-summary/call.d.ts.map +1 -1
- package/dist/providers/utils/auto-retry-fetch.d.ts.map +1 -1
- package/dist/providers/utils/index.d.ts +0 -1
- package/dist/providers/utils/index.d.ts.map +1 -1
- package/dist/test-utils/asset-id.d.ts +8 -0
- package/dist/test-utils/asset-id.d.ts.map +1 -0
- package/dist/test-utils/index.d.ts +4 -0
- package/dist/test-utils/index.d.ts.map +1 -1
- package/dist/test-utils/launchNode.d.ts +8 -1
- package/dist/test-utils/launchNode.d.ts.map +1 -1
- package/dist/test-utils/setup-test-provider-and-wallets.d.ts +33 -0
- package/dist/test-utils/setup-test-provider-and-wallets.d.ts.map +1 -0
- package/dist/test-utils/test-message.d.ts +28 -0
- package/dist/test-utils/test-message.d.ts.map +1 -0
- package/dist/test-utils/wallet-config.d.ts +49 -0
- package/dist/test-utils/wallet-config.d.ts.map +1 -0
- package/dist/test-utils.global.js +1465 -418
- package/dist/test-utils.global.js.map +1 -1
- package/dist/test-utils.js +523 -272
- package/dist/test-utils.js.map +1 -1
- package/dist/test-utils.mjs +413 -166
- package/dist/test-utils.mjs.map +1 -1
- package/package.json +16 -15
- package/dist/providers/utils/sleep.d.ts +0 -3
- package/dist/providers/utils/sleep.d.ts.map +0 -1
package/dist/index.global.js
CHANGED
@@ -29470,7 +29470,7 @@ spurious results.`);
|
|
29470
29470
|
// ../versions/dist/index.mjs
|
29471
29471
|
function getBuiltinVersions() {
|
29472
29472
|
return {
|
29473
|
-
FORC: "0.
|
29473
|
+
FORC: "0.56.1",
|
29474
29474
|
FUEL_CORE: "0.26.0",
|
29475
29475
|
FUELS: "0.85.0"
|
29476
29476
|
};
|
@@ -29985,6 +29985,13 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
29985
29985
|
};
|
29986
29986
|
var DateTime = _DateTime;
|
29987
29987
|
__publicField3(DateTime, "TAI64_NULL", "");
|
29988
|
+
function sleep(time) {
|
29989
|
+
return new Promise((resolve) => {
|
29990
|
+
setTimeout(() => {
|
29991
|
+
resolve(true);
|
29992
|
+
}, time);
|
29993
|
+
});
|
29994
|
+
}
|
29988
29995
|
function isDefined(value) {
|
29989
29996
|
return value !== void 0;
|
29990
29997
|
}
|
@@ -31092,6 +31099,19 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
31092
31099
|
__defNormalProp4(obj, typeof key !== "symbol" ? key + "" : key, value);
|
31093
31100
|
return value;
|
31094
31101
|
};
|
31102
|
+
var __accessCheck2 = (obj, member, msg) => {
|
31103
|
+
if (!member.has(obj))
|
31104
|
+
throw TypeError("Cannot " + msg);
|
31105
|
+
};
|
31106
|
+
var __privateAdd2 = (obj, member, value) => {
|
31107
|
+
if (member.has(obj))
|
31108
|
+
throw TypeError("Cannot add the same private member more than once");
|
31109
|
+
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
31110
|
+
};
|
31111
|
+
var __privateMethod2 = (obj, member, method) => {
|
31112
|
+
__accessCheck2(obj, member, "access private method");
|
31113
|
+
return method;
|
31114
|
+
};
|
31095
31115
|
var Coder = class {
|
31096
31116
|
name;
|
31097
31117
|
type;
|
@@ -31123,6 +31143,7 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
31123
31143
|
var enumRegEx = /^enum (?<name>\w+)$/;
|
31124
31144
|
var tupleRegEx = /^\((?<items>.*)\)$/;
|
31125
31145
|
var genericRegEx = /^generic (?<name>\w+)$/;
|
31146
|
+
var ENCODING_V0 = "0";
|
31126
31147
|
var ENCODING_V1 = "1";
|
31127
31148
|
var WORD_SIZE = 8;
|
31128
31149
|
var BYTES_32 = 32;
|
@@ -31133,6 +31154,10 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
31133
31154
|
var TX_LEN = WORD_SIZE * 4;
|
31134
31155
|
var TX_POINTER_LEN = WORD_SIZE * 2;
|
31135
31156
|
var MAX_BYTES = 2 ** 32 - 1;
|
31157
|
+
var calculateVmTxMemory = ({ maxInputs }) => BYTES_32 + // Tx ID
|
31158
|
+
ASSET_ID_LEN + // Base asset ID
|
31159
|
+
// Asset ID/Balance coin input pairs
|
31160
|
+
maxInputs * (ASSET_ID_LEN + WORD_SIZE) + WORD_SIZE;
|
31136
31161
|
var SCRIPT_FIXED_SIZE = WORD_SIZE + // Identifier
|
31137
31162
|
WORD_SIZE + // Gas limit
|
31138
31163
|
WORD_SIZE + // Script size
|
@@ -31163,6 +31188,125 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
31163
31188
|
WORD_SIZE + // Predicate size
|
31164
31189
|
WORD_SIZE + // Predicate data size
|
31165
31190
|
WORD_SIZE;
|
31191
|
+
var encodedLengths = {
|
31192
|
+
u64: WORD_SIZE,
|
31193
|
+
u256: WORD_SIZE * 4
|
31194
|
+
};
|
31195
|
+
var BigNumberCoder = class extends Coder {
|
31196
|
+
constructor(baseType) {
|
31197
|
+
super("bigNumber", baseType, encodedLengths[baseType]);
|
31198
|
+
}
|
31199
|
+
encode(value) {
|
31200
|
+
let bytes2;
|
31201
|
+
try {
|
31202
|
+
bytes2 = toBytes2(value, this.encodedLength);
|
31203
|
+
} catch (error) {
|
31204
|
+
throw new FuelError(ErrorCode.ENCODE_ERROR, `Invalid ${this.type}.`);
|
31205
|
+
}
|
31206
|
+
return bytes2;
|
31207
|
+
}
|
31208
|
+
decode(data, offset) {
|
31209
|
+
if (data.length < this.encodedLength) {
|
31210
|
+
throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid ${this.type} data size.`);
|
31211
|
+
}
|
31212
|
+
let bytes2 = data.slice(offset, offset + this.encodedLength);
|
31213
|
+
bytes2 = bytes2.slice(0, this.encodedLength);
|
31214
|
+
if (bytes2.length !== this.encodedLength) {
|
31215
|
+
throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid ${this.type} byte data size.`);
|
31216
|
+
}
|
31217
|
+
return [bn(bytes2), offset + this.encodedLength];
|
31218
|
+
}
|
31219
|
+
};
|
31220
|
+
var VEC_PROPERTY_SPACE = 3;
|
31221
|
+
var BASE_VECTOR_OFFSET = VEC_PROPERTY_SPACE * WORD_SIZE;
|
31222
|
+
var RAW_SLICE_PROPERTY_SPACE = 2;
|
31223
|
+
var BASE_RAW_SLICE_OFFSET = RAW_SLICE_PROPERTY_SPACE * WORD_SIZE;
|
31224
|
+
function concatWithDynamicData(items) {
|
31225
|
+
const topLevelData = {};
|
31226
|
+
let totalIndex = 0;
|
31227
|
+
const objects = items.map((item) => {
|
31228
|
+
const dynamicData = item.dynamicData;
|
31229
|
+
if (dynamicData) {
|
31230
|
+
Object.entries(dynamicData).forEach(([pointerIndex, vData]) => {
|
31231
|
+
topLevelData[parseInt(pointerIndex, 10) + totalIndex] = vData;
|
31232
|
+
});
|
31233
|
+
}
|
31234
|
+
const byteArray = arrayify(item);
|
31235
|
+
totalIndex += byteArray.byteLength / WORD_SIZE;
|
31236
|
+
return byteArray;
|
31237
|
+
});
|
31238
|
+
const length = objects.reduce((accum, item) => accum + item.length, 0);
|
31239
|
+
const result = new Uint8Array(length);
|
31240
|
+
objects.reduce((offset, object) => {
|
31241
|
+
result.set(object, offset);
|
31242
|
+
return offset + object.length;
|
31243
|
+
}, 0);
|
31244
|
+
if (Object.keys(topLevelData).length) {
|
31245
|
+
result.dynamicData = topLevelData;
|
31246
|
+
}
|
31247
|
+
return result;
|
31248
|
+
}
|
31249
|
+
function unpackDynamicData(results, baseOffset, dataOffset) {
|
31250
|
+
if (!results.dynamicData) {
|
31251
|
+
return concat([results]);
|
31252
|
+
}
|
31253
|
+
let cumulativeDynamicByteLength = 0;
|
31254
|
+
let updatedResults = results;
|
31255
|
+
Object.entries(results.dynamicData).forEach(([pointerIndex, vData]) => {
|
31256
|
+
const pointerOffset = parseInt(pointerIndex, 10) * WORD_SIZE;
|
31257
|
+
const adjustedValue = new BigNumberCoder("u64").encode(
|
31258
|
+
dataOffset + baseOffset + cumulativeDynamicByteLength
|
31259
|
+
);
|
31260
|
+
updatedResults.set(adjustedValue, pointerOffset);
|
31261
|
+
const dataToAppend = vData.dynamicData ? (
|
31262
|
+
// unpack child dynamic data
|
31263
|
+
unpackDynamicData(
|
31264
|
+
vData,
|
31265
|
+
baseOffset,
|
31266
|
+
dataOffset + vData.byteLength + cumulativeDynamicByteLength
|
31267
|
+
)
|
31268
|
+
) : vData;
|
31269
|
+
updatedResults = concat([updatedResults, dataToAppend]);
|
31270
|
+
cumulativeDynamicByteLength += dataToAppend.byteLength;
|
31271
|
+
});
|
31272
|
+
return updatedResults;
|
31273
|
+
}
|
31274
|
+
var chunkByLength = (data, length = WORD_SIZE) => {
|
31275
|
+
const chunks = [];
|
31276
|
+
let offset = 0;
|
31277
|
+
let chunk = data.slice(offset, offset + length);
|
31278
|
+
while (chunk.length) {
|
31279
|
+
chunks.push(chunk);
|
31280
|
+
offset += length;
|
31281
|
+
chunk = data.slice(offset, offset + length);
|
31282
|
+
}
|
31283
|
+
return chunks;
|
31284
|
+
};
|
31285
|
+
var isPointerType = (type3) => {
|
31286
|
+
switch (type3) {
|
31287
|
+
case "u8":
|
31288
|
+
case "u16":
|
31289
|
+
case "u32":
|
31290
|
+
case "u64":
|
31291
|
+
case "bool": {
|
31292
|
+
return false;
|
31293
|
+
}
|
31294
|
+
default: {
|
31295
|
+
return true;
|
31296
|
+
}
|
31297
|
+
}
|
31298
|
+
};
|
31299
|
+
var isHeapType = (type3) => type3 === VEC_CODER_TYPE || type3 === BYTES_CODER_TYPE || type3 === STD_STRING_CODER_TYPE;
|
31300
|
+
var isMultipleOfWordSize = (length) => length % WORD_SIZE === 0;
|
31301
|
+
var getWordSizePadding = (length) => WORD_SIZE - length % WORD_SIZE;
|
31302
|
+
var rightPadToWordSize = (encoded) => {
|
31303
|
+
if (isMultipleOfWordSize(encoded.length)) {
|
31304
|
+
return encoded;
|
31305
|
+
}
|
31306
|
+
const padding = new Uint8Array(WORD_SIZE - encoded.length % WORD_SIZE);
|
31307
|
+
return concatBytes2([encoded, padding]);
|
31308
|
+
};
|
31309
|
+
var isUint8Array = (value) => value instanceof Uint8Array;
|
31166
31310
|
var ArrayCoder = class extends Coder {
|
31167
31311
|
coder;
|
31168
31312
|
length;
|
@@ -31178,7 +31322,7 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
31178
31322
|
if (this.length !== value.length) {
|
31179
31323
|
throw new FuelError(ErrorCode.ENCODE_ERROR, `Types/values length mismatch.`);
|
31180
31324
|
}
|
31181
|
-
return
|
31325
|
+
return concatWithDynamicData(Array.from(value).map((v) => this.coder.encode(v)));
|
31182
31326
|
}
|
31183
31327
|
decode(data, offset) {
|
31184
31328
|
if (data.length < this.encodedLength || data.length > MAX_BYTES) {
|
@@ -31255,42 +31399,16 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
31255
31399
|
return [toHex(bytes2, this.encodedLength), offset + this.encodedLength];
|
31256
31400
|
}
|
31257
31401
|
};
|
31258
|
-
var encodedLengths = {
|
31259
|
-
u64: WORD_SIZE,
|
31260
|
-
u256: WORD_SIZE * 4
|
31261
|
-
};
|
31262
|
-
var BigNumberCoder = class extends Coder {
|
31263
|
-
constructor(baseType) {
|
31264
|
-
super("bigNumber", baseType, encodedLengths[baseType]);
|
31265
|
-
}
|
31266
|
-
encode(value) {
|
31267
|
-
let bytes2;
|
31268
|
-
try {
|
31269
|
-
bytes2 = toBytes2(value, this.encodedLength);
|
31270
|
-
} catch (error) {
|
31271
|
-
throw new FuelError(ErrorCode.ENCODE_ERROR, `Invalid ${this.type}.`);
|
31272
|
-
}
|
31273
|
-
return bytes2;
|
31274
|
-
}
|
31275
|
-
decode(data, offset) {
|
31276
|
-
if (data.length < this.encodedLength) {
|
31277
|
-
throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid ${this.type} data size.`);
|
31278
|
-
}
|
31279
|
-
let bytes2 = data.slice(offset, offset + this.encodedLength);
|
31280
|
-
bytes2 = bytes2.slice(0, this.encodedLength);
|
31281
|
-
if (bytes2.length !== this.encodedLength) {
|
31282
|
-
throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid ${this.type} byte data size.`);
|
31283
|
-
}
|
31284
|
-
return [bn(bytes2), offset + this.encodedLength];
|
31285
|
-
}
|
31286
|
-
};
|
31287
31402
|
var BooleanCoder = class extends Coder {
|
31403
|
+
paddingLength;
|
31288
31404
|
options;
|
31289
31405
|
constructor(options = {
|
31290
|
-
|
31406
|
+
isSmallBytes: false,
|
31407
|
+
isRightPadded: false
|
31291
31408
|
}) {
|
31292
|
-
const
|
31293
|
-
super("boolean", "boolean",
|
31409
|
+
const paddingLength = options.isSmallBytes ? 1 : 8;
|
31410
|
+
super("boolean", "boolean", paddingLength);
|
31411
|
+
this.paddingLength = paddingLength;
|
31294
31412
|
this.options = options;
|
31295
31413
|
}
|
31296
31414
|
encode(value) {
|
@@ -31298,45 +31416,73 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
31298
31416
|
if (!isTrueBool) {
|
31299
31417
|
throw new FuelError(ErrorCode.ENCODE_ERROR, `Invalid boolean value.`);
|
31300
31418
|
}
|
31301
|
-
|
31419
|
+
const output2 = toBytes2(value ? 1 : 0, this.paddingLength);
|
31420
|
+
if (this.options.isRightPadded) {
|
31421
|
+
return output2.reverse();
|
31422
|
+
}
|
31423
|
+
return output2;
|
31302
31424
|
}
|
31303
31425
|
decode(data, offset) {
|
31304
|
-
if (data.length < this.
|
31426
|
+
if (data.length < this.paddingLength) {
|
31305
31427
|
throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid boolean data size.`);
|
31306
31428
|
}
|
31307
|
-
|
31308
|
-
if (
|
31309
|
-
|
31429
|
+
let bytes2;
|
31430
|
+
if (this.options.isRightPadded) {
|
31431
|
+
bytes2 = data.slice(offset, offset + 1);
|
31432
|
+
} else {
|
31433
|
+
bytes2 = data.slice(offset, offset + this.paddingLength);
|
31310
31434
|
}
|
31311
|
-
|
31435
|
+
const decodedValue = bn(bytes2);
|
31436
|
+
if (decodedValue.isZero()) {
|
31437
|
+
return [false, offset + this.paddingLength];
|
31438
|
+
}
|
31439
|
+
if (!decodedValue.eq(bn(1))) {
|
31312
31440
|
throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid boolean value.`);
|
31313
31441
|
}
|
31314
|
-
return [true, offset + this.
|
31442
|
+
return [true, offset + this.paddingLength];
|
31315
31443
|
}
|
31316
31444
|
};
|
31445
|
+
var _getPaddedData;
|
31446
|
+
var getPaddedData_fn;
|
31317
31447
|
var ByteCoder = class extends Coder {
|
31318
31448
|
constructor() {
|
31319
|
-
super("struct", "struct Bytes",
|
31449
|
+
super("struct", "struct Bytes", BASE_VECTOR_OFFSET);
|
31450
|
+
__privateAdd2(this, _getPaddedData);
|
31320
31451
|
}
|
31321
31452
|
encode(value) {
|
31322
|
-
const
|
31323
|
-
const
|
31324
|
-
|
31453
|
+
const parts = [];
|
31454
|
+
const pointer = new BigNumberCoder("u64").encode(BASE_VECTOR_OFFSET);
|
31455
|
+
const data = __privateMethod2(this, _getPaddedData, getPaddedData_fn).call(this, value);
|
31456
|
+
pointer.dynamicData = {
|
31457
|
+
0: concatWithDynamicData([data])
|
31458
|
+
};
|
31459
|
+
parts.push(pointer);
|
31460
|
+
parts.push(new BigNumberCoder("u64").encode(data.byteLength));
|
31461
|
+
parts.push(new BigNumberCoder("u64").encode(value.length));
|
31462
|
+
return concatWithDynamicData(parts);
|
31325
31463
|
}
|
31326
31464
|
decode(data, offset) {
|
31327
|
-
if (data.length <
|
31465
|
+
if (data.length < BASE_VECTOR_OFFSET) {
|
31328
31466
|
throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid byte data size.`);
|
31329
31467
|
}
|
31330
|
-
const
|
31331
|
-
const
|
31332
|
-
const
|
31333
|
-
|
31334
|
-
if (dataBytes.length !== length) {
|
31468
|
+
const len = data.slice(16, 24);
|
31469
|
+
const encodedLength = bn(new BigNumberCoder("u64").decode(len, 0)[0]).toNumber();
|
31470
|
+
const byteData = data.slice(BASE_VECTOR_OFFSET, BASE_VECTOR_OFFSET + encodedLength);
|
31471
|
+
if (byteData.length !== encodedLength) {
|
31335
31472
|
throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid bytes byte data size.`);
|
31336
31473
|
}
|
31337
|
-
return [
|
31474
|
+
return [byteData, offset + BASE_VECTOR_OFFSET];
|
31338
31475
|
}
|
31339
31476
|
};
|
31477
|
+
_getPaddedData = /* @__PURE__ */ new WeakSet();
|
31478
|
+
getPaddedData_fn = function(value) {
|
31479
|
+
const data = value instanceof Uint8Array ? [value] : [new Uint8Array(value)];
|
31480
|
+
const paddingLength = (WORD_SIZE - value.length % WORD_SIZE) % WORD_SIZE;
|
31481
|
+
if (paddingLength) {
|
31482
|
+
data.push(new Uint8Array(paddingLength));
|
31483
|
+
}
|
31484
|
+
return concat(data);
|
31485
|
+
};
|
31340
31486
|
__publicField4(ByteCoder, "memorySize", 1);
|
31341
31487
|
var isFullyNativeEnum = (enumCoders) => Object.values(enumCoders).every(
|
31342
31488
|
// @ts-expect-error complicated types
|
@@ -31380,7 +31526,8 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
31380
31526
|
const valueCoder = this.coders[caseKey];
|
31381
31527
|
const caseIndex = Object.keys(this.coders).indexOf(caseKey);
|
31382
31528
|
const encodedValue = valueCoder.encode(value[caseKey]);
|
31383
|
-
|
31529
|
+
const padding = new Uint8Array(this.#encodedValueSize - valueCoder.encodedLength);
|
31530
|
+
return concatWithDynamicData([this.#caseIndexCoder.encode(caseIndex), padding, encodedValue]);
|
31384
31531
|
}
|
31385
31532
|
#decodeNativeEnum(caseKey, newOffset) {
|
31386
31533
|
return [caseKey, newOffset];
|
@@ -31389,8 +31536,10 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
31389
31536
|
if (data.length < this.#encodedValueSize) {
|
31390
31537
|
throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid enum data size.`);
|
31391
31538
|
}
|
31392
|
-
|
31393
|
-
|
31539
|
+
let newOffset = offset;
|
31540
|
+
let decoded;
|
31541
|
+
[decoded, newOffset] = new BigNumberCoder("u64").decode(data, newOffset);
|
31542
|
+
const caseIndex = toNumber(decoded);
|
31394
31543
|
const caseKey = Object.keys(this.coders)[caseIndex];
|
31395
31544
|
if (!caseKey) {
|
31396
31545
|
throw new FuelError(
|
@@ -31399,35 +31548,67 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
31399
31548
|
);
|
31400
31549
|
}
|
31401
31550
|
const valueCoder = this.coders[caseKey];
|
31402
|
-
const
|
31403
|
-
|
31551
|
+
const padding = this.#encodedValueSize - valueCoder.encodedLength;
|
31552
|
+
newOffset += padding;
|
31553
|
+
[decoded, newOffset] = valueCoder.decode(data, newOffset);
|
31404
31554
|
if (isFullyNativeEnum(this.coders)) {
|
31405
31555
|
return this.#decodeNativeEnum(caseKey, newOffset);
|
31406
31556
|
}
|
31407
31557
|
return [{ [caseKey]: decoded }, newOffset];
|
31408
31558
|
}
|
31409
31559
|
};
|
31410
|
-
var
|
31411
|
-
|
31412
|
-
|
31413
|
-
|
31414
|
-
|
31415
|
-
|
31416
|
-
|
31417
|
-
return
|
31418
|
-
|
31419
|
-
|
31560
|
+
var OptionCoder = class extends EnumCoder {
|
31561
|
+
encode(value) {
|
31562
|
+
const result = super.encode(this.toSwayOption(value));
|
31563
|
+
return result;
|
31564
|
+
}
|
31565
|
+
toSwayOption(input) {
|
31566
|
+
if (input !== void 0) {
|
31567
|
+
return { Some: input };
|
31568
|
+
}
|
31569
|
+
return { None: [] };
|
31570
|
+
}
|
31571
|
+
decode(data, offset) {
|
31572
|
+
if (data.length < this.encodedLength) {
|
31573
|
+
throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid option data size.`);
|
31574
|
+
}
|
31575
|
+
const [decoded, newOffset] = super.decode(data, offset);
|
31576
|
+
return [this.toOption(decoded), newOffset];
|
31577
|
+
}
|
31578
|
+
toOption(output2) {
|
31579
|
+
if (output2 && "Some" in output2) {
|
31580
|
+
return output2.Some;
|
31581
|
+
}
|
31582
|
+
return void 0;
|
31420
31583
|
}
|
31421
31584
|
};
|
31422
31585
|
var NumberCoder = class extends Coder {
|
31586
|
+
// This is to align the bits to the total bytes
|
31587
|
+
// See https://github.com/FuelLabs/fuel-specs/blob/master/specs/protocol/abi.md#unsigned-integers
|
31588
|
+
length;
|
31589
|
+
paddingLength;
|
31423
31590
|
baseType;
|
31424
31591
|
options;
|
31425
31592
|
constructor(baseType, options = {
|
31426
|
-
|
31593
|
+
isSmallBytes: false,
|
31594
|
+
isRightPadded: false
|
31427
31595
|
}) {
|
31428
|
-
const
|
31429
|
-
super("number", baseType,
|
31596
|
+
const paddingLength = options.isSmallBytes && baseType === "u8" ? 1 : 8;
|
31597
|
+
super("number", baseType, paddingLength);
|
31430
31598
|
this.baseType = baseType;
|
31599
|
+
switch (baseType) {
|
31600
|
+
case "u8":
|
31601
|
+
this.length = 1;
|
31602
|
+
break;
|
31603
|
+
case "u16":
|
31604
|
+
this.length = 2;
|
31605
|
+
break;
|
31606
|
+
case "u32":
|
31607
|
+
default:
|
31608
|
+
this.length = 4;
|
31609
|
+
break;
|
31610
|
+
}
|
31611
|
+
this.paddingLength = paddingLength;
|
31431
31612
|
this.options = options;
|
31432
31613
|
}
|
31433
31614
|
encode(value) {
|
@@ -31437,140 +31618,142 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
31437
31618
|
} catch (error) {
|
31438
31619
|
throw new FuelError(ErrorCode.ENCODE_ERROR, `Invalid ${this.baseType}.`);
|
31439
31620
|
}
|
31440
|
-
if (bytes2.length > this.
|
31621
|
+
if (bytes2.length > this.length) {
|
31441
31622
|
throw new FuelError(ErrorCode.ENCODE_ERROR, `Invalid ${this.baseType}, too many bytes.`);
|
31442
31623
|
}
|
31443
|
-
|
31444
|
-
|
31445
|
-
|
31446
|
-
if (data.length < this.encodedLength) {
|
31447
|
-
throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid number data size.`);
|
31448
|
-
}
|
31449
|
-
const bytes2 = data.slice(offset, offset + this.encodedLength);
|
31450
|
-
if (bytes2.length !== this.encodedLength) {
|
31451
|
-
throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid number byte data size.`);
|
31624
|
+
const output2 = toBytes2(bytes2, this.paddingLength);
|
31625
|
+
if (this.baseType !== "u8") {
|
31626
|
+
return output2;
|
31452
31627
|
}
|
31453
|
-
return
|
31454
|
-
}
|
31455
|
-
};
|
31456
|
-
var OptionCoder = class extends EnumCoder {
|
31457
|
-
encode(value) {
|
31458
|
-
const result = super.encode(this.toSwayOption(value));
|
31459
|
-
return result;
|
31628
|
+
return this.options.isRightPadded ? output2.reverse() : output2;
|
31460
31629
|
}
|
31461
|
-
|
31462
|
-
|
31463
|
-
|
31630
|
+
decodeU8(data, offset) {
|
31631
|
+
let bytes2;
|
31632
|
+
if (this.options.isRightPadded) {
|
31633
|
+
bytes2 = data.slice(offset, offset + 1);
|
31634
|
+
} else {
|
31635
|
+
bytes2 = data.slice(offset, offset + this.paddingLength);
|
31636
|
+
bytes2 = bytes2.slice(this.paddingLength - this.length, this.paddingLength);
|
31464
31637
|
}
|
31465
|
-
return
|
31638
|
+
return [toNumber(bytes2), offset + this.paddingLength];
|
31466
31639
|
}
|
31467
31640
|
decode(data, offset) {
|
31468
|
-
|
31469
|
-
|
31470
|
-
}
|
31471
|
-
toOption(output2) {
|
31472
|
-
if (output2 && "Some" in output2) {
|
31473
|
-
return output2.Some;
|
31641
|
+
if (data.length < this.paddingLength) {
|
31642
|
+
throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid number data size.`);
|
31474
31643
|
}
|
31475
|
-
|
31644
|
+
if (this.baseType === "u8") {
|
31645
|
+
return this.decodeU8(data, offset);
|
31646
|
+
}
|
31647
|
+
let bytes2 = data.slice(offset, offset + this.paddingLength);
|
31648
|
+
bytes2 = bytes2.slice(8 - this.length, 8);
|
31649
|
+
if (bytes2.length !== this.paddingLength - (this.paddingLength - this.length)) {
|
31650
|
+
throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid number byte data size.`);
|
31651
|
+
}
|
31652
|
+
return [toNumber(bytes2), offset + 8];
|
31476
31653
|
}
|
31477
31654
|
};
|
31478
31655
|
var RawSliceCoder = class extends Coder {
|
31479
31656
|
constructor() {
|
31480
|
-
super("raw untyped slice", "raw untyped slice",
|
31657
|
+
super("raw untyped slice", "raw untyped slice", BASE_RAW_SLICE_OFFSET);
|
31481
31658
|
}
|
31482
31659
|
encode(value) {
|
31483
31660
|
if (!Array.isArray(value)) {
|
31484
31661
|
throw new FuelError(ErrorCode.ENCODE_ERROR, `Expected array value.`);
|
31485
31662
|
}
|
31486
|
-
const
|
31487
|
-
const
|
31488
|
-
const
|
31489
|
-
|
31663
|
+
const parts = [];
|
31664
|
+
const coder = new NumberCoder("u8", { isSmallBytes: true });
|
31665
|
+
const pointer = new BigNumberCoder("u64").encode(
|
31666
|
+
BASE_RAW_SLICE_OFFSET
|
31667
|
+
);
|
31668
|
+
pointer.dynamicData = {
|
31669
|
+
0: concatWithDynamicData(value.map((v) => coder.encode(v)))
|
31670
|
+
};
|
31671
|
+
parts.push(pointer);
|
31672
|
+
parts.push(new BigNumberCoder("u64").encode(value.length));
|
31673
|
+
return concatWithDynamicData(parts);
|
31490
31674
|
}
|
31491
31675
|
decode(data, offset) {
|
31492
|
-
|
31493
|
-
|
31494
|
-
|
31495
|
-
|
31496
|
-
|
31497
|
-
const length = bn(new BigNumberCoder("u64").decode(lengthBytes, 0)[0]).toNumber();
|
31498
|
-
const dataBytes = data.slice(offsetAndLength, offsetAndLength + length);
|
31499
|
-
if (dataBytes.length !== length) {
|
31500
|
-
throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid raw slice byte data size.`);
|
31501
|
-
}
|
31502
|
-
const internalCoder = new ArrayCoder(new NumberCoder("u8"), length);
|
31676
|
+
const dataBytes = data.slice(offset);
|
31677
|
+
const internalCoder = new ArrayCoder(
|
31678
|
+
new NumberCoder("u8", { isSmallBytes: true }),
|
31679
|
+
dataBytes.length
|
31680
|
+
);
|
31503
31681
|
const [decodedValue] = internalCoder.decode(dataBytes, 0);
|
31504
|
-
return [decodedValue,
|
31682
|
+
return [decodedValue, offset + dataBytes.length];
|
31505
31683
|
}
|
31506
31684
|
};
|
31685
|
+
var _getPaddedData2;
|
31686
|
+
var getPaddedData_fn2;
|
31507
31687
|
var StdStringCoder = class extends Coder {
|
31508
31688
|
constructor() {
|
31509
|
-
super("struct", "struct String",
|
31689
|
+
super("struct", "struct String", 1);
|
31690
|
+
__privateAdd2(this, _getPaddedData2);
|
31510
31691
|
}
|
31511
31692
|
encode(value) {
|
31512
|
-
const
|
31513
|
-
const
|
31514
|
-
|
31693
|
+
const parts = [];
|
31694
|
+
const pointer = new BigNumberCoder("u64").encode(BASE_VECTOR_OFFSET);
|
31695
|
+
const data = __privateMethod2(this, _getPaddedData2, getPaddedData_fn2).call(this, value);
|
31696
|
+
pointer.dynamicData = {
|
31697
|
+
0: concatWithDynamicData([data])
|
31698
|
+
};
|
31699
|
+
parts.push(pointer);
|
31700
|
+
parts.push(new BigNumberCoder("u64").encode(data.byteLength));
|
31701
|
+
parts.push(new BigNumberCoder("u64").encode(value.length));
|
31702
|
+
return concatWithDynamicData(parts);
|
31515
31703
|
}
|
31516
31704
|
decode(data, offset) {
|
31517
31705
|
if (data.length < this.encodedLength) {
|
31518
31706
|
throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid std string data size.`);
|
31519
31707
|
}
|
31520
|
-
const
|
31521
|
-
const
|
31522
|
-
const
|
31523
|
-
|
31524
|
-
if (dataBytes.length !== length) {
|
31708
|
+
const len = data.slice(16, 24);
|
31709
|
+
const encodedLength = bn(new BigNumberCoder("u64").decode(len, 0)[0]).toNumber();
|
31710
|
+
const byteData = data.slice(BASE_VECTOR_OFFSET, BASE_VECTOR_OFFSET + encodedLength);
|
31711
|
+
if (byteData.length !== encodedLength) {
|
31525
31712
|
throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid std string byte data size.`);
|
31526
31713
|
}
|
31527
|
-
|
31714
|
+
const value = toUtf8String(byteData);
|
31715
|
+
return [value, offset + BASE_VECTOR_OFFSET];
|
31528
31716
|
}
|
31529
31717
|
};
|
31718
|
+
_getPaddedData2 = /* @__PURE__ */ new WeakSet();
|
31719
|
+
getPaddedData_fn2 = function(value) {
|
31720
|
+
const data = [toUtf8Bytes(value)];
|
31721
|
+
const paddingLength = (WORD_SIZE - value.length % WORD_SIZE) % WORD_SIZE;
|
31722
|
+
if (paddingLength) {
|
31723
|
+
data.push(new Uint8Array(paddingLength));
|
31724
|
+
}
|
31725
|
+
return concat(data);
|
31726
|
+
};
|
31530
31727
|
__publicField4(StdStringCoder, "memorySize", 1);
|
31531
|
-
var
|
31532
|
-
|
31533
|
-
|
31728
|
+
var StringCoder = class extends Coder {
|
31729
|
+
length;
|
31730
|
+
#paddingLength;
|
31731
|
+
constructor(length) {
|
31732
|
+
let paddingLength = (8 - length) % 8;
|
31733
|
+
paddingLength = paddingLength < 0 ? paddingLength + 8 : paddingLength;
|
31734
|
+
super("string", `str[${length}]`, length + paddingLength);
|
31735
|
+
this.length = length;
|
31736
|
+
this.#paddingLength = paddingLength;
|
31534
31737
|
}
|
31535
31738
|
encode(value) {
|
31536
|
-
|
31537
|
-
const lengthBytes = new BigNumberCoder("u64").encode(value.length);
|
31538
|
-
return new Uint8Array([...lengthBytes, ...bytes2]);
|
31539
|
-
}
|
31540
|
-
decode(data, offset) {
|
31541
|
-
if (data.length < this.encodedLength) {
|
31542
|
-
throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid string slice data size.`);
|
31543
|
-
}
|
31544
|
-
const offsetAndLength = offset + WORD_SIZE;
|
31545
|
-
const lengthBytes = data.slice(offset, offsetAndLength);
|
31546
|
-
const length = bn(new BigNumberCoder("u64").decode(lengthBytes, 0)[0]).toNumber();
|
31547
|
-
const bytes2 = data.slice(offsetAndLength, offsetAndLength + length);
|
31548
|
-
if (bytes2.length !== length) {
|
31549
|
-
throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid string slice byte data size.`);
|
31550
|
-
}
|
31551
|
-
return [toUtf8String(bytes2), offsetAndLength + length];
|
31552
|
-
}
|
31553
|
-
};
|
31554
|
-
__publicField4(StrSliceCoder, "memorySize", 1);
|
31555
|
-
var StringCoder = class extends Coder {
|
31556
|
-
constructor(length) {
|
31557
|
-
super("string", `str[${length}]`, length);
|
31558
|
-
}
|
31559
|
-
encode(value) {
|
31560
|
-
if (value.length !== this.encodedLength) {
|
31739
|
+
if (this.length !== value.length) {
|
31561
31740
|
throw new FuelError(ErrorCode.ENCODE_ERROR, `Value length mismatch during encode.`);
|
31562
31741
|
}
|
31563
|
-
|
31742
|
+
const encoded = toUtf8Bytes(value);
|
31743
|
+
const padding = new Uint8Array(this.#paddingLength);
|
31744
|
+
return concat([encoded, padding]);
|
31564
31745
|
}
|
31565
31746
|
decode(data, offset) {
|
31566
31747
|
if (data.length < this.encodedLength) {
|
31567
31748
|
throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid string data size.`);
|
31568
31749
|
}
|
31569
|
-
const bytes2 = data.slice(offset, offset + this.
|
31570
|
-
if (bytes2.length !== this.
|
31750
|
+
const bytes2 = data.slice(offset, offset + this.length);
|
31751
|
+
if (bytes2.length !== this.length) {
|
31571
31752
|
throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid string byte data size.`);
|
31572
31753
|
}
|
31573
|
-
|
31754
|
+
const value = toUtf8String(bytes2);
|
31755
|
+
const padding = this.#paddingLength;
|
31756
|
+
return [value, offset + this.length + padding];
|
31574
31757
|
}
|
31575
31758
|
};
|
31576
31759
|
var StructCoder = class extends Coder {
|
@@ -31586,19 +31769,22 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
31586
31769
|
this.coders = coders;
|
31587
31770
|
}
|
31588
31771
|
encode(value) {
|
31589
|
-
|
31590
|
-
|
31591
|
-
|
31592
|
-
|
31593
|
-
|
31594
|
-
|
31595
|
-
|
31596
|
-
|
31597
|
-
|
31598
|
-
|
31599
|
-
|
31600
|
-
|
31601
|
-
|
31772
|
+
const encodedFields = Object.keys(this.coders).map((fieldName) => {
|
31773
|
+
const fieldCoder = this.coders[fieldName];
|
31774
|
+
const fieldValue = value[fieldName];
|
31775
|
+
if (!(fieldCoder instanceof OptionCoder) && fieldValue == null) {
|
31776
|
+
throw new FuelError(
|
31777
|
+
ErrorCode.ENCODE_ERROR,
|
31778
|
+
`Invalid ${this.type}. Field "${fieldName}" not present.`
|
31779
|
+
);
|
31780
|
+
}
|
31781
|
+
const encoded = fieldCoder.encode(fieldValue);
|
31782
|
+
if (!isMultipleOfWordSize(encoded.length)) {
|
31783
|
+
return rightPadToWordSize(encoded);
|
31784
|
+
}
|
31785
|
+
return encoded;
|
31786
|
+
});
|
31787
|
+
return concatWithDynamicData([concatWithDynamicData(encodedFields)]);
|
31602
31788
|
}
|
31603
31789
|
decode(data, offset) {
|
31604
31790
|
if (data.length < this.encodedLength) {
|
@@ -31609,6 +31795,9 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
31609
31795
|
const fieldCoder = this.coders[fieldName];
|
31610
31796
|
let decoded;
|
31611
31797
|
[decoded, newOffset] = fieldCoder.decode(data, newOffset);
|
31798
|
+
if (!isMultipleOfWordSize(newOffset)) {
|
31799
|
+
newOffset += getWordSizePadding(newOffset);
|
31800
|
+
}
|
31612
31801
|
obj[fieldName] = decoded;
|
31613
31802
|
return obj;
|
31614
31803
|
}, {});
|
@@ -31626,7 +31815,15 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
31626
31815
|
if (this.coders.length !== value.length) {
|
31627
31816
|
throw new FuelError(ErrorCode.ENCODE_ERROR, `Types/values length mismatch.`);
|
31628
31817
|
}
|
31629
|
-
return
|
31818
|
+
return concatWithDynamicData(
|
31819
|
+
this.coders.map((coder, i) => {
|
31820
|
+
const encoded = coder.encode(value[i]);
|
31821
|
+
if (!isMultipleOfWordSize(encoded.length)) {
|
31822
|
+
return rightPadToWordSize(encoded);
|
31823
|
+
}
|
31824
|
+
return encoded;
|
31825
|
+
})
|
31826
|
+
);
|
31630
31827
|
}
|
31631
31828
|
decode(data, offset) {
|
31632
31829
|
if (data.length < this.encodedLength) {
|
@@ -31636,19 +31833,19 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
31636
31833
|
const decodedValue = this.coders.map((coder) => {
|
31637
31834
|
let decoded;
|
31638
31835
|
[decoded, newOffset] = coder.decode(data, newOffset);
|
31836
|
+
if (!isMultipleOfWordSize(newOffset)) {
|
31837
|
+
newOffset += getWordSizePadding(newOffset);
|
31838
|
+
}
|
31639
31839
|
return decoded;
|
31640
31840
|
});
|
31641
31841
|
return [decodedValue, newOffset];
|
31642
31842
|
}
|
31643
31843
|
};
|
31644
|
-
var isUint8Array = (value) => value instanceof Uint8Array;
|
31645
31844
|
var VecCoder = class extends Coder {
|
31646
31845
|
coder;
|
31647
|
-
#isOptionVec;
|
31648
31846
|
constructor(coder) {
|
31649
|
-
super("struct", `struct Vec`, coder.encodedLength +
|
31847
|
+
super("struct", `struct Vec`, coder.encodedLength + BASE_VECTOR_OFFSET);
|
31650
31848
|
this.coder = coder;
|
31651
|
-
this.#isOptionVec = this.coder instanceof OptionCoder;
|
31652
31849
|
}
|
31653
31850
|
encode(value) {
|
31654
31851
|
if (!Array.isArray(value) && !isUint8Array(value)) {
|
@@ -31657,39 +31854,40 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
31657
31854
|
`Expected array value, or a Uint8Array. You can use arrayify to convert a value to a Uint8Array.`
|
31658
31855
|
);
|
31659
31856
|
}
|
31660
|
-
const
|
31661
|
-
|
31662
|
-
|
31663
|
-
|
31664
|
-
|
31665
|
-
|
31666
|
-
|
31857
|
+
const parts = [];
|
31858
|
+
const pointer = new BigNumberCoder("u64").encode(BASE_VECTOR_OFFSET);
|
31859
|
+
pointer.dynamicData = {
|
31860
|
+
0: concatWithDynamicData(Array.from(value).map((v) => this.coder.encode(v)))
|
31861
|
+
};
|
31862
|
+
parts.push(pointer);
|
31863
|
+
parts.push(new BigNumberCoder("u64").encode(value.length));
|
31864
|
+
parts.push(new BigNumberCoder("u64").encode(value.length));
|
31865
|
+
return concatWithDynamicData(parts);
|
31667
31866
|
}
|
31668
31867
|
decode(data, offset) {
|
31669
|
-
if (
|
31868
|
+
if (data.length < BASE_VECTOR_OFFSET || data.length > MAX_BYTES) {
|
31670
31869
|
throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid vec data size.`);
|
31671
31870
|
}
|
31672
|
-
const
|
31673
|
-
const
|
31674
|
-
const
|
31675
|
-
const
|
31676
|
-
|
31677
|
-
if (!this.#isOptionVec && dataBytes.length !== dataLength2) {
|
31871
|
+
const len = data.slice(16, 24);
|
31872
|
+
const encodedLength = bn(new BigNumberCoder("u64").decode(len, 0)[0]).toNumber();
|
31873
|
+
const vectorRawDataLength = encodedLength * this.coder.encodedLength;
|
31874
|
+
const vectorRawData = data.slice(BASE_VECTOR_OFFSET, BASE_VECTOR_OFFSET + vectorRawDataLength);
|
31875
|
+
if (vectorRawData.length !== vectorRawDataLength) {
|
31678
31876
|
throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid vec byte data size.`);
|
31679
31877
|
}
|
31680
|
-
|
31681
|
-
|
31682
|
-
|
31683
|
-
|
31684
|
-
|
31685
|
-
|
31686
|
-
}
|
31687
|
-
return [chunks, newOffset];
|
31878
|
+
return [
|
31879
|
+
chunkByLength(vectorRawData, this.coder.encodedLength).map(
|
31880
|
+
(chunk) => this.coder.decode(chunk, 0)[0]
|
31881
|
+
),
|
31882
|
+
offset + BASE_VECTOR_OFFSET
|
31883
|
+
];
|
31688
31884
|
}
|
31689
31885
|
};
|
31690
31886
|
var getEncodingVersion = (encoding) => {
|
31691
31887
|
switch (encoding) {
|
31692
31888
|
case void 0:
|
31889
|
+
case ENCODING_V0:
|
31890
|
+
return ENCODING_V0;
|
31693
31891
|
case ENCODING_V1:
|
31694
31892
|
return ENCODING_V1;
|
31695
31893
|
default:
|
@@ -31750,151 +31948,629 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
31750
31948
|
type3.typeParameters ?? ResolvedAbiType.getImplicitGenericTypeParameters(abi, type3.components)
|
31751
31949
|
);
|
31752
31950
|
}
|
31753
|
-
static getResolvedGenericComponents(abi, arg, components, typeParameters) {
|
31754
|
-
if (components === null) {
|
31755
|
-
return null;
|
31756
|
-
}
|
31757
|
-
if (typeParameters === null || typeParameters.length === 0) {
|
31758
|
-
return components.map((c) => new ResolvedAbiType(abi, c));
|
31951
|
+
static getResolvedGenericComponents(abi, arg, components, typeParameters) {
|
31952
|
+
if (components === null) {
|
31953
|
+
return null;
|
31954
|
+
}
|
31955
|
+
if (typeParameters === null || typeParameters.length === 0) {
|
31956
|
+
return components.map((c) => new ResolvedAbiType(abi, c));
|
31957
|
+
}
|
31958
|
+
const typeParametersAndArgsMap = typeParameters.reduce(
|
31959
|
+
(obj, typeParameter, typeParameterIndex) => {
|
31960
|
+
const o = { ...obj };
|
31961
|
+
o[typeParameter] = structuredClone(
|
31962
|
+
arg.typeArguments?.[typeParameterIndex]
|
31963
|
+
);
|
31964
|
+
return o;
|
31965
|
+
},
|
31966
|
+
{}
|
31967
|
+
);
|
31968
|
+
const resolvedComponents = this.resolveGenericArgTypes(
|
31969
|
+
abi,
|
31970
|
+
components,
|
31971
|
+
typeParametersAndArgsMap
|
31972
|
+
);
|
31973
|
+
return resolvedComponents.map((c) => new ResolvedAbiType(abi, c));
|
31974
|
+
}
|
31975
|
+
static resolveGenericArgTypes(abi, args, typeParametersAndArgsMap) {
|
31976
|
+
return args.map((arg) => {
|
31977
|
+
if (typeParametersAndArgsMap[arg.type] !== void 0) {
|
31978
|
+
return {
|
31979
|
+
...typeParametersAndArgsMap[arg.type],
|
31980
|
+
name: arg.name
|
31981
|
+
};
|
31982
|
+
}
|
31983
|
+
if (arg.typeArguments) {
|
31984
|
+
return {
|
31985
|
+
...structuredClone(arg),
|
31986
|
+
typeArguments: this.resolveGenericArgTypes(
|
31987
|
+
abi,
|
31988
|
+
arg.typeArguments,
|
31989
|
+
typeParametersAndArgsMap
|
31990
|
+
)
|
31991
|
+
};
|
31992
|
+
}
|
31993
|
+
const argType = findTypeById(abi, arg.type);
|
31994
|
+
const implicitTypeParameters = this.getImplicitGenericTypeParameters(abi, argType.components);
|
31995
|
+
if (implicitTypeParameters && implicitTypeParameters.length > 0) {
|
31996
|
+
return {
|
31997
|
+
...structuredClone(arg),
|
31998
|
+
typeArguments: implicitTypeParameters.map((itp) => typeParametersAndArgsMap[itp])
|
31999
|
+
};
|
32000
|
+
}
|
32001
|
+
return arg;
|
32002
|
+
});
|
32003
|
+
}
|
32004
|
+
static getImplicitGenericTypeParameters(abi, args, implicitGenericParametersParam) {
|
32005
|
+
if (!Array.isArray(args)) {
|
32006
|
+
return null;
|
32007
|
+
}
|
32008
|
+
const implicitGenericParameters = implicitGenericParametersParam ?? [];
|
32009
|
+
args.forEach((a) => {
|
32010
|
+
const argType = findTypeById(abi, a.type);
|
32011
|
+
if (genericRegEx.test(argType.type)) {
|
32012
|
+
implicitGenericParameters.push(argType.typeId);
|
32013
|
+
return;
|
32014
|
+
}
|
32015
|
+
if (!Array.isArray(a.typeArguments)) {
|
32016
|
+
return;
|
32017
|
+
}
|
32018
|
+
this.getImplicitGenericTypeParameters(abi, a.typeArguments, implicitGenericParameters);
|
32019
|
+
});
|
32020
|
+
return implicitGenericParameters.length > 0 ? implicitGenericParameters : null;
|
32021
|
+
}
|
32022
|
+
getSignature() {
|
32023
|
+
const prefix = this.getArgSignaturePrefix();
|
32024
|
+
const content = this.getArgSignatureContent();
|
32025
|
+
return `${prefix}${content}`;
|
32026
|
+
}
|
32027
|
+
getArgSignaturePrefix() {
|
32028
|
+
const structMatch = structRegEx.test(this.type);
|
32029
|
+
if (structMatch) {
|
32030
|
+
return "s";
|
32031
|
+
}
|
32032
|
+
const arrayMatch = arrayRegEx.test(this.type);
|
32033
|
+
if (arrayMatch) {
|
32034
|
+
return "a";
|
32035
|
+
}
|
32036
|
+
const enumMatch = enumRegEx.test(this.type);
|
32037
|
+
if (enumMatch) {
|
32038
|
+
return "e";
|
32039
|
+
}
|
32040
|
+
return "";
|
32041
|
+
}
|
32042
|
+
getArgSignatureContent() {
|
32043
|
+
if (this.type === "raw untyped ptr") {
|
32044
|
+
return "rawptr";
|
32045
|
+
}
|
32046
|
+
if (this.type === "raw untyped slice") {
|
32047
|
+
return "rawslice";
|
32048
|
+
}
|
32049
|
+
const strMatch = stringRegEx.exec(this.type)?.groups;
|
32050
|
+
if (strMatch) {
|
32051
|
+
return `str[${strMatch.length}]`;
|
32052
|
+
}
|
32053
|
+
if (this.components === null) {
|
32054
|
+
return this.type;
|
32055
|
+
}
|
32056
|
+
const arrayMatch = arrayRegEx.exec(this.type)?.groups;
|
32057
|
+
if (arrayMatch) {
|
32058
|
+
return `[${this.components[0].getSignature()};${arrayMatch.length}]`;
|
32059
|
+
}
|
32060
|
+
const typeArgumentsSignature = this.originalTypeArguments !== null ? `<${this.originalTypeArguments.map((a) => new ResolvedAbiType(this.abi, a).getSignature()).join(",")}>` : "";
|
32061
|
+
const componentsSignature = `(${this.components.map((c) => c.getSignature()).join(",")})`;
|
32062
|
+
return `${typeArgumentsSignature}${componentsSignature}`;
|
32063
|
+
}
|
32064
|
+
};
|
32065
|
+
function getCoders(components, options) {
|
32066
|
+
const { getCoder: getCoder3 } = options;
|
32067
|
+
return components.reduce((obj, component) => {
|
32068
|
+
const o = obj;
|
32069
|
+
o[component.name] = getCoder3(component, options);
|
32070
|
+
return o;
|
32071
|
+
}, {});
|
32072
|
+
}
|
32073
|
+
var getCoder = (resolvedAbiType, options) => {
|
32074
|
+
switch (resolvedAbiType.type) {
|
32075
|
+
case U8_CODER_TYPE:
|
32076
|
+
case U16_CODER_TYPE:
|
32077
|
+
case U32_CODER_TYPE:
|
32078
|
+
return new NumberCoder(resolvedAbiType.type, options);
|
32079
|
+
case U64_CODER_TYPE:
|
32080
|
+
case RAW_PTR_CODER_TYPE:
|
32081
|
+
return new BigNumberCoder("u64");
|
32082
|
+
case U256_CODER_TYPE:
|
32083
|
+
return new BigNumberCoder("u256");
|
32084
|
+
case RAW_SLICE_CODER_TYPE:
|
32085
|
+
return new RawSliceCoder();
|
32086
|
+
case BOOL_CODER_TYPE:
|
32087
|
+
return new BooleanCoder(options);
|
32088
|
+
case B256_CODER_TYPE:
|
32089
|
+
return new B256Coder();
|
32090
|
+
case B512_CODER_TYPE:
|
32091
|
+
return new B512Coder();
|
32092
|
+
case BYTES_CODER_TYPE:
|
32093
|
+
return new ByteCoder();
|
32094
|
+
case STD_STRING_CODER_TYPE:
|
32095
|
+
return new StdStringCoder();
|
32096
|
+
default:
|
32097
|
+
break;
|
32098
|
+
}
|
32099
|
+
const stringMatch = stringRegEx.exec(resolvedAbiType.type)?.groups;
|
32100
|
+
if (stringMatch) {
|
32101
|
+
const length = parseInt(stringMatch.length, 10);
|
32102
|
+
return new StringCoder(length);
|
32103
|
+
}
|
32104
|
+
const components = resolvedAbiType.components;
|
32105
|
+
const arrayMatch = arrayRegEx.exec(resolvedAbiType.type)?.groups;
|
32106
|
+
if (arrayMatch) {
|
32107
|
+
const length = parseInt(arrayMatch.length, 10);
|
32108
|
+
const arg = components[0];
|
32109
|
+
if (!arg) {
|
32110
|
+
throw new FuelError(
|
32111
|
+
ErrorCode.INVALID_COMPONENT,
|
32112
|
+
`The provided Array type is missing an item of 'component'.`
|
32113
|
+
);
|
32114
|
+
}
|
32115
|
+
const arrayElementCoder = getCoder(arg, { isSmallBytes: true });
|
32116
|
+
return new ArrayCoder(arrayElementCoder, length);
|
32117
|
+
}
|
32118
|
+
if (resolvedAbiType.type === VEC_CODER_TYPE) {
|
32119
|
+
const arg = findVectorBufferArgument(components);
|
32120
|
+
const argType = new ResolvedAbiType(resolvedAbiType.abi, arg);
|
32121
|
+
const itemCoder = getCoder(argType, { isSmallBytes: true, encoding: ENCODING_V0 });
|
32122
|
+
return new VecCoder(itemCoder);
|
32123
|
+
}
|
32124
|
+
const structMatch = structRegEx.exec(resolvedAbiType.type)?.groups;
|
32125
|
+
if (structMatch) {
|
32126
|
+
const coders = getCoders(components, { isRightPadded: true, getCoder });
|
32127
|
+
return new StructCoder(structMatch.name, coders);
|
32128
|
+
}
|
32129
|
+
const enumMatch = enumRegEx.exec(resolvedAbiType.type)?.groups;
|
32130
|
+
if (enumMatch) {
|
32131
|
+
const coders = getCoders(components, { getCoder });
|
32132
|
+
const isOptionEnum = resolvedAbiType.type === OPTION_CODER_TYPE;
|
32133
|
+
if (isOptionEnum) {
|
32134
|
+
return new OptionCoder(enumMatch.name, coders);
|
32135
|
+
}
|
32136
|
+
return new EnumCoder(enumMatch.name, coders);
|
32137
|
+
}
|
32138
|
+
const tupleMatch = tupleRegEx.exec(resolvedAbiType.type)?.groups;
|
32139
|
+
if (tupleMatch) {
|
32140
|
+
const coders = components.map(
|
32141
|
+
(component) => getCoder(component, { isRightPadded: true, encoding: ENCODING_V0 })
|
32142
|
+
);
|
32143
|
+
return new TupleCoder(coders);
|
32144
|
+
}
|
32145
|
+
if (resolvedAbiType.type === STR_SLICE_CODER_TYPE) {
|
32146
|
+
throw new FuelError(
|
32147
|
+
ErrorCode.INVALID_DATA,
|
32148
|
+
"String slices can not be decoded from logs. Convert the slice to `str[N]` with `__to_str_array`"
|
32149
|
+
);
|
32150
|
+
}
|
32151
|
+
throw new FuelError(
|
32152
|
+
ErrorCode.CODER_NOT_FOUND,
|
32153
|
+
`Coder not found: ${JSON.stringify(resolvedAbiType)}.`
|
32154
|
+
);
|
32155
|
+
};
|
32156
|
+
var BooleanCoder2 = class extends Coder {
|
32157
|
+
constructor() {
|
32158
|
+
super("boolean", "boolean", 1);
|
32159
|
+
}
|
32160
|
+
encode(value) {
|
32161
|
+
const isTrueBool = value === true || value === false;
|
32162
|
+
if (!isTrueBool) {
|
32163
|
+
throw new FuelError(ErrorCode.ENCODE_ERROR, `Invalid boolean value.`);
|
32164
|
+
}
|
32165
|
+
return toBytes2(value ? 1 : 0, this.encodedLength);
|
32166
|
+
}
|
32167
|
+
decode(data, offset) {
|
32168
|
+
if (data.length < this.encodedLength) {
|
32169
|
+
throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid boolean data size.`);
|
32170
|
+
}
|
32171
|
+
const bytes2 = bn(data.slice(offset, offset + this.encodedLength));
|
32172
|
+
if (bytes2.isZero()) {
|
32173
|
+
return [false, offset + this.encodedLength];
|
32174
|
+
}
|
32175
|
+
if (!bytes2.eq(bn(1))) {
|
32176
|
+
throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid boolean value.`);
|
32177
|
+
}
|
32178
|
+
return [true, offset + this.encodedLength];
|
32179
|
+
}
|
32180
|
+
};
|
32181
|
+
var ByteCoder2 = class extends Coder {
|
32182
|
+
constructor() {
|
32183
|
+
super("struct", "struct Bytes", WORD_SIZE);
|
32184
|
+
}
|
32185
|
+
encode(value) {
|
32186
|
+
const bytes2 = value instanceof Uint8Array ? value : new Uint8Array(value);
|
32187
|
+
const lengthBytes = new BigNumberCoder("u64").encode(bytes2.length);
|
32188
|
+
return new Uint8Array([...lengthBytes, ...bytes2]);
|
32189
|
+
}
|
32190
|
+
decode(data, offset) {
|
32191
|
+
if (data.length < WORD_SIZE) {
|
32192
|
+
throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid byte data size.`);
|
32193
|
+
}
|
32194
|
+
const offsetAndLength = offset + WORD_SIZE;
|
32195
|
+
const lengthBytes = data.slice(offset, offsetAndLength);
|
32196
|
+
const length = bn(new BigNumberCoder("u64").decode(lengthBytes, 0)[0]).toNumber();
|
32197
|
+
const dataBytes = data.slice(offsetAndLength, offsetAndLength + length);
|
32198
|
+
if (dataBytes.length !== length) {
|
32199
|
+
throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid bytes byte data size.`);
|
32200
|
+
}
|
32201
|
+
return [dataBytes, offsetAndLength + length];
|
32202
|
+
}
|
32203
|
+
};
|
32204
|
+
__publicField4(ByteCoder2, "memorySize", 1);
|
32205
|
+
var isFullyNativeEnum2 = (enumCoders) => Object.values(enumCoders).every(
|
32206
|
+
// @ts-expect-error complicated types
|
32207
|
+
({ type: type3, coders }) => type3 === "()" && JSON.stringify(coders) === JSON.stringify([])
|
32208
|
+
);
|
32209
|
+
var EnumCoder2 = class extends Coder {
|
32210
|
+
name;
|
32211
|
+
coders;
|
32212
|
+
#caseIndexCoder;
|
32213
|
+
#encodedValueSize;
|
32214
|
+
constructor(name, coders) {
|
32215
|
+
const caseIndexCoder = new BigNumberCoder("u64");
|
32216
|
+
const encodedValueSize = Object.values(coders).reduce(
|
32217
|
+
(max, coder) => Math.max(max, coder.encodedLength),
|
32218
|
+
0
|
32219
|
+
);
|
32220
|
+
super(`enum ${name}`, `enum ${name}`, caseIndexCoder.encodedLength + encodedValueSize);
|
32221
|
+
this.name = name;
|
32222
|
+
this.coders = coders;
|
32223
|
+
this.#caseIndexCoder = caseIndexCoder;
|
32224
|
+
this.#encodedValueSize = encodedValueSize;
|
32225
|
+
}
|
32226
|
+
#encodeNativeEnum(value) {
|
32227
|
+
const valueCoder = this.coders[value];
|
32228
|
+
const encodedValue = valueCoder.encode([]);
|
32229
|
+
const caseIndex = Object.keys(this.coders).indexOf(value);
|
32230
|
+
const padding = new Uint8Array(this.#encodedValueSize - valueCoder.encodedLength);
|
32231
|
+
return concat([this.#caseIndexCoder.encode(caseIndex), padding, encodedValue]);
|
32232
|
+
}
|
32233
|
+
encode(value) {
|
32234
|
+
if (typeof value === "string" && this.coders[value]) {
|
32235
|
+
return this.#encodeNativeEnum(value);
|
32236
|
+
}
|
32237
|
+
const [caseKey, ...empty] = Object.keys(value);
|
32238
|
+
if (!caseKey) {
|
32239
|
+
throw new FuelError(ErrorCode.INVALID_DECODE_VALUE, "A field for the case must be provided.");
|
32240
|
+
}
|
32241
|
+
if (empty.length !== 0) {
|
32242
|
+
throw new FuelError(ErrorCode.INVALID_DECODE_VALUE, "Only one field must be provided.");
|
32243
|
+
}
|
32244
|
+
const valueCoder = this.coders[caseKey];
|
32245
|
+
const caseIndex = Object.keys(this.coders).indexOf(caseKey);
|
32246
|
+
const encodedValue = valueCoder.encode(value[caseKey]);
|
32247
|
+
return new Uint8Array([...this.#caseIndexCoder.encode(caseIndex), ...encodedValue]);
|
32248
|
+
}
|
32249
|
+
#decodeNativeEnum(caseKey, newOffset) {
|
32250
|
+
return [caseKey, newOffset];
|
32251
|
+
}
|
32252
|
+
decode(data, offset) {
|
32253
|
+
if (data.length < this.#encodedValueSize) {
|
32254
|
+
throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid enum data size.`);
|
32255
|
+
}
|
32256
|
+
const caseBytes = new BigNumberCoder("u64").decode(data, offset)[0];
|
32257
|
+
const caseIndex = toNumber(caseBytes);
|
32258
|
+
const caseKey = Object.keys(this.coders)[caseIndex];
|
32259
|
+
if (!caseKey) {
|
32260
|
+
throw new FuelError(
|
32261
|
+
ErrorCode.INVALID_DECODE_VALUE,
|
32262
|
+
`Invalid caseIndex "${caseIndex}". Valid cases: ${Object.keys(this.coders)}.`
|
32263
|
+
);
|
32264
|
+
}
|
32265
|
+
const valueCoder = this.coders[caseKey];
|
32266
|
+
const offsetAndCase = offset + WORD_SIZE;
|
32267
|
+
const [decoded, newOffset] = valueCoder.decode(data, offsetAndCase);
|
32268
|
+
if (isFullyNativeEnum2(this.coders)) {
|
32269
|
+
return this.#decodeNativeEnum(caseKey, newOffset);
|
32270
|
+
}
|
32271
|
+
return [{ [caseKey]: decoded }, newOffset];
|
32272
|
+
}
|
32273
|
+
};
|
32274
|
+
var getLength = (baseType) => {
|
32275
|
+
switch (baseType) {
|
32276
|
+
case "u8":
|
32277
|
+
return 1;
|
32278
|
+
case "u16":
|
32279
|
+
return 2;
|
32280
|
+
case "u32":
|
32281
|
+
return 4;
|
32282
|
+
default:
|
32283
|
+
throw new FuelError(ErrorCode.TYPE_NOT_SUPPORTED, `Invalid number type: ${baseType}`);
|
32284
|
+
}
|
32285
|
+
};
|
32286
|
+
var NumberCoder2 = class extends Coder {
|
32287
|
+
length;
|
32288
|
+
baseType;
|
32289
|
+
constructor(baseType) {
|
32290
|
+
const length = getLength(baseType);
|
32291
|
+
super("number", baseType, length);
|
32292
|
+
this.baseType = baseType;
|
32293
|
+
this.length = length;
|
32294
|
+
}
|
32295
|
+
encode(value) {
|
32296
|
+
let bytes2;
|
32297
|
+
try {
|
32298
|
+
bytes2 = toBytes2(value);
|
32299
|
+
} catch (error) {
|
32300
|
+
throw new FuelError(ErrorCode.ENCODE_ERROR, `Invalid ${this.baseType}.`);
|
32301
|
+
}
|
32302
|
+
if (bytes2.length > this.length) {
|
32303
|
+
throw new FuelError(ErrorCode.ENCODE_ERROR, `Invalid ${this.baseType}, too many bytes.`);
|
32304
|
+
}
|
32305
|
+
return toBytes2(bytes2, this.length);
|
32306
|
+
}
|
32307
|
+
decode(data, offset) {
|
32308
|
+
if (data.length < this.encodedLength) {
|
32309
|
+
throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid number data size.`);
|
32310
|
+
}
|
32311
|
+
const bytes2 = data.slice(offset, offset + this.length);
|
32312
|
+
if (bytes2.length !== this.encodedLength) {
|
32313
|
+
throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid number byte data size.`);
|
32314
|
+
}
|
32315
|
+
return [toNumber(bytes2), offset + this.length];
|
32316
|
+
}
|
32317
|
+
};
|
32318
|
+
var OptionCoder2 = class extends EnumCoder2 {
|
32319
|
+
encode(value) {
|
32320
|
+
const result = super.encode(this.toSwayOption(value));
|
32321
|
+
return result;
|
32322
|
+
}
|
32323
|
+
toSwayOption(input) {
|
32324
|
+
if (input !== void 0) {
|
32325
|
+
return { Some: input };
|
32326
|
+
}
|
32327
|
+
return { None: [] };
|
32328
|
+
}
|
32329
|
+
decode(data, offset) {
|
32330
|
+
const [decoded, newOffset] = super.decode(data, offset);
|
32331
|
+
return [this.toOption(decoded), newOffset];
|
32332
|
+
}
|
32333
|
+
toOption(output2) {
|
32334
|
+
if (output2 && "Some" in output2) {
|
32335
|
+
return output2.Some;
|
32336
|
+
}
|
32337
|
+
return void 0;
|
32338
|
+
}
|
32339
|
+
};
|
32340
|
+
var RawSliceCoder2 = class extends Coder {
|
32341
|
+
constructor() {
|
32342
|
+
super("raw untyped slice", "raw untyped slice", WORD_SIZE);
|
32343
|
+
}
|
32344
|
+
encode(value) {
|
32345
|
+
if (!Array.isArray(value)) {
|
32346
|
+
throw new FuelError(ErrorCode.ENCODE_ERROR, `Expected array value.`);
|
32347
|
+
}
|
32348
|
+
const internalCoder = new ArrayCoder(new NumberCoder2("u8"), value.length);
|
32349
|
+
const bytes2 = internalCoder.encode(value);
|
32350
|
+
const lengthBytes = new BigNumberCoder("u64").encode(bytes2.length);
|
32351
|
+
return new Uint8Array([...lengthBytes, ...bytes2]);
|
32352
|
+
}
|
32353
|
+
decode(data, offset) {
|
32354
|
+
if (data.length < this.encodedLength) {
|
32355
|
+
throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid raw slice data size.`);
|
32356
|
+
}
|
32357
|
+
const offsetAndLength = offset + WORD_SIZE;
|
32358
|
+
const lengthBytes = data.slice(offset, offsetAndLength);
|
32359
|
+
const length = bn(new BigNumberCoder("u64").decode(lengthBytes, 0)[0]).toNumber();
|
32360
|
+
const dataBytes = data.slice(offsetAndLength, offsetAndLength + length);
|
32361
|
+
if (dataBytes.length !== length) {
|
32362
|
+
throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid raw slice byte data size.`);
|
32363
|
+
}
|
32364
|
+
const internalCoder = new ArrayCoder(new NumberCoder2("u8"), length);
|
32365
|
+
const [decodedValue] = internalCoder.decode(dataBytes, 0);
|
32366
|
+
return [decodedValue, offsetAndLength + length];
|
32367
|
+
}
|
32368
|
+
};
|
32369
|
+
var StdStringCoder2 = class extends Coder {
|
32370
|
+
constructor() {
|
32371
|
+
super("struct", "struct String", WORD_SIZE);
|
32372
|
+
}
|
32373
|
+
encode(value) {
|
32374
|
+
const bytes2 = toUtf8Bytes(value);
|
32375
|
+
const lengthBytes = new BigNumberCoder("u64").encode(value.length);
|
32376
|
+
return new Uint8Array([...lengthBytes, ...bytes2]);
|
32377
|
+
}
|
32378
|
+
decode(data, offset) {
|
32379
|
+
if (data.length < this.encodedLength) {
|
32380
|
+
throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid std string data size.`);
|
32381
|
+
}
|
32382
|
+
const offsetAndLength = offset + WORD_SIZE;
|
32383
|
+
const lengthBytes = data.slice(offset, offsetAndLength);
|
32384
|
+
const length = bn(new BigNumberCoder("u64").decode(lengthBytes, 0)[0]).toNumber();
|
32385
|
+
const dataBytes = data.slice(offsetAndLength, offsetAndLength + length);
|
32386
|
+
if (dataBytes.length !== length) {
|
32387
|
+
throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid std string byte data size.`);
|
32388
|
+
}
|
32389
|
+
return [toUtf8String(dataBytes), offsetAndLength + length];
|
32390
|
+
}
|
32391
|
+
};
|
32392
|
+
__publicField4(StdStringCoder2, "memorySize", 1);
|
32393
|
+
var StrSliceCoder = class extends Coder {
|
32394
|
+
constructor() {
|
32395
|
+
super("strSlice", "str", WORD_SIZE);
|
32396
|
+
}
|
32397
|
+
encode(value) {
|
32398
|
+
const bytes2 = toUtf8Bytes(value);
|
32399
|
+
const lengthBytes = new BigNumberCoder("u64").encode(value.length);
|
32400
|
+
return new Uint8Array([...lengthBytes, ...bytes2]);
|
32401
|
+
}
|
32402
|
+
decode(data, offset) {
|
32403
|
+
if (data.length < this.encodedLength) {
|
32404
|
+
throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid string slice data size.`);
|
32405
|
+
}
|
32406
|
+
const offsetAndLength = offset + WORD_SIZE;
|
32407
|
+
const lengthBytes = data.slice(offset, offsetAndLength);
|
32408
|
+
const length = bn(new BigNumberCoder("u64").decode(lengthBytes, 0)[0]).toNumber();
|
32409
|
+
const bytes2 = data.slice(offsetAndLength, offsetAndLength + length);
|
32410
|
+
if (bytes2.length !== length) {
|
32411
|
+
throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid string slice byte data size.`);
|
32412
|
+
}
|
32413
|
+
return [toUtf8String(bytes2), offsetAndLength + length];
|
32414
|
+
}
|
32415
|
+
};
|
32416
|
+
__publicField4(StrSliceCoder, "memorySize", 1);
|
32417
|
+
var StringCoder2 = class extends Coder {
|
32418
|
+
constructor(length) {
|
32419
|
+
super("string", `str[${length}]`, length);
|
32420
|
+
}
|
32421
|
+
encode(value) {
|
32422
|
+
if (value.length !== this.encodedLength) {
|
32423
|
+
throw new FuelError(ErrorCode.ENCODE_ERROR, `Value length mismatch during encode.`);
|
32424
|
+
}
|
32425
|
+
return toUtf8Bytes(value);
|
32426
|
+
}
|
32427
|
+
decode(data, offset) {
|
32428
|
+
if (data.length < this.encodedLength) {
|
32429
|
+
throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid string data size.`);
|
32430
|
+
}
|
32431
|
+
const bytes2 = data.slice(offset, offset + this.encodedLength);
|
32432
|
+
if (bytes2.length !== this.encodedLength) {
|
32433
|
+
throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid string byte data size.`);
|
32434
|
+
}
|
32435
|
+
return [toUtf8String(bytes2), offset + this.encodedLength];
|
32436
|
+
}
|
32437
|
+
};
|
32438
|
+
var StructCoder2 = class extends Coder {
|
32439
|
+
name;
|
32440
|
+
coders;
|
32441
|
+
constructor(name, coders) {
|
32442
|
+
const encodedLength = Object.values(coders).reduce(
|
32443
|
+
(acc, coder) => acc + coder.encodedLength,
|
32444
|
+
0
|
32445
|
+
);
|
32446
|
+
super("struct", `struct ${name}`, encodedLength);
|
32447
|
+
this.name = name;
|
32448
|
+
this.coders = coders;
|
32449
|
+
}
|
32450
|
+
encode(value) {
|
32451
|
+
return concatBytes2(
|
32452
|
+
Object.keys(this.coders).map((fieldName) => {
|
32453
|
+
const fieldCoder = this.coders[fieldName];
|
32454
|
+
const fieldValue = value[fieldName];
|
32455
|
+
if (!(fieldCoder instanceof OptionCoder2) && fieldValue == null) {
|
32456
|
+
throw new FuelError(
|
32457
|
+
ErrorCode.ENCODE_ERROR,
|
32458
|
+
`Invalid ${this.type}. Field "${fieldName}" not present.`
|
32459
|
+
);
|
32460
|
+
}
|
32461
|
+
return fieldCoder.encode(fieldValue);
|
32462
|
+
})
|
32463
|
+
);
|
32464
|
+
}
|
32465
|
+
decode(data, offset) {
|
32466
|
+
if (data.length < this.encodedLength) {
|
32467
|
+
throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid struct data size.`);
|
31759
32468
|
}
|
31760
|
-
|
31761
|
-
|
31762
|
-
|
31763
|
-
|
31764
|
-
|
31765
|
-
|
31766
|
-
|
31767
|
-
|
31768
|
-
|
31769
|
-
);
|
31770
|
-
const resolvedComponents = this.resolveGenericArgTypes(
|
31771
|
-
abi,
|
31772
|
-
components,
|
31773
|
-
typeParametersAndArgsMap
|
31774
|
-
);
|
31775
|
-
return resolvedComponents.map((c) => new ResolvedAbiType(abi, c));
|
32469
|
+
let newOffset = offset;
|
32470
|
+
const decodedValue = Object.keys(this.coders).reduce((obj, fieldName) => {
|
32471
|
+
const fieldCoder = this.coders[fieldName];
|
32472
|
+
let decoded;
|
32473
|
+
[decoded, newOffset] = fieldCoder.decode(data, newOffset);
|
32474
|
+
obj[fieldName] = decoded;
|
32475
|
+
return obj;
|
32476
|
+
}, {});
|
32477
|
+
return [decodedValue, newOffset];
|
31776
32478
|
}
|
31777
|
-
|
31778
|
-
|
31779
|
-
|
31780
|
-
|
31781
|
-
|
31782
|
-
|
31783
|
-
|
31784
|
-
}
|
31785
|
-
if (arg.typeArguments) {
|
31786
|
-
return {
|
31787
|
-
...structuredClone(arg),
|
31788
|
-
typeArguments: this.resolveGenericArgTypes(
|
31789
|
-
abi,
|
31790
|
-
arg.typeArguments,
|
31791
|
-
typeParametersAndArgsMap
|
31792
|
-
)
|
31793
|
-
};
|
31794
|
-
}
|
31795
|
-
const argType = findTypeById(abi, arg.type);
|
31796
|
-
const implicitTypeParameters = this.getImplicitGenericTypeParameters(abi, argType.components);
|
31797
|
-
if (implicitTypeParameters && implicitTypeParameters.length > 0) {
|
31798
|
-
return {
|
31799
|
-
...structuredClone(arg),
|
31800
|
-
typeArguments: implicitTypeParameters.map((itp) => typeParametersAndArgsMap[itp])
|
31801
|
-
};
|
31802
|
-
}
|
31803
|
-
return arg;
|
31804
|
-
});
|
32479
|
+
};
|
32480
|
+
var TupleCoder2 = class extends Coder {
|
32481
|
+
coders;
|
32482
|
+
constructor(coders) {
|
32483
|
+
const encodedLength = coders.reduce((acc, coder) => acc + coder.encodedLength, 0);
|
32484
|
+
super("tuple", `(${coders.map((coder) => coder.type).join(", ")})`, encodedLength);
|
32485
|
+
this.coders = coders;
|
31805
32486
|
}
|
31806
|
-
|
31807
|
-
if (
|
31808
|
-
|
32487
|
+
encode(value) {
|
32488
|
+
if (this.coders.length !== value.length) {
|
32489
|
+
throw new FuelError(ErrorCode.ENCODE_ERROR, `Types/values length mismatch.`);
|
31809
32490
|
}
|
31810
|
-
|
31811
|
-
|
31812
|
-
|
31813
|
-
|
31814
|
-
|
31815
|
-
|
31816
|
-
|
31817
|
-
|
31818
|
-
|
31819
|
-
|
31820
|
-
|
32491
|
+
return concatBytes2(this.coders.map((coder, i) => coder.encode(value[i])));
|
32492
|
+
}
|
32493
|
+
decode(data, offset) {
|
32494
|
+
if (data.length < this.encodedLength) {
|
32495
|
+
throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid tuple data size.`);
|
32496
|
+
}
|
32497
|
+
let newOffset = offset;
|
32498
|
+
const decodedValue = this.coders.map((coder) => {
|
32499
|
+
let decoded;
|
32500
|
+
[decoded, newOffset] = coder.decode(data, newOffset);
|
32501
|
+
return decoded;
|
31821
32502
|
});
|
31822
|
-
return
|
32503
|
+
return [decodedValue, newOffset];
|
31823
32504
|
}
|
31824
|
-
|
31825
|
-
|
31826
|
-
|
31827
|
-
|
32505
|
+
};
|
32506
|
+
var VecCoder2 = class extends Coder {
|
32507
|
+
coder;
|
32508
|
+
#isOptionVec;
|
32509
|
+
constructor(coder) {
|
32510
|
+
super("struct", `struct Vec`, coder.encodedLength + WORD_SIZE);
|
32511
|
+
this.coder = coder;
|
32512
|
+
this.#isOptionVec = this.coder instanceof OptionCoder2;
|
31828
32513
|
}
|
31829
|
-
|
31830
|
-
|
31831
|
-
|
31832
|
-
|
31833
|
-
|
31834
|
-
|
31835
|
-
if (arrayMatch) {
|
31836
|
-
return "a";
|
32514
|
+
encode(value) {
|
32515
|
+
if (!Array.isArray(value) && !isUint8Array(value)) {
|
32516
|
+
throw new FuelError(
|
32517
|
+
ErrorCode.ENCODE_ERROR,
|
32518
|
+
`Expected array value, or a Uint8Array. You can use arrayify to convert a value to a Uint8Array.`
|
32519
|
+
);
|
31837
32520
|
}
|
31838
|
-
const
|
31839
|
-
if (
|
31840
|
-
return
|
32521
|
+
const lengthCoder = new BigNumberCoder("u64");
|
32522
|
+
if (isUint8Array(value)) {
|
32523
|
+
return new Uint8Array([...lengthCoder.encode(value.length), ...value]);
|
31841
32524
|
}
|
31842
|
-
|
32525
|
+
const bytes2 = value.map((v) => this.coder.encode(v));
|
32526
|
+
const lengthBytes = lengthCoder.encode(value.length);
|
32527
|
+
return new Uint8Array([...lengthBytes, ...concatBytes2(bytes2)]);
|
31843
32528
|
}
|
31844
|
-
|
31845
|
-
if (this.
|
31846
|
-
|
31847
|
-
}
|
31848
|
-
if (this.type === "raw untyped slice") {
|
31849
|
-
return "rawslice";
|
31850
|
-
}
|
31851
|
-
const strMatch = stringRegEx.exec(this.type)?.groups;
|
31852
|
-
if (strMatch) {
|
31853
|
-
return `str[${strMatch.length}]`;
|
32529
|
+
decode(data, offset) {
|
32530
|
+
if (!this.#isOptionVec && (data.length < this.encodedLength || data.length > MAX_BYTES)) {
|
32531
|
+
throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid vec data size.`);
|
31854
32532
|
}
|
31855
|
-
|
31856
|
-
|
32533
|
+
const offsetAndLength = offset + WORD_SIZE;
|
32534
|
+
const lengthBytes = data.slice(offset, offsetAndLength);
|
32535
|
+
const length = bn(new BigNumberCoder("u64").decode(lengthBytes, 0)[0]).toNumber();
|
32536
|
+
const dataLength2 = length * this.coder.encodedLength;
|
32537
|
+
const dataBytes = data.slice(offsetAndLength, offsetAndLength + dataLength2);
|
32538
|
+
if (!this.#isOptionVec && dataBytes.length !== dataLength2) {
|
32539
|
+
throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid vec byte data size.`);
|
31857
32540
|
}
|
31858
|
-
|
31859
|
-
|
31860
|
-
|
32541
|
+
let newOffset = offsetAndLength;
|
32542
|
+
const chunks = [];
|
32543
|
+
for (let i = 0; i < length; i++) {
|
32544
|
+
const [decoded, optionOffset] = this.coder.decode(data, newOffset);
|
32545
|
+
chunks.push(decoded);
|
32546
|
+
newOffset = optionOffset;
|
31861
32547
|
}
|
31862
|
-
|
31863
|
-
const componentsSignature = `(${this.components.map((c) => c.getSignature()).join(",")})`;
|
31864
|
-
return `${typeArgumentsSignature}${componentsSignature}`;
|
32548
|
+
return [chunks, newOffset];
|
31865
32549
|
}
|
31866
32550
|
};
|
31867
|
-
|
31868
|
-
const { getCoder: getCoder2 } = options;
|
31869
|
-
return components.reduce((obj, component) => {
|
31870
|
-
const o = obj;
|
31871
|
-
o[component.name] = getCoder2(component, options);
|
31872
|
-
return o;
|
31873
|
-
}, {});
|
31874
|
-
}
|
31875
|
-
var getCoder = (resolvedAbiType, _options) => {
|
32551
|
+
var getCoder2 = (resolvedAbiType, _options) => {
|
31876
32552
|
switch (resolvedAbiType.type) {
|
31877
32553
|
case U8_CODER_TYPE:
|
31878
32554
|
case U16_CODER_TYPE:
|
31879
32555
|
case U32_CODER_TYPE:
|
31880
|
-
return new
|
32556
|
+
return new NumberCoder2(resolvedAbiType.type);
|
31881
32557
|
case U64_CODER_TYPE:
|
31882
32558
|
case RAW_PTR_CODER_TYPE:
|
31883
32559
|
return new BigNumberCoder("u64");
|
31884
32560
|
case U256_CODER_TYPE:
|
31885
32561
|
return new BigNumberCoder("u256");
|
31886
32562
|
case RAW_SLICE_CODER_TYPE:
|
31887
|
-
return new
|
32563
|
+
return new RawSliceCoder2();
|
31888
32564
|
case BOOL_CODER_TYPE:
|
31889
|
-
return new
|
32565
|
+
return new BooleanCoder2();
|
31890
32566
|
case B256_CODER_TYPE:
|
31891
32567
|
return new B256Coder();
|
31892
32568
|
case B512_CODER_TYPE:
|
31893
32569
|
return new B512Coder();
|
31894
32570
|
case BYTES_CODER_TYPE:
|
31895
|
-
return new
|
32571
|
+
return new ByteCoder2();
|
31896
32572
|
case STD_STRING_CODER_TYPE:
|
31897
|
-
return new
|
32573
|
+
return new StdStringCoder2();
|
31898
32574
|
case STR_SLICE_CODER_TYPE:
|
31899
32575
|
return new StrSliceCoder();
|
31900
32576
|
default:
|
@@ -31903,7 +32579,7 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
31903
32579
|
const stringMatch = stringRegEx.exec(resolvedAbiType.type)?.groups;
|
31904
32580
|
if (stringMatch) {
|
31905
32581
|
const length = parseInt(stringMatch.length, 10);
|
31906
|
-
return new
|
32582
|
+
return new StringCoder2(length);
|
31907
32583
|
}
|
31908
32584
|
const components = resolvedAbiType.components;
|
31909
32585
|
const arrayMatch = arrayRegEx.exec(resolvedAbiType.type)?.groups;
|
@@ -31916,42 +32592,46 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
31916
32592
|
`The provided Array type is missing an item of 'component'.`
|
31917
32593
|
);
|
31918
32594
|
}
|
31919
|
-
const arrayElementCoder =
|
32595
|
+
const arrayElementCoder = getCoder2(arg, { isSmallBytes: true });
|
31920
32596
|
return new ArrayCoder(arrayElementCoder, length);
|
31921
32597
|
}
|
31922
32598
|
if (resolvedAbiType.type === VEC_CODER_TYPE) {
|
31923
32599
|
const arg = findVectorBufferArgument(components);
|
31924
32600
|
const argType = new ResolvedAbiType(resolvedAbiType.abi, arg);
|
31925
|
-
const itemCoder =
|
31926
|
-
return new
|
32601
|
+
const itemCoder = getCoder2(argType, { isSmallBytes: true, encoding: ENCODING_V0 });
|
32602
|
+
return new VecCoder2(itemCoder);
|
31927
32603
|
}
|
31928
32604
|
const structMatch = structRegEx.exec(resolvedAbiType.type)?.groups;
|
31929
32605
|
if (structMatch) {
|
31930
|
-
const coders = getCoders(components, { getCoder });
|
31931
|
-
return new
|
32606
|
+
const coders = getCoders(components, { isRightPadded: true, getCoder: getCoder2 });
|
32607
|
+
return new StructCoder2(structMatch.name, coders);
|
31932
32608
|
}
|
31933
32609
|
const enumMatch = enumRegEx.exec(resolvedAbiType.type)?.groups;
|
31934
32610
|
if (enumMatch) {
|
31935
|
-
const coders = getCoders(components, { getCoder });
|
32611
|
+
const coders = getCoders(components, { getCoder: getCoder2 });
|
31936
32612
|
const isOptionEnum = resolvedAbiType.type === OPTION_CODER_TYPE;
|
31937
32613
|
if (isOptionEnum) {
|
31938
|
-
return new
|
32614
|
+
return new OptionCoder2(enumMatch.name, coders);
|
31939
32615
|
}
|
31940
|
-
return new
|
32616
|
+
return new EnumCoder2(enumMatch.name, coders);
|
31941
32617
|
}
|
31942
32618
|
const tupleMatch = tupleRegEx.exec(resolvedAbiType.type)?.groups;
|
31943
32619
|
if (tupleMatch) {
|
31944
|
-
const coders = components.map(
|
31945
|
-
|
32620
|
+
const coders = components.map(
|
32621
|
+
(component) => getCoder2(component, { isRightPadded: true, encoding: ENCODING_V0 })
|
32622
|
+
);
|
32623
|
+
return new TupleCoder2(coders);
|
31946
32624
|
}
|
31947
32625
|
throw new FuelError(
|
31948
32626
|
ErrorCode.CODER_NOT_FOUND,
|
31949
32627
|
`Coder not found: ${JSON.stringify(resolvedAbiType)}.`
|
31950
32628
|
);
|
31951
32629
|
};
|
31952
|
-
function getCoderForEncoding(encoding =
|
32630
|
+
function getCoderForEncoding(encoding = ENCODING_V0) {
|
31953
32631
|
switch (encoding) {
|
31954
32632
|
case ENCODING_V1:
|
32633
|
+
return getCoder2;
|
32634
|
+
case ENCODING_V0:
|
31955
32635
|
return getCoder;
|
31956
32636
|
default:
|
31957
32637
|
throw new FuelError(
|
@@ -31962,7 +32642,7 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
31962
32642
|
}
|
31963
32643
|
var AbiCoder = class {
|
31964
32644
|
static getCoder(abi, argument, options = {
|
31965
|
-
|
32645
|
+
isSmallBytes: false
|
31966
32646
|
}) {
|
31967
32647
|
const resolvedAbiType = new ResolvedAbiType(abi, argument);
|
31968
32648
|
return getCoderForEncoding(options.encoding)(resolvedAbiType, options);
|
@@ -31982,6 +32662,8 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
31982
32662
|
name;
|
31983
32663
|
jsonFn;
|
31984
32664
|
attributes;
|
32665
|
+
isInputDataPointer;
|
32666
|
+
outputMetadata;
|
31985
32667
|
jsonAbi;
|
31986
32668
|
constructor(jsonAbi, name) {
|
31987
32669
|
this.jsonAbi = jsonAbi;
|
@@ -31989,8 +32671,13 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
31989
32671
|
this.name = name;
|
31990
32672
|
this.signature = FunctionFragment.getSignature(this.jsonAbi, this.jsonFn);
|
31991
32673
|
this.selector = FunctionFragment.getFunctionSelector(this.signature);
|
31992
|
-
this.selectorBytes = new
|
32674
|
+
this.selectorBytes = new StdStringCoder2().encode(name);
|
31993
32675
|
this.encoding = getEncodingVersion(jsonAbi.encoding);
|
32676
|
+
this.isInputDataPointer = this.#isInputDataPointer();
|
32677
|
+
this.outputMetadata = {
|
32678
|
+
isHeapType: this.#isOutputDataHeap(),
|
32679
|
+
encodedLength: this.#getOutputEncodedLength()
|
32680
|
+
};
|
31994
32681
|
this.attributes = this.jsonFn.attributes ?? [];
|
31995
32682
|
}
|
31996
32683
|
static getSignature(abi, fn) {
|
@@ -32003,7 +32690,29 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
32003
32690
|
const hashedFunctionSignature = sha2562(bufferFromString2(functionSignature, "utf-8"));
|
32004
32691
|
return bn(hashedFunctionSignature.slice(0, 10)).toHex(8);
|
32005
32692
|
}
|
32006
|
-
|
32693
|
+
#isInputDataPointer() {
|
32694
|
+
const inputTypes = this.jsonFn.inputs.map((i) => findTypeById(this.jsonAbi, i.type));
|
32695
|
+
return this.jsonFn.inputs.length > 1 || isPointerType(inputTypes[0]?.type || "");
|
32696
|
+
}
|
32697
|
+
#isOutputDataHeap() {
|
32698
|
+
const outputType = findTypeById(this.jsonAbi, this.jsonFn.output.type);
|
32699
|
+
return isHeapType(outputType?.type || "");
|
32700
|
+
}
|
32701
|
+
#getOutputEncodedLength() {
|
32702
|
+
try {
|
32703
|
+
const heapCoder = AbiCoder.getCoder(this.jsonAbi, this.jsonFn.output);
|
32704
|
+
if (heapCoder instanceof VecCoder) {
|
32705
|
+
return heapCoder.coder.encodedLength;
|
32706
|
+
}
|
32707
|
+
if (heapCoder instanceof ByteCoder) {
|
32708
|
+
return ByteCoder.memorySize;
|
32709
|
+
}
|
32710
|
+
return heapCoder.encodedLength;
|
32711
|
+
} catch (e) {
|
32712
|
+
return 0;
|
32713
|
+
}
|
32714
|
+
}
|
32715
|
+
encodeArguments(values, offset = 0) {
|
32007
32716
|
FunctionFragment.verifyArgsAndInputsAlign(values, this.jsonFn.inputs, this.jsonAbi);
|
32008
32717
|
const shallowCopyValues = values.slice();
|
32009
32718
|
const nonEmptyInputs = findNonEmptyInputs(this.jsonAbi, this.jsonFn.inputs);
|
@@ -32013,10 +32722,15 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
32013
32722
|
}
|
32014
32723
|
const coders = nonEmptyInputs.map(
|
32015
32724
|
(t) => AbiCoder.getCoder(this.jsonAbi, t, {
|
32725
|
+
isRightPadded: nonEmptyInputs.length > 1,
|
32016
32726
|
encoding: this.encoding
|
32017
32727
|
})
|
32018
32728
|
);
|
32019
|
-
|
32729
|
+
if (this.encoding === ENCODING_V1) {
|
32730
|
+
return new TupleCoder2(coders).encode(shallowCopyValues);
|
32731
|
+
}
|
32732
|
+
const results = new TupleCoder(coders).encode(shallowCopyValues);
|
32733
|
+
return unpackDynamicData(results, offset, results.byteLength);
|
32020
32734
|
}
|
32021
32735
|
static verifyArgsAndInputsAlign(args, inputs, abi) {
|
32022
32736
|
if (args.length === inputs.length) {
|
@@ -32125,9 +32839,9 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
32125
32839
|
const fragment = typeof functionFragment === "string" ? this.getFunction(functionFragment) : functionFragment;
|
32126
32840
|
return fragment.decodeArguments(data);
|
32127
32841
|
}
|
32128
|
-
encodeFunctionData(functionFragment, values) {
|
32842
|
+
encodeFunctionData(functionFragment, values, offset = 0) {
|
32129
32843
|
const fragment = typeof functionFragment === "string" ? this.getFunction(functionFragment) : functionFragment;
|
32130
|
-
return fragment.encodeArguments(values);
|
32844
|
+
return fragment.encodeArguments(values, offset);
|
32131
32845
|
}
|
32132
32846
|
// Decode the result of a function call
|
32133
32847
|
decodeFunctionResult(functionFragment, data) {
|
@@ -32155,7 +32869,9 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
32155
32869
|
);
|
32156
32870
|
}
|
32157
32871
|
return AbiCoder.encode(this.jsonAbi, configurable.configurableType, value, {
|
32158
|
-
|
32872
|
+
isRightPadded: true,
|
32873
|
+
// TODO: Review support for configurables in v1 encoding when it becomes available
|
32874
|
+
encoding: ENCODING_V0
|
32159
32875
|
});
|
32160
32876
|
}
|
32161
32877
|
getTypeById(typeId) {
|
@@ -32205,8 +32921,8 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
32205
32921
|
var TxPointerCoder = class extends StructCoder {
|
32206
32922
|
constructor() {
|
32207
32923
|
super("TxPointer", {
|
32208
|
-
blockHeight: new NumberCoder("u32"
|
32209
|
-
txIndex: new NumberCoder("u16"
|
32924
|
+
blockHeight: new NumberCoder("u32"),
|
32925
|
+
txIndex: new NumberCoder("u16")
|
32210
32926
|
});
|
32211
32927
|
}
|
32212
32928
|
};
|
@@ -32223,12 +32939,12 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
32223
32939
|
encode(value) {
|
32224
32940
|
const parts = [];
|
32225
32941
|
parts.push(new B256Coder().encode(value.txID));
|
32226
|
-
parts.push(new NumberCoder("u16"
|
32942
|
+
parts.push(new NumberCoder("u16").encode(value.outputIndex));
|
32227
32943
|
parts.push(new B256Coder().encode(value.owner));
|
32228
32944
|
parts.push(new BigNumberCoder("u64").encode(value.amount));
|
32229
32945
|
parts.push(new B256Coder().encode(value.assetId));
|
32230
32946
|
parts.push(new TxPointerCoder().encode(value.txPointer));
|
32231
|
-
parts.push(new NumberCoder("u16"
|
32947
|
+
parts.push(new NumberCoder("u16").encode(value.witnessIndex));
|
32232
32948
|
parts.push(new BigNumberCoder("u64").encode(value.predicateGasUsed));
|
32233
32949
|
parts.push(new BigNumberCoder("u64").encode(value.predicateLength));
|
32234
32950
|
parts.push(new BigNumberCoder("u64").encode(value.predicateDataLength));
|
@@ -32243,7 +32959,7 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
32243
32959
|
let o = offset;
|
32244
32960
|
[decoded, o] = new B256Coder().decode(data, o);
|
32245
32961
|
const txID = decoded;
|
32246
|
-
[decoded, o] = new NumberCoder("u16"
|
32962
|
+
[decoded, o] = new NumberCoder("u16").decode(data, o);
|
32247
32963
|
const outputIndex = decoded;
|
32248
32964
|
[decoded, o] = new B256Coder().decode(data, o);
|
32249
32965
|
const owner = decoded;
|
@@ -32253,7 +32969,7 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
32253
32969
|
const assetId = decoded;
|
32254
32970
|
[decoded, o] = new TxPointerCoder().decode(data, o);
|
32255
32971
|
const txPointer = decoded;
|
32256
|
-
[decoded, o] = new NumberCoder("u16"
|
32972
|
+
[decoded, o] = new NumberCoder("u16").decode(data, o);
|
32257
32973
|
const witnessIndex = Number(decoded);
|
32258
32974
|
[decoded, o] = new BigNumberCoder("u64").decode(data, o);
|
32259
32975
|
const predicateGasUsed = decoded;
|
@@ -32292,7 +33008,7 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
32292
33008
|
encode(value) {
|
32293
33009
|
const parts = [];
|
32294
33010
|
parts.push(new B256Coder().encode(value.txID));
|
32295
|
-
parts.push(new NumberCoder("u16"
|
33011
|
+
parts.push(new NumberCoder("u16").encode(value.outputIndex));
|
32296
33012
|
parts.push(new B256Coder().encode(value.balanceRoot));
|
32297
33013
|
parts.push(new B256Coder().encode(value.stateRoot));
|
32298
33014
|
parts.push(new TxPointerCoder().encode(value.txPointer));
|
@@ -32304,7 +33020,7 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
32304
33020
|
let o = offset;
|
32305
33021
|
[decoded, o] = new B256Coder().decode(data, o);
|
32306
33022
|
const txID = decoded;
|
32307
|
-
[decoded, o] = new NumberCoder("u16"
|
33023
|
+
[decoded, o] = new NumberCoder("u16").decode(data, o);
|
32308
33024
|
const outputIndex = decoded;
|
32309
33025
|
[decoded, o] = new B256Coder().decode(data, o);
|
32310
33026
|
const balanceRoot = decoded;
|
@@ -32353,7 +33069,7 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
32353
33069
|
parts.push(new ByteArrayCoder(32).encode(value.recipient));
|
32354
33070
|
parts.push(new BigNumberCoder("u64").encode(value.amount));
|
32355
33071
|
parts.push(new ByteArrayCoder(32).encode(value.nonce));
|
32356
|
-
parts.push(new NumberCoder("u16"
|
33072
|
+
parts.push(new NumberCoder("u16").encode(value.witnessIndex));
|
32357
33073
|
parts.push(new BigNumberCoder("u64").encode(value.predicateGasUsed));
|
32358
33074
|
parts.push(new BigNumberCoder("u64").encode(data.length));
|
32359
33075
|
parts.push(new BigNumberCoder("u64").encode(value.predicateLength));
|
@@ -32382,11 +33098,11 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
32382
33098
|
const amount = decoded;
|
32383
33099
|
[decoded, o] = new B256Coder().decode(data, o);
|
32384
33100
|
const nonce = decoded;
|
32385
|
-
[decoded, o] = new NumberCoder("u16"
|
33101
|
+
[decoded, o] = new NumberCoder("u16").decode(data, o);
|
32386
33102
|
const witnessIndex = Number(decoded);
|
32387
33103
|
[decoded, o] = new BigNumberCoder("u64").decode(data, o);
|
32388
33104
|
const predicateGasUsed = decoded;
|
32389
|
-
[decoded, o] = new NumberCoder("u32"
|
33105
|
+
[decoded, o] = new NumberCoder("u32").decode(data, o);
|
32390
33106
|
const dataLength2 = decoded;
|
32391
33107
|
[decoded, o] = new BigNumberCoder("u64").decode(data, o);
|
32392
33108
|
const predicateLength = decoded;
|
@@ -32424,7 +33140,7 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
32424
33140
|
}
|
32425
33141
|
encode(value) {
|
32426
33142
|
const parts = [];
|
32427
|
-
parts.push(new NumberCoder("u8"
|
33143
|
+
parts.push(new NumberCoder("u8").encode(value.type));
|
32428
33144
|
const { type: type3 } = value;
|
32429
33145
|
switch (type3) {
|
32430
33146
|
case 0: {
|
@@ -32451,7 +33167,7 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
32451
33167
|
decode(data, offset) {
|
32452
33168
|
let decoded;
|
32453
33169
|
let o = offset;
|
32454
|
-
[decoded, o] = new NumberCoder("u8"
|
33170
|
+
[decoded, o] = new NumberCoder("u8").decode(data, o);
|
32455
33171
|
const type3 = decoded;
|
32456
33172
|
switch (type3) {
|
32457
33173
|
case 0: {
|
@@ -32520,7 +33236,7 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
32520
33236
|
}
|
32521
33237
|
encode(value) {
|
32522
33238
|
const parts = [];
|
32523
|
-
parts.push(new NumberCoder("u8"
|
33239
|
+
parts.push(new NumberCoder("u8").encode(value.inputIndex));
|
32524
33240
|
parts.push(new B256Coder().encode(value.balanceRoot));
|
32525
33241
|
parts.push(new B256Coder().encode(value.stateRoot));
|
32526
33242
|
return concat(parts);
|
@@ -32528,7 +33244,7 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
32528
33244
|
decode(data, offset) {
|
32529
33245
|
let decoded;
|
32530
33246
|
let o = offset;
|
32531
|
-
[decoded, o] = new NumberCoder("u8"
|
33247
|
+
[decoded, o] = new NumberCoder("u8").decode(data, o);
|
32532
33248
|
const inputIndex = decoded;
|
32533
33249
|
[decoded, o] = new B256Coder().decode(data, o);
|
32534
33250
|
const balanceRoot = decoded;
|
@@ -32640,7 +33356,7 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
32640
33356
|
}
|
32641
33357
|
encode(value) {
|
32642
33358
|
const parts = [];
|
32643
|
-
parts.push(new NumberCoder("u8"
|
33359
|
+
parts.push(new NumberCoder("u8").encode(value.type));
|
32644
33360
|
const { type: type3 } = value;
|
32645
33361
|
switch (type3) {
|
32646
33362
|
case 0: {
|
@@ -32675,7 +33391,7 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
32675
33391
|
decode(data, offset) {
|
32676
33392
|
let decoded;
|
32677
33393
|
let o = offset;
|
32678
|
-
[decoded, o] = new NumberCoder("u8"
|
33394
|
+
[decoded, o] = new NumberCoder("u8").decode(data, o);
|
32679
33395
|
const type3 = decoded;
|
32680
33396
|
switch (type3) {
|
32681
33397
|
case 0: {
|
@@ -32743,7 +33459,7 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
32743
33459
|
parts.push(new BigNumberCoder("u64").encode(data));
|
32744
33460
|
break;
|
32745
33461
|
case 4:
|
32746
|
-
parts.push(new NumberCoder("u32"
|
33462
|
+
parts.push(new NumberCoder("u32").encode(data));
|
32747
33463
|
break;
|
32748
33464
|
default: {
|
32749
33465
|
throw new FuelError(ErrorCode.INVALID_POLICY_TYPE, `Invalid policy type: ${type3}`);
|
@@ -32766,10 +33482,7 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
32766
33482
|
policies.push({ type: 2, data: witnessLimit });
|
32767
33483
|
}
|
32768
33484
|
if (policyTypes & 4) {
|
32769
|
-
const [maturity, nextOffset] = new NumberCoder("u32"
|
32770
|
-
data,
|
32771
|
-
o
|
32772
|
-
);
|
33485
|
+
const [maturity, nextOffset] = new NumberCoder("u32").decode(data, o);
|
32773
33486
|
o = nextOffset;
|
32774
33487
|
policies.push({ type: 4, data: maturity });
|
32775
33488
|
}
|
@@ -32816,7 +33529,7 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
32816
33529
|
parts.push(new B256Coder().encode(value.recipient));
|
32817
33530
|
parts.push(new BigNumberCoder("u64").encode(value.amount));
|
32818
33531
|
parts.push(new B256Coder().encode(value.nonce));
|
32819
|
-
parts.push(new NumberCoder("u16"
|
33532
|
+
parts.push(new NumberCoder("u16").encode(value.data.length));
|
32820
33533
|
parts.push(new B256Coder().encode(value.digest));
|
32821
33534
|
parts.push(new ByteArrayCoder(value.data.length).encode(value.data));
|
32822
33535
|
return concat(parts);
|
@@ -32832,7 +33545,7 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
32832
33545
|
const amount = decoded;
|
32833
33546
|
[decoded, o] = new B256Coder().decode(data, o);
|
32834
33547
|
const nonce = decoded;
|
32835
|
-
[decoded, o] = new NumberCoder("u16"
|
33548
|
+
[decoded, o] = new NumberCoder("u16").decode(data, o);
|
32836
33549
|
const len = decoded;
|
32837
33550
|
[decoded, o] = new B256Coder().decode(data, o);
|
32838
33551
|
const digest = decoded;
|
@@ -32956,11 +33669,11 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
32956
33669
|
encode(upgradePurposeType) {
|
32957
33670
|
const parts = [];
|
32958
33671
|
const { type: type3 } = upgradePurposeType;
|
32959
|
-
parts.push(new NumberCoder("u8"
|
33672
|
+
parts.push(new NumberCoder("u8").encode(type3));
|
32960
33673
|
switch (type3) {
|
32961
33674
|
case 0: {
|
32962
33675
|
const data = upgradePurposeType.data;
|
32963
|
-
parts.push(new NumberCoder("u16"
|
33676
|
+
parts.push(new NumberCoder("u16").encode(data.witnessIndex));
|
32964
33677
|
parts.push(new B256Coder().encode(data.checksum));
|
32965
33678
|
break;
|
32966
33679
|
}
|
@@ -32981,11 +33694,11 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
32981
33694
|
decode(data, offset) {
|
32982
33695
|
let o = offset;
|
32983
33696
|
let decoded;
|
32984
|
-
[decoded, o] = new NumberCoder("u8"
|
33697
|
+
[decoded, o] = new NumberCoder("u8").decode(data, o);
|
32985
33698
|
const type3 = decoded;
|
32986
33699
|
switch (type3) {
|
32987
33700
|
case 0: {
|
32988
|
-
[decoded, o] = new NumberCoder("u16"
|
33701
|
+
[decoded, o] = new NumberCoder("u16").decode(data, o);
|
32989
33702
|
const witnessIndex = decoded;
|
32990
33703
|
[decoded, o] = new B256Coder().decode(data, o);
|
32991
33704
|
const checksum = decoded;
|
@@ -33016,14 +33729,14 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
33016
33729
|
}
|
33017
33730
|
encode(value) {
|
33018
33731
|
const parts = [];
|
33019
|
-
parts.push(new NumberCoder("u32"
|
33732
|
+
parts.push(new NumberCoder("u32").encode(value.dataLength));
|
33020
33733
|
parts.push(new ByteArrayCoder(value.dataLength).encode(value.data));
|
33021
33734
|
return concat(parts);
|
33022
33735
|
}
|
33023
33736
|
decode(data, offset) {
|
33024
33737
|
let decoded;
|
33025
33738
|
let o = offset;
|
33026
|
-
[decoded, o] = new NumberCoder("u32"
|
33739
|
+
[decoded, o] = new NumberCoder("u32").decode(data, o);
|
33027
33740
|
const dataLength2 = decoded;
|
33028
33741
|
[decoded, o] = new ByteArrayCoder(dataLength2).decode(data, o);
|
33029
33742
|
const witnessData = decoded;
|
@@ -33054,10 +33767,10 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
33054
33767
|
parts.push(new B256Coder().encode(value.receiptsRoot));
|
33055
33768
|
parts.push(new BigNumberCoder("u64").encode(value.scriptLength));
|
33056
33769
|
parts.push(new BigNumberCoder("u64").encode(value.scriptDataLength));
|
33057
|
-
parts.push(new NumberCoder("u32"
|
33058
|
-
parts.push(new NumberCoder("u16"
|
33059
|
-
parts.push(new NumberCoder("u16"
|
33060
|
-
parts.push(new NumberCoder("u16"
|
33770
|
+
parts.push(new NumberCoder("u32").encode(value.policyTypes));
|
33771
|
+
parts.push(new NumberCoder("u16").encode(value.inputsCount));
|
33772
|
+
parts.push(new NumberCoder("u16").encode(value.outputsCount));
|
33773
|
+
parts.push(new NumberCoder("u16").encode(value.witnessesCount));
|
33061
33774
|
parts.push(new ByteArrayCoder(value.scriptLength.toNumber()).encode(value.script));
|
33062
33775
|
parts.push(new ByteArrayCoder(value.scriptDataLength.toNumber()).encode(value.scriptData));
|
33063
33776
|
parts.push(new PoliciesCoder().encode(value.policies));
|
@@ -33077,13 +33790,13 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
33077
33790
|
const scriptLength = decoded;
|
33078
33791
|
[decoded, o] = new BigNumberCoder("u64").decode(data, o);
|
33079
33792
|
const scriptDataLength = decoded;
|
33080
|
-
[decoded, o] = new NumberCoder("u32"
|
33793
|
+
[decoded, o] = new NumberCoder("u32").decode(data, o);
|
33081
33794
|
const policyTypes = decoded;
|
33082
|
-
[decoded, o] = new NumberCoder("u16"
|
33795
|
+
[decoded, o] = new NumberCoder("u16").decode(data, o);
|
33083
33796
|
const inputsCount = decoded;
|
33084
|
-
[decoded, o] = new NumberCoder("u16"
|
33797
|
+
[decoded, o] = new NumberCoder("u16").decode(data, o);
|
33085
33798
|
const outputsCount = decoded;
|
33086
|
-
[decoded, o] = new NumberCoder("u16"
|
33799
|
+
[decoded, o] = new NumberCoder("u16").decode(data, o);
|
33087
33800
|
const witnessesCount = decoded;
|
33088
33801
|
[decoded, o] = new ByteArrayCoder(scriptLength.toNumber()).decode(data, o);
|
33089
33802
|
const script = decoded;
|
@@ -33125,13 +33838,13 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
33125
33838
|
}
|
33126
33839
|
encode(value) {
|
33127
33840
|
const parts = [];
|
33128
|
-
parts.push(new NumberCoder("u16"
|
33841
|
+
parts.push(new NumberCoder("u16").encode(value.bytecodeWitnessIndex));
|
33129
33842
|
parts.push(new B256Coder().encode(value.salt));
|
33130
33843
|
parts.push(new BigNumberCoder("u64").encode(value.storageSlotsCount));
|
33131
|
-
parts.push(new NumberCoder("u32"
|
33132
|
-
parts.push(new NumberCoder("u16"
|
33133
|
-
parts.push(new NumberCoder("u16"
|
33134
|
-
parts.push(new NumberCoder("u16"
|
33844
|
+
parts.push(new NumberCoder("u32").encode(value.policyTypes));
|
33845
|
+
parts.push(new NumberCoder("u16").encode(value.inputsCount));
|
33846
|
+
parts.push(new NumberCoder("u16").encode(value.outputsCount));
|
33847
|
+
parts.push(new NumberCoder("u16").encode(value.witnessesCount));
|
33135
33848
|
parts.push(
|
33136
33849
|
new ArrayCoder(new StorageSlotCoder(), value.storageSlotsCount.toNumber()).encode(
|
33137
33850
|
value.storageSlots
|
@@ -33146,19 +33859,19 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
33146
33859
|
decode(data, offset) {
|
33147
33860
|
let decoded;
|
33148
33861
|
let o = offset;
|
33149
|
-
[decoded, o] = new NumberCoder("u16"
|
33862
|
+
[decoded, o] = new NumberCoder("u16").decode(data, o);
|
33150
33863
|
const bytecodeWitnessIndex = decoded;
|
33151
33864
|
[decoded, o] = new B256Coder().decode(data, o);
|
33152
33865
|
const salt = decoded;
|
33153
33866
|
[decoded, o] = new BigNumberCoder("u64").decode(data, o);
|
33154
33867
|
const storageSlotsCount = decoded;
|
33155
|
-
[decoded, o] = new NumberCoder("u32"
|
33868
|
+
[decoded, o] = new NumberCoder("u32").decode(data, o);
|
33156
33869
|
const policyTypes = decoded;
|
33157
|
-
[decoded, o] = new NumberCoder("u16"
|
33870
|
+
[decoded, o] = new NumberCoder("u16").decode(data, o);
|
33158
33871
|
const inputsCount = decoded;
|
33159
|
-
[decoded, o] = new NumberCoder("u16"
|
33872
|
+
[decoded, o] = new NumberCoder("u16").decode(data, o);
|
33160
33873
|
const outputsCount = decoded;
|
33161
|
-
[decoded, o] = new NumberCoder("u16"
|
33874
|
+
[decoded, o] = new NumberCoder("u16").decode(data, o);
|
33162
33875
|
const witnessesCount = decoded;
|
33163
33876
|
[decoded, o] = new ArrayCoder(new StorageSlotCoder(), storageSlotsCount.toNumber()).decode(
|
33164
33877
|
data,
|
@@ -33372,7 +34085,7 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
33372
34085
|
}
|
33373
34086
|
encode(value) {
|
33374
34087
|
const parts = [];
|
33375
|
-
parts.push(new NumberCoder("u8"
|
34088
|
+
parts.push(new NumberCoder("u8").encode(value.type));
|
33376
34089
|
const { type: type3 } = value;
|
33377
34090
|
switch (value.type) {
|
33378
34091
|
case 0: {
|
@@ -33415,7 +34128,7 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
33415
34128
|
decode(data, offset) {
|
33416
34129
|
let decoded;
|
33417
34130
|
let o = offset;
|
33418
|
-
[decoded, o] = new NumberCoder("u8"
|
34131
|
+
[decoded, o] = new NumberCoder("u8").decode(data, o);
|
33419
34132
|
const type3 = decoded;
|
33420
34133
|
switch (type3) {
|
33421
34134
|
case 0: {
|
@@ -38492,15 +39205,6 @@ ${MessageCoinFragmentDoc}`;
|
|
38492
39205
|
return normalize2(clone_default(root));
|
38493
39206
|
}
|
38494
39207
|
|
38495
|
-
// src/providers/utils/sleep.ts
|
38496
|
-
function sleep(time) {
|
38497
|
-
return new Promise((resolve) => {
|
38498
|
-
setTimeout(() => {
|
38499
|
-
resolve(true);
|
38500
|
-
}, time);
|
38501
|
-
});
|
38502
|
-
}
|
38503
|
-
|
38504
39208
|
// src/providers/utils/extract-tx-error.ts
|
38505
39209
|
var assemblePanicError = (status) => {
|
38506
39210
|
let errorMessage = `The transaction reverted with reason: "${status.reason}".`;
|
@@ -39142,6 +39846,15 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
|
|
39142
39846
|
}
|
39143
39847
|
});
|
39144
39848
|
}
|
39849
|
+
shiftPredicateData() {
|
39850
|
+
this.inputs.forEach((input) => {
|
39851
|
+
if ("predicateData" in input && "padPredicateData" in input && typeof input.padPredicateData === "function") {
|
39852
|
+
input.predicateData = input.padPredicateData(
|
39853
|
+
BaseTransactionRequest.getPolicyMeta(this).policies.length
|
39854
|
+
);
|
39855
|
+
}
|
39856
|
+
});
|
39857
|
+
}
|
39145
39858
|
};
|
39146
39859
|
|
39147
39860
|
// src/providers/transaction-request/hash-transaction.ts
|
@@ -39606,27 +40319,37 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
|
|
39606
40319
|
};
|
39607
40320
|
|
39608
40321
|
// src/providers/transaction-summary/call.ts
|
39609
|
-
var getFunctionCall = ({ abi, receipt }) => {
|
40322
|
+
var getFunctionCall = ({ abi, receipt, rawPayload, maxInputs }) => {
|
39610
40323
|
const abiInterface = new Interface(abi);
|
39611
40324
|
const callFunctionSelector = receipt.param1.toHex(8);
|
39612
40325
|
const functionFragment = abiInterface.getFunction(callFunctionSelector);
|
39613
40326
|
const inputs = functionFragment.jsonFn.inputs;
|
39614
|
-
|
40327
|
+
let encodedArgs;
|
40328
|
+
if (functionFragment.isInputDataPointer) {
|
40329
|
+
if (rawPayload) {
|
40330
|
+
const argsOffset = bn(receipt.param2).sub(calculateVmTxMemory({ maxInputs: maxInputs.toNumber() })).toNumber();
|
40331
|
+
encodedArgs = `0x${rawPayload.slice(2).slice(argsOffset * 2)}`;
|
40332
|
+
}
|
40333
|
+
} else {
|
40334
|
+
encodedArgs = receipt.param2.toHex();
|
40335
|
+
}
|
39615
40336
|
let argumentsProvided;
|
39616
|
-
|
39617
|
-
|
39618
|
-
|
39619
|
-
|
39620
|
-
|
39621
|
-
|
39622
|
-
|
39623
|
-
|
39624
|
-
|
39625
|
-
|
39626
|
-
|
39627
|
-
|
39628
|
-
|
39629
|
-
|
40337
|
+
if (encodedArgs) {
|
40338
|
+
const data = functionFragment.decodeArguments(encodedArgs);
|
40339
|
+
if (data) {
|
40340
|
+
argumentsProvided = inputs.reduce((prev, input, index) => {
|
40341
|
+
const value = data[index];
|
40342
|
+
const name = input.name;
|
40343
|
+
if (name) {
|
40344
|
+
return {
|
40345
|
+
...prev,
|
40346
|
+
// reparse to remove bn
|
40347
|
+
[name]: JSON.parse(JSON.stringify(value))
|
40348
|
+
};
|
40349
|
+
}
|
40350
|
+
return prev;
|
40351
|
+
}, {});
|
40352
|
+
}
|
39630
40353
|
}
|
39631
40354
|
const call = {
|
39632
40355
|
functionSignature: functionFragment.signature,
|
@@ -42123,6 +42846,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
42123
42846
|
cacheRequestInputsResourcesFromOwner(request.inputs, this.address)
|
42124
42847
|
);
|
42125
42848
|
request.addResources(resources);
|
42849
|
+
request.shiftPredicateData();
|
42126
42850
|
request.updatePredicateGasUsed(estimatedPredicates);
|
42127
42851
|
const requestToReestimate2 = clone_default(request);
|
42128
42852
|
if (addedSignatures) {
|
@@ -42154,6 +42878,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
42154
42878
|
}
|
42155
42879
|
fundingAttempts += 1;
|
42156
42880
|
}
|
42881
|
+
request.shiftPredicateData();
|
42157
42882
|
request.updatePredicateGasUsed(estimatedPredicates);
|
42158
42883
|
const requestToReestimate = clone_default(request);
|
42159
42884
|
if (addedSignatures) {
|
@@ -47227,6 +47952,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
47227
47952
|
*/
|
47228
47953
|
populateTransactionPredicateData(transactionRequestLike) {
|
47229
47954
|
const request = transactionRequestify(transactionRequestLike);
|
47955
|
+
const { policies } = BaseTransactionRequest.getPolicyMeta(request);
|
47230
47956
|
const placeholderIndex = this.getIndexFromPlaceholderWitness(request);
|
47231
47957
|
if (placeholderIndex !== -1) {
|
47232
47958
|
request.removeWitness(placeholderIndex);
|
@@ -47234,7 +47960,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
47234
47960
|
request.inputs.filter(isRequestInputResource).forEach((input) => {
|
47235
47961
|
if (isRequestInputResourceFromOwner(input, this.address)) {
|
47236
47962
|
input.predicate = hexlify(this.bytes);
|
47237
|
-
input.predicateData = hexlify(this.getPredicateData());
|
47963
|
+
input.predicateData = hexlify(this.getPredicateData(policies.length));
|
47238
47964
|
input.witnessIndex = 0;
|
47239
47965
|
}
|
47240
47966
|
});
|
@@ -47260,12 +47986,17 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
47260
47986
|
const transactionRequest = transactionRequestify(transactionRequestLike);
|
47261
47987
|
return super.simulateTransaction(transactionRequest, { estimateTxDependencies: false });
|
47262
47988
|
}
|
47263
|
-
getPredicateData() {
|
47989
|
+
getPredicateData(policiesLength) {
|
47264
47990
|
if (!this.predicateData.length) {
|
47265
47991
|
return new Uint8Array();
|
47266
47992
|
}
|
47267
47993
|
const mainFn = this.interface?.functions.main;
|
47268
|
-
|
47994
|
+
const paddedCode = new ByteArrayCoder(this.bytes.length).encode(this.bytes);
|
47995
|
+
const VM_TX_MEMORY = calculateVmTxMemory({
|
47996
|
+
maxInputs: this.provider.getChain().consensusParameters.txParameters.maxInputs.toNumber()
|
47997
|
+
});
|
47998
|
+
const OFFSET = VM_TX_MEMORY + SCRIPT_FIXED_SIZE + INPUT_COIN_FIXED_SIZE + WORD_SIZE + paddedCode.byteLength + policiesLength * WORD_SIZE;
|
47999
|
+
return mainFn?.encodeArguments(this.predicateData, OFFSET) || new Uint8Array();
|
47269
48000
|
}
|
47270
48001
|
/**
|
47271
48002
|
* Processes the predicate data and returns the altered bytecode and interface.
|
@@ -47314,7 +48045,8 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
47314
48045
|
);
|
47315
48046
|
return resources.map((resource) => ({
|
47316
48047
|
...resource,
|
47317
|
-
predicate: hexlify(this.bytes)
|
48048
|
+
predicate: hexlify(this.bytes),
|
48049
|
+
padPredicateData: (policiesLength) => hexlify(this.getPredicateData(policiesLength))
|
47318
48050
|
}));
|
47319
48051
|
}
|
47320
48052
|
/**
|