@fuel-ts/account 0.0.0-rc-1356-20240514125020 → 0.0.0-rc-2238-20240514153703
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 +432 -1164
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +234 -254
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +118 -145
- package/dist/index.mjs.map +1 -1
- package/dist/predicate/predicate.d.ts.map +1 -1
- package/dist/providers/coin.d.ts +0 -1
- package/dist/providers/coin.d.ts.map +1 -1
- package/dist/providers/message.d.ts +0 -1
- package/dist/providers/message.d.ts.map +1 -1
- package/dist/providers/transaction-request/input.d.ts +0 -2
- package/dist/providers/transaction-request/input.d.ts.map +1 -1
- package/dist/providers/transaction-request/transaction-request.d.ts +0 -1
- 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 +1 -0
- package/dist/providers/utils/index.d.ts.map +1 -1
- package/dist/providers/utils/sleep.d.ts +3 -0
- package/dist/providers/utils/sleep.d.ts.map +1 -0
- package/dist/test-utils/index.d.ts +0 -4
- package/dist/test-utils/index.d.ts.map +1 -1
- package/dist/test-utils/launchNode.d.ts +1 -8
- package/dist/test-utils/launchNode.d.ts.map +1 -1
- package/dist/test-utils.global.js +428 -1475
- package/dist/test-utils.global.js.map +1 -1
- package/dist/test-utils.js +272 -523
- package/dist/test-utils.js.map +1 -1
- package/dist/test-utils.mjs +166 -413
- package/dist/test-utils.mjs.map +1 -1
- package/package.json +15 -16
- package/dist/test-utils/asset-id.d.ts +0 -8
- package/dist/test-utils/asset-id.d.ts.map +0 -1
- package/dist/test-utils/setup-test-provider-and-wallets.d.ts +0 -33
- package/dist/test-utils/setup-test-provider-and-wallets.d.ts.map +0 -1
- package/dist/test-utils/test-message.d.ts +0 -28
- package/dist/test-utils/test-message.d.ts.map +0 -1
- package/dist/test-utils/wallet-config.d.ts +0 -49
- package/dist/test-utils/wallet-config.d.ts.map +0 -1
@@ -32432,7 +32432,7 @@ spurious results.`);
|
|
32432
32432
|
// ../versions/dist/index.mjs
|
32433
32433
|
function getBuiltinVersions() {
|
32434
32434
|
return {
|
32435
|
-
FORC: "0.
|
32435
|
+
FORC: "0.58.0",
|
32436
32436
|
FUEL_CORE: "0.26.0",
|
32437
32437
|
FUELS: "0.85.0"
|
32438
32438
|
};
|
@@ -32933,13 +32933,6 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
32933
32933
|
};
|
32934
32934
|
var DateTime = _DateTime;
|
32935
32935
|
__publicField3(DateTime, "TAI64_NULL", "");
|
32936
|
-
function sleep(time) {
|
32937
|
-
return new Promise((resolve) => {
|
32938
|
-
setTimeout(() => {
|
32939
|
-
resolve(true);
|
32940
|
-
}, time);
|
32941
|
-
});
|
32942
|
-
}
|
32943
32936
|
var chainConfig_default = {
|
32944
32937
|
chain_name: "local_testnet",
|
32945
32938
|
consensus_parameters: {
|
@@ -33694,9 +33687,9 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
33694
33687
|
da_block_height: 0
|
33695
33688
|
};
|
33696
33689
|
var defaultSnapshotConfigs = {
|
33697
|
-
|
33698
|
-
|
33699
|
-
|
33690
|
+
chainConfigJson: chainConfig_default,
|
33691
|
+
metadataJson: metadata_default,
|
33692
|
+
stateConfigJson: stateConfig_default
|
33700
33693
|
};
|
33701
33694
|
var defaultConsensusKey = "0xa449b1ffee0e2205fa924c6740cc48b3b473aa28587df6dab12abc245d1f5298";
|
33702
33695
|
function isDefined(value) {
|
@@ -34319,72 +34312,11 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
34319
34312
|
};
|
34320
34313
|
}
|
34321
34314
|
|
34322
|
-
// ../../node_modules/.pnpm/ramda@0.29.0/node_modules/ramda/es/internal/_curry2.js
|
34323
|
-
function _curry2(fn) {
|
34324
|
-
return function f2(a, b) {
|
34325
|
-
switch (arguments.length) {
|
34326
|
-
case 0:
|
34327
|
-
return f2;
|
34328
|
-
case 1:
|
34329
|
-
return _isPlaceholder(a) ? f2 : _curry1(function(_b) {
|
34330
|
-
return fn(a, _b);
|
34331
|
-
});
|
34332
|
-
default:
|
34333
|
-
return _isPlaceholder(a) && _isPlaceholder(b) ? f2 : _isPlaceholder(a) ? _curry1(function(_a) {
|
34334
|
-
return fn(_a, b);
|
34335
|
-
}) : _isPlaceholder(b) ? _curry1(function(_b) {
|
34336
|
-
return fn(a, _b);
|
34337
|
-
}) : fn(a, b);
|
34338
|
-
}
|
34339
|
-
};
|
34340
|
-
}
|
34341
|
-
|
34342
|
-
// ../../node_modules/.pnpm/ramda@0.29.0/node_modules/ramda/es/internal/_curry3.js
|
34343
|
-
function _curry3(fn) {
|
34344
|
-
return function f3(a, b, c) {
|
34345
|
-
switch (arguments.length) {
|
34346
|
-
case 0:
|
34347
|
-
return f3;
|
34348
|
-
case 1:
|
34349
|
-
return _isPlaceholder(a) ? f3 : _curry2(function(_b, _c) {
|
34350
|
-
return fn(a, _b, _c);
|
34351
|
-
});
|
34352
|
-
case 2:
|
34353
|
-
return _isPlaceholder(a) && _isPlaceholder(b) ? f3 : _isPlaceholder(a) ? _curry2(function(_a, _c) {
|
34354
|
-
return fn(_a, b, _c);
|
34355
|
-
}) : _isPlaceholder(b) ? _curry2(function(_b, _c) {
|
34356
|
-
return fn(a, _b, _c);
|
34357
|
-
}) : _curry1(function(_c) {
|
34358
|
-
return fn(a, b, _c);
|
34359
|
-
});
|
34360
|
-
default:
|
34361
|
-
return _isPlaceholder(a) && _isPlaceholder(b) && _isPlaceholder(c) ? f3 : _isPlaceholder(a) && _isPlaceholder(b) ? _curry2(function(_a, _b) {
|
34362
|
-
return fn(_a, _b, c);
|
34363
|
-
}) : _isPlaceholder(a) && _isPlaceholder(c) ? _curry2(function(_a, _c) {
|
34364
|
-
return fn(_a, b, _c);
|
34365
|
-
}) : _isPlaceholder(b) && _isPlaceholder(c) ? _curry2(function(_b, _c) {
|
34366
|
-
return fn(a, _b, _c);
|
34367
|
-
}) : _isPlaceholder(a) ? _curry1(function(_a) {
|
34368
|
-
return fn(_a, b, c);
|
34369
|
-
}) : _isPlaceholder(b) ? _curry1(function(_b) {
|
34370
|
-
return fn(a, _b, c);
|
34371
|
-
}) : _isPlaceholder(c) ? _curry1(function(_c) {
|
34372
|
-
return fn(a, b, _c);
|
34373
|
-
}) : fn(a, b, c);
|
34374
|
-
}
|
34375
|
-
};
|
34376
|
-
}
|
34377
|
-
|
34378
34315
|
// ../../node_modules/.pnpm/ramda@0.29.0/node_modules/ramda/es/internal/_isArray.js
|
34379
34316
|
var isArray_default = Array.isArray || function _isArray(val) {
|
34380
34317
|
return val != null && val.length >= 0 && Object.prototype.toString.call(val) === "[object Array]";
|
34381
34318
|
};
|
34382
34319
|
|
34383
|
-
// ../../node_modules/.pnpm/ramda@0.29.0/node_modules/ramda/es/internal/_has.js
|
34384
|
-
function _has(prop, obj) {
|
34385
|
-
return Object.prototype.hasOwnProperty.call(obj, prop);
|
34386
|
-
}
|
34387
|
-
|
34388
34320
|
// ../../node_modules/.pnpm/ramda@0.29.0/node_modules/ramda/es/type.js
|
34389
34321
|
var type = /* @__PURE__ */ _curry1(function type2(val) {
|
34390
34322
|
return val === null ? "Null" : val === void 0 ? "Undefined" : Object.prototype.toString.call(val).slice(8, -1);
|
@@ -34401,11 +34333,6 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
34401
34333
|
return d.getUTCFullYear() + "-" + pad(d.getUTCMonth() + 1) + "-" + pad(d.getUTCDate()) + "T" + pad(d.getUTCHours()) + ":" + pad(d.getUTCMinutes()) + ":" + pad(d.getUTCSeconds()) + "." + (d.getUTCMilliseconds() / 1e3).toFixed(3).slice(2, 5) + "Z";
|
34402
34334
|
};
|
34403
34335
|
|
34404
|
-
// ../../node_modules/.pnpm/ramda@0.29.0/node_modules/ramda/es/internal/_isObject.js
|
34405
|
-
function _isObject(x) {
|
34406
|
-
return Object.prototype.toString.call(x) === "[object Object]";
|
34407
|
-
}
|
34408
|
-
|
34409
34336
|
// ../../node_modules/.pnpm/ramda@0.29.0/node_modules/ramda/es/internal/_isInteger.js
|
34410
34337
|
var isInteger_default = Number.isInteger || function _isInteger(n) {
|
34411
34338
|
return n << 0 === n;
|
@@ -34519,46 +34446,6 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
34519
34446
|
});
|
34520
34447
|
var clone_default = clone;
|
34521
34448
|
|
34522
|
-
// ../../node_modules/.pnpm/ramda@0.29.0/node_modules/ramda/es/mergeWithKey.js
|
34523
|
-
var mergeWithKey = /* @__PURE__ */ _curry3(function mergeWithKey2(fn, l, r) {
|
34524
|
-
var result = {};
|
34525
|
-
var k;
|
34526
|
-
l = l || {};
|
34527
|
-
r = r || {};
|
34528
|
-
for (k in l) {
|
34529
|
-
if (_has(k, l)) {
|
34530
|
-
result[k] = _has(k, r) ? fn(k, l[k], r[k]) : l[k];
|
34531
|
-
}
|
34532
|
-
}
|
34533
|
-
for (k in r) {
|
34534
|
-
if (_has(k, r) && !_has(k, result)) {
|
34535
|
-
result[k] = r[k];
|
34536
|
-
}
|
34537
|
-
}
|
34538
|
-
return result;
|
34539
|
-
});
|
34540
|
-
var mergeWithKey_default = mergeWithKey;
|
34541
|
-
|
34542
|
-
// ../../node_modules/.pnpm/ramda@0.29.0/node_modules/ramda/es/mergeDeepWithKey.js
|
34543
|
-
var mergeDeepWithKey = /* @__PURE__ */ _curry3(function mergeDeepWithKey2(fn, lObj, rObj) {
|
34544
|
-
return mergeWithKey_default(function(k, lVal, rVal) {
|
34545
|
-
if (_isObject(lVal) && _isObject(rVal)) {
|
34546
|
-
return mergeDeepWithKey2(fn, lVal, rVal);
|
34547
|
-
} else {
|
34548
|
-
return fn(k, lVal, rVal);
|
34549
|
-
}
|
34550
|
-
}, lObj, rObj);
|
34551
|
-
});
|
34552
|
-
var mergeDeepWithKey_default = mergeDeepWithKey;
|
34553
|
-
|
34554
|
-
// ../../node_modules/.pnpm/ramda@0.29.0/node_modules/ramda/es/mergeDeepRight.js
|
34555
|
-
var mergeDeepRight = /* @__PURE__ */ _curry2(function mergeDeepRight2(lObj, rObj) {
|
34556
|
-
return mergeDeepWithKey_default(function(k, lVal, rVal) {
|
34557
|
-
return rVal;
|
34558
|
-
}, lObj, rObj);
|
34559
|
-
});
|
34560
|
-
var mergeDeepRight_default = mergeDeepRight;
|
34561
|
-
|
34562
34449
|
// ../../node_modules/.pnpm/ramda@0.29.0/node_modules/ramda/es/trim.js
|
34563
34450
|
var hasProtoTrim = typeof String.prototype.trim === "function";
|
34564
34451
|
|
@@ -34912,19 +34799,6 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
34912
34799
|
__defNormalProp4(obj, typeof key !== "symbol" ? key + "" : key, value);
|
34913
34800
|
return value;
|
34914
34801
|
};
|
34915
|
-
var __accessCheck2 = (obj, member, msg) => {
|
34916
|
-
if (!member.has(obj))
|
34917
|
-
throw TypeError("Cannot " + msg);
|
34918
|
-
};
|
34919
|
-
var __privateAdd2 = (obj, member, value) => {
|
34920
|
-
if (member.has(obj))
|
34921
|
-
throw TypeError("Cannot add the same private member more than once");
|
34922
|
-
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
34923
|
-
};
|
34924
|
-
var __privateMethod2 = (obj, member, method) => {
|
34925
|
-
__accessCheck2(obj, member, "access private method");
|
34926
|
-
return method;
|
34927
|
-
};
|
34928
34802
|
var Coder = class {
|
34929
34803
|
name;
|
34930
34804
|
type;
|
@@ -34956,7 +34830,6 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
34956
34830
|
var enumRegEx = /^enum (?<name>\w+)$/;
|
34957
34831
|
var tupleRegEx = /^\((?<items>.*)\)$/;
|
34958
34832
|
var genericRegEx = /^generic (?<name>\w+)$/;
|
34959
|
-
var ENCODING_V0 = "0";
|
34960
34833
|
var ENCODING_V1 = "1";
|
34961
34834
|
var WORD_SIZE = 8;
|
34962
34835
|
var BYTES_32 = 32;
|
@@ -34967,10 +34840,6 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
34967
34840
|
var TX_LEN = WORD_SIZE * 4;
|
34968
34841
|
var TX_POINTER_LEN = WORD_SIZE * 2;
|
34969
34842
|
var MAX_BYTES = 2 ** 32 - 1;
|
34970
|
-
var calculateVmTxMemory = ({ maxInputs }) => BYTES_32 + // Tx ID
|
34971
|
-
ASSET_ID_LEN + // Base asset ID
|
34972
|
-
// Asset ID/Balance coin input pairs
|
34973
|
-
maxInputs * (ASSET_ID_LEN + WORD_SIZE) + WORD_SIZE;
|
34974
34843
|
var SCRIPT_FIXED_SIZE = WORD_SIZE + // Identifier
|
34975
34844
|
WORD_SIZE + // Gas limit
|
34976
34845
|
WORD_SIZE + // Script size
|
@@ -35001,125 +34870,6 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
35001
34870
|
WORD_SIZE + // Predicate size
|
35002
34871
|
WORD_SIZE + // Predicate data size
|
35003
34872
|
WORD_SIZE;
|
35004
|
-
var encodedLengths = {
|
35005
|
-
u64: WORD_SIZE,
|
35006
|
-
u256: WORD_SIZE * 4
|
35007
|
-
};
|
35008
|
-
var BigNumberCoder = class extends Coder {
|
35009
|
-
constructor(baseType) {
|
35010
|
-
super("bigNumber", baseType, encodedLengths[baseType]);
|
35011
|
-
}
|
35012
|
-
encode(value) {
|
35013
|
-
let bytes2;
|
35014
|
-
try {
|
35015
|
-
bytes2 = toBytes2(value, this.encodedLength);
|
35016
|
-
} catch (error) {
|
35017
|
-
throw new FuelError(ErrorCode.ENCODE_ERROR, `Invalid ${this.type}.`);
|
35018
|
-
}
|
35019
|
-
return bytes2;
|
35020
|
-
}
|
35021
|
-
decode(data, offset) {
|
35022
|
-
if (data.length < this.encodedLength) {
|
35023
|
-
throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid ${this.type} data size.`);
|
35024
|
-
}
|
35025
|
-
let bytes2 = data.slice(offset, offset + this.encodedLength);
|
35026
|
-
bytes2 = bytes2.slice(0, this.encodedLength);
|
35027
|
-
if (bytes2.length !== this.encodedLength) {
|
35028
|
-
throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid ${this.type} byte data size.`);
|
35029
|
-
}
|
35030
|
-
return [bn(bytes2), offset + this.encodedLength];
|
35031
|
-
}
|
35032
|
-
};
|
35033
|
-
var VEC_PROPERTY_SPACE = 3;
|
35034
|
-
var BASE_VECTOR_OFFSET = VEC_PROPERTY_SPACE * WORD_SIZE;
|
35035
|
-
var RAW_SLICE_PROPERTY_SPACE = 2;
|
35036
|
-
var BASE_RAW_SLICE_OFFSET = RAW_SLICE_PROPERTY_SPACE * WORD_SIZE;
|
35037
|
-
function concatWithDynamicData(items) {
|
35038
|
-
const topLevelData = {};
|
35039
|
-
let totalIndex = 0;
|
35040
|
-
const objects = items.map((item) => {
|
35041
|
-
const dynamicData = item.dynamicData;
|
35042
|
-
if (dynamicData) {
|
35043
|
-
Object.entries(dynamicData).forEach(([pointerIndex, vData]) => {
|
35044
|
-
topLevelData[parseInt(pointerIndex, 10) + totalIndex] = vData;
|
35045
|
-
});
|
35046
|
-
}
|
35047
|
-
const byteArray = arrayify(item);
|
35048
|
-
totalIndex += byteArray.byteLength / WORD_SIZE;
|
35049
|
-
return byteArray;
|
35050
|
-
});
|
35051
|
-
const length = objects.reduce((accum, item) => accum + item.length, 0);
|
35052
|
-
const result = new Uint8Array(length);
|
35053
|
-
objects.reduce((offset, object) => {
|
35054
|
-
result.set(object, offset);
|
35055
|
-
return offset + object.length;
|
35056
|
-
}, 0);
|
35057
|
-
if (Object.keys(topLevelData).length) {
|
35058
|
-
result.dynamicData = topLevelData;
|
35059
|
-
}
|
35060
|
-
return result;
|
35061
|
-
}
|
35062
|
-
function unpackDynamicData(results, baseOffset, dataOffset) {
|
35063
|
-
if (!results.dynamicData) {
|
35064
|
-
return concat([results]);
|
35065
|
-
}
|
35066
|
-
let cumulativeDynamicByteLength = 0;
|
35067
|
-
let updatedResults = results;
|
35068
|
-
Object.entries(results.dynamicData).forEach(([pointerIndex, vData]) => {
|
35069
|
-
const pointerOffset = parseInt(pointerIndex, 10) * WORD_SIZE;
|
35070
|
-
const adjustedValue = new BigNumberCoder("u64").encode(
|
35071
|
-
dataOffset + baseOffset + cumulativeDynamicByteLength
|
35072
|
-
);
|
35073
|
-
updatedResults.set(adjustedValue, pointerOffset);
|
35074
|
-
const dataToAppend = vData.dynamicData ? (
|
35075
|
-
// unpack child dynamic data
|
35076
|
-
unpackDynamicData(
|
35077
|
-
vData,
|
35078
|
-
baseOffset,
|
35079
|
-
dataOffset + vData.byteLength + cumulativeDynamicByteLength
|
35080
|
-
)
|
35081
|
-
) : vData;
|
35082
|
-
updatedResults = concat([updatedResults, dataToAppend]);
|
35083
|
-
cumulativeDynamicByteLength += dataToAppend.byteLength;
|
35084
|
-
});
|
35085
|
-
return updatedResults;
|
35086
|
-
}
|
35087
|
-
var chunkByLength = (data, length = WORD_SIZE) => {
|
35088
|
-
const chunks = [];
|
35089
|
-
let offset = 0;
|
35090
|
-
let chunk = data.slice(offset, offset + length);
|
35091
|
-
while (chunk.length) {
|
35092
|
-
chunks.push(chunk);
|
35093
|
-
offset += length;
|
35094
|
-
chunk = data.slice(offset, offset + length);
|
35095
|
-
}
|
35096
|
-
return chunks;
|
35097
|
-
};
|
35098
|
-
var isPointerType = (type3) => {
|
35099
|
-
switch (type3) {
|
35100
|
-
case "u8":
|
35101
|
-
case "u16":
|
35102
|
-
case "u32":
|
35103
|
-
case "u64":
|
35104
|
-
case "bool": {
|
35105
|
-
return false;
|
35106
|
-
}
|
35107
|
-
default: {
|
35108
|
-
return true;
|
35109
|
-
}
|
35110
|
-
}
|
35111
|
-
};
|
35112
|
-
var isHeapType = (type3) => type3 === VEC_CODER_TYPE || type3 === BYTES_CODER_TYPE || type3 === STD_STRING_CODER_TYPE;
|
35113
|
-
var isMultipleOfWordSize = (length) => length % WORD_SIZE === 0;
|
35114
|
-
var getWordSizePadding = (length) => WORD_SIZE - length % WORD_SIZE;
|
35115
|
-
var rightPadToWordSize = (encoded) => {
|
35116
|
-
if (isMultipleOfWordSize(encoded.length)) {
|
35117
|
-
return encoded;
|
35118
|
-
}
|
35119
|
-
const padding = new Uint8Array(WORD_SIZE - encoded.length % WORD_SIZE);
|
35120
|
-
return concatBytes2([encoded, padding]);
|
35121
|
-
};
|
35122
|
-
var isUint8Array = (value) => value instanceof Uint8Array;
|
35123
34873
|
var ArrayCoder = class extends Coder {
|
35124
34874
|
coder;
|
35125
34875
|
length;
|
@@ -35135,7 +34885,7 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
35135
34885
|
if (this.length !== value.length) {
|
35136
34886
|
throw new FuelError(ErrorCode.ENCODE_ERROR, `Types/values length mismatch.`);
|
35137
34887
|
}
|
35138
|
-
return
|
34888
|
+
return concat(Array.from(value).map((v) => this.coder.encode(v)));
|
35139
34889
|
}
|
35140
34890
|
decode(data, offset) {
|
35141
34891
|
if (data.length < this.encodedLength || data.length > MAX_BYTES) {
|
@@ -35212,16 +34962,42 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
35212
34962
|
return [toHex(bytes2, this.encodedLength), offset + this.encodedLength];
|
35213
34963
|
}
|
35214
34964
|
};
|
34965
|
+
var encodedLengths = {
|
34966
|
+
u64: WORD_SIZE,
|
34967
|
+
u256: WORD_SIZE * 4
|
34968
|
+
};
|
34969
|
+
var BigNumberCoder = class extends Coder {
|
34970
|
+
constructor(baseType) {
|
34971
|
+
super("bigNumber", baseType, encodedLengths[baseType]);
|
34972
|
+
}
|
34973
|
+
encode(value) {
|
34974
|
+
let bytes2;
|
34975
|
+
try {
|
34976
|
+
bytes2 = toBytes2(value, this.encodedLength);
|
34977
|
+
} catch (error) {
|
34978
|
+
throw new FuelError(ErrorCode.ENCODE_ERROR, `Invalid ${this.type}.`);
|
34979
|
+
}
|
34980
|
+
return bytes2;
|
34981
|
+
}
|
34982
|
+
decode(data, offset) {
|
34983
|
+
if (data.length < this.encodedLength) {
|
34984
|
+
throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid ${this.type} data size.`);
|
34985
|
+
}
|
34986
|
+
let bytes2 = data.slice(offset, offset + this.encodedLength);
|
34987
|
+
bytes2 = bytes2.slice(0, this.encodedLength);
|
34988
|
+
if (bytes2.length !== this.encodedLength) {
|
34989
|
+
throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid ${this.type} byte data size.`);
|
34990
|
+
}
|
34991
|
+
return [bn(bytes2), offset + this.encodedLength];
|
34992
|
+
}
|
34993
|
+
};
|
35215
34994
|
var BooleanCoder = class extends Coder {
|
35216
|
-
paddingLength;
|
35217
34995
|
options;
|
35218
34996
|
constructor(options = {
|
35219
|
-
|
35220
|
-
isRightPadded: false
|
34997
|
+
padToWordSize: false
|
35221
34998
|
}) {
|
35222
|
-
const
|
35223
|
-
super("boolean", "boolean",
|
35224
|
-
this.paddingLength = paddingLength;
|
34999
|
+
const encodedLength = options.padToWordSize ? WORD_SIZE : 1;
|
35000
|
+
super("boolean", "boolean", encodedLength);
|
35225
35001
|
this.options = options;
|
35226
35002
|
}
|
35227
35003
|
encode(value) {
|
@@ -35229,73 +35005,45 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
35229
35005
|
if (!isTrueBool) {
|
35230
35006
|
throw new FuelError(ErrorCode.ENCODE_ERROR, `Invalid boolean value.`);
|
35231
35007
|
}
|
35232
|
-
|
35233
|
-
if (this.options.isRightPadded) {
|
35234
|
-
return output2.reverse();
|
35235
|
-
}
|
35236
|
-
return output2;
|
35008
|
+
return toBytes2(value ? 1 : 0, this.encodedLength);
|
35237
35009
|
}
|
35238
35010
|
decode(data, offset) {
|
35239
|
-
if (data.length < this.
|
35011
|
+
if (data.length < this.encodedLength) {
|
35240
35012
|
throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid boolean data size.`);
|
35241
35013
|
}
|
35242
|
-
|
35243
|
-
if (
|
35244
|
-
|
35245
|
-
} else {
|
35246
|
-
bytes2 = data.slice(offset, offset + this.paddingLength);
|
35247
|
-
}
|
35248
|
-
const decodedValue = bn(bytes2);
|
35249
|
-
if (decodedValue.isZero()) {
|
35250
|
-
return [false, offset + this.paddingLength];
|
35014
|
+
const bytes2 = bn(data.slice(offset, offset + this.encodedLength));
|
35015
|
+
if (bytes2.isZero()) {
|
35016
|
+
return [false, offset + this.encodedLength];
|
35251
35017
|
}
|
35252
|
-
if (!
|
35018
|
+
if (!bytes2.eq(bn(1))) {
|
35253
35019
|
throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid boolean value.`);
|
35254
35020
|
}
|
35255
|
-
return [true, offset + this.
|
35021
|
+
return [true, offset + this.encodedLength];
|
35256
35022
|
}
|
35257
35023
|
};
|
35258
|
-
var _getPaddedData;
|
35259
|
-
var getPaddedData_fn;
|
35260
35024
|
var ByteCoder = class extends Coder {
|
35261
35025
|
constructor() {
|
35262
|
-
super("struct", "struct Bytes",
|
35263
|
-
__privateAdd2(this, _getPaddedData);
|
35026
|
+
super("struct", "struct Bytes", WORD_SIZE);
|
35264
35027
|
}
|
35265
35028
|
encode(value) {
|
35266
|
-
const
|
35267
|
-
const
|
35268
|
-
|
35269
|
-
pointer.dynamicData = {
|
35270
|
-
0: concatWithDynamicData([data])
|
35271
|
-
};
|
35272
|
-
parts.push(pointer);
|
35273
|
-
parts.push(new BigNumberCoder("u64").encode(data.byteLength));
|
35274
|
-
parts.push(new BigNumberCoder("u64").encode(value.length));
|
35275
|
-
return concatWithDynamicData(parts);
|
35029
|
+
const bytes2 = value instanceof Uint8Array ? value : new Uint8Array(value);
|
35030
|
+
const lengthBytes = new BigNumberCoder("u64").encode(bytes2.length);
|
35031
|
+
return new Uint8Array([...lengthBytes, ...bytes2]);
|
35276
35032
|
}
|
35277
35033
|
decode(data, offset) {
|
35278
|
-
if (data.length <
|
35034
|
+
if (data.length < WORD_SIZE) {
|
35279
35035
|
throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid byte data size.`);
|
35280
35036
|
}
|
35281
|
-
const
|
35282
|
-
const
|
35283
|
-
const
|
35284
|
-
|
35037
|
+
const offsetAndLength = offset + WORD_SIZE;
|
35038
|
+
const lengthBytes = data.slice(offset, offsetAndLength);
|
35039
|
+
const length = bn(new BigNumberCoder("u64").decode(lengthBytes, 0)[0]).toNumber();
|
35040
|
+
const dataBytes = data.slice(offsetAndLength, offsetAndLength + length);
|
35041
|
+
if (dataBytes.length !== length) {
|
35285
35042
|
throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid bytes byte data size.`);
|
35286
35043
|
}
|
35287
|
-
return [
|
35044
|
+
return [dataBytes, offsetAndLength + length];
|
35288
35045
|
}
|
35289
35046
|
};
|
35290
|
-
_getPaddedData = /* @__PURE__ */ new WeakSet();
|
35291
|
-
getPaddedData_fn = function(value) {
|
35292
|
-
const data = value instanceof Uint8Array ? [value] : [new Uint8Array(value)];
|
35293
|
-
const paddingLength = (WORD_SIZE - value.length % WORD_SIZE) % WORD_SIZE;
|
35294
|
-
if (paddingLength) {
|
35295
|
-
data.push(new Uint8Array(paddingLength));
|
35296
|
-
}
|
35297
|
-
return concat(data);
|
35298
|
-
};
|
35299
35047
|
__publicField4(ByteCoder, "memorySize", 1);
|
35300
35048
|
var isFullyNativeEnum = (enumCoders) => Object.values(enumCoders).every(
|
35301
35049
|
// @ts-expect-error complicated types
|
@@ -35339,8 +35087,7 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
35339
35087
|
const valueCoder = this.coders[caseKey];
|
35340
35088
|
const caseIndex = Object.keys(this.coders).indexOf(caseKey);
|
35341
35089
|
const encodedValue = valueCoder.encode(value[caseKey]);
|
35342
|
-
|
35343
|
-
return concatWithDynamicData([this.#caseIndexCoder.encode(caseIndex), padding, encodedValue]);
|
35090
|
+
return new Uint8Array([...this.#caseIndexCoder.encode(caseIndex), ...encodedValue]);
|
35344
35091
|
}
|
35345
35092
|
#decodeNativeEnum(caseKey, newOffset) {
|
35346
35093
|
return [caseKey, newOffset];
|
@@ -35349,10 +35096,8 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
35349
35096
|
if (data.length < this.#encodedValueSize) {
|
35350
35097
|
throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid enum data size.`);
|
35351
35098
|
}
|
35352
|
-
|
35353
|
-
|
35354
|
-
[decoded, newOffset] = new BigNumberCoder("u64").decode(data, newOffset);
|
35355
|
-
const caseIndex = toNumber(decoded);
|
35099
|
+
const caseBytes = new BigNumberCoder("u64").decode(data, offset)[0];
|
35100
|
+
const caseIndex = toNumber(caseBytes);
|
35356
35101
|
const caseKey = Object.keys(this.coders)[caseIndex];
|
35357
35102
|
if (!caseKey) {
|
35358
35103
|
throw new FuelError(
|
@@ -35361,67 +35106,35 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
35361
35106
|
);
|
35362
35107
|
}
|
35363
35108
|
const valueCoder = this.coders[caseKey];
|
35364
|
-
const
|
35365
|
-
newOffset
|
35366
|
-
[decoded, newOffset] = valueCoder.decode(data, newOffset);
|
35109
|
+
const offsetAndCase = offset + WORD_SIZE;
|
35110
|
+
const [decoded, newOffset] = valueCoder.decode(data, offsetAndCase);
|
35367
35111
|
if (isFullyNativeEnum(this.coders)) {
|
35368
35112
|
return this.#decodeNativeEnum(caseKey, newOffset);
|
35369
35113
|
}
|
35370
35114
|
return [{ [caseKey]: decoded }, newOffset];
|
35371
35115
|
}
|
35372
35116
|
};
|
35373
|
-
var
|
35374
|
-
|
35375
|
-
|
35376
|
-
|
35377
|
-
|
35378
|
-
|
35379
|
-
|
35380
|
-
return
|
35381
|
-
|
35382
|
-
|
35383
|
-
}
|
35384
|
-
decode(data, offset) {
|
35385
|
-
if (data.length < this.encodedLength) {
|
35386
|
-
throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid option data size.`);
|
35387
|
-
}
|
35388
|
-
const [decoded, newOffset] = super.decode(data, offset);
|
35389
|
-
return [this.toOption(decoded), newOffset];
|
35390
|
-
}
|
35391
|
-
toOption(output2) {
|
35392
|
-
if (output2 && "Some" in output2) {
|
35393
|
-
return output2.Some;
|
35394
|
-
}
|
35395
|
-
return void 0;
|
35117
|
+
var getLength = (baseType) => {
|
35118
|
+
switch (baseType) {
|
35119
|
+
case "u8":
|
35120
|
+
return 1;
|
35121
|
+
case "u16":
|
35122
|
+
return 2;
|
35123
|
+
case "u32":
|
35124
|
+
return 4;
|
35125
|
+
default:
|
35126
|
+
throw new FuelError(ErrorCode.TYPE_NOT_SUPPORTED, `Invalid number type: ${baseType}`);
|
35396
35127
|
}
|
35397
35128
|
};
|
35398
35129
|
var NumberCoder = class extends Coder {
|
35399
|
-
// This is to align the bits to the total bytes
|
35400
|
-
// See https://github.com/FuelLabs/fuel-specs/blob/master/specs/protocol/abi.md#unsigned-integers
|
35401
|
-
length;
|
35402
|
-
paddingLength;
|
35403
35130
|
baseType;
|
35404
35131
|
options;
|
35405
35132
|
constructor(baseType, options = {
|
35406
|
-
|
35407
|
-
isRightPadded: false
|
35133
|
+
padToWordSize: false
|
35408
35134
|
}) {
|
35409
|
-
const
|
35410
|
-
super("number", baseType,
|
35135
|
+
const length = options.padToWordSize ? WORD_SIZE : getLength(baseType);
|
35136
|
+
super("number", baseType, length);
|
35411
35137
|
this.baseType = baseType;
|
35412
|
-
switch (baseType) {
|
35413
|
-
case "u8":
|
35414
|
-
this.length = 1;
|
35415
|
-
break;
|
35416
|
-
case "u16":
|
35417
|
-
this.length = 2;
|
35418
|
-
break;
|
35419
|
-
case "u32":
|
35420
|
-
default:
|
35421
|
-
this.length = 4;
|
35422
|
-
break;
|
35423
|
-
}
|
35424
|
-
this.paddingLength = paddingLength;
|
35425
35138
|
this.options = options;
|
35426
35139
|
}
|
35427
35140
|
encode(value) {
|
@@ -35431,142 +35144,140 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
35431
35144
|
} catch (error) {
|
35432
35145
|
throw new FuelError(ErrorCode.ENCODE_ERROR, `Invalid ${this.baseType}.`);
|
35433
35146
|
}
|
35434
|
-
if (bytes2.length > this.
|
35147
|
+
if (bytes2.length > this.encodedLength) {
|
35435
35148
|
throw new FuelError(ErrorCode.ENCODE_ERROR, `Invalid ${this.baseType}, too many bytes.`);
|
35436
35149
|
}
|
35437
|
-
|
35438
|
-
if (this.baseType !== "u8") {
|
35439
|
-
return output2;
|
35440
|
-
}
|
35441
|
-
return this.options.isRightPadded ? output2.reverse() : output2;
|
35442
|
-
}
|
35443
|
-
decodeU8(data, offset) {
|
35444
|
-
let bytes2;
|
35445
|
-
if (this.options.isRightPadded) {
|
35446
|
-
bytes2 = data.slice(offset, offset + 1);
|
35447
|
-
} else {
|
35448
|
-
bytes2 = data.slice(offset, offset + this.paddingLength);
|
35449
|
-
bytes2 = bytes2.slice(this.paddingLength - this.length, this.paddingLength);
|
35450
|
-
}
|
35451
|
-
return [toNumber(bytes2), offset + this.paddingLength];
|
35150
|
+
return toBytes2(bytes2, this.encodedLength);
|
35452
35151
|
}
|
35453
35152
|
decode(data, offset) {
|
35454
|
-
if (data.length < this.
|
35153
|
+
if (data.length < this.encodedLength) {
|
35455
35154
|
throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid number data size.`);
|
35456
35155
|
}
|
35457
|
-
|
35458
|
-
|
35459
|
-
}
|
35460
|
-
let bytes2 = data.slice(offset, offset + this.paddingLength);
|
35461
|
-
bytes2 = bytes2.slice(8 - this.length, 8);
|
35462
|
-
if (bytes2.length !== this.paddingLength - (this.paddingLength - this.length)) {
|
35156
|
+
const bytes2 = data.slice(offset, offset + this.encodedLength);
|
35157
|
+
if (bytes2.length !== this.encodedLength) {
|
35463
35158
|
throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid number byte data size.`);
|
35464
35159
|
}
|
35465
|
-
return [toNumber(bytes2), offset +
|
35160
|
+
return [toNumber(bytes2), offset + this.encodedLength];
|
35466
35161
|
}
|
35467
35162
|
};
|
35468
|
-
var
|
35469
|
-
constructor() {
|
35470
|
-
super("raw untyped slice", "raw untyped slice", BASE_RAW_SLICE_OFFSET);
|
35471
|
-
}
|
35163
|
+
var OptionCoder = class extends EnumCoder {
|
35472
35164
|
encode(value) {
|
35473
|
-
|
35474
|
-
|
35165
|
+
const result = super.encode(this.toSwayOption(value));
|
35166
|
+
return result;
|
35167
|
+
}
|
35168
|
+
toSwayOption(input) {
|
35169
|
+
if (input !== void 0) {
|
35170
|
+
return { Some: input };
|
35475
35171
|
}
|
35476
|
-
|
35477
|
-
const coder = new NumberCoder("u8", { isSmallBytes: true });
|
35478
|
-
const pointer = new BigNumberCoder("u64").encode(
|
35479
|
-
BASE_RAW_SLICE_OFFSET
|
35480
|
-
);
|
35481
|
-
pointer.dynamicData = {
|
35482
|
-
0: concatWithDynamicData(value.map((v) => coder.encode(v)))
|
35483
|
-
};
|
35484
|
-
parts.push(pointer);
|
35485
|
-
parts.push(new BigNumberCoder("u64").encode(value.length));
|
35486
|
-
return concatWithDynamicData(parts);
|
35172
|
+
return { None: [] };
|
35487
35173
|
}
|
35488
35174
|
decode(data, offset) {
|
35489
|
-
const
|
35490
|
-
|
35491
|
-
|
35492
|
-
|
35493
|
-
)
|
35494
|
-
|
35495
|
-
|
35175
|
+
const [decoded, newOffset] = super.decode(data, offset);
|
35176
|
+
return [this.toOption(decoded), newOffset];
|
35177
|
+
}
|
35178
|
+
toOption(output2) {
|
35179
|
+
if (output2 && "Some" in output2) {
|
35180
|
+
return output2.Some;
|
35181
|
+
}
|
35182
|
+
return void 0;
|
35496
35183
|
}
|
35497
35184
|
};
|
35498
|
-
var
|
35499
|
-
var getPaddedData_fn2;
|
35500
|
-
var StdStringCoder = class extends Coder {
|
35185
|
+
var RawSliceCoder = class extends Coder {
|
35501
35186
|
constructor() {
|
35502
|
-
super("
|
35503
|
-
__privateAdd2(this, _getPaddedData2);
|
35187
|
+
super("raw untyped slice", "raw untyped slice", WORD_SIZE);
|
35504
35188
|
}
|
35505
35189
|
encode(value) {
|
35506
|
-
|
35507
|
-
|
35508
|
-
|
35509
|
-
|
35510
|
-
|
35511
|
-
|
35512
|
-
|
35513
|
-
parts.push(new BigNumberCoder("u64").encode(data.byteLength));
|
35514
|
-
parts.push(new BigNumberCoder("u64").encode(value.length));
|
35515
|
-
return concatWithDynamicData(parts);
|
35190
|
+
if (!Array.isArray(value)) {
|
35191
|
+
throw new FuelError(ErrorCode.ENCODE_ERROR, `Expected array value.`);
|
35192
|
+
}
|
35193
|
+
const internalCoder = new ArrayCoder(new NumberCoder("u8"), value.length);
|
35194
|
+
const bytes2 = internalCoder.encode(value);
|
35195
|
+
const lengthBytes = new BigNumberCoder("u64").encode(bytes2.length);
|
35196
|
+
return new Uint8Array([...lengthBytes, ...bytes2]);
|
35516
35197
|
}
|
35517
35198
|
decode(data, offset) {
|
35518
35199
|
if (data.length < this.encodedLength) {
|
35519
|
-
throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid
|
35200
|
+
throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid raw slice data size.`);
|
35520
35201
|
}
|
35521
|
-
const
|
35522
|
-
const
|
35523
|
-
const
|
35524
|
-
|
35525
|
-
|
35202
|
+
const offsetAndLength = offset + WORD_SIZE;
|
35203
|
+
const lengthBytes = data.slice(offset, offsetAndLength);
|
35204
|
+
const length = bn(new BigNumberCoder("u64").decode(lengthBytes, 0)[0]).toNumber();
|
35205
|
+
const dataBytes = data.slice(offsetAndLength, offsetAndLength + length);
|
35206
|
+
if (dataBytes.length !== length) {
|
35207
|
+
throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid raw slice byte data size.`);
|
35526
35208
|
}
|
35527
|
-
const
|
35528
|
-
|
35209
|
+
const internalCoder = new ArrayCoder(new NumberCoder("u8"), length);
|
35210
|
+
const [decodedValue] = internalCoder.decode(dataBytes, 0);
|
35211
|
+
return [decodedValue, offsetAndLength + length];
|
35529
35212
|
}
|
35530
35213
|
};
|
35531
|
-
|
35532
|
-
|
35533
|
-
|
35534
|
-
|
35535
|
-
|
35536
|
-
|
35537
|
-
|
35538
|
-
|
35214
|
+
var StdStringCoder = class extends Coder {
|
35215
|
+
constructor() {
|
35216
|
+
super("struct", "struct String", WORD_SIZE);
|
35217
|
+
}
|
35218
|
+
encode(value) {
|
35219
|
+
const bytes2 = toUtf8Bytes(value);
|
35220
|
+
const lengthBytes = new BigNumberCoder("u64").encode(value.length);
|
35221
|
+
return new Uint8Array([...lengthBytes, ...bytes2]);
|
35222
|
+
}
|
35223
|
+
decode(data, offset) {
|
35224
|
+
if (data.length < this.encodedLength) {
|
35225
|
+
throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid std string data size.`);
|
35226
|
+
}
|
35227
|
+
const offsetAndLength = offset + WORD_SIZE;
|
35228
|
+
const lengthBytes = data.slice(offset, offsetAndLength);
|
35229
|
+
const length = bn(new BigNumberCoder("u64").decode(lengthBytes, 0)[0]).toNumber();
|
35230
|
+
const dataBytes = data.slice(offsetAndLength, offsetAndLength + length);
|
35231
|
+
if (dataBytes.length !== length) {
|
35232
|
+
throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid std string byte data size.`);
|
35233
|
+
}
|
35234
|
+
return [toUtf8String(dataBytes), offsetAndLength + length];
|
35235
|
+
}
|
35539
35236
|
};
|
35540
35237
|
__publicField4(StdStringCoder, "memorySize", 1);
|
35238
|
+
var StrSliceCoder = class extends Coder {
|
35239
|
+
constructor() {
|
35240
|
+
super("strSlice", "str", WORD_SIZE);
|
35241
|
+
}
|
35242
|
+
encode(value) {
|
35243
|
+
const bytes2 = toUtf8Bytes(value);
|
35244
|
+
const lengthBytes = new BigNumberCoder("u64").encode(value.length);
|
35245
|
+
return new Uint8Array([...lengthBytes, ...bytes2]);
|
35246
|
+
}
|
35247
|
+
decode(data, offset) {
|
35248
|
+
if (data.length < this.encodedLength) {
|
35249
|
+
throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid string slice data size.`);
|
35250
|
+
}
|
35251
|
+
const offsetAndLength = offset + WORD_SIZE;
|
35252
|
+
const lengthBytes = data.slice(offset, offsetAndLength);
|
35253
|
+
const length = bn(new BigNumberCoder("u64").decode(lengthBytes, 0)[0]).toNumber();
|
35254
|
+
const bytes2 = data.slice(offsetAndLength, offsetAndLength + length);
|
35255
|
+
if (bytes2.length !== length) {
|
35256
|
+
throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid string slice byte data size.`);
|
35257
|
+
}
|
35258
|
+
return [toUtf8String(bytes2), offsetAndLength + length];
|
35259
|
+
}
|
35260
|
+
};
|
35261
|
+
__publicField4(StrSliceCoder, "memorySize", 1);
|
35541
35262
|
var StringCoder = class extends Coder {
|
35542
|
-
length;
|
35543
|
-
#paddingLength;
|
35544
35263
|
constructor(length) {
|
35545
|
-
|
35546
|
-
paddingLength = paddingLength < 0 ? paddingLength + 8 : paddingLength;
|
35547
|
-
super("string", `str[${length}]`, length + paddingLength);
|
35548
|
-
this.length = length;
|
35549
|
-
this.#paddingLength = paddingLength;
|
35264
|
+
super("string", `str[${length}]`, length);
|
35550
35265
|
}
|
35551
35266
|
encode(value) {
|
35552
|
-
if (
|
35267
|
+
if (value.length !== this.encodedLength) {
|
35553
35268
|
throw new FuelError(ErrorCode.ENCODE_ERROR, `Value length mismatch during encode.`);
|
35554
35269
|
}
|
35555
|
-
|
35556
|
-
const padding = new Uint8Array(this.#paddingLength);
|
35557
|
-
return concat([encoded, padding]);
|
35270
|
+
return toUtf8Bytes(value);
|
35558
35271
|
}
|
35559
35272
|
decode(data, offset) {
|
35560
35273
|
if (data.length < this.encodedLength) {
|
35561
35274
|
throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid string data size.`);
|
35562
35275
|
}
|
35563
|
-
const bytes2 = data.slice(offset, offset + this.
|
35564
|
-
if (bytes2.length !== this.
|
35276
|
+
const bytes2 = data.slice(offset, offset + this.encodedLength);
|
35277
|
+
if (bytes2.length !== this.encodedLength) {
|
35565
35278
|
throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid string byte data size.`);
|
35566
35279
|
}
|
35567
|
-
|
35568
|
-
const padding = this.#paddingLength;
|
35569
|
-
return [value, offset + this.length + padding];
|
35280
|
+
return [toUtf8String(bytes2), offset + this.encodedLength];
|
35570
35281
|
}
|
35571
35282
|
};
|
35572
35283
|
var StructCoder = class extends Coder {
|
@@ -35582,22 +35293,19 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
35582
35293
|
this.coders = coders;
|
35583
35294
|
}
|
35584
35295
|
encode(value) {
|
35585
|
-
|
35586
|
-
|
35587
|
-
|
35588
|
-
|
35589
|
-
|
35590
|
-
|
35591
|
-
|
35592
|
-
|
35593
|
-
|
35594
|
-
|
35595
|
-
|
35596
|
-
|
35597
|
-
|
35598
|
-
return encoded;
|
35599
|
-
});
|
35600
|
-
return concatWithDynamicData([concatWithDynamicData(encodedFields)]);
|
35296
|
+
return concatBytes2(
|
35297
|
+
Object.keys(this.coders).map((fieldName) => {
|
35298
|
+
const fieldCoder = this.coders[fieldName];
|
35299
|
+
const fieldValue = value[fieldName];
|
35300
|
+
if (!(fieldCoder instanceof OptionCoder) && fieldValue == null) {
|
35301
|
+
throw new FuelError(
|
35302
|
+
ErrorCode.ENCODE_ERROR,
|
35303
|
+
`Invalid ${this.type}. Field "${fieldName}" not present.`
|
35304
|
+
);
|
35305
|
+
}
|
35306
|
+
return fieldCoder.encode(fieldValue);
|
35307
|
+
})
|
35308
|
+
);
|
35601
35309
|
}
|
35602
35310
|
decode(data, offset) {
|
35603
35311
|
if (data.length < this.encodedLength) {
|
@@ -35608,9 +35316,6 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
35608
35316
|
const fieldCoder = this.coders[fieldName];
|
35609
35317
|
let decoded;
|
35610
35318
|
[decoded, newOffset] = fieldCoder.decode(data, newOffset);
|
35611
|
-
if (!isMultipleOfWordSize(newOffset)) {
|
35612
|
-
newOffset += getWordSizePadding(newOffset);
|
35613
|
-
}
|
35614
35319
|
obj[fieldName] = decoded;
|
35615
35320
|
return obj;
|
35616
35321
|
}, {});
|
@@ -35628,15 +35333,7 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
35628
35333
|
if (this.coders.length !== value.length) {
|
35629
35334
|
throw new FuelError(ErrorCode.ENCODE_ERROR, `Types/values length mismatch.`);
|
35630
35335
|
}
|
35631
|
-
return
|
35632
|
-
this.coders.map((coder, i) => {
|
35633
|
-
const encoded = coder.encode(value[i]);
|
35634
|
-
if (!isMultipleOfWordSize(encoded.length)) {
|
35635
|
-
return rightPadToWordSize(encoded);
|
35636
|
-
}
|
35637
|
-
return encoded;
|
35638
|
-
})
|
35639
|
-
);
|
35336
|
+
return concatBytes2(this.coders.map((coder, i) => coder.encode(value[i])));
|
35640
35337
|
}
|
35641
35338
|
decode(data, offset) {
|
35642
35339
|
if (data.length < this.encodedLength) {
|
@@ -35646,19 +35343,19 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
35646
35343
|
const decodedValue = this.coders.map((coder) => {
|
35647
35344
|
let decoded;
|
35648
35345
|
[decoded, newOffset] = coder.decode(data, newOffset);
|
35649
|
-
if (!isMultipleOfWordSize(newOffset)) {
|
35650
|
-
newOffset += getWordSizePadding(newOffset);
|
35651
|
-
}
|
35652
35346
|
return decoded;
|
35653
35347
|
});
|
35654
35348
|
return [decodedValue, newOffset];
|
35655
35349
|
}
|
35656
35350
|
};
|
35351
|
+
var isUint8Array = (value) => value instanceof Uint8Array;
|
35657
35352
|
var VecCoder = class extends Coder {
|
35658
35353
|
coder;
|
35354
|
+
#isOptionVec;
|
35659
35355
|
constructor(coder) {
|
35660
|
-
super("struct", `struct Vec`, coder.encodedLength +
|
35356
|
+
super("struct", `struct Vec`, coder.encodedLength + WORD_SIZE);
|
35661
35357
|
this.coder = coder;
|
35358
|
+
this.#isOptionVec = this.coder instanceof OptionCoder;
|
35662
35359
|
}
|
35663
35360
|
encode(value) {
|
35664
35361
|
if (!Array.isArray(value) && !isUint8Array(value)) {
|
@@ -35667,40 +35364,39 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
35667
35364
|
`Expected array value, or a Uint8Array. You can use arrayify to convert a value to a Uint8Array.`
|
35668
35365
|
);
|
35669
35366
|
}
|
35670
|
-
const
|
35671
|
-
|
35672
|
-
|
35673
|
-
|
35674
|
-
|
35675
|
-
|
35676
|
-
|
35677
|
-
parts.push(new BigNumberCoder("u64").encode(value.length));
|
35678
|
-
return concatWithDynamicData(parts);
|
35367
|
+
const lengthCoder = new BigNumberCoder("u64");
|
35368
|
+
if (isUint8Array(value)) {
|
35369
|
+
return new Uint8Array([...lengthCoder.encode(value.length), ...value]);
|
35370
|
+
}
|
35371
|
+
const bytes2 = value.map((v) => this.coder.encode(v));
|
35372
|
+
const lengthBytes = lengthCoder.encode(value.length);
|
35373
|
+
return new Uint8Array([...lengthBytes, ...concatBytes2(bytes2)]);
|
35679
35374
|
}
|
35680
35375
|
decode(data, offset) {
|
35681
|
-
if (data.length <
|
35376
|
+
if (!this.#isOptionVec && (data.length < this.encodedLength || data.length > MAX_BYTES)) {
|
35682
35377
|
throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid vec data size.`);
|
35683
35378
|
}
|
35684
|
-
const
|
35685
|
-
const
|
35686
|
-
const
|
35687
|
-
const
|
35688
|
-
|
35379
|
+
const offsetAndLength = offset + WORD_SIZE;
|
35380
|
+
const lengthBytes = data.slice(offset, offsetAndLength);
|
35381
|
+
const length = bn(new BigNumberCoder("u64").decode(lengthBytes, 0)[0]).toNumber();
|
35382
|
+
const dataLength2 = length * this.coder.encodedLength;
|
35383
|
+
const dataBytes = data.slice(offsetAndLength, offsetAndLength + dataLength2);
|
35384
|
+
if (!this.#isOptionVec && dataBytes.length !== dataLength2) {
|
35689
35385
|
throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid vec byte data size.`);
|
35690
35386
|
}
|
35691
|
-
|
35692
|
-
|
35693
|
-
|
35694
|
-
)
|
35695
|
-
|
35696
|
-
|
35387
|
+
let newOffset = offsetAndLength;
|
35388
|
+
const chunks = [];
|
35389
|
+
for (let i = 0; i < length; i++) {
|
35390
|
+
const [decoded, optionOffset] = this.coder.decode(data, newOffset);
|
35391
|
+
chunks.push(decoded);
|
35392
|
+
newOffset = optionOffset;
|
35393
|
+
}
|
35394
|
+
return [chunks, newOffset];
|
35697
35395
|
}
|
35698
35396
|
};
|
35699
35397
|
var getEncodingVersion = (encoding) => {
|
35700
35398
|
switch (encoding) {
|
35701
35399
|
case void 0:
|
35702
|
-
case ENCODING_V0:
|
35703
|
-
return ENCODING_V0;
|
35704
35400
|
case ENCODING_V1:
|
35705
35401
|
return ENCODING_V1;
|
35706
35402
|
default:
|
@@ -35803,587 +35499,109 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
35803
35499
|
)
|
35804
35500
|
};
|
35805
35501
|
}
|
35806
|
-
const argType = findTypeById(abi, arg.type);
|
35807
|
-
const implicitTypeParameters = this.getImplicitGenericTypeParameters(abi, argType.components);
|
35808
|
-
if (implicitTypeParameters && implicitTypeParameters.length > 0) {
|
35809
|
-
return {
|
35810
|
-
...structuredClone(arg),
|
35811
|
-
typeArguments: implicitTypeParameters.map((itp) => typeParametersAndArgsMap[itp])
|
35812
|
-
};
|
35813
|
-
}
|
35814
|
-
return arg;
|
35815
|
-
});
|
35816
|
-
}
|
35817
|
-
static getImplicitGenericTypeParameters(abi, args, implicitGenericParametersParam) {
|
35818
|
-
if (!Array.isArray(args)) {
|
35819
|
-
return null;
|
35820
|
-
}
|
35821
|
-
const implicitGenericParameters = implicitGenericParametersParam ?? [];
|
35822
|
-
args.forEach((a) => {
|
35823
|
-
const argType = findTypeById(abi, a.type);
|
35824
|
-
if (genericRegEx.test(argType.type)) {
|
35825
|
-
implicitGenericParameters.push(argType.typeId);
|
35826
|
-
return;
|
35827
|
-
}
|
35828
|
-
if (!Array.isArray(a.typeArguments)) {
|
35829
|
-
return;
|
35830
|
-
}
|
35831
|
-
this.getImplicitGenericTypeParameters(abi, a.typeArguments, implicitGenericParameters);
|
35832
|
-
});
|
35833
|
-
return implicitGenericParameters.length > 0 ? implicitGenericParameters : null;
|
35834
|
-
}
|
35835
|
-
getSignature() {
|
35836
|
-
const prefix = this.getArgSignaturePrefix();
|
35837
|
-
const content = this.getArgSignatureContent();
|
35838
|
-
return `${prefix}${content}`;
|
35839
|
-
}
|
35840
|
-
getArgSignaturePrefix() {
|
35841
|
-
const structMatch = structRegEx.test(this.type);
|
35842
|
-
if (structMatch) {
|
35843
|
-
return "s";
|
35844
|
-
}
|
35845
|
-
const arrayMatch = arrayRegEx.test(this.type);
|
35846
|
-
if (arrayMatch) {
|
35847
|
-
return "a";
|
35848
|
-
}
|
35849
|
-
const enumMatch = enumRegEx.test(this.type);
|
35850
|
-
if (enumMatch) {
|
35851
|
-
return "e";
|
35852
|
-
}
|
35853
|
-
return "";
|
35854
|
-
}
|
35855
|
-
getArgSignatureContent() {
|
35856
|
-
if (this.type === "raw untyped ptr") {
|
35857
|
-
return "rawptr";
|
35858
|
-
}
|
35859
|
-
if (this.type === "raw untyped slice") {
|
35860
|
-
return "rawslice";
|
35861
|
-
}
|
35862
|
-
const strMatch = stringRegEx.exec(this.type)?.groups;
|
35863
|
-
if (strMatch) {
|
35864
|
-
return `str[${strMatch.length}]`;
|
35865
|
-
}
|
35866
|
-
if (this.components === null) {
|
35867
|
-
return this.type;
|
35868
|
-
}
|
35869
|
-
const arrayMatch = arrayRegEx.exec(this.type)?.groups;
|
35870
|
-
if (arrayMatch) {
|
35871
|
-
return `[${this.components[0].getSignature()};${arrayMatch.length}]`;
|
35872
|
-
}
|
35873
|
-
const typeArgumentsSignature = this.originalTypeArguments !== null ? `<${this.originalTypeArguments.map((a) => new ResolvedAbiType(this.abi, a).getSignature()).join(",")}>` : "";
|
35874
|
-
const componentsSignature = `(${this.components.map((c) => c.getSignature()).join(",")})`;
|
35875
|
-
return `${typeArgumentsSignature}${componentsSignature}`;
|
35876
|
-
}
|
35877
|
-
};
|
35878
|
-
function getCoders(components, options) {
|
35879
|
-
const { getCoder: getCoder3 } = options;
|
35880
|
-
return components.reduce((obj, component) => {
|
35881
|
-
const o = obj;
|
35882
|
-
o[component.name] = getCoder3(component, options);
|
35883
|
-
return o;
|
35884
|
-
}, {});
|
35885
|
-
}
|
35886
|
-
var getCoder = (resolvedAbiType, options) => {
|
35887
|
-
switch (resolvedAbiType.type) {
|
35888
|
-
case U8_CODER_TYPE:
|
35889
|
-
case U16_CODER_TYPE:
|
35890
|
-
case U32_CODER_TYPE:
|
35891
|
-
return new NumberCoder(resolvedAbiType.type, options);
|
35892
|
-
case U64_CODER_TYPE:
|
35893
|
-
case RAW_PTR_CODER_TYPE:
|
35894
|
-
return new BigNumberCoder("u64");
|
35895
|
-
case U256_CODER_TYPE:
|
35896
|
-
return new BigNumberCoder("u256");
|
35897
|
-
case RAW_SLICE_CODER_TYPE:
|
35898
|
-
return new RawSliceCoder();
|
35899
|
-
case BOOL_CODER_TYPE:
|
35900
|
-
return new BooleanCoder(options);
|
35901
|
-
case B256_CODER_TYPE:
|
35902
|
-
return new B256Coder();
|
35903
|
-
case B512_CODER_TYPE:
|
35904
|
-
return new B512Coder();
|
35905
|
-
case BYTES_CODER_TYPE:
|
35906
|
-
return new ByteCoder();
|
35907
|
-
case STD_STRING_CODER_TYPE:
|
35908
|
-
return new StdStringCoder();
|
35909
|
-
default:
|
35910
|
-
break;
|
35911
|
-
}
|
35912
|
-
const stringMatch = stringRegEx.exec(resolvedAbiType.type)?.groups;
|
35913
|
-
if (stringMatch) {
|
35914
|
-
const length = parseInt(stringMatch.length, 10);
|
35915
|
-
return new StringCoder(length);
|
35916
|
-
}
|
35917
|
-
const components = resolvedAbiType.components;
|
35918
|
-
const arrayMatch = arrayRegEx.exec(resolvedAbiType.type)?.groups;
|
35919
|
-
if (arrayMatch) {
|
35920
|
-
const length = parseInt(arrayMatch.length, 10);
|
35921
|
-
const arg = components[0];
|
35922
|
-
if (!arg) {
|
35923
|
-
throw new FuelError(
|
35924
|
-
ErrorCode.INVALID_COMPONENT,
|
35925
|
-
`The provided Array type is missing an item of 'component'.`
|
35926
|
-
);
|
35927
|
-
}
|
35928
|
-
const arrayElementCoder = getCoder(arg, { isSmallBytes: true });
|
35929
|
-
return new ArrayCoder(arrayElementCoder, length);
|
35930
|
-
}
|
35931
|
-
if (resolvedAbiType.type === VEC_CODER_TYPE) {
|
35932
|
-
const arg = findVectorBufferArgument(components);
|
35933
|
-
const argType = new ResolvedAbiType(resolvedAbiType.abi, arg);
|
35934
|
-
const itemCoder = getCoder(argType, { isSmallBytes: true, encoding: ENCODING_V0 });
|
35935
|
-
return new VecCoder(itemCoder);
|
35936
|
-
}
|
35937
|
-
const structMatch = structRegEx.exec(resolvedAbiType.type)?.groups;
|
35938
|
-
if (structMatch) {
|
35939
|
-
const coders = getCoders(components, { isRightPadded: true, getCoder });
|
35940
|
-
return new StructCoder(structMatch.name, coders);
|
35941
|
-
}
|
35942
|
-
const enumMatch = enumRegEx.exec(resolvedAbiType.type)?.groups;
|
35943
|
-
if (enumMatch) {
|
35944
|
-
const coders = getCoders(components, { getCoder });
|
35945
|
-
const isOptionEnum = resolvedAbiType.type === OPTION_CODER_TYPE;
|
35946
|
-
if (isOptionEnum) {
|
35947
|
-
return new OptionCoder(enumMatch.name, coders);
|
35948
|
-
}
|
35949
|
-
return new EnumCoder(enumMatch.name, coders);
|
35950
|
-
}
|
35951
|
-
const tupleMatch = tupleRegEx.exec(resolvedAbiType.type)?.groups;
|
35952
|
-
if (tupleMatch) {
|
35953
|
-
const coders = components.map(
|
35954
|
-
(component) => getCoder(component, { isRightPadded: true, encoding: ENCODING_V0 })
|
35955
|
-
);
|
35956
|
-
return new TupleCoder(coders);
|
35957
|
-
}
|
35958
|
-
if (resolvedAbiType.type === STR_SLICE_CODER_TYPE) {
|
35959
|
-
throw new FuelError(
|
35960
|
-
ErrorCode.INVALID_DATA,
|
35961
|
-
"String slices can not be decoded from logs. Convert the slice to `str[N]` with `__to_str_array`"
|
35962
|
-
);
|
35963
|
-
}
|
35964
|
-
throw new FuelError(
|
35965
|
-
ErrorCode.CODER_NOT_FOUND,
|
35966
|
-
`Coder not found: ${JSON.stringify(resolvedAbiType)}.`
|
35967
|
-
);
|
35968
|
-
};
|
35969
|
-
var BooleanCoder2 = class extends Coder {
|
35970
|
-
constructor() {
|
35971
|
-
super("boolean", "boolean", 1);
|
35972
|
-
}
|
35973
|
-
encode(value) {
|
35974
|
-
const isTrueBool = value === true || value === false;
|
35975
|
-
if (!isTrueBool) {
|
35976
|
-
throw new FuelError(ErrorCode.ENCODE_ERROR, `Invalid boolean value.`);
|
35977
|
-
}
|
35978
|
-
return toBytes2(value ? 1 : 0, this.encodedLength);
|
35979
|
-
}
|
35980
|
-
decode(data, offset) {
|
35981
|
-
if (data.length < this.encodedLength) {
|
35982
|
-
throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid boolean data size.`);
|
35983
|
-
}
|
35984
|
-
const bytes2 = bn(data.slice(offset, offset + this.encodedLength));
|
35985
|
-
if (bytes2.isZero()) {
|
35986
|
-
return [false, offset + this.encodedLength];
|
35987
|
-
}
|
35988
|
-
if (!bytes2.eq(bn(1))) {
|
35989
|
-
throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid boolean value.`);
|
35990
|
-
}
|
35991
|
-
return [true, offset + this.encodedLength];
|
35992
|
-
}
|
35993
|
-
};
|
35994
|
-
var ByteCoder2 = class extends Coder {
|
35995
|
-
constructor() {
|
35996
|
-
super("struct", "struct Bytes", WORD_SIZE);
|
35997
|
-
}
|
35998
|
-
encode(value) {
|
35999
|
-
const bytes2 = value instanceof Uint8Array ? value : new Uint8Array(value);
|
36000
|
-
const lengthBytes = new BigNumberCoder("u64").encode(bytes2.length);
|
36001
|
-
return new Uint8Array([...lengthBytes, ...bytes2]);
|
36002
|
-
}
|
36003
|
-
decode(data, offset) {
|
36004
|
-
if (data.length < WORD_SIZE) {
|
36005
|
-
throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid byte data size.`);
|
36006
|
-
}
|
36007
|
-
const offsetAndLength = offset + WORD_SIZE;
|
36008
|
-
const lengthBytes = data.slice(offset, offsetAndLength);
|
36009
|
-
const length = bn(new BigNumberCoder("u64").decode(lengthBytes, 0)[0]).toNumber();
|
36010
|
-
const dataBytes = data.slice(offsetAndLength, offsetAndLength + length);
|
36011
|
-
if (dataBytes.length !== length) {
|
36012
|
-
throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid bytes byte data size.`);
|
36013
|
-
}
|
36014
|
-
return [dataBytes, offsetAndLength + length];
|
36015
|
-
}
|
36016
|
-
};
|
36017
|
-
__publicField4(ByteCoder2, "memorySize", 1);
|
36018
|
-
var isFullyNativeEnum2 = (enumCoders) => Object.values(enumCoders).every(
|
36019
|
-
// @ts-expect-error complicated types
|
36020
|
-
({ type: type3, coders }) => type3 === "()" && JSON.stringify(coders) === JSON.stringify([])
|
36021
|
-
);
|
36022
|
-
var EnumCoder2 = class extends Coder {
|
36023
|
-
name;
|
36024
|
-
coders;
|
36025
|
-
#caseIndexCoder;
|
36026
|
-
#encodedValueSize;
|
36027
|
-
constructor(name, coders) {
|
36028
|
-
const caseIndexCoder = new BigNumberCoder("u64");
|
36029
|
-
const encodedValueSize = Object.values(coders).reduce(
|
36030
|
-
(max, coder) => Math.max(max, coder.encodedLength),
|
36031
|
-
0
|
36032
|
-
);
|
36033
|
-
super(`enum ${name}`, `enum ${name}`, caseIndexCoder.encodedLength + encodedValueSize);
|
36034
|
-
this.name = name;
|
36035
|
-
this.coders = coders;
|
36036
|
-
this.#caseIndexCoder = caseIndexCoder;
|
36037
|
-
this.#encodedValueSize = encodedValueSize;
|
36038
|
-
}
|
36039
|
-
#encodeNativeEnum(value) {
|
36040
|
-
const valueCoder = this.coders[value];
|
36041
|
-
const encodedValue = valueCoder.encode([]);
|
36042
|
-
const caseIndex = Object.keys(this.coders).indexOf(value);
|
36043
|
-
const padding = new Uint8Array(this.#encodedValueSize - valueCoder.encodedLength);
|
36044
|
-
return concat([this.#caseIndexCoder.encode(caseIndex), padding, encodedValue]);
|
36045
|
-
}
|
36046
|
-
encode(value) {
|
36047
|
-
if (typeof value === "string" && this.coders[value]) {
|
36048
|
-
return this.#encodeNativeEnum(value);
|
36049
|
-
}
|
36050
|
-
const [caseKey, ...empty] = Object.keys(value);
|
36051
|
-
if (!caseKey) {
|
36052
|
-
throw new FuelError(ErrorCode.INVALID_DECODE_VALUE, "A field for the case must be provided.");
|
36053
|
-
}
|
36054
|
-
if (empty.length !== 0) {
|
36055
|
-
throw new FuelError(ErrorCode.INVALID_DECODE_VALUE, "Only one field must be provided.");
|
36056
|
-
}
|
36057
|
-
const valueCoder = this.coders[caseKey];
|
36058
|
-
const caseIndex = Object.keys(this.coders).indexOf(caseKey);
|
36059
|
-
const encodedValue = valueCoder.encode(value[caseKey]);
|
36060
|
-
return new Uint8Array([...this.#caseIndexCoder.encode(caseIndex), ...encodedValue]);
|
36061
|
-
}
|
36062
|
-
#decodeNativeEnum(caseKey, newOffset) {
|
36063
|
-
return [caseKey, newOffset];
|
36064
|
-
}
|
36065
|
-
decode(data, offset) {
|
36066
|
-
if (data.length < this.#encodedValueSize) {
|
36067
|
-
throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid enum data size.`);
|
36068
|
-
}
|
36069
|
-
const caseBytes = new BigNumberCoder("u64").decode(data, offset)[0];
|
36070
|
-
const caseIndex = toNumber(caseBytes);
|
36071
|
-
const caseKey = Object.keys(this.coders)[caseIndex];
|
36072
|
-
if (!caseKey) {
|
36073
|
-
throw new FuelError(
|
36074
|
-
ErrorCode.INVALID_DECODE_VALUE,
|
36075
|
-
`Invalid caseIndex "${caseIndex}". Valid cases: ${Object.keys(this.coders)}.`
|
36076
|
-
);
|
36077
|
-
}
|
36078
|
-
const valueCoder = this.coders[caseKey];
|
36079
|
-
const offsetAndCase = offset + WORD_SIZE;
|
36080
|
-
const [decoded, newOffset] = valueCoder.decode(data, offsetAndCase);
|
36081
|
-
if (isFullyNativeEnum2(this.coders)) {
|
36082
|
-
return this.#decodeNativeEnum(caseKey, newOffset);
|
36083
|
-
}
|
36084
|
-
return [{ [caseKey]: decoded }, newOffset];
|
36085
|
-
}
|
36086
|
-
};
|
36087
|
-
var getLength = (baseType) => {
|
36088
|
-
switch (baseType) {
|
36089
|
-
case "u8":
|
36090
|
-
return 1;
|
36091
|
-
case "u16":
|
36092
|
-
return 2;
|
36093
|
-
case "u32":
|
36094
|
-
return 4;
|
36095
|
-
default:
|
36096
|
-
throw new FuelError(ErrorCode.TYPE_NOT_SUPPORTED, `Invalid number type: ${baseType}`);
|
36097
|
-
}
|
36098
|
-
};
|
36099
|
-
var NumberCoder2 = class extends Coder {
|
36100
|
-
length;
|
36101
|
-
baseType;
|
36102
|
-
constructor(baseType) {
|
36103
|
-
const length = getLength(baseType);
|
36104
|
-
super("number", baseType, length);
|
36105
|
-
this.baseType = baseType;
|
36106
|
-
this.length = length;
|
36107
|
-
}
|
36108
|
-
encode(value) {
|
36109
|
-
let bytes2;
|
36110
|
-
try {
|
36111
|
-
bytes2 = toBytes2(value);
|
36112
|
-
} catch (error) {
|
36113
|
-
throw new FuelError(ErrorCode.ENCODE_ERROR, `Invalid ${this.baseType}.`);
|
36114
|
-
}
|
36115
|
-
if (bytes2.length > this.length) {
|
36116
|
-
throw new FuelError(ErrorCode.ENCODE_ERROR, `Invalid ${this.baseType}, too many bytes.`);
|
36117
|
-
}
|
36118
|
-
return toBytes2(bytes2, this.length);
|
36119
|
-
}
|
36120
|
-
decode(data, offset) {
|
36121
|
-
if (data.length < this.encodedLength) {
|
36122
|
-
throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid number data size.`);
|
36123
|
-
}
|
36124
|
-
const bytes2 = data.slice(offset, offset + this.length);
|
36125
|
-
if (bytes2.length !== this.encodedLength) {
|
36126
|
-
throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid number byte data size.`);
|
36127
|
-
}
|
36128
|
-
return [toNumber(bytes2), offset + this.length];
|
36129
|
-
}
|
36130
|
-
};
|
36131
|
-
var OptionCoder2 = class extends EnumCoder2 {
|
36132
|
-
encode(value) {
|
36133
|
-
const result = super.encode(this.toSwayOption(value));
|
36134
|
-
return result;
|
36135
|
-
}
|
36136
|
-
toSwayOption(input) {
|
36137
|
-
if (input !== void 0) {
|
36138
|
-
return { Some: input };
|
36139
|
-
}
|
36140
|
-
return { None: [] };
|
36141
|
-
}
|
36142
|
-
decode(data, offset) {
|
36143
|
-
const [decoded, newOffset] = super.decode(data, offset);
|
36144
|
-
return [this.toOption(decoded), newOffset];
|
36145
|
-
}
|
36146
|
-
toOption(output2) {
|
36147
|
-
if (output2 && "Some" in output2) {
|
36148
|
-
return output2.Some;
|
36149
|
-
}
|
36150
|
-
return void 0;
|
36151
|
-
}
|
36152
|
-
};
|
36153
|
-
var RawSliceCoder2 = class extends Coder {
|
36154
|
-
constructor() {
|
36155
|
-
super("raw untyped slice", "raw untyped slice", WORD_SIZE);
|
36156
|
-
}
|
36157
|
-
encode(value) {
|
36158
|
-
if (!Array.isArray(value)) {
|
36159
|
-
throw new FuelError(ErrorCode.ENCODE_ERROR, `Expected array value.`);
|
36160
|
-
}
|
36161
|
-
const internalCoder = new ArrayCoder(new NumberCoder2("u8"), value.length);
|
36162
|
-
const bytes2 = internalCoder.encode(value);
|
36163
|
-
const lengthBytes = new BigNumberCoder("u64").encode(bytes2.length);
|
36164
|
-
return new Uint8Array([...lengthBytes, ...bytes2]);
|
36165
|
-
}
|
36166
|
-
decode(data, offset) {
|
36167
|
-
if (data.length < this.encodedLength) {
|
36168
|
-
throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid raw slice data size.`);
|
36169
|
-
}
|
36170
|
-
const offsetAndLength = offset + WORD_SIZE;
|
36171
|
-
const lengthBytes = data.slice(offset, offsetAndLength);
|
36172
|
-
const length = bn(new BigNumberCoder("u64").decode(lengthBytes, 0)[0]).toNumber();
|
36173
|
-
const dataBytes = data.slice(offsetAndLength, offsetAndLength + length);
|
36174
|
-
if (dataBytes.length !== length) {
|
36175
|
-
throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid raw slice byte data size.`);
|
36176
|
-
}
|
36177
|
-
const internalCoder = new ArrayCoder(new NumberCoder2("u8"), length);
|
36178
|
-
const [decodedValue] = internalCoder.decode(dataBytes, 0);
|
36179
|
-
return [decodedValue, offsetAndLength + length];
|
36180
|
-
}
|
36181
|
-
};
|
36182
|
-
var StdStringCoder2 = class extends Coder {
|
36183
|
-
constructor() {
|
36184
|
-
super("struct", "struct String", WORD_SIZE);
|
36185
|
-
}
|
36186
|
-
encode(value) {
|
36187
|
-
const bytes2 = toUtf8Bytes(value);
|
36188
|
-
const lengthBytes = new BigNumberCoder("u64").encode(value.length);
|
36189
|
-
return new Uint8Array([...lengthBytes, ...bytes2]);
|
36190
|
-
}
|
36191
|
-
decode(data, offset) {
|
36192
|
-
if (data.length < this.encodedLength) {
|
36193
|
-
throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid std string data size.`);
|
36194
|
-
}
|
36195
|
-
const offsetAndLength = offset + WORD_SIZE;
|
36196
|
-
const lengthBytes = data.slice(offset, offsetAndLength);
|
36197
|
-
const length = bn(new BigNumberCoder("u64").decode(lengthBytes, 0)[0]).toNumber();
|
36198
|
-
const dataBytes = data.slice(offsetAndLength, offsetAndLength + length);
|
36199
|
-
if (dataBytes.length !== length) {
|
36200
|
-
throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid std string byte data size.`);
|
36201
|
-
}
|
36202
|
-
return [toUtf8String(dataBytes), offsetAndLength + length];
|
36203
|
-
}
|
36204
|
-
};
|
36205
|
-
__publicField4(StdStringCoder2, "memorySize", 1);
|
36206
|
-
var StrSliceCoder = class extends Coder {
|
36207
|
-
constructor() {
|
36208
|
-
super("strSlice", "str", WORD_SIZE);
|
36209
|
-
}
|
36210
|
-
encode(value) {
|
36211
|
-
const bytes2 = toUtf8Bytes(value);
|
36212
|
-
const lengthBytes = new BigNumberCoder("u64").encode(value.length);
|
36213
|
-
return new Uint8Array([...lengthBytes, ...bytes2]);
|
36214
|
-
}
|
36215
|
-
decode(data, offset) {
|
36216
|
-
if (data.length < this.encodedLength) {
|
36217
|
-
throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid string slice data size.`);
|
36218
|
-
}
|
36219
|
-
const offsetAndLength = offset + WORD_SIZE;
|
36220
|
-
const lengthBytes = data.slice(offset, offsetAndLength);
|
36221
|
-
const length = bn(new BigNumberCoder("u64").decode(lengthBytes, 0)[0]).toNumber();
|
36222
|
-
const bytes2 = data.slice(offsetAndLength, offsetAndLength + length);
|
36223
|
-
if (bytes2.length !== length) {
|
36224
|
-
throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid string slice byte data size.`);
|
36225
|
-
}
|
36226
|
-
return [toUtf8String(bytes2), offsetAndLength + length];
|
36227
|
-
}
|
36228
|
-
};
|
36229
|
-
__publicField4(StrSliceCoder, "memorySize", 1);
|
36230
|
-
var StringCoder2 = class extends Coder {
|
36231
|
-
constructor(length) {
|
36232
|
-
super("string", `str[${length}]`, length);
|
36233
|
-
}
|
36234
|
-
encode(value) {
|
36235
|
-
if (value.length !== this.encodedLength) {
|
36236
|
-
throw new FuelError(ErrorCode.ENCODE_ERROR, `Value length mismatch during encode.`);
|
36237
|
-
}
|
36238
|
-
return toUtf8Bytes(value);
|
36239
|
-
}
|
36240
|
-
decode(data, offset) {
|
36241
|
-
if (data.length < this.encodedLength) {
|
36242
|
-
throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid string data size.`);
|
36243
|
-
}
|
36244
|
-
const bytes2 = data.slice(offset, offset + this.encodedLength);
|
36245
|
-
if (bytes2.length !== this.encodedLength) {
|
36246
|
-
throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid string byte data size.`);
|
36247
|
-
}
|
36248
|
-
return [toUtf8String(bytes2), offset + this.encodedLength];
|
36249
|
-
}
|
36250
|
-
};
|
36251
|
-
var StructCoder2 = class extends Coder {
|
36252
|
-
name;
|
36253
|
-
coders;
|
36254
|
-
constructor(name, coders) {
|
36255
|
-
const encodedLength = Object.values(coders).reduce(
|
36256
|
-
(acc, coder) => acc + coder.encodedLength,
|
36257
|
-
0
|
36258
|
-
);
|
36259
|
-
super("struct", `struct ${name}`, encodedLength);
|
36260
|
-
this.name = name;
|
36261
|
-
this.coders = coders;
|
36262
|
-
}
|
36263
|
-
encode(value) {
|
36264
|
-
return concatBytes2(
|
36265
|
-
Object.keys(this.coders).map((fieldName) => {
|
36266
|
-
const fieldCoder = this.coders[fieldName];
|
36267
|
-
const fieldValue = value[fieldName];
|
36268
|
-
if (!(fieldCoder instanceof OptionCoder2) && fieldValue == null) {
|
36269
|
-
throw new FuelError(
|
36270
|
-
ErrorCode.ENCODE_ERROR,
|
36271
|
-
`Invalid ${this.type}. Field "${fieldName}" not present.`
|
36272
|
-
);
|
36273
|
-
}
|
36274
|
-
return fieldCoder.encode(fieldValue);
|
36275
|
-
})
|
36276
|
-
);
|
36277
|
-
}
|
36278
|
-
decode(data, offset) {
|
36279
|
-
if (data.length < this.encodedLength) {
|
36280
|
-
throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid struct data size.`);
|
36281
|
-
}
|
36282
|
-
let newOffset = offset;
|
36283
|
-
const decodedValue = Object.keys(this.coders).reduce((obj, fieldName) => {
|
36284
|
-
const fieldCoder = this.coders[fieldName];
|
36285
|
-
let decoded;
|
36286
|
-
[decoded, newOffset] = fieldCoder.decode(data, newOffset);
|
36287
|
-
obj[fieldName] = decoded;
|
36288
|
-
return obj;
|
36289
|
-
}, {});
|
36290
|
-
return [decodedValue, newOffset];
|
36291
|
-
}
|
36292
|
-
};
|
36293
|
-
var TupleCoder2 = class extends Coder {
|
36294
|
-
coders;
|
36295
|
-
constructor(coders) {
|
36296
|
-
const encodedLength = coders.reduce((acc, coder) => acc + coder.encodedLength, 0);
|
36297
|
-
super("tuple", `(${coders.map((coder) => coder.type).join(", ")})`, encodedLength);
|
36298
|
-
this.coders = coders;
|
36299
|
-
}
|
36300
|
-
encode(value) {
|
36301
|
-
if (this.coders.length !== value.length) {
|
36302
|
-
throw new FuelError(ErrorCode.ENCODE_ERROR, `Types/values length mismatch.`);
|
36303
|
-
}
|
36304
|
-
return concatBytes2(this.coders.map((coder, i) => coder.encode(value[i])));
|
35502
|
+
const argType = findTypeById(abi, arg.type);
|
35503
|
+
const implicitTypeParameters = this.getImplicitGenericTypeParameters(abi, argType.components);
|
35504
|
+
if (implicitTypeParameters && implicitTypeParameters.length > 0) {
|
35505
|
+
return {
|
35506
|
+
...structuredClone(arg),
|
35507
|
+
typeArguments: implicitTypeParameters.map((itp) => typeParametersAndArgsMap[itp])
|
35508
|
+
};
|
35509
|
+
}
|
35510
|
+
return arg;
|
35511
|
+
});
|
36305
35512
|
}
|
36306
|
-
|
36307
|
-
if (
|
36308
|
-
|
35513
|
+
static getImplicitGenericTypeParameters(abi, args, implicitGenericParametersParam) {
|
35514
|
+
if (!Array.isArray(args)) {
|
35515
|
+
return null;
|
36309
35516
|
}
|
36310
|
-
|
36311
|
-
|
36312
|
-
|
36313
|
-
|
36314
|
-
|
35517
|
+
const implicitGenericParameters = implicitGenericParametersParam ?? [];
|
35518
|
+
args.forEach((a) => {
|
35519
|
+
const argType = findTypeById(abi, a.type);
|
35520
|
+
if (genericRegEx.test(argType.type)) {
|
35521
|
+
implicitGenericParameters.push(argType.typeId);
|
35522
|
+
return;
|
35523
|
+
}
|
35524
|
+
if (!Array.isArray(a.typeArguments)) {
|
35525
|
+
return;
|
35526
|
+
}
|
35527
|
+
this.getImplicitGenericTypeParameters(abi, a.typeArguments, implicitGenericParameters);
|
36315
35528
|
});
|
36316
|
-
return
|
35529
|
+
return implicitGenericParameters.length > 0 ? implicitGenericParameters : null;
|
36317
35530
|
}
|
36318
|
-
|
36319
|
-
|
36320
|
-
|
36321
|
-
|
36322
|
-
constructor(coder) {
|
36323
|
-
super("struct", `struct Vec`, coder.encodedLength + WORD_SIZE);
|
36324
|
-
this.coder = coder;
|
36325
|
-
this.#isOptionVec = this.coder instanceof OptionCoder2;
|
35531
|
+
getSignature() {
|
35532
|
+
const prefix = this.getArgSignaturePrefix();
|
35533
|
+
const content = this.getArgSignatureContent();
|
35534
|
+
return `${prefix}${content}`;
|
36326
35535
|
}
|
36327
|
-
|
36328
|
-
|
36329
|
-
|
36330
|
-
|
36331
|
-
`Expected array value, or a Uint8Array. You can use arrayify to convert a value to a Uint8Array.`
|
36332
|
-
);
|
35536
|
+
getArgSignaturePrefix() {
|
35537
|
+
const structMatch = structRegEx.test(this.type);
|
35538
|
+
if (structMatch) {
|
35539
|
+
return "s";
|
36333
35540
|
}
|
36334
|
-
const
|
36335
|
-
if (
|
36336
|
-
return
|
35541
|
+
const arrayMatch = arrayRegEx.test(this.type);
|
35542
|
+
if (arrayMatch) {
|
35543
|
+
return "a";
|
36337
35544
|
}
|
36338
|
-
const
|
36339
|
-
|
36340
|
-
|
35545
|
+
const enumMatch = enumRegEx.test(this.type);
|
35546
|
+
if (enumMatch) {
|
35547
|
+
return "e";
|
35548
|
+
}
|
35549
|
+
return "";
|
36341
35550
|
}
|
36342
|
-
|
36343
|
-
if (
|
36344
|
-
|
35551
|
+
getArgSignatureContent() {
|
35552
|
+
if (this.type === "raw untyped ptr") {
|
35553
|
+
return "rawptr";
|
36345
35554
|
}
|
36346
|
-
|
36347
|
-
|
36348
|
-
const length = bn(new BigNumberCoder("u64").decode(lengthBytes, 0)[0]).toNumber();
|
36349
|
-
const dataLength2 = length * this.coder.encodedLength;
|
36350
|
-
const dataBytes = data.slice(offsetAndLength, offsetAndLength + dataLength2);
|
36351
|
-
if (!this.#isOptionVec && dataBytes.length !== dataLength2) {
|
36352
|
-
throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid vec byte data size.`);
|
35555
|
+
if (this.type === "raw untyped slice") {
|
35556
|
+
return "rawslice";
|
36353
35557
|
}
|
36354
|
-
|
36355
|
-
|
36356
|
-
|
36357
|
-
const [decoded, optionOffset] = this.coder.decode(data, newOffset);
|
36358
|
-
chunks.push(decoded);
|
36359
|
-
newOffset = optionOffset;
|
35558
|
+
const strMatch = stringRegEx.exec(this.type)?.groups;
|
35559
|
+
if (strMatch) {
|
35560
|
+
return `str[${strMatch.length}]`;
|
36360
35561
|
}
|
36361
|
-
|
35562
|
+
if (this.components === null) {
|
35563
|
+
return this.type;
|
35564
|
+
}
|
35565
|
+
const arrayMatch = arrayRegEx.exec(this.type)?.groups;
|
35566
|
+
if (arrayMatch) {
|
35567
|
+
return `[${this.components[0].getSignature()};${arrayMatch.length}]`;
|
35568
|
+
}
|
35569
|
+
const typeArgumentsSignature = this.originalTypeArguments !== null ? `<${this.originalTypeArguments.map((a) => new ResolvedAbiType(this.abi, a).getSignature()).join(",")}>` : "";
|
35570
|
+
const componentsSignature = `(${this.components.map((c) => c.getSignature()).join(",")})`;
|
35571
|
+
return `${typeArgumentsSignature}${componentsSignature}`;
|
36362
35572
|
}
|
36363
35573
|
};
|
36364
|
-
|
35574
|
+
function getCoders(components, options) {
|
35575
|
+
const { getCoder: getCoder2 } = options;
|
35576
|
+
return components.reduce((obj, component) => {
|
35577
|
+
const o = obj;
|
35578
|
+
o[component.name] = getCoder2(component, options);
|
35579
|
+
return o;
|
35580
|
+
}, {});
|
35581
|
+
}
|
35582
|
+
var getCoder = (resolvedAbiType, _options) => {
|
36365
35583
|
switch (resolvedAbiType.type) {
|
36366
35584
|
case U8_CODER_TYPE:
|
36367
35585
|
case U16_CODER_TYPE:
|
36368
35586
|
case U32_CODER_TYPE:
|
36369
|
-
return new
|
35587
|
+
return new NumberCoder(resolvedAbiType.type);
|
36370
35588
|
case U64_CODER_TYPE:
|
36371
35589
|
case RAW_PTR_CODER_TYPE:
|
36372
35590
|
return new BigNumberCoder("u64");
|
36373
35591
|
case U256_CODER_TYPE:
|
36374
35592
|
return new BigNumberCoder("u256");
|
36375
35593
|
case RAW_SLICE_CODER_TYPE:
|
36376
|
-
return new
|
35594
|
+
return new RawSliceCoder();
|
36377
35595
|
case BOOL_CODER_TYPE:
|
36378
|
-
return new
|
35596
|
+
return new BooleanCoder();
|
36379
35597
|
case B256_CODER_TYPE:
|
36380
35598
|
return new B256Coder();
|
36381
35599
|
case B512_CODER_TYPE:
|
36382
35600
|
return new B512Coder();
|
36383
35601
|
case BYTES_CODER_TYPE:
|
36384
|
-
return new
|
35602
|
+
return new ByteCoder();
|
36385
35603
|
case STD_STRING_CODER_TYPE:
|
36386
|
-
return new
|
35604
|
+
return new StdStringCoder();
|
36387
35605
|
case STR_SLICE_CODER_TYPE:
|
36388
35606
|
return new StrSliceCoder();
|
36389
35607
|
default:
|
@@ -36392,7 +35610,7 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
36392
35610
|
const stringMatch = stringRegEx.exec(resolvedAbiType.type)?.groups;
|
36393
35611
|
if (stringMatch) {
|
36394
35612
|
const length = parseInt(stringMatch.length, 10);
|
36395
|
-
return new
|
35613
|
+
return new StringCoder(length);
|
36396
35614
|
}
|
36397
35615
|
const components = resolvedAbiType.components;
|
36398
35616
|
const arrayMatch = arrayRegEx.exec(resolvedAbiType.type)?.groups;
|
@@ -36405,46 +35623,42 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
36405
35623
|
`The provided Array type is missing an item of 'component'.`
|
36406
35624
|
);
|
36407
35625
|
}
|
36408
|
-
const arrayElementCoder =
|
35626
|
+
const arrayElementCoder = getCoder(arg);
|
36409
35627
|
return new ArrayCoder(arrayElementCoder, length);
|
36410
35628
|
}
|
36411
35629
|
if (resolvedAbiType.type === VEC_CODER_TYPE) {
|
36412
35630
|
const arg = findVectorBufferArgument(components);
|
36413
35631
|
const argType = new ResolvedAbiType(resolvedAbiType.abi, arg);
|
36414
|
-
const itemCoder =
|
36415
|
-
return new
|
35632
|
+
const itemCoder = getCoder(argType, { encoding: ENCODING_V1 });
|
35633
|
+
return new VecCoder(itemCoder);
|
36416
35634
|
}
|
36417
35635
|
const structMatch = structRegEx.exec(resolvedAbiType.type)?.groups;
|
36418
35636
|
if (structMatch) {
|
36419
|
-
const coders = getCoders(components, {
|
36420
|
-
return new
|
35637
|
+
const coders = getCoders(components, { getCoder });
|
35638
|
+
return new StructCoder(structMatch.name, coders);
|
36421
35639
|
}
|
36422
35640
|
const enumMatch = enumRegEx.exec(resolvedAbiType.type)?.groups;
|
36423
35641
|
if (enumMatch) {
|
36424
|
-
const coders = getCoders(components, { getCoder
|
35642
|
+
const coders = getCoders(components, { getCoder });
|
36425
35643
|
const isOptionEnum = resolvedAbiType.type === OPTION_CODER_TYPE;
|
36426
35644
|
if (isOptionEnum) {
|
36427
|
-
return new
|
35645
|
+
return new OptionCoder(enumMatch.name, coders);
|
36428
35646
|
}
|
36429
|
-
return new
|
35647
|
+
return new EnumCoder(enumMatch.name, coders);
|
36430
35648
|
}
|
36431
35649
|
const tupleMatch = tupleRegEx.exec(resolvedAbiType.type)?.groups;
|
36432
35650
|
if (tupleMatch) {
|
36433
|
-
const coders = components.map(
|
36434
|
-
|
36435
|
-
);
|
36436
|
-
return new TupleCoder2(coders);
|
35651
|
+
const coders = components.map((component) => getCoder(component, { encoding: ENCODING_V1 }));
|
35652
|
+
return new TupleCoder(coders);
|
36437
35653
|
}
|
36438
35654
|
throw new FuelError(
|
36439
35655
|
ErrorCode.CODER_NOT_FOUND,
|
36440
35656
|
`Coder not found: ${JSON.stringify(resolvedAbiType)}.`
|
36441
35657
|
);
|
36442
35658
|
};
|
36443
|
-
function getCoderForEncoding(encoding =
|
35659
|
+
function getCoderForEncoding(encoding = ENCODING_V1) {
|
36444
35660
|
switch (encoding) {
|
36445
35661
|
case ENCODING_V1:
|
36446
|
-
return getCoder2;
|
36447
|
-
case ENCODING_V0:
|
36448
35662
|
return getCoder;
|
36449
35663
|
default:
|
36450
35664
|
throw new FuelError(
|
@@ -36455,7 +35669,7 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
36455
35669
|
}
|
36456
35670
|
var AbiCoder = class {
|
36457
35671
|
static getCoder(abi, argument, options = {
|
36458
|
-
|
35672
|
+
padToWordSize: false
|
36459
35673
|
}) {
|
36460
35674
|
const resolvedAbiType = new ResolvedAbiType(abi, argument);
|
36461
35675
|
return getCoderForEncoding(options.encoding)(resolvedAbiType, options);
|
@@ -36475,8 +35689,6 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
36475
35689
|
name;
|
36476
35690
|
jsonFn;
|
36477
35691
|
attributes;
|
36478
|
-
isInputDataPointer;
|
36479
|
-
outputMetadata;
|
36480
35692
|
jsonAbi;
|
36481
35693
|
constructor(jsonAbi, name) {
|
36482
35694
|
this.jsonAbi = jsonAbi;
|
@@ -36484,13 +35696,8 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
36484
35696
|
this.name = name;
|
36485
35697
|
this.signature = FunctionFragment.getSignature(this.jsonAbi, this.jsonFn);
|
36486
35698
|
this.selector = FunctionFragment.getFunctionSelector(this.signature);
|
36487
|
-
this.selectorBytes = new
|
35699
|
+
this.selectorBytes = new StdStringCoder().encode(name);
|
36488
35700
|
this.encoding = getEncodingVersion(jsonAbi.encoding);
|
36489
|
-
this.isInputDataPointer = this.#isInputDataPointer();
|
36490
|
-
this.outputMetadata = {
|
36491
|
-
isHeapType: this.#isOutputDataHeap(),
|
36492
|
-
encodedLength: this.#getOutputEncodedLength()
|
36493
|
-
};
|
36494
35701
|
this.attributes = this.jsonFn.attributes ?? [];
|
36495
35702
|
}
|
36496
35703
|
static getSignature(abi, fn) {
|
@@ -36503,29 +35710,7 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
36503
35710
|
const hashedFunctionSignature = sha2562(bufferFromString2(functionSignature, "utf-8"));
|
36504
35711
|
return bn(hashedFunctionSignature.slice(0, 10)).toHex(8);
|
36505
35712
|
}
|
36506
|
-
|
36507
|
-
const inputTypes = this.jsonFn.inputs.map((i) => findTypeById(this.jsonAbi, i.type));
|
36508
|
-
return this.jsonFn.inputs.length > 1 || isPointerType(inputTypes[0]?.type || "");
|
36509
|
-
}
|
36510
|
-
#isOutputDataHeap() {
|
36511
|
-
const outputType = findTypeById(this.jsonAbi, this.jsonFn.output.type);
|
36512
|
-
return isHeapType(outputType?.type || "");
|
36513
|
-
}
|
36514
|
-
#getOutputEncodedLength() {
|
36515
|
-
try {
|
36516
|
-
const heapCoder = AbiCoder.getCoder(this.jsonAbi, this.jsonFn.output);
|
36517
|
-
if (heapCoder instanceof VecCoder) {
|
36518
|
-
return heapCoder.coder.encodedLength;
|
36519
|
-
}
|
36520
|
-
if (heapCoder instanceof ByteCoder) {
|
36521
|
-
return ByteCoder.memorySize;
|
36522
|
-
}
|
36523
|
-
return heapCoder.encodedLength;
|
36524
|
-
} catch (e) {
|
36525
|
-
return 0;
|
36526
|
-
}
|
36527
|
-
}
|
36528
|
-
encodeArguments(values, offset = 0) {
|
35713
|
+
encodeArguments(values) {
|
36529
35714
|
FunctionFragment.verifyArgsAndInputsAlign(values, this.jsonFn.inputs, this.jsonAbi);
|
36530
35715
|
const shallowCopyValues = values.slice();
|
36531
35716
|
const nonEmptyInputs = findNonEmptyInputs(this.jsonAbi, this.jsonFn.inputs);
|
@@ -36535,15 +35720,10 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
36535
35720
|
}
|
36536
35721
|
const coders = nonEmptyInputs.map(
|
36537
35722
|
(t) => AbiCoder.getCoder(this.jsonAbi, t, {
|
36538
|
-
isRightPadded: nonEmptyInputs.length > 1,
|
36539
35723
|
encoding: this.encoding
|
36540
35724
|
})
|
36541
35725
|
);
|
36542
|
-
|
36543
|
-
return new TupleCoder2(coders).encode(shallowCopyValues);
|
36544
|
-
}
|
36545
|
-
const results = new TupleCoder(coders).encode(shallowCopyValues);
|
36546
|
-
return unpackDynamicData(results, offset, results.byteLength);
|
35726
|
+
return new TupleCoder(coders).encode(shallowCopyValues);
|
36547
35727
|
}
|
36548
35728
|
static verifyArgsAndInputsAlign(args, inputs, abi) {
|
36549
35729
|
if (args.length === inputs.length) {
|
@@ -36652,9 +35832,9 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
36652
35832
|
const fragment = typeof functionFragment === "string" ? this.getFunction(functionFragment) : functionFragment;
|
36653
35833
|
return fragment.decodeArguments(data);
|
36654
35834
|
}
|
36655
|
-
encodeFunctionData(functionFragment, values
|
35835
|
+
encodeFunctionData(functionFragment, values) {
|
36656
35836
|
const fragment = typeof functionFragment === "string" ? this.getFunction(functionFragment) : functionFragment;
|
36657
|
-
return fragment.encodeArguments(values
|
35837
|
+
return fragment.encodeArguments(values);
|
36658
35838
|
}
|
36659
35839
|
// Decode the result of a function call
|
36660
35840
|
decodeFunctionResult(functionFragment, data) {
|
@@ -36682,9 +35862,7 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
36682
35862
|
);
|
36683
35863
|
}
|
36684
35864
|
return AbiCoder.encode(this.jsonAbi, configurable.configurableType, value, {
|
36685
|
-
|
36686
|
-
// TODO: Review support for configurables in v1 encoding when it becomes available
|
36687
|
-
encoding: ENCODING_V0
|
35865
|
+
encoding: this.encoding
|
36688
35866
|
});
|
36689
35867
|
}
|
36690
35868
|
getTypeById(typeId) {
|
@@ -36734,8 +35912,8 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
36734
35912
|
var TxPointerCoder = class extends StructCoder {
|
36735
35913
|
constructor() {
|
36736
35914
|
super("TxPointer", {
|
36737
|
-
blockHeight: new NumberCoder("u32"),
|
36738
|
-
txIndex: new NumberCoder("u16")
|
35915
|
+
blockHeight: new NumberCoder("u32", { padToWordSize: true }),
|
35916
|
+
txIndex: new NumberCoder("u16", { padToWordSize: true })
|
36739
35917
|
});
|
36740
35918
|
}
|
36741
35919
|
};
|
@@ -36752,12 +35930,12 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
36752
35930
|
encode(value) {
|
36753
35931
|
const parts = [];
|
36754
35932
|
parts.push(new B256Coder().encode(value.txID));
|
36755
|
-
parts.push(new NumberCoder("u16").encode(value.outputIndex));
|
35933
|
+
parts.push(new NumberCoder("u16", { padToWordSize: true }).encode(value.outputIndex));
|
36756
35934
|
parts.push(new B256Coder().encode(value.owner));
|
36757
35935
|
parts.push(new BigNumberCoder("u64").encode(value.amount));
|
36758
35936
|
parts.push(new B256Coder().encode(value.assetId));
|
36759
35937
|
parts.push(new TxPointerCoder().encode(value.txPointer));
|
36760
|
-
parts.push(new NumberCoder("u16").encode(value.witnessIndex));
|
35938
|
+
parts.push(new NumberCoder("u16", { padToWordSize: true }).encode(value.witnessIndex));
|
36761
35939
|
parts.push(new BigNumberCoder("u64").encode(value.predicateGasUsed));
|
36762
35940
|
parts.push(new BigNumberCoder("u64").encode(value.predicateLength));
|
36763
35941
|
parts.push(new BigNumberCoder("u64").encode(value.predicateDataLength));
|
@@ -36772,7 +35950,7 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
36772
35950
|
let o = offset;
|
36773
35951
|
[decoded, o] = new B256Coder().decode(data, o);
|
36774
35952
|
const txID = decoded;
|
36775
|
-
[decoded, o] = new NumberCoder("u16").decode(data, o);
|
35953
|
+
[decoded, o] = new NumberCoder("u16", { padToWordSize: true }).decode(data, o);
|
36776
35954
|
const outputIndex = decoded;
|
36777
35955
|
[decoded, o] = new B256Coder().decode(data, o);
|
36778
35956
|
const owner = decoded;
|
@@ -36782,7 +35960,7 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
36782
35960
|
const assetId = decoded;
|
36783
35961
|
[decoded, o] = new TxPointerCoder().decode(data, o);
|
36784
35962
|
const txPointer = decoded;
|
36785
|
-
[decoded, o] = new NumberCoder("u16").decode(data, o);
|
35963
|
+
[decoded, o] = new NumberCoder("u16", { padToWordSize: true }).decode(data, o);
|
36786
35964
|
const witnessIndex = Number(decoded);
|
36787
35965
|
[decoded, o] = new BigNumberCoder("u64").decode(data, o);
|
36788
35966
|
const predicateGasUsed = decoded;
|
@@ -36821,7 +35999,7 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
36821
35999
|
encode(value) {
|
36822
36000
|
const parts = [];
|
36823
36001
|
parts.push(new B256Coder().encode(value.txID));
|
36824
|
-
parts.push(new NumberCoder("u16").encode(value.outputIndex));
|
36002
|
+
parts.push(new NumberCoder("u16", { padToWordSize: true }).encode(value.outputIndex));
|
36825
36003
|
parts.push(new B256Coder().encode(value.balanceRoot));
|
36826
36004
|
parts.push(new B256Coder().encode(value.stateRoot));
|
36827
36005
|
parts.push(new TxPointerCoder().encode(value.txPointer));
|
@@ -36833,7 +36011,7 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
36833
36011
|
let o = offset;
|
36834
36012
|
[decoded, o] = new B256Coder().decode(data, o);
|
36835
36013
|
const txID = decoded;
|
36836
|
-
[decoded, o] = new NumberCoder("u16").decode(data, o);
|
36014
|
+
[decoded, o] = new NumberCoder("u16", { padToWordSize: true }).decode(data, o);
|
36837
36015
|
const outputIndex = decoded;
|
36838
36016
|
[decoded, o] = new B256Coder().decode(data, o);
|
36839
36017
|
const balanceRoot = decoded;
|
@@ -36882,7 +36060,7 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
36882
36060
|
parts.push(new ByteArrayCoder(32).encode(value.recipient));
|
36883
36061
|
parts.push(new BigNumberCoder("u64").encode(value.amount));
|
36884
36062
|
parts.push(new ByteArrayCoder(32).encode(value.nonce));
|
36885
|
-
parts.push(new NumberCoder("u16").encode(value.witnessIndex));
|
36063
|
+
parts.push(new NumberCoder("u16", { padToWordSize: true }).encode(value.witnessIndex));
|
36886
36064
|
parts.push(new BigNumberCoder("u64").encode(value.predicateGasUsed));
|
36887
36065
|
parts.push(new BigNumberCoder("u64").encode(data.length));
|
36888
36066
|
parts.push(new BigNumberCoder("u64").encode(value.predicateLength));
|
@@ -36911,11 +36089,11 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
36911
36089
|
const amount = decoded;
|
36912
36090
|
[decoded, o] = new B256Coder().decode(data, o);
|
36913
36091
|
const nonce = decoded;
|
36914
|
-
[decoded, o] = new NumberCoder("u16").decode(data, o);
|
36092
|
+
[decoded, o] = new NumberCoder("u16", { padToWordSize: true }).decode(data, o);
|
36915
36093
|
const witnessIndex = Number(decoded);
|
36916
36094
|
[decoded, o] = new BigNumberCoder("u64").decode(data, o);
|
36917
36095
|
const predicateGasUsed = decoded;
|
36918
|
-
[decoded, o] = new NumberCoder("u32").decode(data, o);
|
36096
|
+
[decoded, o] = new NumberCoder("u32", { padToWordSize: true }).decode(data, o);
|
36919
36097
|
const dataLength2 = decoded;
|
36920
36098
|
[decoded, o] = new BigNumberCoder("u64").decode(data, o);
|
36921
36099
|
const predicateLength = decoded;
|
@@ -36953,7 +36131,7 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
36953
36131
|
}
|
36954
36132
|
encode(value) {
|
36955
36133
|
const parts = [];
|
36956
|
-
parts.push(new NumberCoder("u8").encode(value.type));
|
36134
|
+
parts.push(new NumberCoder("u8", { padToWordSize: true }).encode(value.type));
|
36957
36135
|
const { type: type3 } = value;
|
36958
36136
|
switch (type3) {
|
36959
36137
|
case 0: {
|
@@ -36980,7 +36158,7 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
36980
36158
|
decode(data, offset) {
|
36981
36159
|
let decoded;
|
36982
36160
|
let o = offset;
|
36983
|
-
[decoded, o] = new NumberCoder("u8").decode(data, o);
|
36161
|
+
[decoded, o] = new NumberCoder("u8", { padToWordSize: true }).decode(data, o);
|
36984
36162
|
const type3 = decoded;
|
36985
36163
|
switch (type3) {
|
36986
36164
|
case 0: {
|
@@ -37049,7 +36227,7 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
37049
36227
|
}
|
37050
36228
|
encode(value) {
|
37051
36229
|
const parts = [];
|
37052
|
-
parts.push(new NumberCoder("u8").encode(value.inputIndex));
|
36230
|
+
parts.push(new NumberCoder("u8", { padToWordSize: true }).encode(value.inputIndex));
|
37053
36231
|
parts.push(new B256Coder().encode(value.balanceRoot));
|
37054
36232
|
parts.push(new B256Coder().encode(value.stateRoot));
|
37055
36233
|
return concat(parts);
|
@@ -37057,7 +36235,7 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
37057
36235
|
decode(data, offset) {
|
37058
36236
|
let decoded;
|
37059
36237
|
let o = offset;
|
37060
|
-
[decoded, o] = new NumberCoder("u8").decode(data, o);
|
36238
|
+
[decoded, o] = new NumberCoder("u8", { padToWordSize: true }).decode(data, o);
|
37061
36239
|
const inputIndex = decoded;
|
37062
36240
|
[decoded, o] = new B256Coder().decode(data, o);
|
37063
36241
|
const balanceRoot = decoded;
|
@@ -37169,7 +36347,7 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
37169
36347
|
}
|
37170
36348
|
encode(value) {
|
37171
36349
|
const parts = [];
|
37172
|
-
parts.push(new NumberCoder("u8").encode(value.type));
|
36350
|
+
parts.push(new NumberCoder("u8", { padToWordSize: true }).encode(value.type));
|
37173
36351
|
const { type: type3 } = value;
|
37174
36352
|
switch (type3) {
|
37175
36353
|
case 0: {
|
@@ -37204,7 +36382,7 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
37204
36382
|
decode(data, offset) {
|
37205
36383
|
let decoded;
|
37206
36384
|
let o = offset;
|
37207
|
-
[decoded, o] = new NumberCoder("u8").decode(data, o);
|
36385
|
+
[decoded, o] = new NumberCoder("u8", { padToWordSize: true }).decode(data, o);
|
37208
36386
|
const type3 = decoded;
|
37209
36387
|
switch (type3) {
|
37210
36388
|
case 0: {
|
@@ -37272,7 +36450,7 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
37272
36450
|
parts.push(new BigNumberCoder("u64").encode(data));
|
37273
36451
|
break;
|
37274
36452
|
case 4:
|
37275
|
-
parts.push(new NumberCoder("u32").encode(data));
|
36453
|
+
parts.push(new NumberCoder("u32", { padToWordSize: true }).encode(data));
|
37276
36454
|
break;
|
37277
36455
|
default: {
|
37278
36456
|
throw new FuelError(ErrorCode.INVALID_POLICY_TYPE, `Invalid policy type: ${type3}`);
|
@@ -37295,7 +36473,10 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
37295
36473
|
policies.push({ type: 2, data: witnessLimit });
|
37296
36474
|
}
|
37297
36475
|
if (policyTypes & 4) {
|
37298
|
-
const [maturity, nextOffset] = new NumberCoder("u32").decode(
|
36476
|
+
const [maturity, nextOffset] = new NumberCoder("u32", { padToWordSize: true }).decode(
|
36477
|
+
data,
|
36478
|
+
o
|
36479
|
+
);
|
37299
36480
|
o = nextOffset;
|
37300
36481
|
policies.push({ type: 4, data: maturity });
|
37301
36482
|
}
|
@@ -37342,7 +36523,7 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
37342
36523
|
parts.push(new B256Coder().encode(value.recipient));
|
37343
36524
|
parts.push(new BigNumberCoder("u64").encode(value.amount));
|
37344
36525
|
parts.push(new B256Coder().encode(value.nonce));
|
37345
|
-
parts.push(new NumberCoder("u16").encode(value.data.length));
|
36526
|
+
parts.push(new NumberCoder("u16", { padToWordSize: true }).encode(value.data.length));
|
37346
36527
|
parts.push(new B256Coder().encode(value.digest));
|
37347
36528
|
parts.push(new ByteArrayCoder(value.data.length).encode(value.data));
|
37348
36529
|
return concat(parts);
|
@@ -37358,7 +36539,7 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
37358
36539
|
const amount = decoded;
|
37359
36540
|
[decoded, o] = new B256Coder().decode(data, o);
|
37360
36541
|
const nonce = decoded;
|
37361
|
-
[decoded, o] = new NumberCoder("u16").decode(data, o);
|
36542
|
+
[decoded, o] = new NumberCoder("u16", { padToWordSize: true }).decode(data, o);
|
37362
36543
|
const len = decoded;
|
37363
36544
|
[decoded, o] = new B256Coder().decode(data, o);
|
37364
36545
|
const digest = decoded;
|
@@ -37482,11 +36663,11 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
37482
36663
|
encode(upgradePurposeType) {
|
37483
36664
|
const parts = [];
|
37484
36665
|
const { type: type3 } = upgradePurposeType;
|
37485
|
-
parts.push(new NumberCoder("u8").encode(type3));
|
36666
|
+
parts.push(new NumberCoder("u8", { padToWordSize: true }).encode(type3));
|
37486
36667
|
switch (type3) {
|
37487
36668
|
case 0: {
|
37488
36669
|
const data = upgradePurposeType.data;
|
37489
|
-
parts.push(new NumberCoder("u16").encode(data.witnessIndex));
|
36670
|
+
parts.push(new NumberCoder("u16", { padToWordSize: true }).encode(data.witnessIndex));
|
37490
36671
|
parts.push(new B256Coder().encode(data.checksum));
|
37491
36672
|
break;
|
37492
36673
|
}
|
@@ -37507,11 +36688,11 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
37507
36688
|
decode(data, offset) {
|
37508
36689
|
let o = offset;
|
37509
36690
|
let decoded;
|
37510
|
-
[decoded, o] = new NumberCoder("u8").decode(data, o);
|
36691
|
+
[decoded, o] = new NumberCoder("u8", { padToWordSize: true }).decode(data, o);
|
37511
36692
|
const type3 = decoded;
|
37512
36693
|
switch (type3) {
|
37513
36694
|
case 0: {
|
37514
|
-
[decoded, o] = new NumberCoder("u16").decode(data, o);
|
36695
|
+
[decoded, o] = new NumberCoder("u16", { padToWordSize: true }).decode(data, o);
|
37515
36696
|
const witnessIndex = decoded;
|
37516
36697
|
[decoded, o] = new B256Coder().decode(data, o);
|
37517
36698
|
const checksum = decoded;
|
@@ -37542,14 +36723,14 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
37542
36723
|
}
|
37543
36724
|
encode(value) {
|
37544
36725
|
const parts = [];
|
37545
|
-
parts.push(new NumberCoder("u32").encode(value.dataLength));
|
36726
|
+
parts.push(new NumberCoder("u32", { padToWordSize: true }).encode(value.dataLength));
|
37546
36727
|
parts.push(new ByteArrayCoder(value.dataLength).encode(value.data));
|
37547
36728
|
return concat(parts);
|
37548
36729
|
}
|
37549
36730
|
decode(data, offset) {
|
37550
36731
|
let decoded;
|
37551
36732
|
let o = offset;
|
37552
|
-
[decoded, o] = new NumberCoder("u32").decode(data, o);
|
36733
|
+
[decoded, o] = new NumberCoder("u32", { padToWordSize: true }).decode(data, o);
|
37553
36734
|
const dataLength2 = decoded;
|
37554
36735
|
[decoded, o] = new ByteArrayCoder(dataLength2).decode(data, o);
|
37555
36736
|
const witnessData = decoded;
|
@@ -37580,10 +36761,10 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
37580
36761
|
parts.push(new B256Coder().encode(value.receiptsRoot));
|
37581
36762
|
parts.push(new BigNumberCoder("u64").encode(value.scriptLength));
|
37582
36763
|
parts.push(new BigNumberCoder("u64").encode(value.scriptDataLength));
|
37583
|
-
parts.push(new NumberCoder("u32").encode(value.policyTypes));
|
37584
|
-
parts.push(new NumberCoder("u16").encode(value.inputsCount));
|
37585
|
-
parts.push(new NumberCoder("u16").encode(value.outputsCount));
|
37586
|
-
parts.push(new NumberCoder("u16").encode(value.witnessesCount));
|
36764
|
+
parts.push(new NumberCoder("u32", { padToWordSize: true }).encode(value.policyTypes));
|
36765
|
+
parts.push(new NumberCoder("u16", { padToWordSize: true }).encode(value.inputsCount));
|
36766
|
+
parts.push(new NumberCoder("u16", { padToWordSize: true }).encode(value.outputsCount));
|
36767
|
+
parts.push(new NumberCoder("u16", { padToWordSize: true }).encode(value.witnessesCount));
|
37587
36768
|
parts.push(new ByteArrayCoder(value.scriptLength.toNumber()).encode(value.script));
|
37588
36769
|
parts.push(new ByteArrayCoder(value.scriptDataLength.toNumber()).encode(value.scriptData));
|
37589
36770
|
parts.push(new PoliciesCoder().encode(value.policies));
|
@@ -37603,13 +36784,13 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
37603
36784
|
const scriptLength = decoded;
|
37604
36785
|
[decoded, o] = new BigNumberCoder("u64").decode(data, o);
|
37605
36786
|
const scriptDataLength = decoded;
|
37606
|
-
[decoded, o] = new NumberCoder("u32").decode(data, o);
|
36787
|
+
[decoded, o] = new NumberCoder("u32", { padToWordSize: true }).decode(data, o);
|
37607
36788
|
const policyTypes = decoded;
|
37608
|
-
[decoded, o] = new NumberCoder("u16").decode(data, o);
|
36789
|
+
[decoded, o] = new NumberCoder("u16", { padToWordSize: true }).decode(data, o);
|
37609
36790
|
const inputsCount = decoded;
|
37610
|
-
[decoded, o] = new NumberCoder("u16").decode(data, o);
|
36791
|
+
[decoded, o] = new NumberCoder("u16", { padToWordSize: true }).decode(data, o);
|
37611
36792
|
const outputsCount = decoded;
|
37612
|
-
[decoded, o] = new NumberCoder("u16").decode(data, o);
|
36793
|
+
[decoded, o] = new NumberCoder("u16", { padToWordSize: true }).decode(data, o);
|
37613
36794
|
const witnessesCount = decoded;
|
37614
36795
|
[decoded, o] = new ByteArrayCoder(scriptLength.toNumber()).decode(data, o);
|
37615
36796
|
const script = decoded;
|
@@ -37651,13 +36832,13 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
37651
36832
|
}
|
37652
36833
|
encode(value) {
|
37653
36834
|
const parts = [];
|
37654
|
-
parts.push(new NumberCoder("u16").encode(value.bytecodeWitnessIndex));
|
36835
|
+
parts.push(new NumberCoder("u16", { padToWordSize: true }).encode(value.bytecodeWitnessIndex));
|
37655
36836
|
parts.push(new B256Coder().encode(value.salt));
|
37656
36837
|
parts.push(new BigNumberCoder("u64").encode(value.storageSlotsCount));
|
37657
|
-
parts.push(new NumberCoder("u32").encode(value.policyTypes));
|
37658
|
-
parts.push(new NumberCoder("u16").encode(value.inputsCount));
|
37659
|
-
parts.push(new NumberCoder("u16").encode(value.outputsCount));
|
37660
|
-
parts.push(new NumberCoder("u16").encode(value.witnessesCount));
|
36838
|
+
parts.push(new NumberCoder("u32", { padToWordSize: true }).encode(value.policyTypes));
|
36839
|
+
parts.push(new NumberCoder("u16", { padToWordSize: true }).encode(value.inputsCount));
|
36840
|
+
parts.push(new NumberCoder("u16", { padToWordSize: true }).encode(value.outputsCount));
|
36841
|
+
parts.push(new NumberCoder("u16", { padToWordSize: true }).encode(value.witnessesCount));
|
37661
36842
|
parts.push(
|
37662
36843
|
new ArrayCoder(new StorageSlotCoder(), value.storageSlotsCount.toNumber()).encode(
|
37663
36844
|
value.storageSlots
|
@@ -37672,19 +36853,19 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
37672
36853
|
decode(data, offset) {
|
37673
36854
|
let decoded;
|
37674
36855
|
let o = offset;
|
37675
|
-
[decoded, o] = new NumberCoder("u16").decode(data, o);
|
36856
|
+
[decoded, o] = new NumberCoder("u16", { padToWordSize: true }).decode(data, o);
|
37676
36857
|
const bytecodeWitnessIndex = decoded;
|
37677
36858
|
[decoded, o] = new B256Coder().decode(data, o);
|
37678
36859
|
const salt = decoded;
|
37679
36860
|
[decoded, o] = new BigNumberCoder("u64").decode(data, o);
|
37680
36861
|
const storageSlotsCount = decoded;
|
37681
|
-
[decoded, o] = new NumberCoder("u32").decode(data, o);
|
36862
|
+
[decoded, o] = new NumberCoder("u32", { padToWordSize: true }).decode(data, o);
|
37682
36863
|
const policyTypes = decoded;
|
37683
|
-
[decoded, o] = new NumberCoder("u16").decode(data, o);
|
36864
|
+
[decoded, o] = new NumberCoder("u16", { padToWordSize: true }).decode(data, o);
|
37684
36865
|
const inputsCount = decoded;
|
37685
|
-
[decoded, o] = new NumberCoder("u16").decode(data, o);
|
36866
|
+
[decoded, o] = new NumberCoder("u16", { padToWordSize: true }).decode(data, o);
|
37686
36867
|
const outputsCount = decoded;
|
37687
|
-
[decoded, o] = new NumberCoder("u16").decode(data, o);
|
36868
|
+
[decoded, o] = new NumberCoder("u16", { padToWordSize: true }).decode(data, o);
|
37688
36869
|
const witnessesCount = decoded;
|
37689
36870
|
[decoded, o] = new ArrayCoder(new StorageSlotCoder(), storageSlotsCount.toNumber()).decode(
|
37690
36871
|
data,
|
@@ -37898,7 +37079,7 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
37898
37079
|
}
|
37899
37080
|
encode(value) {
|
37900
37081
|
const parts = [];
|
37901
|
-
parts.push(new NumberCoder("u8").encode(value.type));
|
37082
|
+
parts.push(new NumberCoder("u8", { padToWordSize: true }).encode(value.type));
|
37902
37083
|
const { type: type3 } = value;
|
37903
37084
|
switch (value.type) {
|
37904
37085
|
case 0: {
|
@@ -37941,7 +37122,7 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
37941
37122
|
decode(data, offset) {
|
37942
37123
|
let decoded;
|
37943
37124
|
let o = offset;
|
37944
|
-
[decoded, o] = new NumberCoder("u8").decode(data, o);
|
37125
|
+
[decoded, o] = new NumberCoder("u8", { padToWordSize: true }).decode(data, o);
|
37945
37126
|
const type3 = decoded;
|
37946
37127
|
switch (type3) {
|
37947
37128
|
case 0: {
|
@@ -42954,6 +42135,15 @@ ${MessageCoinFragmentDoc}`;
|
|
42954
42135
|
return normalize2(clone_default(root));
|
42955
42136
|
}
|
42956
42137
|
|
42138
|
+
// src/providers/utils/sleep.ts
|
42139
|
+
function sleep(time) {
|
42140
|
+
return new Promise((resolve) => {
|
42141
|
+
setTimeout(() => {
|
42142
|
+
resolve(true);
|
42143
|
+
}, time);
|
42144
|
+
});
|
42145
|
+
}
|
42146
|
+
|
42957
42147
|
// src/providers/utils/extract-tx-error.ts
|
42958
42148
|
var assemblePanicError = (status) => {
|
42959
42149
|
let errorMessage = `The transaction reverted with reason: "${status.reason}".`;
|
@@ -43567,15 +42757,6 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
|
|
43567
42757
|
}
|
43568
42758
|
});
|
43569
42759
|
}
|
43570
|
-
shiftPredicateData() {
|
43571
|
-
this.inputs.forEach((input) => {
|
43572
|
-
if ("predicateData" in input && "padPredicateData" in input && typeof input.padPredicateData === "function") {
|
43573
|
-
input.predicateData = input.padPredicateData(
|
43574
|
-
BaseTransactionRequest.getPolicyMeta(this).policies.length
|
43575
|
-
);
|
43576
|
-
}
|
43577
|
-
});
|
43578
|
-
}
|
43579
42760
|
};
|
43580
42761
|
|
43581
42762
|
// src/providers/transaction-request/hash-transaction.ts
|
@@ -44040,37 +43221,27 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
|
|
44040
43221
|
};
|
44041
43222
|
|
44042
43223
|
// src/providers/transaction-summary/call.ts
|
44043
|
-
var getFunctionCall = ({ abi, receipt
|
43224
|
+
var getFunctionCall = ({ abi, receipt }) => {
|
44044
43225
|
const abiInterface = new Interface(abi);
|
44045
43226
|
const callFunctionSelector = receipt.param1.toHex(8);
|
44046
43227
|
const functionFragment = abiInterface.getFunction(callFunctionSelector);
|
44047
43228
|
const inputs = functionFragment.jsonFn.inputs;
|
44048
|
-
|
44049
|
-
if (functionFragment.isInputDataPointer) {
|
44050
|
-
if (rawPayload) {
|
44051
|
-
const argsOffset = bn(receipt.param2).sub(calculateVmTxMemory({ maxInputs: maxInputs.toNumber() })).toNumber();
|
44052
|
-
encodedArgs = `0x${rawPayload.slice(2).slice(argsOffset * 2)}`;
|
44053
|
-
}
|
44054
|
-
} else {
|
44055
|
-
encodedArgs = receipt.param2.toHex();
|
44056
|
-
}
|
43229
|
+
const encodedArgs = receipt.param2.toHex();
|
44057
43230
|
let argumentsProvided;
|
44058
|
-
|
44059
|
-
|
44060
|
-
|
44061
|
-
|
44062
|
-
|
44063
|
-
|
44064
|
-
|
44065
|
-
|
44066
|
-
|
44067
|
-
|
44068
|
-
|
44069
|
-
|
44070
|
-
|
44071
|
-
|
44072
|
-
}, {});
|
44073
|
-
}
|
43231
|
+
const data = functionFragment.decodeArguments(encodedArgs);
|
43232
|
+
if (data) {
|
43233
|
+
argumentsProvided = inputs.reduce((prev, input, index) => {
|
43234
|
+
const value = data[index];
|
43235
|
+
const name = input.name;
|
43236
|
+
if (name) {
|
43237
|
+
return {
|
43238
|
+
...prev,
|
43239
|
+
// reparse to remove bn
|
43240
|
+
[name]: JSON.parse(JSON.stringify(value))
|
43241
|
+
};
|
43242
|
+
}
|
43243
|
+
return prev;
|
43244
|
+
}, {});
|
44074
43245
|
}
|
44075
43246
|
const call = {
|
44076
43247
|
functionSignature: functionFragment.signature,
|
@@ -46347,7 +45518,6 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
46347
45518
|
cacheRequestInputsResourcesFromOwner(request.inputs, this.address)
|
46348
45519
|
);
|
46349
45520
|
request.addResources(resources);
|
46350
|
-
request.shiftPredicateData();
|
46351
45521
|
request.updatePredicateGasUsed(estimatedPredicates);
|
46352
45522
|
const requestToReestimate2 = clone_default(request);
|
46353
45523
|
if (addedSignatures) {
|
@@ -46379,7 +45549,6 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
46379
45549
|
}
|
46380
45550
|
fundingAttempts += 1;
|
46381
45551
|
}
|
46382
|
-
request.shiftPredicateData();
|
46383
45552
|
request.updatePredicateGasUsed(estimatedPredicates);
|
46384
45553
|
const requestToReestimate = clone_default(request);
|
46385
45554
|
if (addedSignatures) {
|
@@ -51015,40 +50184,6 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
51015
50184
|
}
|
51016
50185
|
}
|
51017
50186
|
};
|
51018
|
-
function getFinalStateConfigJSON({ stateConfig, chainConfig }) {
|
51019
|
-
const defaultCoins = defaultSnapshotConfigs.stateConfig.coins.map((coin) => ({
|
51020
|
-
...coin,
|
51021
|
-
amount: "18446744073709551615"
|
51022
|
-
}));
|
51023
|
-
const defaultMessages = defaultSnapshotConfigs.stateConfig.messages.map((message) => ({
|
51024
|
-
...message,
|
51025
|
-
amount: "18446744073709551615"
|
51026
|
-
}));
|
51027
|
-
const coins = defaultCoins.concat(stateConfig.coins.map((coin) => ({ ...coin, amount: coin.amount.toString() }))).filter((coin, index, self2) => self2.findIndex((c) => c.tx_id === coin.tx_id) === index);
|
51028
|
-
const messages = defaultMessages.concat(stateConfig.messages.map((msg) => ({ ...msg, amount: msg.amount.toString() }))).filter((msg, index, self2) => self2.findIndex((m) => m.nonce === msg.nonce) === index);
|
51029
|
-
if (!process.env.GENESIS_SECRET) {
|
51030
|
-
const pk = Signer.generatePrivateKey();
|
51031
|
-
const signer = new Signer(pk);
|
51032
|
-
process.env.GENESIS_SECRET = hexlify(pk);
|
51033
|
-
coins.push({
|
51034
|
-
tx_id: hexlify(randomBytes22(UTXO_ID_LEN)),
|
51035
|
-
owner: signer.address.toHexString(),
|
51036
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
51037
|
-
amount: "18446744073709551615",
|
51038
|
-
asset_id: chainConfig.consensus_parameters.V1.base_asset_id,
|
51039
|
-
output_index: 0,
|
51040
|
-
tx_pointer_block_height: 0,
|
51041
|
-
tx_pointer_tx_idx: 0
|
51042
|
-
});
|
51043
|
-
}
|
51044
|
-
const json = JSON.stringify({
|
51045
|
-
...stateConfig,
|
51046
|
-
coins,
|
51047
|
-
messages
|
51048
|
-
});
|
51049
|
-
const regexMakeNumber = /("amount":)"(\d+)"/gm;
|
51050
|
-
return json.replace(regexMakeNumber, "$1$2");
|
51051
|
-
}
|
51052
50187
|
var launchNode = async ({
|
51053
50188
|
ip,
|
51054
50189
|
port,
|
@@ -51056,8 +50191,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
51056
50191
|
useSystemFuelCore = false,
|
51057
50192
|
loggingEnabled = true,
|
51058
50193
|
debugEnabled = false,
|
51059
|
-
basePath
|
51060
|
-
snapshotConfig = defaultSnapshotConfigs
|
50194
|
+
basePath
|
51061
50195
|
}) => (
|
51062
50196
|
// eslint-disable-next-line no-async-promise-executor
|
51063
50197
|
new Promise(async (resolve, reject) => {
|
@@ -51086,23 +50220,56 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
51086
50220
|
let snapshotDirToUse;
|
51087
50221
|
const prefix = basePath || import_os.default.tmpdir();
|
51088
50222
|
const suffix = basePath ? "" : (0, import_crypto19.randomUUID)();
|
51089
|
-
const
|
50223
|
+
const tempDirPath = import_path8.default.join(prefix, ".fuels", suffix, "snapshotDir");
|
51090
50224
|
if (snapshotDir) {
|
51091
50225
|
snapshotDirToUse = snapshotDir;
|
51092
50226
|
} else {
|
51093
|
-
if (!(0, import_fs2.existsSync)(
|
51094
|
-
(0, import_fs2.mkdirSync)(
|
51095
|
-
}
|
51096
|
-
|
51097
|
-
const
|
51098
|
-
|
51099
|
-
|
51100
|
-
|
51101
|
-
|
51102
|
-
|
51103
|
-
|
51104
|
-
|
51105
|
-
|
50227
|
+
if (!(0, import_fs2.existsSync)(tempDirPath)) {
|
50228
|
+
(0, import_fs2.mkdirSync)(tempDirPath, { recursive: true });
|
50229
|
+
}
|
50230
|
+
let { stateConfigJson } = defaultSnapshotConfigs;
|
50231
|
+
const { chainConfigJson, metadataJson } = defaultSnapshotConfigs;
|
50232
|
+
stateConfigJson = {
|
50233
|
+
...stateConfigJson,
|
50234
|
+
coins: [
|
50235
|
+
...stateConfigJson.coins.map((coin) => ({
|
50236
|
+
...coin,
|
50237
|
+
amount: "18446744073709551615"
|
50238
|
+
}))
|
50239
|
+
],
|
50240
|
+
messages: stateConfigJson.messages.map((message) => ({
|
50241
|
+
...message,
|
50242
|
+
amount: "18446744073709551615"
|
50243
|
+
}))
|
50244
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
50245
|
+
};
|
50246
|
+
if (!process.env.GENESIS_SECRET) {
|
50247
|
+
const pk = Signer.generatePrivateKey();
|
50248
|
+
const signer = new Signer(pk);
|
50249
|
+
process.env.GENESIS_SECRET = hexlify(pk);
|
50250
|
+
stateConfigJson.coins.push({
|
50251
|
+
tx_id: hexlify(randomBytes22(UTXO_ID_LEN)),
|
50252
|
+
owner: signer.address.toHexString(),
|
50253
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
50254
|
+
amount: "18446744073709551615",
|
50255
|
+
asset_id: chainConfigJson.consensus_parameters.V1.base_asset_id,
|
50256
|
+
output_index: 0,
|
50257
|
+
tx_pointer_block_height: 0,
|
50258
|
+
tx_pointer_tx_idx: 0
|
50259
|
+
});
|
50260
|
+
}
|
50261
|
+
let fixedStateConfigJSON = JSON.stringify(stateConfigJson);
|
50262
|
+
const regexMakeNumber = /("amount":)"(\d+)"/gm;
|
50263
|
+
fixedStateConfigJSON = fixedStateConfigJSON.replace(regexMakeNumber, "$1$2");
|
50264
|
+
const chainConfigWritePath = import_path8.default.join(tempDirPath, "chainConfig.json");
|
50265
|
+
const stateConfigWritePath = import_path8.default.join(tempDirPath, "stateConfig.json");
|
50266
|
+
const metadataWritePath = import_path8.default.join(tempDirPath, "metadata.json");
|
50267
|
+
const stateTransitionWritePath = import_path8.default.join(tempDirPath, "state_transition_bytecode.wasm");
|
50268
|
+
(0, import_fs2.writeFileSync)(chainConfigWritePath, JSON.stringify(chainConfigJson), "utf8");
|
50269
|
+
(0, import_fs2.writeFileSync)(stateConfigWritePath, fixedStateConfigJSON, "utf8");
|
50270
|
+
(0, import_fs2.writeFileSync)(metadataWritePath, JSON.stringify(metadataJson), "utf8");
|
50271
|
+
(0, import_fs2.writeFileSync)(stateTransitionWritePath, JSON.stringify(""));
|
50272
|
+
snapshotDirToUse = tempDirPath;
|
51106
50273
|
}
|
51107
50274
|
const child = (0, import_child_process.spawn)(
|
51108
50275
|
command,
|
@@ -51110,7 +50277,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
51110
50277
|
"run",
|
51111
50278
|
["--ip", ipToUse],
|
51112
50279
|
["--port", portToUse],
|
51113
|
-
useInMemoryDb ? ["--db-type", "in-memory"] : ["--db-path",
|
50280
|
+
useInMemoryDb ? ["--db-type", "in-memory"] : ["--db-path", tempDirPath],
|
51114
50281
|
["--min-gas-price", "1"],
|
51115
50282
|
poaInstant ? ["--poa-instant", "true"] : [],
|
51116
50283
|
["--consensus-key", consensusKey],
|
@@ -51132,28 +50299,23 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
51132
50299
|
}
|
51133
50300
|
const cleanupConfig = {
|
51134
50301
|
child,
|
51135
|
-
configPath:
|
50302
|
+
configPath: tempDirPath,
|
51136
50303
|
killFn: import_tree_kill.default,
|
51137
50304
|
state: {
|
51138
50305
|
isDead: false
|
51139
50306
|
}
|
51140
50307
|
};
|
51141
50308
|
child.stderr.on("data", (chunk) => {
|
51142
|
-
|
51143
|
-
if (text.indexOf(graphQLStartSubstring) !== -1) {
|
51144
|
-
const rows = text.split("\n");
|
51145
|
-
const rowWithUrl = rows.find((row) => row.indexOf(graphQLStartSubstring) !== -1);
|
51146
|
-
const [realIp, realPort] = rowWithUrl.split(" ").at(-1).trim().split(":");
|
50309
|
+
if (chunk.indexOf(graphQLStartSubstring) !== -1) {
|
51147
50310
|
resolve({
|
51148
50311
|
cleanup: () => killNode(cleanupConfig),
|
51149
|
-
ip:
|
51150
|
-
port:
|
51151
|
-
url: `http://${realIp}:${realPort}/v1/graphql`,
|
50312
|
+
ip: ipToUse,
|
50313
|
+
port: portToUse,
|
51152
50314
|
snapshotDir: snapshotDirToUse
|
51153
50315
|
});
|
51154
50316
|
}
|
51155
|
-
if (/error/i.test(
|
51156
|
-
reject(
|
50317
|
+
if (/error/i.test(chunk)) {
|
50318
|
+
reject(chunk.toString());
|
51157
50319
|
}
|
51158
50320
|
});
|
51159
50321
|
process.on("exit", () => killNode(cleanupConfig));
|
@@ -51186,215 +50348,6 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
51186
50348
|
};
|
51187
50349
|
return { wallets, stop: cleanup, provider };
|
51188
50350
|
};
|
51189
|
-
|
51190
|
-
// src/test-utils/asset-id.ts
|
51191
|
-
var _AssetId = class {
|
51192
|
-
constructor(value) {
|
51193
|
-
this.value = value;
|
51194
|
-
}
|
51195
|
-
static random() {
|
51196
|
-
return new _AssetId(hexlify(randomBytes22(32)));
|
51197
|
-
}
|
51198
|
-
};
|
51199
|
-
var AssetId = _AssetId;
|
51200
|
-
__publicField(AssetId, "A", new _AssetId(
|
51201
|
-
"0x0101010101010101010101010101010101010101010101010101010101010101"
|
51202
|
-
));
|
51203
|
-
__publicField(AssetId, "B", new _AssetId(
|
51204
|
-
"0x0202020202020202020202020202020202020202020202020202020202020202"
|
51205
|
-
));
|
51206
|
-
|
51207
|
-
// src/test-utils/wallet-config.ts
|
51208
|
-
var WalletConfig = class {
|
51209
|
-
initialState;
|
51210
|
-
options;
|
51211
|
-
wallets;
|
51212
|
-
generateWallets = () => {
|
51213
|
-
const generatedWallets = [];
|
51214
|
-
for (let index = 1; index <= this.options.count; index++) {
|
51215
|
-
generatedWallets.push(new WalletUnlocked(randomBytes22(32)));
|
51216
|
-
}
|
51217
|
-
return generatedWallets;
|
51218
|
-
};
|
51219
|
-
constructor(baseAssetId, config) {
|
51220
|
-
const BASE_ASSET_ID = baseAssetId.startsWith("0x") ? baseAssetId : `0x${baseAssetId}`;
|
51221
|
-
WalletConfig.guard(config);
|
51222
|
-
this.options = config;
|
51223
|
-
const { assets: assets2, coinsPerAsset, amountPerCoin, messages } = this.options;
|
51224
|
-
this.wallets = this.generateWallets();
|
51225
|
-
this.initialState = {
|
51226
|
-
messages: WalletConfig.createMessages(this.wallets, messages),
|
51227
|
-
coins: WalletConfig.createCoins(
|
51228
|
-
this.wallets,
|
51229
|
-
BASE_ASSET_ID,
|
51230
|
-
assets2,
|
51231
|
-
coinsPerAsset,
|
51232
|
-
amountPerCoin
|
51233
|
-
)
|
51234
|
-
};
|
51235
|
-
}
|
51236
|
-
apply(snapshotConfig) {
|
51237
|
-
return {
|
51238
|
-
...snapshotConfig,
|
51239
|
-
stateConfig: {
|
51240
|
-
...snapshotConfig?.stateConfig ?? defaultSnapshotConfigs.stateConfig,
|
51241
|
-
coins: this.initialState.coins.concat(snapshotConfig?.stateConfig?.coins || []),
|
51242
|
-
messages: this.initialState.messages.concat(snapshotConfig?.stateConfig?.messages ?? [])
|
51243
|
-
}
|
51244
|
-
};
|
51245
|
-
}
|
51246
|
-
static createMessages(wallets, messages) {
|
51247
|
-
return messages.map((msg) => wallets.map((wallet) => msg.toChainMessage(wallet.address))).flatMap((x) => x);
|
51248
|
-
}
|
51249
|
-
static createCoins(wallets, baseAssetId, assets2, coinsPerAsset, amountPerCoin) {
|
51250
|
-
const coins = [];
|
51251
|
-
let assetIds = [baseAssetId];
|
51252
|
-
if (Array.isArray(assets2)) {
|
51253
|
-
assetIds = assetIds.concat(assets2.map((a) => a.value));
|
51254
|
-
} else {
|
51255
|
-
for (let index = 0; index < assets2 - 1; index++) {
|
51256
|
-
assetIds.push(AssetId.random().value);
|
51257
|
-
}
|
51258
|
-
}
|
51259
|
-
wallets.map((wallet) => wallet.address.toHexString()).forEach((walletAddress) => {
|
51260
|
-
assetIds.forEach((assetId) => {
|
51261
|
-
for (let index = 0; index < coinsPerAsset; index++) {
|
51262
|
-
coins.push({
|
51263
|
-
amount: amountPerCoin,
|
51264
|
-
asset_id: assetId,
|
51265
|
-
owner: walletAddress,
|
51266
|
-
tx_pointer_block_height: 0,
|
51267
|
-
tx_pointer_tx_idx: 0,
|
51268
|
-
output_index: 0,
|
51269
|
-
tx_id: hexlify(randomBytes22(32))
|
51270
|
-
});
|
51271
|
-
}
|
51272
|
-
});
|
51273
|
-
});
|
51274
|
-
return coins;
|
51275
|
-
}
|
51276
|
-
static guard({
|
51277
|
-
count: wallets,
|
51278
|
-
assets: assets2,
|
51279
|
-
coinsPerAsset,
|
51280
|
-
amountPerCoin
|
51281
|
-
}) {
|
51282
|
-
if (Array.isArray(wallets) && wallets.length === 0 || typeof wallets === "number" && wallets <= 0) {
|
51283
|
-
throw new FuelError(
|
51284
|
-
FuelError.CODES.INVALID_INPUT_PARAMETERS,
|
51285
|
-
"Number of wallets must be greater than zero."
|
51286
|
-
);
|
51287
|
-
}
|
51288
|
-
if (Array.isArray(assets2) && assets2.length === 0 || typeof assets2 === "number" && assets2 <= 0) {
|
51289
|
-
throw new FuelError(
|
51290
|
-
FuelError.CODES.INVALID_INPUT_PARAMETERS,
|
51291
|
-
"Number of assets per wallet must be greater than zero."
|
51292
|
-
);
|
51293
|
-
}
|
51294
|
-
if (coinsPerAsset <= 0) {
|
51295
|
-
throw new FuelError(
|
51296
|
-
FuelError.CODES.INVALID_INPUT_PARAMETERS,
|
51297
|
-
"Number of coins per asset must be greater than zero."
|
51298
|
-
);
|
51299
|
-
}
|
51300
|
-
if (amountPerCoin <= 0) {
|
51301
|
-
throw new FuelError(
|
51302
|
-
FuelError.CODES.INVALID_INPUT_PARAMETERS,
|
51303
|
-
"Amount per coin must be greater than zero."
|
51304
|
-
);
|
51305
|
-
}
|
51306
|
-
}
|
51307
|
-
};
|
51308
|
-
|
51309
|
-
// src/test-utils/setup-test-provider-and-wallets.ts
|
51310
|
-
var defaultWalletConfigOptions = {
|
51311
|
-
count: 2,
|
51312
|
-
assets: [AssetId.A, AssetId.B],
|
51313
|
-
coinsPerAsset: 1,
|
51314
|
-
amountPerCoin: 1e10,
|
51315
|
-
messages: []
|
51316
|
-
};
|
51317
|
-
async function setupTestProviderAndWallets({
|
51318
|
-
walletConfig: walletConfigOptions = {},
|
51319
|
-
providerOptions,
|
51320
|
-
nodeOptions = {}
|
51321
|
-
} = {}) {
|
51322
|
-
Symbol.dispose ??= Symbol("Symbol.dispose");
|
51323
|
-
const walletConfig = new WalletConfig(
|
51324
|
-
nodeOptions.snapshotConfig?.chainConfig?.consensus_parameters?.V1?.base_asset_id ?? defaultSnapshotConfigs.chainConfig.consensus_parameters.V1.base_asset_id,
|
51325
|
-
{
|
51326
|
-
...defaultWalletConfigOptions,
|
51327
|
-
...walletConfigOptions
|
51328
|
-
}
|
51329
|
-
);
|
51330
|
-
const { cleanup, url } = await launchNode({
|
51331
|
-
loggingEnabled: false,
|
51332
|
-
...nodeOptions,
|
51333
|
-
snapshotConfig: mergeDeepRight_default(
|
51334
|
-
defaultSnapshotConfigs,
|
51335
|
-
walletConfig.apply(nodeOptions?.snapshotConfig)
|
51336
|
-
),
|
51337
|
-
port: "0"
|
51338
|
-
});
|
51339
|
-
let provider;
|
51340
|
-
try {
|
51341
|
-
provider = await Provider.create(url, providerOptions);
|
51342
|
-
} catch (err) {
|
51343
|
-
cleanup();
|
51344
|
-
throw err;
|
51345
|
-
}
|
51346
|
-
const wallets = walletConfig.wallets;
|
51347
|
-
wallets.forEach((wallet) => {
|
51348
|
-
wallet.connect(provider);
|
51349
|
-
});
|
51350
|
-
return {
|
51351
|
-
provider,
|
51352
|
-
wallets,
|
51353
|
-
cleanup,
|
51354
|
-
[Symbol.dispose]: cleanup
|
51355
|
-
};
|
51356
|
-
}
|
51357
|
-
|
51358
|
-
// src/test-utils/test-message.ts
|
51359
|
-
var TestMessage = class {
|
51360
|
-
sender;
|
51361
|
-
recipient;
|
51362
|
-
nonce;
|
51363
|
-
amount;
|
51364
|
-
data;
|
51365
|
-
da_height;
|
51366
|
-
/**
|
51367
|
-
* A helper class to create messages for testing purposes.
|
51368
|
-
*
|
51369
|
-
* Used in tandem with `WalletConfig`.
|
51370
|
-
* It can also be used standalone and passed into the initial state of a chain via the `.toChainMessage` method.
|
51371
|
-
*/
|
51372
|
-
constructor({
|
51373
|
-
sender = Address.fromRandom(),
|
51374
|
-
recipient = Address.fromRandom(),
|
51375
|
-
nonce = hexlify(randomBytes22(32)),
|
51376
|
-
amount = 1e6,
|
51377
|
-
data = "02",
|
51378
|
-
da_height = 0
|
51379
|
-
} = {}) {
|
51380
|
-
this.sender = sender;
|
51381
|
-
this.recipient = recipient;
|
51382
|
-
this.nonce = nonce;
|
51383
|
-
this.amount = amount;
|
51384
|
-
this.data = data;
|
51385
|
-
this.da_height = da_height;
|
51386
|
-
}
|
51387
|
-
toChainMessage(recipient) {
|
51388
|
-
return {
|
51389
|
-
sender: this.sender.toB256(),
|
51390
|
-
recipient: recipient?.toB256() ?? this.recipient.toB256(),
|
51391
|
-
nonce: this.nonce,
|
51392
|
-
amount: bn(this.amount).toNumber(),
|
51393
|
-
data: this.data,
|
51394
|
-
da_height: this.da_height
|
51395
|
-
};
|
51396
|
-
}
|
51397
|
-
};
|
51398
50351
|
})();
|
51399
50352
|
/*! Bundled license information:
|
51400
50353
|
|