@fuel-ts/account 0.0.0-rc-2238-20240514123009 → 0.0.0-rc-1356-20240514125020
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of @fuel-ts/account might be problematic. Click here for more details.
- package/dist/account.d.ts.map +1 -1
- package/dist/index.global.js +1140 -408
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +254 -234
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +145 -118
- package/dist/index.mjs.map +1 -1
- package/dist/predicate/predicate.d.ts.map +1 -1
- package/dist/providers/coin.d.ts +1 -0
- package/dist/providers/coin.d.ts.map +1 -1
- package/dist/providers/message.d.ts +1 -0
- package/dist/providers/message.d.ts.map +1 -1
- package/dist/providers/transaction-request/input.d.ts +2 -0
- package/dist/providers/transaction-request/input.d.ts.map +1 -1
- package/dist/providers/transaction-request/transaction-request.d.ts +1 -0
- package/dist/providers/transaction-request/transaction-request.d.ts.map +1 -1
- package/dist/providers/transaction-summary/call.d.ts +1 -1
- package/dist/providers/transaction-summary/call.d.ts.map +1 -1
- package/dist/providers/utils/auto-retry-fetch.d.ts.map +1 -1
- package/dist/providers/utils/index.d.ts +0 -1
- package/dist/providers/utils/index.d.ts.map +1 -1
- package/dist/test-utils/asset-id.d.ts +8 -0
- package/dist/test-utils/asset-id.d.ts.map +1 -0
- package/dist/test-utils/index.d.ts +4 -0
- package/dist/test-utils/index.d.ts.map +1 -1
- package/dist/test-utils/launchNode.d.ts +8 -1
- package/dist/test-utils/launchNode.d.ts.map +1 -1
- package/dist/test-utils/setup-test-provider-and-wallets.d.ts +33 -0
- package/dist/test-utils/setup-test-provider-and-wallets.d.ts.map +1 -0
- package/dist/test-utils/test-message.d.ts +28 -0
- package/dist/test-utils/test-message.d.ts.map +1 -0
- package/dist/test-utils/wallet-config.d.ts +49 -0
- package/dist/test-utils/wallet-config.d.ts.map +1 -0
- package/dist/test-utils.global.js +1465 -418
- package/dist/test-utils.global.js.map +1 -1
- package/dist/test-utils.js +523 -272
- package/dist/test-utils.js.map +1 -1
- package/dist/test-utils.mjs +413 -166
- package/dist/test-utils.mjs.map +1 -1
- package/package.json +16 -15
- package/dist/providers/utils/sleep.d.ts +0 -3
- package/dist/providers/utils/sleep.d.ts.map +0 -1
@@ -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.56.1",
|
32436
32436
|
FUEL_CORE: "0.26.0",
|
32437
32437
|
FUELS: "0.85.0"
|
32438
32438
|
};
|
@@ -32933,6 +32933,13 @@ 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
|
+
}
|
32936
32943
|
var chainConfig_default = {
|
32937
32944
|
chain_name: "local_testnet",
|
32938
32945
|
consensus_parameters: {
|
@@ -33687,9 +33694,9 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
33687
33694
|
da_block_height: 0
|
33688
33695
|
};
|
33689
33696
|
var defaultSnapshotConfigs = {
|
33690
|
-
|
33691
|
-
|
33692
|
-
|
33697
|
+
chainConfig: chainConfig_default,
|
33698
|
+
metadata: metadata_default,
|
33699
|
+
stateConfig: stateConfig_default
|
33693
33700
|
};
|
33694
33701
|
var defaultConsensusKey = "0xa449b1ffee0e2205fa924c6740cc48b3b473aa28587df6dab12abc245d1f5298";
|
33695
33702
|
function isDefined(value) {
|
@@ -34312,11 +34319,72 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
34312
34319
|
};
|
34313
34320
|
}
|
34314
34321
|
|
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
|
+
|
34315
34378
|
// ../../node_modules/.pnpm/ramda@0.29.0/node_modules/ramda/es/internal/_isArray.js
|
34316
34379
|
var isArray_default = Array.isArray || function _isArray(val) {
|
34317
34380
|
return val != null && val.length >= 0 && Object.prototype.toString.call(val) === "[object Array]";
|
34318
34381
|
};
|
34319
34382
|
|
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
|
+
|
34320
34388
|
// ../../node_modules/.pnpm/ramda@0.29.0/node_modules/ramda/es/type.js
|
34321
34389
|
var type = /* @__PURE__ */ _curry1(function type2(val) {
|
34322
34390
|
return val === null ? "Null" : val === void 0 ? "Undefined" : Object.prototype.toString.call(val).slice(8, -1);
|
@@ -34333,6 +34401,11 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
34333
34401
|
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";
|
34334
34402
|
};
|
34335
34403
|
|
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
|
+
|
34336
34409
|
// ../../node_modules/.pnpm/ramda@0.29.0/node_modules/ramda/es/internal/_isInteger.js
|
34337
34410
|
var isInteger_default = Number.isInteger || function _isInteger(n) {
|
34338
34411
|
return n << 0 === n;
|
@@ -34446,6 +34519,46 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
34446
34519
|
});
|
34447
34520
|
var clone_default = clone;
|
34448
34521
|
|
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
|
+
|
34449
34562
|
// ../../node_modules/.pnpm/ramda@0.29.0/node_modules/ramda/es/trim.js
|
34450
34563
|
var hasProtoTrim = typeof String.prototype.trim === "function";
|
34451
34564
|
|
@@ -34799,6 +34912,19 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
34799
34912
|
__defNormalProp4(obj, typeof key !== "symbol" ? key + "" : key, value);
|
34800
34913
|
return value;
|
34801
34914
|
};
|
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
|
+
};
|
34802
34928
|
var Coder = class {
|
34803
34929
|
name;
|
34804
34930
|
type;
|
@@ -34830,6 +34956,7 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
34830
34956
|
var enumRegEx = /^enum (?<name>\w+)$/;
|
34831
34957
|
var tupleRegEx = /^\((?<items>.*)\)$/;
|
34832
34958
|
var genericRegEx = /^generic (?<name>\w+)$/;
|
34959
|
+
var ENCODING_V0 = "0";
|
34833
34960
|
var ENCODING_V1 = "1";
|
34834
34961
|
var WORD_SIZE = 8;
|
34835
34962
|
var BYTES_32 = 32;
|
@@ -34840,6 +34967,10 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
34840
34967
|
var TX_LEN = WORD_SIZE * 4;
|
34841
34968
|
var TX_POINTER_LEN = WORD_SIZE * 2;
|
34842
34969
|
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;
|
34843
34974
|
var SCRIPT_FIXED_SIZE = WORD_SIZE + // Identifier
|
34844
34975
|
WORD_SIZE + // Gas limit
|
34845
34976
|
WORD_SIZE + // Script size
|
@@ -34870,6 +35001,125 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
34870
35001
|
WORD_SIZE + // Predicate size
|
34871
35002
|
WORD_SIZE + // Predicate data size
|
34872
35003
|
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;
|
34873
35123
|
var ArrayCoder = class extends Coder {
|
34874
35124
|
coder;
|
34875
35125
|
length;
|
@@ -34885,7 +35135,7 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
34885
35135
|
if (this.length !== value.length) {
|
34886
35136
|
throw new FuelError(ErrorCode.ENCODE_ERROR, `Types/values length mismatch.`);
|
34887
35137
|
}
|
34888
|
-
return
|
35138
|
+
return concatWithDynamicData(Array.from(value).map((v) => this.coder.encode(v)));
|
34889
35139
|
}
|
34890
35140
|
decode(data, offset) {
|
34891
35141
|
if (data.length < this.encodedLength || data.length > MAX_BYTES) {
|
@@ -34962,42 +35212,16 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
34962
35212
|
return [toHex(bytes2, this.encodedLength), offset + this.encodedLength];
|
34963
35213
|
}
|
34964
35214
|
};
|
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
|
-
};
|
34994
35215
|
var BooleanCoder = class extends Coder {
|
35216
|
+
paddingLength;
|
34995
35217
|
options;
|
34996
35218
|
constructor(options = {
|
34997
|
-
|
35219
|
+
isSmallBytes: false,
|
35220
|
+
isRightPadded: false
|
34998
35221
|
}) {
|
34999
|
-
const
|
35000
|
-
super("boolean", "boolean",
|
35222
|
+
const paddingLength = options.isSmallBytes ? 1 : 8;
|
35223
|
+
super("boolean", "boolean", paddingLength);
|
35224
|
+
this.paddingLength = paddingLength;
|
35001
35225
|
this.options = options;
|
35002
35226
|
}
|
35003
35227
|
encode(value) {
|
@@ -35005,45 +35229,73 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
35005
35229
|
if (!isTrueBool) {
|
35006
35230
|
throw new FuelError(ErrorCode.ENCODE_ERROR, `Invalid boolean value.`);
|
35007
35231
|
}
|
35008
|
-
|
35232
|
+
const output2 = toBytes2(value ? 1 : 0, this.paddingLength);
|
35233
|
+
if (this.options.isRightPadded) {
|
35234
|
+
return output2.reverse();
|
35235
|
+
}
|
35236
|
+
return output2;
|
35009
35237
|
}
|
35010
35238
|
decode(data, offset) {
|
35011
|
-
if (data.length < this.
|
35239
|
+
if (data.length < this.paddingLength) {
|
35012
35240
|
throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid boolean data size.`);
|
35013
35241
|
}
|
35014
|
-
|
35015
|
-
if (
|
35016
|
-
|
35242
|
+
let bytes2;
|
35243
|
+
if (this.options.isRightPadded) {
|
35244
|
+
bytes2 = data.slice(offset, offset + 1);
|
35245
|
+
} else {
|
35246
|
+
bytes2 = data.slice(offset, offset + this.paddingLength);
|
35017
35247
|
}
|
35018
|
-
|
35248
|
+
const decodedValue = bn(bytes2);
|
35249
|
+
if (decodedValue.isZero()) {
|
35250
|
+
return [false, offset + this.paddingLength];
|
35251
|
+
}
|
35252
|
+
if (!decodedValue.eq(bn(1))) {
|
35019
35253
|
throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid boolean value.`);
|
35020
35254
|
}
|
35021
|
-
return [true, offset + this.
|
35255
|
+
return [true, offset + this.paddingLength];
|
35022
35256
|
}
|
35023
35257
|
};
|
35258
|
+
var _getPaddedData;
|
35259
|
+
var getPaddedData_fn;
|
35024
35260
|
var ByteCoder = class extends Coder {
|
35025
35261
|
constructor() {
|
35026
|
-
super("struct", "struct Bytes",
|
35262
|
+
super("struct", "struct Bytes", BASE_VECTOR_OFFSET);
|
35263
|
+
__privateAdd2(this, _getPaddedData);
|
35027
35264
|
}
|
35028
35265
|
encode(value) {
|
35029
|
-
const
|
35030
|
-
const
|
35031
|
-
|
35266
|
+
const parts = [];
|
35267
|
+
const pointer = new BigNumberCoder("u64").encode(BASE_VECTOR_OFFSET);
|
35268
|
+
const data = __privateMethod2(this, _getPaddedData, getPaddedData_fn).call(this, value);
|
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);
|
35032
35276
|
}
|
35033
35277
|
decode(data, offset) {
|
35034
|
-
if (data.length <
|
35278
|
+
if (data.length < BASE_VECTOR_OFFSET) {
|
35035
35279
|
throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid byte data size.`);
|
35036
35280
|
}
|
35037
|
-
const
|
35038
|
-
const
|
35039
|
-
const
|
35040
|
-
|
35041
|
-
if (dataBytes.length !== length) {
|
35281
|
+
const len = data.slice(16, 24);
|
35282
|
+
const encodedLength = bn(new BigNumberCoder("u64").decode(len, 0)[0]).toNumber();
|
35283
|
+
const byteData = data.slice(BASE_VECTOR_OFFSET, BASE_VECTOR_OFFSET + encodedLength);
|
35284
|
+
if (byteData.length !== encodedLength) {
|
35042
35285
|
throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid bytes byte data size.`);
|
35043
35286
|
}
|
35044
|
-
return [
|
35287
|
+
return [byteData, offset + BASE_VECTOR_OFFSET];
|
35045
35288
|
}
|
35046
35289
|
};
|
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
|
+
};
|
35047
35299
|
__publicField4(ByteCoder, "memorySize", 1);
|
35048
35300
|
var isFullyNativeEnum = (enumCoders) => Object.values(enumCoders).every(
|
35049
35301
|
// @ts-expect-error complicated types
|
@@ -35087,7 +35339,8 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
35087
35339
|
const valueCoder = this.coders[caseKey];
|
35088
35340
|
const caseIndex = Object.keys(this.coders).indexOf(caseKey);
|
35089
35341
|
const encodedValue = valueCoder.encode(value[caseKey]);
|
35090
|
-
|
35342
|
+
const padding = new Uint8Array(this.#encodedValueSize - valueCoder.encodedLength);
|
35343
|
+
return concatWithDynamicData([this.#caseIndexCoder.encode(caseIndex), padding, encodedValue]);
|
35091
35344
|
}
|
35092
35345
|
#decodeNativeEnum(caseKey, newOffset) {
|
35093
35346
|
return [caseKey, newOffset];
|
@@ -35096,8 +35349,10 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
35096
35349
|
if (data.length < this.#encodedValueSize) {
|
35097
35350
|
throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid enum data size.`);
|
35098
35351
|
}
|
35099
|
-
|
35100
|
-
|
35352
|
+
let newOffset = offset;
|
35353
|
+
let decoded;
|
35354
|
+
[decoded, newOffset] = new BigNumberCoder("u64").decode(data, newOffset);
|
35355
|
+
const caseIndex = toNumber(decoded);
|
35101
35356
|
const caseKey = Object.keys(this.coders)[caseIndex];
|
35102
35357
|
if (!caseKey) {
|
35103
35358
|
throw new FuelError(
|
@@ -35106,35 +35361,67 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
35106
35361
|
);
|
35107
35362
|
}
|
35108
35363
|
const valueCoder = this.coders[caseKey];
|
35109
|
-
const
|
35110
|
-
|
35364
|
+
const padding = this.#encodedValueSize - valueCoder.encodedLength;
|
35365
|
+
newOffset += padding;
|
35366
|
+
[decoded, newOffset] = valueCoder.decode(data, newOffset);
|
35111
35367
|
if (isFullyNativeEnum(this.coders)) {
|
35112
35368
|
return this.#decodeNativeEnum(caseKey, newOffset);
|
35113
35369
|
}
|
35114
35370
|
return [{ [caseKey]: decoded }, newOffset];
|
35115
35371
|
}
|
35116
35372
|
};
|
35117
|
-
var
|
35118
|
-
|
35119
|
-
|
35120
|
-
|
35121
|
-
|
35122
|
-
|
35123
|
-
|
35124
|
-
return
|
35125
|
-
|
35126
|
-
|
35373
|
+
var OptionCoder = class extends EnumCoder {
|
35374
|
+
encode(value) {
|
35375
|
+
const result = super.encode(this.toSwayOption(value));
|
35376
|
+
return result;
|
35377
|
+
}
|
35378
|
+
toSwayOption(input) {
|
35379
|
+
if (input !== void 0) {
|
35380
|
+
return { Some: input };
|
35381
|
+
}
|
35382
|
+
return { None: [] };
|
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;
|
35127
35396
|
}
|
35128
35397
|
};
|
35129
35398
|
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;
|
35130
35403
|
baseType;
|
35131
35404
|
options;
|
35132
35405
|
constructor(baseType, options = {
|
35133
|
-
|
35406
|
+
isSmallBytes: false,
|
35407
|
+
isRightPadded: false
|
35134
35408
|
}) {
|
35135
|
-
const
|
35136
|
-
super("number", baseType,
|
35409
|
+
const paddingLength = options.isSmallBytes && baseType === "u8" ? 1 : 8;
|
35410
|
+
super("number", baseType, paddingLength);
|
35137
35411
|
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;
|
35138
35425
|
this.options = options;
|
35139
35426
|
}
|
35140
35427
|
encode(value) {
|
@@ -35144,140 +35431,142 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
35144
35431
|
} catch (error) {
|
35145
35432
|
throw new FuelError(ErrorCode.ENCODE_ERROR, `Invalid ${this.baseType}.`);
|
35146
35433
|
}
|
35147
|
-
if (bytes2.length > this.
|
35434
|
+
if (bytes2.length > this.length) {
|
35148
35435
|
throw new FuelError(ErrorCode.ENCODE_ERROR, `Invalid ${this.baseType}, too many bytes.`);
|
35149
35436
|
}
|
35150
|
-
|
35437
|
+
const output2 = toBytes2(bytes2, this.paddingLength);
|
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];
|
35151
35452
|
}
|
35152
35453
|
decode(data, offset) {
|
35153
|
-
if (data.length < this.
|
35454
|
+
if (data.length < this.paddingLength) {
|
35154
35455
|
throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid number data size.`);
|
35155
35456
|
}
|
35156
|
-
|
35157
|
-
|
35457
|
+
if (this.baseType === "u8") {
|
35458
|
+
return this.decodeU8(data, offset);
|
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)) {
|
35158
35463
|
throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid number byte data size.`);
|
35159
35464
|
}
|
35160
|
-
return [toNumber(bytes2), offset +
|
35465
|
+
return [toNumber(bytes2), offset + 8];
|
35161
35466
|
}
|
35162
35467
|
};
|
35163
|
-
var
|
35164
|
-
|
35165
|
-
|
35166
|
-
return result;
|
35468
|
+
var RawSliceCoder = class extends Coder {
|
35469
|
+
constructor() {
|
35470
|
+
super("raw untyped slice", "raw untyped slice", BASE_RAW_SLICE_OFFSET);
|
35167
35471
|
}
|
35168
|
-
|
35169
|
-
if (
|
35170
|
-
|
35472
|
+
encode(value) {
|
35473
|
+
if (!Array.isArray(value)) {
|
35474
|
+
throw new FuelError(ErrorCode.ENCODE_ERROR, `Expected array value.`);
|
35171
35475
|
}
|
35172
|
-
|
35476
|
+
const parts = [];
|
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);
|
35173
35487
|
}
|
35174
35488
|
decode(data, offset) {
|
35175
|
-
const
|
35176
|
-
|
35177
|
-
|
35178
|
-
|
35179
|
-
|
35180
|
-
|
35181
|
-
|
35182
|
-
return void 0;
|
35489
|
+
const dataBytes = data.slice(offset);
|
35490
|
+
const internalCoder = new ArrayCoder(
|
35491
|
+
new NumberCoder("u8", { isSmallBytes: true }),
|
35492
|
+
dataBytes.length
|
35493
|
+
);
|
35494
|
+
const [decodedValue] = internalCoder.decode(dataBytes, 0);
|
35495
|
+
return [decodedValue, offset + dataBytes.length];
|
35183
35496
|
}
|
35184
35497
|
};
|
35185
|
-
var
|
35498
|
+
var _getPaddedData2;
|
35499
|
+
var getPaddedData_fn2;
|
35500
|
+
var StdStringCoder = class extends Coder {
|
35186
35501
|
constructor() {
|
35187
|
-
super("
|
35502
|
+
super("struct", "struct String", 1);
|
35503
|
+
__privateAdd2(this, _getPaddedData2);
|
35188
35504
|
}
|
35189
35505
|
encode(value) {
|
35190
|
-
|
35191
|
-
|
35192
|
-
|
35193
|
-
|
35194
|
-
|
35195
|
-
|
35196
|
-
|
35506
|
+
const parts = [];
|
35507
|
+
const pointer = new BigNumberCoder("u64").encode(BASE_VECTOR_OFFSET);
|
35508
|
+
const data = __privateMethod2(this, _getPaddedData2, getPaddedData_fn2).call(this, value);
|
35509
|
+
pointer.dynamicData = {
|
35510
|
+
0: concatWithDynamicData([data])
|
35511
|
+
};
|
35512
|
+
parts.push(pointer);
|
35513
|
+
parts.push(new BigNumberCoder("u64").encode(data.byteLength));
|
35514
|
+
parts.push(new BigNumberCoder("u64").encode(value.length));
|
35515
|
+
return concatWithDynamicData(parts);
|
35197
35516
|
}
|
35198
35517
|
decode(data, offset) {
|
35199
35518
|
if (data.length < this.encodedLength) {
|
35200
|
-
throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid
|
35519
|
+
throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid std string data size.`);
|
35201
35520
|
}
|
35202
|
-
const
|
35203
|
-
const
|
35204
|
-
const
|
35205
|
-
|
35206
|
-
if (dataBytes.length !== length) {
|
35207
|
-
throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid raw slice byte data size.`);
|
35208
|
-
}
|
35209
|
-
const internalCoder = new ArrayCoder(new NumberCoder("u8"), length);
|
35210
|
-
const [decodedValue] = internalCoder.decode(dataBytes, 0);
|
35211
|
-
return [decodedValue, offsetAndLength + length];
|
35212
|
-
}
|
35213
|
-
};
|
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) {
|
35521
|
+
const len = data.slice(16, 24);
|
35522
|
+
const encodedLength = bn(new BigNumberCoder("u64").decode(len, 0)[0]).toNumber();
|
35523
|
+
const byteData = data.slice(BASE_VECTOR_OFFSET, BASE_VECTOR_OFFSET + encodedLength);
|
35524
|
+
if (byteData.length !== encodedLength) {
|
35232
35525
|
throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid std string byte data size.`);
|
35233
35526
|
}
|
35234
|
-
|
35527
|
+
const value = toUtf8String(byteData);
|
35528
|
+
return [value, offset + BASE_VECTOR_OFFSET];
|
35235
35529
|
}
|
35236
35530
|
};
|
35237
|
-
|
35238
|
-
|
35239
|
-
|
35240
|
-
|
35241
|
-
|
35242
|
-
|
35243
|
-
|
35244
|
-
|
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
|
-
}
|
35531
|
+
_getPaddedData2 = /* @__PURE__ */ new WeakSet();
|
35532
|
+
getPaddedData_fn2 = function(value) {
|
35533
|
+
const data = [toUtf8Bytes(value)];
|
35534
|
+
const paddingLength = (WORD_SIZE - value.length % WORD_SIZE) % WORD_SIZE;
|
35535
|
+
if (paddingLength) {
|
35536
|
+
data.push(new Uint8Array(paddingLength));
|
35537
|
+
}
|
35538
|
+
return concat(data);
|
35260
35539
|
};
|
35261
|
-
__publicField4(
|
35540
|
+
__publicField4(StdStringCoder, "memorySize", 1);
|
35262
35541
|
var StringCoder = class extends Coder {
|
35542
|
+
length;
|
35543
|
+
#paddingLength;
|
35263
35544
|
constructor(length) {
|
35264
|
-
|
35545
|
+
let paddingLength = (8 - length) % 8;
|
35546
|
+
paddingLength = paddingLength < 0 ? paddingLength + 8 : paddingLength;
|
35547
|
+
super("string", `str[${length}]`, length + paddingLength);
|
35548
|
+
this.length = length;
|
35549
|
+
this.#paddingLength = paddingLength;
|
35265
35550
|
}
|
35266
35551
|
encode(value) {
|
35267
|
-
if (
|
35552
|
+
if (this.length !== value.length) {
|
35268
35553
|
throw new FuelError(ErrorCode.ENCODE_ERROR, `Value length mismatch during encode.`);
|
35269
35554
|
}
|
35270
|
-
|
35555
|
+
const encoded = toUtf8Bytes(value);
|
35556
|
+
const padding = new Uint8Array(this.#paddingLength);
|
35557
|
+
return concat([encoded, padding]);
|
35271
35558
|
}
|
35272
35559
|
decode(data, offset) {
|
35273
35560
|
if (data.length < this.encodedLength) {
|
35274
35561
|
throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid string data size.`);
|
35275
35562
|
}
|
35276
|
-
const bytes2 = data.slice(offset, offset + this.
|
35277
|
-
if (bytes2.length !== this.
|
35563
|
+
const bytes2 = data.slice(offset, offset + this.length);
|
35564
|
+
if (bytes2.length !== this.length) {
|
35278
35565
|
throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid string byte data size.`);
|
35279
35566
|
}
|
35280
|
-
|
35567
|
+
const value = toUtf8String(bytes2);
|
35568
|
+
const padding = this.#paddingLength;
|
35569
|
+
return [value, offset + this.length + padding];
|
35281
35570
|
}
|
35282
35571
|
};
|
35283
35572
|
var StructCoder = class extends Coder {
|
@@ -35293,19 +35582,22 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
35293
35582
|
this.coders = coders;
|
35294
35583
|
}
|
35295
35584
|
encode(value) {
|
35296
|
-
|
35297
|
-
|
35298
|
-
|
35299
|
-
|
35300
|
-
|
35301
|
-
|
35302
|
-
|
35303
|
-
|
35304
|
-
|
35305
|
-
|
35306
|
-
|
35307
|
-
|
35308
|
-
|
35585
|
+
const encodedFields = Object.keys(this.coders).map((fieldName) => {
|
35586
|
+
const fieldCoder = this.coders[fieldName];
|
35587
|
+
const fieldValue = value[fieldName];
|
35588
|
+
if (!(fieldCoder instanceof OptionCoder) && fieldValue == null) {
|
35589
|
+
throw new FuelError(
|
35590
|
+
ErrorCode.ENCODE_ERROR,
|
35591
|
+
`Invalid ${this.type}. Field "${fieldName}" not present.`
|
35592
|
+
);
|
35593
|
+
}
|
35594
|
+
const encoded = fieldCoder.encode(fieldValue);
|
35595
|
+
if (!isMultipleOfWordSize(encoded.length)) {
|
35596
|
+
return rightPadToWordSize(encoded);
|
35597
|
+
}
|
35598
|
+
return encoded;
|
35599
|
+
});
|
35600
|
+
return concatWithDynamicData([concatWithDynamicData(encodedFields)]);
|
35309
35601
|
}
|
35310
35602
|
decode(data, offset) {
|
35311
35603
|
if (data.length < this.encodedLength) {
|
@@ -35316,6 +35608,9 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
35316
35608
|
const fieldCoder = this.coders[fieldName];
|
35317
35609
|
let decoded;
|
35318
35610
|
[decoded, newOffset] = fieldCoder.decode(data, newOffset);
|
35611
|
+
if (!isMultipleOfWordSize(newOffset)) {
|
35612
|
+
newOffset += getWordSizePadding(newOffset);
|
35613
|
+
}
|
35319
35614
|
obj[fieldName] = decoded;
|
35320
35615
|
return obj;
|
35321
35616
|
}, {});
|
@@ -35333,7 +35628,15 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
35333
35628
|
if (this.coders.length !== value.length) {
|
35334
35629
|
throw new FuelError(ErrorCode.ENCODE_ERROR, `Types/values length mismatch.`);
|
35335
35630
|
}
|
35336
|
-
return
|
35631
|
+
return concatWithDynamicData(
|
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
|
+
);
|
35337
35640
|
}
|
35338
35641
|
decode(data, offset) {
|
35339
35642
|
if (data.length < this.encodedLength) {
|
@@ -35343,19 +35646,19 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
35343
35646
|
const decodedValue = this.coders.map((coder) => {
|
35344
35647
|
let decoded;
|
35345
35648
|
[decoded, newOffset] = coder.decode(data, newOffset);
|
35649
|
+
if (!isMultipleOfWordSize(newOffset)) {
|
35650
|
+
newOffset += getWordSizePadding(newOffset);
|
35651
|
+
}
|
35346
35652
|
return decoded;
|
35347
35653
|
});
|
35348
35654
|
return [decodedValue, newOffset];
|
35349
35655
|
}
|
35350
35656
|
};
|
35351
|
-
var isUint8Array = (value) => value instanceof Uint8Array;
|
35352
35657
|
var VecCoder = class extends Coder {
|
35353
35658
|
coder;
|
35354
|
-
#isOptionVec;
|
35355
35659
|
constructor(coder) {
|
35356
|
-
super("struct", `struct Vec`, coder.encodedLength +
|
35660
|
+
super("struct", `struct Vec`, coder.encodedLength + BASE_VECTOR_OFFSET);
|
35357
35661
|
this.coder = coder;
|
35358
|
-
this.#isOptionVec = this.coder instanceof OptionCoder;
|
35359
35662
|
}
|
35360
35663
|
encode(value) {
|
35361
35664
|
if (!Array.isArray(value) && !isUint8Array(value)) {
|
@@ -35364,39 +35667,40 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
35364
35667
|
`Expected array value, or a Uint8Array. You can use arrayify to convert a value to a Uint8Array.`
|
35365
35668
|
);
|
35366
35669
|
}
|
35367
|
-
const
|
35368
|
-
|
35369
|
-
|
35370
|
-
|
35371
|
-
|
35372
|
-
|
35373
|
-
|
35670
|
+
const parts = [];
|
35671
|
+
const pointer = new BigNumberCoder("u64").encode(BASE_VECTOR_OFFSET);
|
35672
|
+
pointer.dynamicData = {
|
35673
|
+
0: concatWithDynamicData(Array.from(value).map((v) => this.coder.encode(v)))
|
35674
|
+
};
|
35675
|
+
parts.push(pointer);
|
35676
|
+
parts.push(new BigNumberCoder("u64").encode(value.length));
|
35677
|
+
parts.push(new BigNumberCoder("u64").encode(value.length));
|
35678
|
+
return concatWithDynamicData(parts);
|
35374
35679
|
}
|
35375
35680
|
decode(data, offset) {
|
35376
|
-
if (
|
35681
|
+
if (data.length < BASE_VECTOR_OFFSET || data.length > MAX_BYTES) {
|
35377
35682
|
throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid vec data size.`);
|
35378
35683
|
}
|
35379
|
-
const
|
35380
|
-
const
|
35381
|
-
const
|
35382
|
-
const
|
35383
|
-
|
35384
|
-
if (!this.#isOptionVec && dataBytes.length !== dataLength2) {
|
35684
|
+
const len = data.slice(16, 24);
|
35685
|
+
const encodedLength = bn(new BigNumberCoder("u64").decode(len, 0)[0]).toNumber();
|
35686
|
+
const vectorRawDataLength = encodedLength * this.coder.encodedLength;
|
35687
|
+
const vectorRawData = data.slice(BASE_VECTOR_OFFSET, BASE_VECTOR_OFFSET + vectorRawDataLength);
|
35688
|
+
if (vectorRawData.length !== vectorRawDataLength) {
|
35385
35689
|
throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid vec byte data size.`);
|
35386
35690
|
}
|
35387
|
-
|
35388
|
-
|
35389
|
-
|
35390
|
-
|
35391
|
-
|
35392
|
-
|
35393
|
-
}
|
35394
|
-
return [chunks, newOffset];
|
35691
|
+
return [
|
35692
|
+
chunkByLength(vectorRawData, this.coder.encodedLength).map(
|
35693
|
+
(chunk) => this.coder.decode(chunk, 0)[0]
|
35694
|
+
),
|
35695
|
+
offset + BASE_VECTOR_OFFSET
|
35696
|
+
];
|
35395
35697
|
}
|
35396
35698
|
};
|
35397
35699
|
var getEncodingVersion = (encoding) => {
|
35398
35700
|
switch (encoding) {
|
35399
35701
|
case void 0:
|
35702
|
+
case ENCODING_V0:
|
35703
|
+
return ENCODING_V0;
|
35400
35704
|
case ENCODING_V1:
|
35401
35705
|
return ENCODING_V1;
|
35402
35706
|
default:
|
@@ -35510,98 +35814,576 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
35510
35814
|
return arg;
|
35511
35815
|
});
|
35512
35816
|
}
|
35513
|
-
static getImplicitGenericTypeParameters(abi, args, implicitGenericParametersParam) {
|
35514
|
-
if (!Array.isArray(args)) {
|
35515
|
-
return null;
|
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.`);
|
35516
36303
|
}
|
35517
|
-
|
35518
|
-
|
35519
|
-
|
35520
|
-
|
35521
|
-
|
35522
|
-
|
35523
|
-
|
35524
|
-
|
35525
|
-
|
35526
|
-
|
35527
|
-
|
36304
|
+
return concatBytes2(this.coders.map((coder, i) => coder.encode(value[i])));
|
36305
|
+
}
|
36306
|
+
decode(data, offset) {
|
36307
|
+
if (data.length < this.encodedLength) {
|
36308
|
+
throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid tuple data size.`);
|
36309
|
+
}
|
36310
|
+
let newOffset = offset;
|
36311
|
+
const decodedValue = this.coders.map((coder) => {
|
36312
|
+
let decoded;
|
36313
|
+
[decoded, newOffset] = coder.decode(data, newOffset);
|
36314
|
+
return decoded;
|
35528
36315
|
});
|
35529
|
-
return
|
36316
|
+
return [decodedValue, newOffset];
|
35530
36317
|
}
|
35531
|
-
|
35532
|
-
|
35533
|
-
|
35534
|
-
|
36318
|
+
};
|
36319
|
+
var VecCoder2 = class extends Coder {
|
36320
|
+
coder;
|
36321
|
+
#isOptionVec;
|
36322
|
+
constructor(coder) {
|
36323
|
+
super("struct", `struct Vec`, coder.encodedLength + WORD_SIZE);
|
36324
|
+
this.coder = coder;
|
36325
|
+
this.#isOptionVec = this.coder instanceof OptionCoder2;
|
35535
36326
|
}
|
35536
|
-
|
35537
|
-
|
35538
|
-
|
35539
|
-
|
35540
|
-
|
35541
|
-
|
35542
|
-
if (arrayMatch) {
|
35543
|
-
return "a";
|
36327
|
+
encode(value) {
|
36328
|
+
if (!Array.isArray(value) && !isUint8Array(value)) {
|
36329
|
+
throw new FuelError(
|
36330
|
+
ErrorCode.ENCODE_ERROR,
|
36331
|
+
`Expected array value, or a Uint8Array. You can use arrayify to convert a value to a Uint8Array.`
|
36332
|
+
);
|
35544
36333
|
}
|
35545
|
-
const
|
35546
|
-
if (
|
35547
|
-
return
|
36334
|
+
const lengthCoder = new BigNumberCoder("u64");
|
36335
|
+
if (isUint8Array(value)) {
|
36336
|
+
return new Uint8Array([...lengthCoder.encode(value.length), ...value]);
|
35548
36337
|
}
|
35549
|
-
|
36338
|
+
const bytes2 = value.map((v) => this.coder.encode(v));
|
36339
|
+
const lengthBytes = lengthCoder.encode(value.length);
|
36340
|
+
return new Uint8Array([...lengthBytes, ...concatBytes2(bytes2)]);
|
35550
36341
|
}
|
35551
|
-
|
35552
|
-
if (this.
|
35553
|
-
|
35554
|
-
}
|
35555
|
-
if (this.type === "raw untyped slice") {
|
35556
|
-
return "rawslice";
|
35557
|
-
}
|
35558
|
-
const strMatch = stringRegEx.exec(this.type)?.groups;
|
35559
|
-
if (strMatch) {
|
35560
|
-
return `str[${strMatch.length}]`;
|
36342
|
+
decode(data, offset) {
|
36343
|
+
if (!this.#isOptionVec && (data.length < this.encodedLength || data.length > MAX_BYTES)) {
|
36344
|
+
throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid vec data size.`);
|
35561
36345
|
}
|
35562
|
-
|
35563
|
-
|
36346
|
+
const offsetAndLength = offset + WORD_SIZE;
|
36347
|
+
const lengthBytes = data.slice(offset, offsetAndLength);
|
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.`);
|
35564
36353
|
}
|
35565
|
-
|
35566
|
-
|
35567
|
-
|
36354
|
+
let newOffset = offsetAndLength;
|
36355
|
+
const chunks = [];
|
36356
|
+
for (let i = 0; i < length; i++) {
|
36357
|
+
const [decoded, optionOffset] = this.coder.decode(data, newOffset);
|
36358
|
+
chunks.push(decoded);
|
36359
|
+
newOffset = optionOffset;
|
35568
36360
|
}
|
35569
|
-
|
35570
|
-
const componentsSignature = `(${this.components.map((c) => c.getSignature()).join(",")})`;
|
35571
|
-
return `${typeArgumentsSignature}${componentsSignature}`;
|
36361
|
+
return [chunks, newOffset];
|
35572
36362
|
}
|
35573
36363
|
};
|
35574
|
-
|
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) => {
|
36364
|
+
var getCoder2 = (resolvedAbiType, _options) => {
|
35583
36365
|
switch (resolvedAbiType.type) {
|
35584
36366
|
case U8_CODER_TYPE:
|
35585
36367
|
case U16_CODER_TYPE:
|
35586
36368
|
case U32_CODER_TYPE:
|
35587
|
-
return new
|
36369
|
+
return new NumberCoder2(resolvedAbiType.type);
|
35588
36370
|
case U64_CODER_TYPE:
|
35589
36371
|
case RAW_PTR_CODER_TYPE:
|
35590
36372
|
return new BigNumberCoder("u64");
|
35591
36373
|
case U256_CODER_TYPE:
|
35592
36374
|
return new BigNumberCoder("u256");
|
35593
36375
|
case RAW_SLICE_CODER_TYPE:
|
35594
|
-
return new
|
36376
|
+
return new RawSliceCoder2();
|
35595
36377
|
case BOOL_CODER_TYPE:
|
35596
|
-
return new
|
36378
|
+
return new BooleanCoder2();
|
35597
36379
|
case B256_CODER_TYPE:
|
35598
36380
|
return new B256Coder();
|
35599
36381
|
case B512_CODER_TYPE:
|
35600
36382
|
return new B512Coder();
|
35601
36383
|
case BYTES_CODER_TYPE:
|
35602
|
-
return new
|
36384
|
+
return new ByteCoder2();
|
35603
36385
|
case STD_STRING_CODER_TYPE:
|
35604
|
-
return new
|
36386
|
+
return new StdStringCoder2();
|
35605
36387
|
case STR_SLICE_CODER_TYPE:
|
35606
36388
|
return new StrSliceCoder();
|
35607
36389
|
default:
|
@@ -35610,7 +36392,7 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
35610
36392
|
const stringMatch = stringRegEx.exec(resolvedAbiType.type)?.groups;
|
35611
36393
|
if (stringMatch) {
|
35612
36394
|
const length = parseInt(stringMatch.length, 10);
|
35613
|
-
return new
|
36395
|
+
return new StringCoder2(length);
|
35614
36396
|
}
|
35615
36397
|
const components = resolvedAbiType.components;
|
35616
36398
|
const arrayMatch = arrayRegEx.exec(resolvedAbiType.type)?.groups;
|
@@ -35623,42 +36405,46 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
35623
36405
|
`The provided Array type is missing an item of 'component'.`
|
35624
36406
|
);
|
35625
36407
|
}
|
35626
|
-
const arrayElementCoder =
|
36408
|
+
const arrayElementCoder = getCoder2(arg, { isSmallBytes: true });
|
35627
36409
|
return new ArrayCoder(arrayElementCoder, length);
|
35628
36410
|
}
|
35629
36411
|
if (resolvedAbiType.type === VEC_CODER_TYPE) {
|
35630
36412
|
const arg = findVectorBufferArgument(components);
|
35631
36413
|
const argType = new ResolvedAbiType(resolvedAbiType.abi, arg);
|
35632
|
-
const itemCoder =
|
35633
|
-
return new
|
36414
|
+
const itemCoder = getCoder2(argType, { isSmallBytes: true, encoding: ENCODING_V0 });
|
36415
|
+
return new VecCoder2(itemCoder);
|
35634
36416
|
}
|
35635
36417
|
const structMatch = structRegEx.exec(resolvedAbiType.type)?.groups;
|
35636
36418
|
if (structMatch) {
|
35637
|
-
const coders = getCoders(components, { getCoder });
|
35638
|
-
return new
|
36419
|
+
const coders = getCoders(components, { isRightPadded: true, getCoder: getCoder2 });
|
36420
|
+
return new StructCoder2(structMatch.name, coders);
|
35639
36421
|
}
|
35640
36422
|
const enumMatch = enumRegEx.exec(resolvedAbiType.type)?.groups;
|
35641
36423
|
if (enumMatch) {
|
35642
|
-
const coders = getCoders(components, { getCoder });
|
36424
|
+
const coders = getCoders(components, { getCoder: getCoder2 });
|
35643
36425
|
const isOptionEnum = resolvedAbiType.type === OPTION_CODER_TYPE;
|
35644
36426
|
if (isOptionEnum) {
|
35645
|
-
return new
|
36427
|
+
return new OptionCoder2(enumMatch.name, coders);
|
35646
36428
|
}
|
35647
|
-
return new
|
36429
|
+
return new EnumCoder2(enumMatch.name, coders);
|
35648
36430
|
}
|
35649
36431
|
const tupleMatch = tupleRegEx.exec(resolvedAbiType.type)?.groups;
|
35650
36432
|
if (tupleMatch) {
|
35651
|
-
const coders = components.map(
|
35652
|
-
|
36433
|
+
const coders = components.map(
|
36434
|
+
(component) => getCoder2(component, { isRightPadded: true, encoding: ENCODING_V0 })
|
36435
|
+
);
|
36436
|
+
return new TupleCoder2(coders);
|
35653
36437
|
}
|
35654
36438
|
throw new FuelError(
|
35655
36439
|
ErrorCode.CODER_NOT_FOUND,
|
35656
36440
|
`Coder not found: ${JSON.stringify(resolvedAbiType)}.`
|
35657
36441
|
);
|
35658
36442
|
};
|
35659
|
-
function getCoderForEncoding(encoding =
|
36443
|
+
function getCoderForEncoding(encoding = ENCODING_V0) {
|
35660
36444
|
switch (encoding) {
|
35661
36445
|
case ENCODING_V1:
|
36446
|
+
return getCoder2;
|
36447
|
+
case ENCODING_V0:
|
35662
36448
|
return getCoder;
|
35663
36449
|
default:
|
35664
36450
|
throw new FuelError(
|
@@ -35669,7 +36455,7 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
35669
36455
|
}
|
35670
36456
|
var AbiCoder = class {
|
35671
36457
|
static getCoder(abi, argument, options = {
|
35672
|
-
|
36458
|
+
isSmallBytes: false
|
35673
36459
|
}) {
|
35674
36460
|
const resolvedAbiType = new ResolvedAbiType(abi, argument);
|
35675
36461
|
return getCoderForEncoding(options.encoding)(resolvedAbiType, options);
|
@@ -35689,6 +36475,8 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
35689
36475
|
name;
|
35690
36476
|
jsonFn;
|
35691
36477
|
attributes;
|
36478
|
+
isInputDataPointer;
|
36479
|
+
outputMetadata;
|
35692
36480
|
jsonAbi;
|
35693
36481
|
constructor(jsonAbi, name) {
|
35694
36482
|
this.jsonAbi = jsonAbi;
|
@@ -35696,8 +36484,13 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
35696
36484
|
this.name = name;
|
35697
36485
|
this.signature = FunctionFragment.getSignature(this.jsonAbi, this.jsonFn);
|
35698
36486
|
this.selector = FunctionFragment.getFunctionSelector(this.signature);
|
35699
|
-
this.selectorBytes = new
|
36487
|
+
this.selectorBytes = new StdStringCoder2().encode(name);
|
35700
36488
|
this.encoding = getEncodingVersion(jsonAbi.encoding);
|
36489
|
+
this.isInputDataPointer = this.#isInputDataPointer();
|
36490
|
+
this.outputMetadata = {
|
36491
|
+
isHeapType: this.#isOutputDataHeap(),
|
36492
|
+
encodedLength: this.#getOutputEncodedLength()
|
36493
|
+
};
|
35701
36494
|
this.attributes = this.jsonFn.attributes ?? [];
|
35702
36495
|
}
|
35703
36496
|
static getSignature(abi, fn) {
|
@@ -35710,7 +36503,29 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
35710
36503
|
const hashedFunctionSignature = sha2562(bufferFromString2(functionSignature, "utf-8"));
|
35711
36504
|
return bn(hashedFunctionSignature.slice(0, 10)).toHex(8);
|
35712
36505
|
}
|
35713
|
-
|
36506
|
+
#isInputDataPointer() {
|
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) {
|
35714
36529
|
FunctionFragment.verifyArgsAndInputsAlign(values, this.jsonFn.inputs, this.jsonAbi);
|
35715
36530
|
const shallowCopyValues = values.slice();
|
35716
36531
|
const nonEmptyInputs = findNonEmptyInputs(this.jsonAbi, this.jsonFn.inputs);
|
@@ -35720,10 +36535,15 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
35720
36535
|
}
|
35721
36536
|
const coders = nonEmptyInputs.map(
|
35722
36537
|
(t) => AbiCoder.getCoder(this.jsonAbi, t, {
|
36538
|
+
isRightPadded: nonEmptyInputs.length > 1,
|
35723
36539
|
encoding: this.encoding
|
35724
36540
|
})
|
35725
36541
|
);
|
35726
|
-
|
36542
|
+
if (this.encoding === ENCODING_V1) {
|
36543
|
+
return new TupleCoder2(coders).encode(shallowCopyValues);
|
36544
|
+
}
|
36545
|
+
const results = new TupleCoder(coders).encode(shallowCopyValues);
|
36546
|
+
return unpackDynamicData(results, offset, results.byteLength);
|
35727
36547
|
}
|
35728
36548
|
static verifyArgsAndInputsAlign(args, inputs, abi) {
|
35729
36549
|
if (args.length === inputs.length) {
|
@@ -35832,9 +36652,9 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
35832
36652
|
const fragment = typeof functionFragment === "string" ? this.getFunction(functionFragment) : functionFragment;
|
35833
36653
|
return fragment.decodeArguments(data);
|
35834
36654
|
}
|
35835
|
-
encodeFunctionData(functionFragment, values) {
|
36655
|
+
encodeFunctionData(functionFragment, values, offset = 0) {
|
35836
36656
|
const fragment = typeof functionFragment === "string" ? this.getFunction(functionFragment) : functionFragment;
|
35837
|
-
return fragment.encodeArguments(values);
|
36657
|
+
return fragment.encodeArguments(values, offset);
|
35838
36658
|
}
|
35839
36659
|
// Decode the result of a function call
|
35840
36660
|
decodeFunctionResult(functionFragment, data) {
|
@@ -35862,7 +36682,9 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
35862
36682
|
);
|
35863
36683
|
}
|
35864
36684
|
return AbiCoder.encode(this.jsonAbi, configurable.configurableType, value, {
|
35865
|
-
|
36685
|
+
isRightPadded: true,
|
36686
|
+
// TODO: Review support for configurables in v1 encoding when it becomes available
|
36687
|
+
encoding: ENCODING_V0
|
35866
36688
|
});
|
35867
36689
|
}
|
35868
36690
|
getTypeById(typeId) {
|
@@ -35912,8 +36734,8 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
35912
36734
|
var TxPointerCoder = class extends StructCoder {
|
35913
36735
|
constructor() {
|
35914
36736
|
super("TxPointer", {
|
35915
|
-
blockHeight: new NumberCoder("u32"
|
35916
|
-
txIndex: new NumberCoder("u16"
|
36737
|
+
blockHeight: new NumberCoder("u32"),
|
36738
|
+
txIndex: new NumberCoder("u16")
|
35917
36739
|
});
|
35918
36740
|
}
|
35919
36741
|
};
|
@@ -35930,12 +36752,12 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
35930
36752
|
encode(value) {
|
35931
36753
|
const parts = [];
|
35932
36754
|
parts.push(new B256Coder().encode(value.txID));
|
35933
|
-
parts.push(new NumberCoder("u16"
|
36755
|
+
parts.push(new NumberCoder("u16").encode(value.outputIndex));
|
35934
36756
|
parts.push(new B256Coder().encode(value.owner));
|
35935
36757
|
parts.push(new BigNumberCoder("u64").encode(value.amount));
|
35936
36758
|
parts.push(new B256Coder().encode(value.assetId));
|
35937
36759
|
parts.push(new TxPointerCoder().encode(value.txPointer));
|
35938
|
-
parts.push(new NumberCoder("u16"
|
36760
|
+
parts.push(new NumberCoder("u16").encode(value.witnessIndex));
|
35939
36761
|
parts.push(new BigNumberCoder("u64").encode(value.predicateGasUsed));
|
35940
36762
|
parts.push(new BigNumberCoder("u64").encode(value.predicateLength));
|
35941
36763
|
parts.push(new BigNumberCoder("u64").encode(value.predicateDataLength));
|
@@ -35950,7 +36772,7 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
35950
36772
|
let o = offset;
|
35951
36773
|
[decoded, o] = new B256Coder().decode(data, o);
|
35952
36774
|
const txID = decoded;
|
35953
|
-
[decoded, o] = new NumberCoder("u16"
|
36775
|
+
[decoded, o] = new NumberCoder("u16").decode(data, o);
|
35954
36776
|
const outputIndex = decoded;
|
35955
36777
|
[decoded, o] = new B256Coder().decode(data, o);
|
35956
36778
|
const owner = decoded;
|
@@ -35960,7 +36782,7 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
35960
36782
|
const assetId = decoded;
|
35961
36783
|
[decoded, o] = new TxPointerCoder().decode(data, o);
|
35962
36784
|
const txPointer = decoded;
|
35963
|
-
[decoded, o] = new NumberCoder("u16"
|
36785
|
+
[decoded, o] = new NumberCoder("u16").decode(data, o);
|
35964
36786
|
const witnessIndex = Number(decoded);
|
35965
36787
|
[decoded, o] = new BigNumberCoder("u64").decode(data, o);
|
35966
36788
|
const predicateGasUsed = decoded;
|
@@ -35999,7 +36821,7 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
35999
36821
|
encode(value) {
|
36000
36822
|
const parts = [];
|
36001
36823
|
parts.push(new B256Coder().encode(value.txID));
|
36002
|
-
parts.push(new NumberCoder("u16"
|
36824
|
+
parts.push(new NumberCoder("u16").encode(value.outputIndex));
|
36003
36825
|
parts.push(new B256Coder().encode(value.balanceRoot));
|
36004
36826
|
parts.push(new B256Coder().encode(value.stateRoot));
|
36005
36827
|
parts.push(new TxPointerCoder().encode(value.txPointer));
|
@@ -36011,7 +36833,7 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
36011
36833
|
let o = offset;
|
36012
36834
|
[decoded, o] = new B256Coder().decode(data, o);
|
36013
36835
|
const txID = decoded;
|
36014
|
-
[decoded, o] = new NumberCoder("u16"
|
36836
|
+
[decoded, o] = new NumberCoder("u16").decode(data, o);
|
36015
36837
|
const outputIndex = decoded;
|
36016
36838
|
[decoded, o] = new B256Coder().decode(data, o);
|
36017
36839
|
const balanceRoot = decoded;
|
@@ -36060,7 +36882,7 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
36060
36882
|
parts.push(new ByteArrayCoder(32).encode(value.recipient));
|
36061
36883
|
parts.push(new BigNumberCoder("u64").encode(value.amount));
|
36062
36884
|
parts.push(new ByteArrayCoder(32).encode(value.nonce));
|
36063
|
-
parts.push(new NumberCoder("u16"
|
36885
|
+
parts.push(new NumberCoder("u16").encode(value.witnessIndex));
|
36064
36886
|
parts.push(new BigNumberCoder("u64").encode(value.predicateGasUsed));
|
36065
36887
|
parts.push(new BigNumberCoder("u64").encode(data.length));
|
36066
36888
|
parts.push(new BigNumberCoder("u64").encode(value.predicateLength));
|
@@ -36089,11 +36911,11 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
36089
36911
|
const amount = decoded;
|
36090
36912
|
[decoded, o] = new B256Coder().decode(data, o);
|
36091
36913
|
const nonce = decoded;
|
36092
|
-
[decoded, o] = new NumberCoder("u16"
|
36914
|
+
[decoded, o] = new NumberCoder("u16").decode(data, o);
|
36093
36915
|
const witnessIndex = Number(decoded);
|
36094
36916
|
[decoded, o] = new BigNumberCoder("u64").decode(data, o);
|
36095
36917
|
const predicateGasUsed = decoded;
|
36096
|
-
[decoded, o] = new NumberCoder("u32"
|
36918
|
+
[decoded, o] = new NumberCoder("u32").decode(data, o);
|
36097
36919
|
const dataLength2 = decoded;
|
36098
36920
|
[decoded, o] = new BigNumberCoder("u64").decode(data, o);
|
36099
36921
|
const predicateLength = decoded;
|
@@ -36131,7 +36953,7 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
36131
36953
|
}
|
36132
36954
|
encode(value) {
|
36133
36955
|
const parts = [];
|
36134
|
-
parts.push(new NumberCoder("u8"
|
36956
|
+
parts.push(new NumberCoder("u8").encode(value.type));
|
36135
36957
|
const { type: type3 } = value;
|
36136
36958
|
switch (type3) {
|
36137
36959
|
case 0: {
|
@@ -36158,7 +36980,7 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
36158
36980
|
decode(data, offset) {
|
36159
36981
|
let decoded;
|
36160
36982
|
let o = offset;
|
36161
|
-
[decoded, o] = new NumberCoder("u8"
|
36983
|
+
[decoded, o] = new NumberCoder("u8").decode(data, o);
|
36162
36984
|
const type3 = decoded;
|
36163
36985
|
switch (type3) {
|
36164
36986
|
case 0: {
|
@@ -36227,7 +37049,7 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
36227
37049
|
}
|
36228
37050
|
encode(value) {
|
36229
37051
|
const parts = [];
|
36230
|
-
parts.push(new NumberCoder("u8"
|
37052
|
+
parts.push(new NumberCoder("u8").encode(value.inputIndex));
|
36231
37053
|
parts.push(new B256Coder().encode(value.balanceRoot));
|
36232
37054
|
parts.push(new B256Coder().encode(value.stateRoot));
|
36233
37055
|
return concat(parts);
|
@@ -36235,7 +37057,7 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
36235
37057
|
decode(data, offset) {
|
36236
37058
|
let decoded;
|
36237
37059
|
let o = offset;
|
36238
|
-
[decoded, o] = new NumberCoder("u8"
|
37060
|
+
[decoded, o] = new NumberCoder("u8").decode(data, o);
|
36239
37061
|
const inputIndex = decoded;
|
36240
37062
|
[decoded, o] = new B256Coder().decode(data, o);
|
36241
37063
|
const balanceRoot = decoded;
|
@@ -36347,7 +37169,7 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
36347
37169
|
}
|
36348
37170
|
encode(value) {
|
36349
37171
|
const parts = [];
|
36350
|
-
parts.push(new NumberCoder("u8"
|
37172
|
+
parts.push(new NumberCoder("u8").encode(value.type));
|
36351
37173
|
const { type: type3 } = value;
|
36352
37174
|
switch (type3) {
|
36353
37175
|
case 0: {
|
@@ -36382,7 +37204,7 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
36382
37204
|
decode(data, offset) {
|
36383
37205
|
let decoded;
|
36384
37206
|
let o = offset;
|
36385
|
-
[decoded, o] = new NumberCoder("u8"
|
37207
|
+
[decoded, o] = new NumberCoder("u8").decode(data, o);
|
36386
37208
|
const type3 = decoded;
|
36387
37209
|
switch (type3) {
|
36388
37210
|
case 0: {
|
@@ -36450,7 +37272,7 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
36450
37272
|
parts.push(new BigNumberCoder("u64").encode(data));
|
36451
37273
|
break;
|
36452
37274
|
case 4:
|
36453
|
-
parts.push(new NumberCoder("u32"
|
37275
|
+
parts.push(new NumberCoder("u32").encode(data));
|
36454
37276
|
break;
|
36455
37277
|
default: {
|
36456
37278
|
throw new FuelError(ErrorCode.INVALID_POLICY_TYPE, `Invalid policy type: ${type3}`);
|
@@ -36473,10 +37295,7 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
36473
37295
|
policies.push({ type: 2, data: witnessLimit });
|
36474
37296
|
}
|
36475
37297
|
if (policyTypes & 4) {
|
36476
|
-
const [maturity, nextOffset] = new NumberCoder("u32"
|
36477
|
-
data,
|
36478
|
-
o
|
36479
|
-
);
|
37298
|
+
const [maturity, nextOffset] = new NumberCoder("u32").decode(data, o);
|
36480
37299
|
o = nextOffset;
|
36481
37300
|
policies.push({ type: 4, data: maturity });
|
36482
37301
|
}
|
@@ -36523,7 +37342,7 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
36523
37342
|
parts.push(new B256Coder().encode(value.recipient));
|
36524
37343
|
parts.push(new BigNumberCoder("u64").encode(value.amount));
|
36525
37344
|
parts.push(new B256Coder().encode(value.nonce));
|
36526
|
-
parts.push(new NumberCoder("u16"
|
37345
|
+
parts.push(new NumberCoder("u16").encode(value.data.length));
|
36527
37346
|
parts.push(new B256Coder().encode(value.digest));
|
36528
37347
|
parts.push(new ByteArrayCoder(value.data.length).encode(value.data));
|
36529
37348
|
return concat(parts);
|
@@ -36539,7 +37358,7 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
36539
37358
|
const amount = decoded;
|
36540
37359
|
[decoded, o] = new B256Coder().decode(data, o);
|
36541
37360
|
const nonce = decoded;
|
36542
|
-
[decoded, o] = new NumberCoder("u16"
|
37361
|
+
[decoded, o] = new NumberCoder("u16").decode(data, o);
|
36543
37362
|
const len = decoded;
|
36544
37363
|
[decoded, o] = new B256Coder().decode(data, o);
|
36545
37364
|
const digest = decoded;
|
@@ -36663,11 +37482,11 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
36663
37482
|
encode(upgradePurposeType) {
|
36664
37483
|
const parts = [];
|
36665
37484
|
const { type: type3 } = upgradePurposeType;
|
36666
|
-
parts.push(new NumberCoder("u8"
|
37485
|
+
parts.push(new NumberCoder("u8").encode(type3));
|
36667
37486
|
switch (type3) {
|
36668
37487
|
case 0: {
|
36669
37488
|
const data = upgradePurposeType.data;
|
36670
|
-
parts.push(new NumberCoder("u16"
|
37489
|
+
parts.push(new NumberCoder("u16").encode(data.witnessIndex));
|
36671
37490
|
parts.push(new B256Coder().encode(data.checksum));
|
36672
37491
|
break;
|
36673
37492
|
}
|
@@ -36688,11 +37507,11 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
36688
37507
|
decode(data, offset) {
|
36689
37508
|
let o = offset;
|
36690
37509
|
let decoded;
|
36691
|
-
[decoded, o] = new NumberCoder("u8"
|
37510
|
+
[decoded, o] = new NumberCoder("u8").decode(data, o);
|
36692
37511
|
const type3 = decoded;
|
36693
37512
|
switch (type3) {
|
36694
37513
|
case 0: {
|
36695
|
-
[decoded, o] = new NumberCoder("u16"
|
37514
|
+
[decoded, o] = new NumberCoder("u16").decode(data, o);
|
36696
37515
|
const witnessIndex = decoded;
|
36697
37516
|
[decoded, o] = new B256Coder().decode(data, o);
|
36698
37517
|
const checksum = decoded;
|
@@ -36723,14 +37542,14 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
36723
37542
|
}
|
36724
37543
|
encode(value) {
|
36725
37544
|
const parts = [];
|
36726
|
-
parts.push(new NumberCoder("u32"
|
37545
|
+
parts.push(new NumberCoder("u32").encode(value.dataLength));
|
36727
37546
|
parts.push(new ByteArrayCoder(value.dataLength).encode(value.data));
|
36728
37547
|
return concat(parts);
|
36729
37548
|
}
|
36730
37549
|
decode(data, offset) {
|
36731
37550
|
let decoded;
|
36732
37551
|
let o = offset;
|
36733
|
-
[decoded, o] = new NumberCoder("u32"
|
37552
|
+
[decoded, o] = new NumberCoder("u32").decode(data, o);
|
36734
37553
|
const dataLength2 = decoded;
|
36735
37554
|
[decoded, o] = new ByteArrayCoder(dataLength2).decode(data, o);
|
36736
37555
|
const witnessData = decoded;
|
@@ -36761,10 +37580,10 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
36761
37580
|
parts.push(new B256Coder().encode(value.receiptsRoot));
|
36762
37581
|
parts.push(new BigNumberCoder("u64").encode(value.scriptLength));
|
36763
37582
|
parts.push(new BigNumberCoder("u64").encode(value.scriptDataLength));
|
36764
|
-
parts.push(new NumberCoder("u32"
|
36765
|
-
parts.push(new NumberCoder("u16"
|
36766
|
-
parts.push(new NumberCoder("u16"
|
36767
|
-
parts.push(new NumberCoder("u16"
|
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));
|
36768
37587
|
parts.push(new ByteArrayCoder(value.scriptLength.toNumber()).encode(value.script));
|
36769
37588
|
parts.push(new ByteArrayCoder(value.scriptDataLength.toNumber()).encode(value.scriptData));
|
36770
37589
|
parts.push(new PoliciesCoder().encode(value.policies));
|
@@ -36784,13 +37603,13 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
36784
37603
|
const scriptLength = decoded;
|
36785
37604
|
[decoded, o] = new BigNumberCoder("u64").decode(data, o);
|
36786
37605
|
const scriptDataLength = decoded;
|
36787
|
-
[decoded, o] = new NumberCoder("u32"
|
37606
|
+
[decoded, o] = new NumberCoder("u32").decode(data, o);
|
36788
37607
|
const policyTypes = decoded;
|
36789
|
-
[decoded, o] = new NumberCoder("u16"
|
37608
|
+
[decoded, o] = new NumberCoder("u16").decode(data, o);
|
36790
37609
|
const inputsCount = decoded;
|
36791
|
-
[decoded, o] = new NumberCoder("u16"
|
37610
|
+
[decoded, o] = new NumberCoder("u16").decode(data, o);
|
36792
37611
|
const outputsCount = decoded;
|
36793
|
-
[decoded, o] = new NumberCoder("u16"
|
37612
|
+
[decoded, o] = new NumberCoder("u16").decode(data, o);
|
36794
37613
|
const witnessesCount = decoded;
|
36795
37614
|
[decoded, o] = new ByteArrayCoder(scriptLength.toNumber()).decode(data, o);
|
36796
37615
|
const script = decoded;
|
@@ -36832,13 +37651,13 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
36832
37651
|
}
|
36833
37652
|
encode(value) {
|
36834
37653
|
const parts = [];
|
36835
|
-
parts.push(new NumberCoder("u16"
|
37654
|
+
parts.push(new NumberCoder("u16").encode(value.bytecodeWitnessIndex));
|
36836
37655
|
parts.push(new B256Coder().encode(value.salt));
|
36837
37656
|
parts.push(new BigNumberCoder("u64").encode(value.storageSlotsCount));
|
36838
|
-
parts.push(new NumberCoder("u32"
|
36839
|
-
parts.push(new NumberCoder("u16"
|
36840
|
-
parts.push(new NumberCoder("u16"
|
36841
|
-
parts.push(new NumberCoder("u16"
|
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));
|
36842
37661
|
parts.push(
|
36843
37662
|
new ArrayCoder(new StorageSlotCoder(), value.storageSlotsCount.toNumber()).encode(
|
36844
37663
|
value.storageSlots
|
@@ -36853,19 +37672,19 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
36853
37672
|
decode(data, offset) {
|
36854
37673
|
let decoded;
|
36855
37674
|
let o = offset;
|
36856
|
-
[decoded, o] = new NumberCoder("u16"
|
37675
|
+
[decoded, o] = new NumberCoder("u16").decode(data, o);
|
36857
37676
|
const bytecodeWitnessIndex = decoded;
|
36858
37677
|
[decoded, o] = new B256Coder().decode(data, o);
|
36859
37678
|
const salt = decoded;
|
36860
37679
|
[decoded, o] = new BigNumberCoder("u64").decode(data, o);
|
36861
37680
|
const storageSlotsCount = decoded;
|
36862
|
-
[decoded, o] = new NumberCoder("u32"
|
37681
|
+
[decoded, o] = new NumberCoder("u32").decode(data, o);
|
36863
37682
|
const policyTypes = decoded;
|
36864
|
-
[decoded, o] = new NumberCoder("u16"
|
37683
|
+
[decoded, o] = new NumberCoder("u16").decode(data, o);
|
36865
37684
|
const inputsCount = decoded;
|
36866
|
-
[decoded, o] = new NumberCoder("u16"
|
37685
|
+
[decoded, o] = new NumberCoder("u16").decode(data, o);
|
36867
37686
|
const outputsCount = decoded;
|
36868
|
-
[decoded, o] = new NumberCoder("u16"
|
37687
|
+
[decoded, o] = new NumberCoder("u16").decode(data, o);
|
36869
37688
|
const witnessesCount = decoded;
|
36870
37689
|
[decoded, o] = new ArrayCoder(new StorageSlotCoder(), storageSlotsCount.toNumber()).decode(
|
36871
37690
|
data,
|
@@ -37079,7 +37898,7 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
37079
37898
|
}
|
37080
37899
|
encode(value) {
|
37081
37900
|
const parts = [];
|
37082
|
-
parts.push(new NumberCoder("u8"
|
37901
|
+
parts.push(new NumberCoder("u8").encode(value.type));
|
37083
37902
|
const { type: type3 } = value;
|
37084
37903
|
switch (value.type) {
|
37085
37904
|
case 0: {
|
@@ -37122,7 +37941,7 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
37122
37941
|
decode(data, offset) {
|
37123
37942
|
let decoded;
|
37124
37943
|
let o = offset;
|
37125
|
-
[decoded, o] = new NumberCoder("u8"
|
37944
|
+
[decoded, o] = new NumberCoder("u8").decode(data, o);
|
37126
37945
|
const type3 = decoded;
|
37127
37946
|
switch (type3) {
|
37128
37947
|
case 0: {
|
@@ -42135,15 +42954,6 @@ ${MessageCoinFragmentDoc}`;
|
|
42135
42954
|
return normalize2(clone_default(root));
|
42136
42955
|
}
|
42137
42956
|
|
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
|
-
|
42147
42957
|
// src/providers/utils/extract-tx-error.ts
|
42148
42958
|
var assemblePanicError = (status) => {
|
42149
42959
|
let errorMessage = `The transaction reverted with reason: "${status.reason}".`;
|
@@ -42757,6 +43567,15 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
|
|
42757
43567
|
}
|
42758
43568
|
});
|
42759
43569
|
}
|
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
|
+
}
|
42760
43579
|
};
|
42761
43580
|
|
42762
43581
|
// src/providers/transaction-request/hash-transaction.ts
|
@@ -43221,27 +44040,37 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
|
|
43221
44040
|
};
|
43222
44041
|
|
43223
44042
|
// src/providers/transaction-summary/call.ts
|
43224
|
-
var getFunctionCall = ({ abi, receipt }) => {
|
44043
|
+
var getFunctionCall = ({ abi, receipt, rawPayload, maxInputs }) => {
|
43225
44044
|
const abiInterface = new Interface(abi);
|
43226
44045
|
const callFunctionSelector = receipt.param1.toHex(8);
|
43227
44046
|
const functionFragment = abiInterface.getFunction(callFunctionSelector);
|
43228
44047
|
const inputs = functionFragment.jsonFn.inputs;
|
43229
|
-
|
44048
|
+
let encodedArgs;
|
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
|
+
}
|
43230
44057
|
let argumentsProvided;
|
43231
|
-
|
43232
|
-
|
43233
|
-
|
43234
|
-
|
43235
|
-
|
43236
|
-
|
43237
|
-
|
43238
|
-
|
43239
|
-
|
43240
|
-
|
43241
|
-
|
43242
|
-
|
43243
|
-
|
43244
|
-
|
44058
|
+
if (encodedArgs) {
|
44059
|
+
const data = functionFragment.decodeArguments(encodedArgs);
|
44060
|
+
if (data) {
|
44061
|
+
argumentsProvided = inputs.reduce((prev, input, index) => {
|
44062
|
+
const value = data[index];
|
44063
|
+
const name = input.name;
|
44064
|
+
if (name) {
|
44065
|
+
return {
|
44066
|
+
...prev,
|
44067
|
+
// reparse to remove bn
|
44068
|
+
[name]: JSON.parse(JSON.stringify(value))
|
44069
|
+
};
|
44070
|
+
}
|
44071
|
+
return prev;
|
44072
|
+
}, {});
|
44073
|
+
}
|
43245
44074
|
}
|
43246
44075
|
const call = {
|
43247
44076
|
functionSignature: functionFragment.signature,
|
@@ -45518,6 +46347,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
45518
46347
|
cacheRequestInputsResourcesFromOwner(request.inputs, this.address)
|
45519
46348
|
);
|
45520
46349
|
request.addResources(resources);
|
46350
|
+
request.shiftPredicateData();
|
45521
46351
|
request.updatePredicateGasUsed(estimatedPredicates);
|
45522
46352
|
const requestToReestimate2 = clone_default(request);
|
45523
46353
|
if (addedSignatures) {
|
@@ -45549,6 +46379,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
45549
46379
|
}
|
45550
46380
|
fundingAttempts += 1;
|
45551
46381
|
}
|
46382
|
+
request.shiftPredicateData();
|
45552
46383
|
request.updatePredicateGasUsed(estimatedPredicates);
|
45553
46384
|
const requestToReestimate = clone_default(request);
|
45554
46385
|
if (addedSignatures) {
|
@@ -50184,6 +51015,40 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
50184
51015
|
}
|
50185
51016
|
}
|
50186
51017
|
};
|
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
|
+
}
|
50187
51052
|
var launchNode = async ({
|
50188
51053
|
ip,
|
50189
51054
|
port,
|
@@ -50191,7 +51056,8 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
50191
51056
|
useSystemFuelCore = false,
|
50192
51057
|
loggingEnabled = true,
|
50193
51058
|
debugEnabled = false,
|
50194
|
-
basePath
|
51059
|
+
basePath,
|
51060
|
+
snapshotConfig = defaultSnapshotConfigs
|
50195
51061
|
}) => (
|
50196
51062
|
// eslint-disable-next-line no-async-promise-executor
|
50197
51063
|
new Promise(async (resolve, reject) => {
|
@@ -50220,56 +51086,23 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
50220
51086
|
let snapshotDirToUse;
|
50221
51087
|
const prefix = basePath || import_os.default.tmpdir();
|
50222
51088
|
const suffix = basePath ? "" : (0, import_crypto19.randomUUID)();
|
50223
|
-
const
|
51089
|
+
const tempDir = import_path8.default.join(prefix, ".fuels", suffix, "snapshotDir");
|
50224
51090
|
if (snapshotDir) {
|
50225
51091
|
snapshotDirToUse = snapshotDir;
|
50226
51092
|
} else {
|
50227
|
-
if (!(0, import_fs2.existsSync)(
|
50228
|
-
(0, import_fs2.mkdirSync)(
|
50229
|
-
}
|
50230
|
-
|
50231
|
-
const
|
50232
|
-
|
50233
|
-
|
50234
|
-
|
50235
|
-
|
50236
|
-
|
50237
|
-
|
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;
|
51093
|
+
if (!(0, import_fs2.existsSync)(tempDir)) {
|
51094
|
+
(0, import_fs2.mkdirSync)(tempDir, { recursive: true });
|
51095
|
+
}
|
51096
|
+
const { metadata } = snapshotConfig;
|
51097
|
+
const metadataPath = import_path8.default.join(tempDir, "metadata.json");
|
51098
|
+
const chainConfigPath = import_path8.default.join(tempDir, metadata.chain_config);
|
51099
|
+
const stateConfigPath = import_path8.default.join(tempDir, metadata.table_encoding.Json.filepath);
|
51100
|
+
const stateTransitionPath = import_path8.default.join(tempDir, "state_transition_bytecode.wasm");
|
51101
|
+
(0, import_fs2.writeFileSync)(chainConfigPath, JSON.stringify(snapshotConfig.chainConfig), "utf8");
|
51102
|
+
(0, import_fs2.writeFileSync)(stateConfigPath, getFinalStateConfigJSON(snapshotConfig), "utf8");
|
51103
|
+
(0, import_fs2.writeFileSync)(metadataPath, JSON.stringify(metadata), "utf8");
|
51104
|
+
(0, import_fs2.writeFileSync)(stateTransitionPath, JSON.stringify(""));
|
51105
|
+
snapshotDirToUse = tempDir;
|
50273
51106
|
}
|
50274
51107
|
const child = (0, import_child_process.spawn)(
|
50275
51108
|
command,
|
@@ -50277,7 +51110,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
50277
51110
|
"run",
|
50278
51111
|
["--ip", ipToUse],
|
50279
51112
|
["--port", portToUse],
|
50280
|
-
useInMemoryDb ? ["--db-type", "in-memory"] : ["--db-path",
|
51113
|
+
useInMemoryDb ? ["--db-type", "in-memory"] : ["--db-path", tempDir],
|
50281
51114
|
["--min-gas-price", "1"],
|
50282
51115
|
poaInstant ? ["--poa-instant", "true"] : [],
|
50283
51116
|
["--consensus-key", consensusKey],
|
@@ -50299,23 +51132,28 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
50299
51132
|
}
|
50300
51133
|
const cleanupConfig = {
|
50301
51134
|
child,
|
50302
|
-
configPath:
|
51135
|
+
configPath: tempDir,
|
50303
51136
|
killFn: import_tree_kill.default,
|
50304
51137
|
state: {
|
50305
51138
|
isDead: false
|
50306
51139
|
}
|
50307
51140
|
};
|
50308
51141
|
child.stderr.on("data", (chunk) => {
|
50309
|
-
|
51142
|
+
const text = typeof chunk === "string" ? chunk : chunk.toString();
|
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(":");
|
50310
51147
|
resolve({
|
50311
51148
|
cleanup: () => killNode(cleanupConfig),
|
50312
|
-
ip:
|
50313
|
-
port:
|
51149
|
+
ip: realIp,
|
51150
|
+
port: realPort,
|
51151
|
+
url: `http://${realIp}:${realPort}/v1/graphql`,
|
50314
51152
|
snapshotDir: snapshotDirToUse
|
50315
51153
|
});
|
50316
51154
|
}
|
50317
|
-
if (/error/i.test(
|
50318
|
-
reject(
|
51155
|
+
if (/error/i.test(text)) {
|
51156
|
+
reject(text.toString());
|
50319
51157
|
}
|
50320
51158
|
});
|
50321
51159
|
process.on("exit", () => killNode(cleanupConfig));
|
@@ -50348,6 +51186,215 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
50348
51186
|
};
|
50349
51187
|
return { wallets, stop: cleanup, provider };
|
50350
51188
|
};
|
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
|
+
};
|
50351
51398
|
})();
|
50352
51399
|
/*! Bundled license information:
|
50353
51400
|
|