@fuel-ts/account 0.0.0-pr-1788-20240222094224 → 0.75.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of @fuel-ts/account might be problematic. Click here for more details.
- package/dist/connectors/fuel-connector.d.ts +2 -1
- package/dist/connectors/fuel-connector.d.ts.map +1 -1
- package/dist/connectors/types/data-type.d.ts +0 -8
- package/dist/connectors/types/data-type.d.ts.map +1 -1
- package/dist/connectors/types/events.d.ts +2 -36
- package/dist/connectors/types/events.d.ts.map +1 -1
- package/dist/connectors/types/index.d.ts +0 -2
- package/dist/connectors/types/index.d.ts.map +1 -1
- package/dist/index.global.js +543 -409
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +143 -172
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +132 -159
- package/dist/index.mjs.map +1 -1
- package/dist/providers/fuel-graphql-subscriber.d.ts +13 -3
- package/dist/providers/fuel-graphql-subscriber.d.ts.map +1 -1
- package/dist/providers/provider.d.ts +9 -3
- package/dist/providers/provider.d.ts.map +1 -1
- package/dist/providers/transaction-request/transaction-request.d.ts.map +1 -1
- package/dist/providers/transaction-summary/operations.d.ts +0 -2
- package/dist/providers/transaction-summary/operations.d.ts.map +1 -1
- package/dist/providers/transaction-summary/output.d.ts +2 -2
- package/dist/providers/transaction-summary/output.d.ts.map +1 -1
- package/dist/providers/transaction-summary/types.d.ts +0 -1
- package/dist/providers/transaction-summary/types.d.ts.map +1 -1
- package/dist/test-utils.global.js +543 -400
- package/dist/test-utils.global.js.map +1 -1
- package/dist/test-utils.js +144 -160
- package/dist/test-utils.js.map +1 -1
- package/dist/test-utils.mjs +132 -148
- package/dist/test-utils.mjs.map +1 -1
- package/package.json +16 -16
- package/dist/connectors/types/asset.d.ts +0 -2
- package/dist/connectors/types/asset.d.ts.map +0 -1
- package/dist/connectors/types/constants.d.ts +0 -7
- package/dist/connectors/types/constants.d.ts.map +0 -1
- package/dist/connectors/types/message.d.ts +0 -15
- package/dist/connectors/types/message.d.ts.map +0 -1
package/dist/index.global.js
CHANGED
@@ -30104,7 +30104,7 @@ spurious results.`);
|
|
30104
30104
|
return {
|
30105
30105
|
FORC: "0.50.0",
|
30106
30106
|
FUEL_CORE: "0.22.1",
|
30107
|
-
FUELS: "0.
|
30107
|
+
FUELS: "0.75.0"
|
30108
30108
|
};
|
30109
30109
|
}
|
30110
30110
|
function parseVersion(version2) {
|
@@ -30170,6 +30170,7 @@ spurious results.`);
|
|
30170
30170
|
ErrorCode2["CODER_NOT_FOUND"] = "coder-not-found";
|
30171
30171
|
ErrorCode2["INVALID_DATA"] = "invalid-data";
|
30172
30172
|
ErrorCode2["FUNCTION_NOT_FOUND"] = "function-not-found";
|
30173
|
+
ErrorCode2["UNSUPPORTED_ENCODING_VERSION"] = "unsupported-encoding-version";
|
30173
30174
|
ErrorCode2["INVALID_BECH32_ADDRESS"] = "invalid-bech32-address";
|
30174
30175
|
ErrorCode2["INVALID_EVM_ADDRESS"] = "invalid-evm-address";
|
30175
30176
|
ErrorCode2["INVALID_B256_ADDRESS"] = "invalid-b256-address";
|
@@ -32680,16 +32681,28 @@ spurious results.`);
|
|
32680
32681
|
this.encodedLength = encodedLength;
|
32681
32682
|
}
|
32682
32683
|
};
|
32684
|
+
var U8_CODER_TYPE = "u8";
|
32685
|
+
var U16_CODER_TYPE = "u16";
|
32686
|
+
var U32_CODER_TYPE = "u32";
|
32687
|
+
var U64_CODER_TYPE = "u64";
|
32688
|
+
var RAW_PTR_CODER_TYPE = "raw untyped ptr";
|
32689
|
+
var RAW_SLICE_CODER_TYPE = "raw untyped slice";
|
32690
|
+
var BOOL_CODER_TYPE = "bool";
|
32691
|
+
var B256_CODER_TYPE = "b256";
|
32692
|
+
var B512_CODER_TYPE = "struct B512";
|
32683
32693
|
var OPTION_CODER_TYPE = "enum Option";
|
32684
32694
|
var VEC_CODER_TYPE = "struct Vec";
|
32685
32695
|
var BYTES_CODER_TYPE = "struct Bytes";
|
32686
32696
|
var STD_STRING_CODER_TYPE = "struct String";
|
32697
|
+
var STR_SLICE_CODER_TYPE = "str";
|
32687
32698
|
var stringRegEx = /str\[(?<length>[0-9]+)\]/;
|
32688
32699
|
var arrayRegEx = /\[(?<item>[\w\s\\[\]]+);\s*(?<length>[0-9]+)\]/;
|
32689
32700
|
var structRegEx = /^struct (?<name>\w+)$/;
|
32690
32701
|
var enumRegEx = /^enum (?<name>\w+)$/;
|
32691
32702
|
var tupleRegEx = /^\((?<items>.*)\)$/;
|
32692
32703
|
var genericRegEx = /^generic (?<name>\w+)$/;
|
32704
|
+
var ENCODING_V0 = "0";
|
32705
|
+
var ENCODING_V1 = "1";
|
32693
32706
|
var WORD_SIZE = 8;
|
32694
32707
|
var BYTES_32 = 32;
|
32695
32708
|
var ASSET_ID_LEN = BYTES_32;
|
@@ -33430,6 +33443,246 @@ spurious results.`);
|
|
33430
33443
|
];
|
33431
33444
|
}
|
33432
33445
|
};
|
33446
|
+
var ResolvedAbiType = class {
|
33447
|
+
abi;
|
33448
|
+
name;
|
33449
|
+
type;
|
33450
|
+
originalTypeArguments;
|
33451
|
+
components;
|
33452
|
+
constructor(abi, argument) {
|
33453
|
+
this.abi = abi;
|
33454
|
+
const type3 = findOrThrow(
|
33455
|
+
abi.types,
|
33456
|
+
(t) => t.typeId === argument.type,
|
33457
|
+
() => {
|
33458
|
+
throw new FuelError(
|
33459
|
+
ErrorCode.TYPE_NOT_FOUND,
|
33460
|
+
`Type does not exist in the provided abi: ${JSON.stringify({
|
33461
|
+
argument,
|
33462
|
+
abi: this.abi
|
33463
|
+
})}`
|
33464
|
+
);
|
33465
|
+
}
|
33466
|
+
);
|
33467
|
+
this.name = argument.name;
|
33468
|
+
this.type = type3.type;
|
33469
|
+
this.originalTypeArguments = argument.typeArguments;
|
33470
|
+
this.components = ResolvedAbiType.getResolvedGenericComponents(
|
33471
|
+
abi,
|
33472
|
+
argument,
|
33473
|
+
type3.components,
|
33474
|
+
type3.typeParameters ?? ResolvedAbiType.getImplicitGenericTypeParameters(abi, type3.components)
|
33475
|
+
);
|
33476
|
+
}
|
33477
|
+
static getResolvedGenericComponents(abi, arg, components, typeParameters) {
|
33478
|
+
if (components === null) {
|
33479
|
+
return null;
|
33480
|
+
}
|
33481
|
+
if (typeParameters === null || typeParameters.length === 0) {
|
33482
|
+
return components.map((c) => new ResolvedAbiType(abi, c));
|
33483
|
+
}
|
33484
|
+
const typeParametersAndArgsMap = typeParameters.reduce(
|
33485
|
+
(obj, typeParameter, typeParameterIndex) => {
|
33486
|
+
const o = { ...obj };
|
33487
|
+
o[typeParameter] = structuredClone(
|
33488
|
+
arg.typeArguments?.[typeParameterIndex]
|
33489
|
+
);
|
33490
|
+
return o;
|
33491
|
+
},
|
33492
|
+
{}
|
33493
|
+
);
|
33494
|
+
const resolvedComponents = this.resolveGenericArgTypes(
|
33495
|
+
abi,
|
33496
|
+
components,
|
33497
|
+
typeParametersAndArgsMap
|
33498
|
+
);
|
33499
|
+
return resolvedComponents.map((c) => new ResolvedAbiType(abi, c));
|
33500
|
+
}
|
33501
|
+
static resolveGenericArgTypes(abi, args, typeParametersAndArgsMap) {
|
33502
|
+
return args.map((arg) => {
|
33503
|
+
if (typeParametersAndArgsMap[arg.type] !== void 0) {
|
33504
|
+
return {
|
33505
|
+
...typeParametersAndArgsMap[arg.type],
|
33506
|
+
name: arg.name
|
33507
|
+
};
|
33508
|
+
}
|
33509
|
+
if (arg.typeArguments) {
|
33510
|
+
return {
|
33511
|
+
...structuredClone(arg),
|
33512
|
+
typeArguments: this.resolveGenericArgTypes(
|
33513
|
+
abi,
|
33514
|
+
arg.typeArguments,
|
33515
|
+
typeParametersAndArgsMap
|
33516
|
+
)
|
33517
|
+
};
|
33518
|
+
}
|
33519
|
+
const argType = findOrThrow(abi.types, (t) => t.typeId === arg.type);
|
33520
|
+
const implicitTypeParameters = this.getImplicitGenericTypeParameters(abi, argType.components);
|
33521
|
+
if (implicitTypeParameters && implicitTypeParameters.length > 0) {
|
33522
|
+
return {
|
33523
|
+
...structuredClone(arg),
|
33524
|
+
typeArguments: implicitTypeParameters.map((itp) => typeParametersAndArgsMap[itp])
|
33525
|
+
};
|
33526
|
+
}
|
33527
|
+
return arg;
|
33528
|
+
});
|
33529
|
+
}
|
33530
|
+
static getImplicitGenericTypeParameters(abi, args, implicitGenericParametersParam) {
|
33531
|
+
if (!Array.isArray(args)) {
|
33532
|
+
return null;
|
33533
|
+
}
|
33534
|
+
const implicitGenericParameters = implicitGenericParametersParam ?? [];
|
33535
|
+
args.forEach((a) => {
|
33536
|
+
const argType = findOrThrow(abi.types, (t) => t.typeId === a.type);
|
33537
|
+
if (genericRegEx.test(argType.type)) {
|
33538
|
+
implicitGenericParameters.push(argType.typeId);
|
33539
|
+
return;
|
33540
|
+
}
|
33541
|
+
if (!Array.isArray(a.typeArguments)) {
|
33542
|
+
return;
|
33543
|
+
}
|
33544
|
+
this.getImplicitGenericTypeParameters(abi, a.typeArguments, implicitGenericParameters);
|
33545
|
+
});
|
33546
|
+
return implicitGenericParameters.length > 0 ? implicitGenericParameters : null;
|
33547
|
+
}
|
33548
|
+
getSignature() {
|
33549
|
+
const prefix = this.getArgSignaturePrefix();
|
33550
|
+
const content = this.getArgSignatureContent();
|
33551
|
+
return `${prefix}${content}`;
|
33552
|
+
}
|
33553
|
+
getArgSignaturePrefix() {
|
33554
|
+
const structMatch = structRegEx.test(this.type);
|
33555
|
+
if (structMatch) {
|
33556
|
+
return "s";
|
33557
|
+
}
|
33558
|
+
const arrayMatch = arrayRegEx.test(this.type);
|
33559
|
+
if (arrayMatch) {
|
33560
|
+
return "a";
|
33561
|
+
}
|
33562
|
+
const enumMatch = enumRegEx.test(this.type);
|
33563
|
+
if (enumMatch) {
|
33564
|
+
return "e";
|
33565
|
+
}
|
33566
|
+
return "";
|
33567
|
+
}
|
33568
|
+
getArgSignatureContent() {
|
33569
|
+
if (this.type === "raw untyped ptr") {
|
33570
|
+
return "rawptr";
|
33571
|
+
}
|
33572
|
+
if (this.type === "raw untyped slice") {
|
33573
|
+
return "rawslice";
|
33574
|
+
}
|
33575
|
+
const strMatch = stringRegEx.exec(this.type)?.groups;
|
33576
|
+
if (strMatch) {
|
33577
|
+
return `str[${strMatch.length}]`;
|
33578
|
+
}
|
33579
|
+
if (this.components === null) {
|
33580
|
+
return this.type;
|
33581
|
+
}
|
33582
|
+
const arrayMatch = arrayRegEx.exec(this.type)?.groups;
|
33583
|
+
if (arrayMatch) {
|
33584
|
+
return `[${this.components[0].getSignature()};${arrayMatch.length}]`;
|
33585
|
+
}
|
33586
|
+
const typeArgumentsSignature = this.originalTypeArguments !== null ? `<${this.originalTypeArguments.map((a) => new ResolvedAbiType(this.abi, a).getSignature()).join(",")}>` : "";
|
33587
|
+
const componentsSignature = `(${this.components.map((c) => c.getSignature()).join(",")})`;
|
33588
|
+
return `${typeArgumentsSignature}${componentsSignature}`;
|
33589
|
+
}
|
33590
|
+
};
|
33591
|
+
function getCoders(components, options) {
|
33592
|
+
const { getCoder: getCoder3 } = options;
|
33593
|
+
return components.reduce((obj, component) => {
|
33594
|
+
const o = obj;
|
33595
|
+
o[component.name] = getCoder3(component, options);
|
33596
|
+
return o;
|
33597
|
+
}, {});
|
33598
|
+
}
|
33599
|
+
var getCoder = (resolvedAbiType, options) => {
|
33600
|
+
switch (resolvedAbiType.type) {
|
33601
|
+
case U8_CODER_TYPE:
|
33602
|
+
case U16_CODER_TYPE:
|
33603
|
+
case U32_CODER_TYPE:
|
33604
|
+
return new NumberCoder(resolvedAbiType.type, options);
|
33605
|
+
case U64_CODER_TYPE:
|
33606
|
+
case RAW_PTR_CODER_TYPE:
|
33607
|
+
return new U64Coder();
|
33608
|
+
case RAW_SLICE_CODER_TYPE:
|
33609
|
+
return new RawSliceCoder();
|
33610
|
+
case BOOL_CODER_TYPE:
|
33611
|
+
return new BooleanCoder(options);
|
33612
|
+
case B256_CODER_TYPE:
|
33613
|
+
return new B256Coder();
|
33614
|
+
case B512_CODER_TYPE:
|
33615
|
+
return new B512Coder();
|
33616
|
+
case BYTES_CODER_TYPE:
|
33617
|
+
return new ByteCoder();
|
33618
|
+
case STD_STRING_CODER_TYPE:
|
33619
|
+
return new StdStringCoder();
|
33620
|
+
default:
|
33621
|
+
break;
|
33622
|
+
}
|
33623
|
+
const stringMatch = stringRegEx.exec(resolvedAbiType.type)?.groups;
|
33624
|
+
if (stringMatch) {
|
33625
|
+
const length = parseInt(stringMatch.length, 10);
|
33626
|
+
return new StringCoder(length);
|
33627
|
+
}
|
33628
|
+
const components = resolvedAbiType.components;
|
33629
|
+
const arrayMatch = arrayRegEx.exec(resolvedAbiType.type)?.groups;
|
33630
|
+
if (arrayMatch) {
|
33631
|
+
const length = parseInt(arrayMatch.length, 10);
|
33632
|
+
const arg = components[0];
|
33633
|
+
if (!arg) {
|
33634
|
+
throw new FuelError(
|
33635
|
+
ErrorCode.INVALID_COMPONENT,
|
33636
|
+
`The provided Array type is missing an item of 'component'.`
|
33637
|
+
);
|
33638
|
+
}
|
33639
|
+
const arrayElementCoder = getCoder(arg, { isSmallBytes: true });
|
33640
|
+
return new ArrayCoder(arrayElementCoder, length);
|
33641
|
+
}
|
33642
|
+
if (resolvedAbiType.type === VEC_CODER_TYPE) {
|
33643
|
+
const arg = findOrThrow(components, (c) => c.name === "buf").originalTypeArguments?.[0];
|
33644
|
+
if (!arg) {
|
33645
|
+
throw new FuelError(
|
33646
|
+
ErrorCode.INVALID_COMPONENT,
|
33647
|
+
`The provided Vec type is missing the 'type argument'.`
|
33648
|
+
);
|
33649
|
+
}
|
33650
|
+
const argType = new ResolvedAbiType(resolvedAbiType.abi, arg);
|
33651
|
+
const itemCoder = getCoder(argType, { isSmallBytes: true, encoding: ENCODING_V0 });
|
33652
|
+
return new VecCoder(itemCoder);
|
33653
|
+
}
|
33654
|
+
const structMatch = structRegEx.exec(resolvedAbiType.type)?.groups;
|
33655
|
+
if (structMatch) {
|
33656
|
+
const coders = getCoders(components, { isRightPadded: true, getCoder });
|
33657
|
+
return new StructCoder(structMatch.name, coders);
|
33658
|
+
}
|
33659
|
+
const enumMatch = enumRegEx.exec(resolvedAbiType.type)?.groups;
|
33660
|
+
if (enumMatch) {
|
33661
|
+
const coders = getCoders(components, { getCoder });
|
33662
|
+
const isOptionEnum = resolvedAbiType.type === OPTION_CODER_TYPE;
|
33663
|
+
if (isOptionEnum) {
|
33664
|
+
return new OptionCoder(enumMatch.name, coders);
|
33665
|
+
}
|
33666
|
+
return new EnumCoder(enumMatch.name, coders);
|
33667
|
+
}
|
33668
|
+
const tupleMatch = tupleRegEx.exec(resolvedAbiType.type)?.groups;
|
33669
|
+
if (tupleMatch) {
|
33670
|
+
const coders = components.map(
|
33671
|
+
(component) => getCoder(component, { isRightPadded: true, encoding: ENCODING_V0 })
|
33672
|
+
);
|
33673
|
+
return new TupleCoder(coders);
|
33674
|
+
}
|
33675
|
+
if (resolvedAbiType.type === STR_SLICE_CODER_TYPE) {
|
33676
|
+
throw new FuelError(
|
33677
|
+
ErrorCode.INVALID_DATA,
|
33678
|
+
"String slices can not be decoded from logs. Convert the slice to `str[N]` with `__to_str_array`"
|
33679
|
+
);
|
33680
|
+
}
|
33681
|
+
throw new FuelError(
|
33682
|
+
ErrorCode.CODER_NOT_FOUND,
|
33683
|
+
`Coder not found: ${JSON.stringify(resolvedAbiType)}.`
|
33684
|
+
);
|
33685
|
+
};
|
33433
33686
|
var BooleanCoder2 = class extends Coder {
|
33434
33687
|
constructor() {
|
33435
33688
|
super("boolean", "boolean", 1);
|
@@ -33457,10 +33710,15 @@ spurious results.`);
|
|
33457
33710
|
};
|
33458
33711
|
var ByteCoder2 = class extends Coder {
|
33459
33712
|
constructor() {
|
33460
|
-
super("struct", "struct Bytes",
|
33713
|
+
super("struct", "struct Bytes", WORD_SIZE);
|
33461
33714
|
}
|
33462
|
-
encode(
|
33463
|
-
|
33715
|
+
encode(value) {
|
33716
|
+
if (!Array.isArray(value)) {
|
33717
|
+
throw new FuelError(ErrorCode.ENCODE_ERROR, `Expected array value.`);
|
33718
|
+
}
|
33719
|
+
const bytes4 = new Uint8Array(value);
|
33720
|
+
const lengthBytes = new U64Coder().encode(value.length);
|
33721
|
+
return new Uint8Array([...lengthBytes, ...bytes4]);
|
33464
33722
|
}
|
33465
33723
|
decode(data, offset) {
|
33466
33724
|
if (data.length < WORD_SIZE) {
|
@@ -33469,12 +33727,11 @@ spurious results.`);
|
|
33469
33727
|
const offsetAndLength = offset + WORD_SIZE;
|
33470
33728
|
const lengthBytes = data.slice(offset, offsetAndLength);
|
33471
33729
|
const length = bn(new U64Coder().decode(lengthBytes, 0)[0]).toNumber();
|
33472
|
-
const
|
33473
|
-
const dataBytes = data.slice(offsetAndLength, offsetAndLength + dataLength2);
|
33730
|
+
const dataBytes = data.slice(offsetAndLength, offsetAndLength + length);
|
33474
33731
|
if (dataBytes.length !== length) {
|
33475
33732
|
throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid bytes byte data size.`);
|
33476
33733
|
}
|
33477
|
-
return [dataBytes,
|
33734
|
+
return [dataBytes, offsetAndLength + length];
|
33478
33735
|
}
|
33479
33736
|
};
|
33480
33737
|
__publicField3(ByteCoder2, "memorySize", 1);
|
@@ -33499,8 +33756,28 @@ spurious results.`);
|
|
33499
33756
|
this.#caseIndexCoder = caseIndexCoder;
|
33500
33757
|
this.#encodedValueSize = encodedValueSize;
|
33501
33758
|
}
|
33502
|
-
|
33503
|
-
|
33759
|
+
#encodeNativeEnum(value) {
|
33760
|
+
const valueCoder = this.coders[value];
|
33761
|
+
const encodedValue = valueCoder.encode([]);
|
33762
|
+
const caseIndex = Object.keys(this.coders).indexOf(value);
|
33763
|
+
const padding = new Uint8Array(this.#encodedValueSize - valueCoder.encodedLength);
|
33764
|
+
return concat([this.#caseIndexCoder.encode(caseIndex), padding, encodedValue]);
|
33765
|
+
}
|
33766
|
+
encode(value) {
|
33767
|
+
if (typeof value === "string" && this.coders[value]) {
|
33768
|
+
return this.#encodeNativeEnum(value);
|
33769
|
+
}
|
33770
|
+
const [caseKey, ...empty] = Object.keys(value);
|
33771
|
+
if (!caseKey) {
|
33772
|
+
throw new FuelError(ErrorCode.INVALID_DECODE_VALUE, "A field for the case must be provided.");
|
33773
|
+
}
|
33774
|
+
if (empty.length !== 0) {
|
33775
|
+
throw new FuelError(ErrorCode.INVALID_DECODE_VALUE, "Only one field must be provided.");
|
33776
|
+
}
|
33777
|
+
const valueCoder = this.coders[caseKey];
|
33778
|
+
const caseIndex = Object.keys(this.coders).indexOf(caseKey);
|
33779
|
+
const encodedValue = valueCoder.encode(value[caseKey]);
|
33780
|
+
return new Uint8Array([...this.#caseIndexCoder.encode(caseIndex), ...encodedValue]);
|
33504
33781
|
}
|
33505
33782
|
#decodeNativeEnum(caseKey, newOffset) {
|
33506
33783
|
return [caseKey, newOffset];
|
@@ -33575,8 +33852,14 @@ spurious results.`);
|
|
33575
33852
|
constructor() {
|
33576
33853
|
super("raw untyped slice", "raw untyped slice", WORD_SIZE);
|
33577
33854
|
}
|
33578
|
-
encode(
|
33579
|
-
|
33855
|
+
encode(value) {
|
33856
|
+
if (!Array.isArray(value)) {
|
33857
|
+
throw new FuelError(ErrorCode.ENCODE_ERROR, `Expected array value.`);
|
33858
|
+
}
|
33859
|
+
const internalCoder = new ArrayCoder(new NumberCoder2("u8"), value.length);
|
33860
|
+
const bytes4 = internalCoder.encode(value);
|
33861
|
+
const lengthBytes = new U64Coder().encode(bytes4.length);
|
33862
|
+
return new Uint8Array([...lengthBytes, ...bytes4]);
|
33580
33863
|
}
|
33581
33864
|
decode(data, offset) {
|
33582
33865
|
if (data.length < this.encodedLength) {
|
@@ -33598,8 +33881,10 @@ spurious results.`);
|
|
33598
33881
|
constructor() {
|
33599
33882
|
super("struct", "struct String", WORD_SIZE);
|
33600
33883
|
}
|
33601
|
-
encode(
|
33602
|
-
|
33884
|
+
encode(value) {
|
33885
|
+
const bytes4 = toUtf8Bytes(value);
|
33886
|
+
const lengthBytes = new U64Coder().encode(value.length);
|
33887
|
+
return new Uint8Array([...lengthBytes, ...bytes4]);
|
33603
33888
|
}
|
33604
33889
|
decode(data, offset) {
|
33605
33890
|
if (data.length < this.encodedLength) {
|
@@ -33649,8 +33934,20 @@ spurious results.`);
|
|
33649
33934
|
this.name = name;
|
33650
33935
|
this.coders = coders;
|
33651
33936
|
}
|
33652
|
-
encode(
|
33653
|
-
|
33937
|
+
encode(value) {
|
33938
|
+
return concatBytes2(
|
33939
|
+
Object.keys(this.coders).map((fieldName) => {
|
33940
|
+
const fieldCoder = this.coders[fieldName];
|
33941
|
+
const fieldValue = value[fieldName];
|
33942
|
+
if (!(fieldCoder instanceof OptionCoder) && fieldValue == null) {
|
33943
|
+
throw new FuelError(
|
33944
|
+
ErrorCode.ENCODE_ERROR,
|
33945
|
+
`Invalid ${this.type}. Field "${fieldName}" not present.`
|
33946
|
+
);
|
33947
|
+
}
|
33948
|
+
return fieldCoder.encode(fieldValue);
|
33949
|
+
})
|
33950
|
+
);
|
33654
33951
|
}
|
33655
33952
|
decode(data, offset) {
|
33656
33953
|
if (data.length < this.encodedLength) {
|
@@ -33678,7 +33975,7 @@ spurious results.`);
|
|
33678
33975
|
if (this.coders.length !== value.length) {
|
33679
33976
|
throw new FuelError(ErrorCode.ENCODE_ERROR, `Types/values length mismatch.`);
|
33680
33977
|
}
|
33681
|
-
|
33978
|
+
return concatBytes2(this.coders.map((coder, i) => coder.encode(value[i])));
|
33682
33979
|
}
|
33683
33980
|
decode(data, offset) {
|
33684
33981
|
if (data.length < this.encodedLength) {
|
@@ -33699,8 +33996,13 @@ spurious results.`);
|
|
33699
33996
|
super("struct", `struct Vec`, coder.encodedLength + WORD_SIZE);
|
33700
33997
|
this.coder = coder;
|
33701
33998
|
}
|
33702
|
-
encode(
|
33703
|
-
|
33999
|
+
encode(value) {
|
34000
|
+
if (!Array.isArray(value)) {
|
34001
|
+
throw new FuelError(ErrorCode.ENCODE_ERROR, `Expected array value.`);
|
34002
|
+
}
|
34003
|
+
const bytes4 = value.map((v) => this.coder.encode(v));
|
34004
|
+
const lengthBytes = new U64Coder().encode(value.length);
|
34005
|
+
return new Uint8Array([...lengthBytes, ...concatBytes2(bytes4)]);
|
33704
34006
|
}
|
33705
34007
|
decode(data, offset) {
|
33706
34008
|
if (data.length < this.encodedLength || data.length > MAX_BYTES) {
|
@@ -33722,157 +34024,112 @@ spurious results.`);
|
|
33722
34024
|
];
|
33723
34025
|
}
|
33724
34026
|
};
|
33725
|
-
var
|
33726
|
-
|
33727
|
-
|
33728
|
-
|
33729
|
-
|
33730
|
-
|
33731
|
-
|
33732
|
-
|
33733
|
-
|
33734
|
-
|
33735
|
-
(
|
33736
|
-
|
33737
|
-
|
33738
|
-
|
33739
|
-
|
33740
|
-
|
33741
|
-
|
33742
|
-
|
33743
|
-
|
33744
|
-
|
33745
|
-
|
33746
|
-
|
33747
|
-
|
33748
|
-
this.originalTypeArguments = argument.typeArguments;
|
33749
|
-
this.components = ResolvedAbiType.getResolvedGenericComponents(
|
33750
|
-
abi,
|
33751
|
-
argument,
|
33752
|
-
type3.components,
|
33753
|
-
type3.typeParameters ?? ResolvedAbiType.getImplicitGenericTypeParameters(abi, type3.components)
|
33754
|
-
);
|
34027
|
+
var getCoder2 = (resolvedAbiType, _options) => {
|
34028
|
+
switch (resolvedAbiType.type) {
|
34029
|
+
case U8_CODER_TYPE:
|
34030
|
+
case U16_CODER_TYPE:
|
34031
|
+
case U32_CODER_TYPE:
|
34032
|
+
return new NumberCoder2(resolvedAbiType.type);
|
34033
|
+
case U64_CODER_TYPE:
|
34034
|
+
case RAW_PTR_CODER_TYPE:
|
34035
|
+
return new U64Coder();
|
34036
|
+
case RAW_SLICE_CODER_TYPE:
|
34037
|
+
return new RawSliceCoder2();
|
34038
|
+
case BOOL_CODER_TYPE:
|
34039
|
+
return new BooleanCoder2();
|
34040
|
+
case B256_CODER_TYPE:
|
34041
|
+
return new B256Coder();
|
34042
|
+
case B512_CODER_TYPE:
|
34043
|
+
return new B512Coder();
|
34044
|
+
case BYTES_CODER_TYPE:
|
34045
|
+
return new ByteCoder2();
|
34046
|
+
case STD_STRING_CODER_TYPE:
|
34047
|
+
return new StdStringCoder2();
|
34048
|
+
default:
|
34049
|
+
break;
|
33755
34050
|
}
|
33756
|
-
|
33757
|
-
|
33758
|
-
|
33759
|
-
|
33760
|
-
|
33761
|
-
|
34051
|
+
const stringMatch = stringRegEx.exec(resolvedAbiType.type)?.groups;
|
34052
|
+
if (stringMatch) {
|
34053
|
+
const length = parseInt(stringMatch.length, 10);
|
34054
|
+
return new StringCoder2(length);
|
34055
|
+
}
|
34056
|
+
const components = resolvedAbiType.components;
|
34057
|
+
const arrayMatch = arrayRegEx.exec(resolvedAbiType.type)?.groups;
|
34058
|
+
if (arrayMatch) {
|
34059
|
+
const length = parseInt(arrayMatch.length, 10);
|
34060
|
+
const arg = components[0];
|
34061
|
+
if (!arg) {
|
34062
|
+
throw new FuelError(
|
34063
|
+
ErrorCode.INVALID_COMPONENT,
|
34064
|
+
`The provided Array type is missing an item of 'component'.`
|
34065
|
+
);
|
33762
34066
|
}
|
33763
|
-
const
|
33764
|
-
|
33765
|
-
const o = { ...obj };
|
33766
|
-
o[typeParameter] = structuredClone(
|
33767
|
-
arg.typeArguments?.[typeParameterIndex]
|
33768
|
-
);
|
33769
|
-
return o;
|
33770
|
-
},
|
33771
|
-
{}
|
33772
|
-
);
|
33773
|
-
const resolvedComponents = this.resolveGenericArgTypes(
|
33774
|
-
abi,
|
33775
|
-
components,
|
33776
|
-
typeParametersAndArgsMap
|
33777
|
-
);
|
33778
|
-
return resolvedComponents.map((c) => new ResolvedAbiType(abi, c));
|
34067
|
+
const arrayElementCoder = getCoder2(arg, { isSmallBytes: true });
|
34068
|
+
return new ArrayCoder(arrayElementCoder, length);
|
33779
34069
|
}
|
33780
|
-
|
33781
|
-
|
33782
|
-
|
33783
|
-
|
33784
|
-
|
33785
|
-
|
33786
|
-
|
33787
|
-
}
|
33788
|
-
if (arg.typeArguments) {
|
33789
|
-
return {
|
33790
|
-
...structuredClone(arg),
|
33791
|
-
typeArguments: this.resolveGenericArgTypes(
|
33792
|
-
abi,
|
33793
|
-
arg.typeArguments,
|
33794
|
-
typeParametersAndArgsMap
|
33795
|
-
)
|
33796
|
-
};
|
33797
|
-
}
|
33798
|
-
const argType = findOrThrow(abi.types, (t) => t.typeId === arg.type);
|
33799
|
-
const implicitTypeParameters = this.getImplicitGenericTypeParameters(abi, argType.components);
|
33800
|
-
if (implicitTypeParameters && implicitTypeParameters.length > 0) {
|
33801
|
-
return {
|
33802
|
-
...structuredClone(arg),
|
33803
|
-
typeArguments: implicitTypeParameters.map((itp) => typeParametersAndArgsMap[itp])
|
33804
|
-
};
|
33805
|
-
}
|
33806
|
-
return arg;
|
33807
|
-
});
|
33808
|
-
}
|
33809
|
-
static getImplicitGenericTypeParameters(abi, args, implicitGenericParametersParam) {
|
33810
|
-
if (!Array.isArray(args)) {
|
33811
|
-
return null;
|
34070
|
+
if (resolvedAbiType.type === VEC_CODER_TYPE) {
|
34071
|
+
const arg = findOrThrow(components, (c) => c.name === "buf").originalTypeArguments?.[0];
|
34072
|
+
if (!arg) {
|
34073
|
+
throw new FuelError(
|
34074
|
+
ErrorCode.INVALID_COMPONENT,
|
34075
|
+
`The provided Vec type is missing the 'type argument'.`
|
34076
|
+
);
|
33812
34077
|
}
|
33813
|
-
const
|
33814
|
-
|
33815
|
-
|
33816
|
-
if (genericRegEx.test(argType.type)) {
|
33817
|
-
implicitGenericParameters.push(argType.typeId);
|
33818
|
-
return;
|
33819
|
-
}
|
33820
|
-
if (!Array.isArray(a.typeArguments)) {
|
33821
|
-
return;
|
33822
|
-
}
|
33823
|
-
this.getImplicitGenericTypeParameters(abi, a.typeArguments, implicitGenericParameters);
|
33824
|
-
});
|
33825
|
-
return implicitGenericParameters.length > 0 ? implicitGenericParameters : null;
|
34078
|
+
const argType = new ResolvedAbiType(resolvedAbiType.abi, arg);
|
34079
|
+
const itemCoder = getCoder2(argType, { isSmallBytes: true, encoding: ENCODING_V0 });
|
34080
|
+
return new VecCoder2(itemCoder);
|
33826
34081
|
}
|
33827
|
-
|
33828
|
-
|
33829
|
-
const
|
33830
|
-
return
|
34082
|
+
const structMatch = structRegEx.exec(resolvedAbiType.type)?.groups;
|
34083
|
+
if (structMatch) {
|
34084
|
+
const coders = getCoders(components, { isRightPadded: true, getCoder: getCoder2 });
|
34085
|
+
return new StructCoder2(structMatch.name, coders);
|
33831
34086
|
}
|
33832
|
-
|
33833
|
-
|
33834
|
-
|
33835
|
-
|
33836
|
-
|
33837
|
-
|
33838
|
-
if (arrayMatch) {
|
33839
|
-
return "a";
|
34087
|
+
const enumMatch = enumRegEx.exec(resolvedAbiType.type)?.groups;
|
34088
|
+
if (enumMatch) {
|
34089
|
+
const coders = getCoders(components, { getCoder: getCoder2 });
|
34090
|
+
const isOptionEnum = resolvedAbiType.type === OPTION_CODER_TYPE;
|
34091
|
+
if (isOptionEnum) {
|
34092
|
+
return new OptionCoder(enumMatch.name, coders);
|
33840
34093
|
}
|
33841
|
-
|
33842
|
-
if (enumMatch) {
|
33843
|
-
return "e";
|
33844
|
-
}
|
33845
|
-
return "";
|
34094
|
+
return new EnumCoder2(enumMatch.name, coders);
|
33846
34095
|
}
|
33847
|
-
|
33848
|
-
|
33849
|
-
|
33850
|
-
|
33851
|
-
|
33852
|
-
|
33853
|
-
}
|
33854
|
-
const strMatch = stringRegEx.exec(this.type)?.groups;
|
33855
|
-
if (strMatch) {
|
33856
|
-
return `str[${strMatch.length}]`;
|
33857
|
-
}
|
33858
|
-
if (this.components === null) {
|
33859
|
-
return this.type;
|
33860
|
-
}
|
33861
|
-
const arrayMatch = arrayRegEx.exec(this.type)?.groups;
|
33862
|
-
if (arrayMatch) {
|
33863
|
-
return `[${this.components[0].getSignature()};${arrayMatch.length}]`;
|
33864
|
-
}
|
33865
|
-
const typeArgumentsSignature = this.originalTypeArguments !== null ? `<${this.originalTypeArguments.map((a) => new ResolvedAbiType(this.abi, a).getSignature()).join(",")}>` : "";
|
33866
|
-
const componentsSignature = `(${this.components.map((c) => c.getSignature()).join(",")})`;
|
33867
|
-
return `${typeArgumentsSignature}${componentsSignature}`;
|
34096
|
+
const tupleMatch = tupleRegEx.exec(resolvedAbiType.type)?.groups;
|
34097
|
+
if (tupleMatch) {
|
34098
|
+
const coders = components.map(
|
34099
|
+
(component) => getCoder2(component, { isRightPadded: true, encoding: ENCODING_V0 })
|
34100
|
+
);
|
34101
|
+
return new TupleCoder2(coders);
|
33868
34102
|
}
|
34103
|
+
if (resolvedAbiType.type === STR_SLICE_CODER_TYPE) {
|
34104
|
+
throw new FuelError(
|
34105
|
+
ErrorCode.INVALID_DATA,
|
34106
|
+
"String slices can not be decoded from logs. Convert the slice to `str[N]` with `__to_str_array`"
|
34107
|
+
);
|
34108
|
+
}
|
34109
|
+
throw new FuelError(
|
34110
|
+
ErrorCode.CODER_NOT_FOUND,
|
34111
|
+
`Coder not found: ${JSON.stringify(resolvedAbiType)}.`
|
34112
|
+
);
|
33869
34113
|
};
|
34114
|
+
function getCoderForEncoding(encoding = ENCODING_V0) {
|
34115
|
+
switch (encoding) {
|
34116
|
+
case ENCODING_V1:
|
34117
|
+
return getCoder2;
|
34118
|
+
case ENCODING_V0:
|
34119
|
+
return getCoder;
|
34120
|
+
default:
|
34121
|
+
throw new FuelError(
|
34122
|
+
ErrorCode.UNSUPPORTED_ENCODING_VERSION,
|
34123
|
+
`Encoding version ${encoding} is unsupported.`
|
34124
|
+
);
|
34125
|
+
}
|
34126
|
+
}
|
33870
34127
|
var AbiCoder = class {
|
33871
34128
|
static getCoder(abi, argument, options = {
|
33872
34129
|
isSmallBytes: false
|
33873
34130
|
}) {
|
33874
34131
|
const resolvedAbiType = new ResolvedAbiType(abi, argument);
|
33875
|
-
return
|
34132
|
+
return getCoderForEncoding(options.encoding)(resolvedAbiType, options);
|
33876
34133
|
}
|
33877
34134
|
static encode(abi, argument, value, options) {
|
33878
34135
|
return this.getCoder(abi, argument, options).encode(value);
|
@@ -33880,103 +34137,6 @@ spurious results.`);
|
|
33880
34137
|
static decode(abi, argument, data, offset, options) {
|
33881
34138
|
return this.getCoder(abi, argument, options).decode(data, offset);
|
33882
34139
|
}
|
33883
|
-
static getCoderImpl(resolvedAbiType, options = {
|
33884
|
-
isSmallBytes: false
|
33885
|
-
}) {
|
33886
|
-
const { version: version2 } = options;
|
33887
|
-
switch (resolvedAbiType.type) {
|
33888
|
-
case "u8":
|
33889
|
-
case "u16":
|
33890
|
-
case "u32":
|
33891
|
-
return version2 ? new NumberCoder2(resolvedAbiType.type) : new NumberCoder(resolvedAbiType.type, options);
|
33892
|
-
case "u64":
|
33893
|
-
case "raw untyped ptr":
|
33894
|
-
return new U64Coder();
|
33895
|
-
case "raw untyped slice":
|
33896
|
-
return version2 ? new RawSliceCoder2() : new RawSliceCoder();
|
33897
|
-
case "bool":
|
33898
|
-
return version2 ? new BooleanCoder2() : new BooleanCoder(options);
|
33899
|
-
case "b256":
|
33900
|
-
return new B256Coder();
|
33901
|
-
case "struct B512":
|
33902
|
-
return new B512Coder();
|
33903
|
-
case BYTES_CODER_TYPE:
|
33904
|
-
return version2 ? new ByteCoder2() : new ByteCoder();
|
33905
|
-
case STD_STRING_CODER_TYPE:
|
33906
|
-
return version2 ? new StdStringCoder2() : new StdStringCoder();
|
33907
|
-
default:
|
33908
|
-
break;
|
33909
|
-
}
|
33910
|
-
const stringMatch = stringRegEx.exec(resolvedAbiType.type)?.groups;
|
33911
|
-
if (stringMatch) {
|
33912
|
-
const length = parseInt(stringMatch.length, 10);
|
33913
|
-
return version2 ? new StringCoder2(length) : new StringCoder(length);
|
33914
|
-
}
|
33915
|
-
const components = resolvedAbiType.components;
|
33916
|
-
const arrayMatch = arrayRegEx.exec(resolvedAbiType.type)?.groups;
|
33917
|
-
if (arrayMatch) {
|
33918
|
-
const length = parseInt(arrayMatch.length, 10);
|
33919
|
-
const arg = components[0];
|
33920
|
-
if (!arg) {
|
33921
|
-
throw new FuelError(
|
33922
|
-
ErrorCode.INVALID_COMPONENT,
|
33923
|
-
`The provided Array type is missing an item of 'component'.`
|
33924
|
-
);
|
33925
|
-
}
|
33926
|
-
const arrayElementCoder = AbiCoder.getCoderImpl(arg, { version: version2, isSmallBytes: true });
|
33927
|
-
return new ArrayCoder(arrayElementCoder, length);
|
33928
|
-
}
|
33929
|
-
if (resolvedAbiType.type === VEC_CODER_TYPE) {
|
33930
|
-
const arg = findOrThrow(components, (c) => c.name === "buf").originalTypeArguments?.[0];
|
33931
|
-
if (!arg) {
|
33932
|
-
throw new FuelError(
|
33933
|
-
ErrorCode.INVALID_COMPONENT,
|
33934
|
-
`The provided Vec type is missing the 'type argument'.`
|
33935
|
-
);
|
33936
|
-
}
|
33937
|
-
const argType = new ResolvedAbiType(resolvedAbiType.abi, arg);
|
33938
|
-
const itemCoder = AbiCoder.getCoderImpl(argType, { version: version2, isSmallBytes: true });
|
33939
|
-
return version2 ? new VecCoder2(itemCoder) : new VecCoder(itemCoder);
|
33940
|
-
}
|
33941
|
-
const structMatch = structRegEx.exec(resolvedAbiType.type)?.groups;
|
33942
|
-
if (structMatch) {
|
33943
|
-
const coders = AbiCoder.getCoders(components, { version: version2, isRightPadded: true });
|
33944
|
-
return version2 ? new StructCoder2(structMatch.name, coders) : new StructCoder(structMatch.name, coders);
|
33945
|
-
}
|
33946
|
-
const enumMatch = enumRegEx.exec(resolvedAbiType.type)?.groups;
|
33947
|
-
if (enumMatch) {
|
33948
|
-
const coders = AbiCoder.getCoders(components, { version: version2 });
|
33949
|
-
const isOptionEnum = resolvedAbiType.type === OPTION_CODER_TYPE;
|
33950
|
-
if (isOptionEnum) {
|
33951
|
-
return new OptionCoder(enumMatch.name, coders);
|
33952
|
-
}
|
33953
|
-
return version2 ? new EnumCoder2(enumMatch.name, coders) : new EnumCoder(enumMatch.name, coders);
|
33954
|
-
}
|
33955
|
-
const tupleMatch = tupleRegEx.exec(resolvedAbiType.type)?.groups;
|
33956
|
-
if (tupleMatch) {
|
33957
|
-
const coders = components.map(
|
33958
|
-
(component) => AbiCoder.getCoderImpl(component, { version: version2, isRightPadded: true })
|
33959
|
-
);
|
33960
|
-
return version2 ? new TupleCoder2(coders) : new TupleCoder(coders);
|
33961
|
-
}
|
33962
|
-
if (resolvedAbiType.type === "str") {
|
33963
|
-
throw new FuelError(
|
33964
|
-
ErrorCode.INVALID_DATA,
|
33965
|
-
"String slices can not be decoded from logs. Convert the slice to `str[N]` with `__to_str_array`"
|
33966
|
-
);
|
33967
|
-
}
|
33968
|
-
throw new FuelError(
|
33969
|
-
ErrorCode.CODER_NOT_FOUND,
|
33970
|
-
`Coder not found: ${JSON.stringify(resolvedAbiType)}.`
|
33971
|
-
);
|
33972
|
-
}
|
33973
|
-
static getCoders(components, options) {
|
33974
|
-
return components.reduce((obj, component) => {
|
33975
|
-
const o = obj;
|
33976
|
-
o[component.name] = AbiCoder.getCoderImpl(component, options);
|
33977
|
-
return o;
|
33978
|
-
}, {});
|
33979
|
-
}
|
33980
34140
|
};
|
33981
34141
|
var FunctionFragment = class {
|
33982
34142
|
signature;
|
@@ -34184,7 +34344,7 @@ spurious results.`);
|
|
34184
34344
|
}
|
34185
34345
|
const { loggedType } = findOrThrow(this.jsonAbi.loggedTypes, (type3) => type3.logId === logId);
|
34186
34346
|
return AbiCoder.decode(this.jsonAbi, loggedType, arrayify(data), 0, {
|
34187
|
-
|
34347
|
+
encoding: this.jsonAbi.encoding
|
34188
34348
|
});
|
34189
34349
|
}
|
34190
34350
|
updateExternalLoggedTypes(id, loggedTypes) {
|
@@ -39646,67 +39806,63 @@ ${MessageCoinFragmentFragmentDoc}`;
|
|
39646
39806
|
}
|
39647
39807
|
|
39648
39808
|
// src/providers/fuel-graphql-subscriber.ts
|
39649
|
-
var
|
39650
|
-
|
39651
|
-
|
39652
|
-
|
39653
|
-
|
39654
|
-
|
39655
|
-
|
39656
|
-
|
39657
|
-
|
39658
|
-
|
39659
|
-
|
39660
|
-
|
39661
|
-
|
39662
|
-
|
39663
|
-
|
39664
|
-
|
39665
|
-
this.readableStreamController.enqueue(
|
39666
|
-
new FuelError(
|
39667
|
-
FuelError.CODES.INVALID_REQUEST,
|
39668
|
-
errors.map((err) => err.message).join("\n\n")
|
39669
|
-
)
|
39670
|
-
);
|
39671
|
-
} else {
|
39672
|
-
this.readableStreamController.enqueue(data);
|
39673
|
-
}
|
39674
|
-
}
|
39809
|
+
var _FuelGraphqlSubscriber = class {
|
39810
|
+
constructor(options) {
|
39811
|
+
this.options = options;
|
39812
|
+
}
|
39813
|
+
stream;
|
39814
|
+
async setStream() {
|
39815
|
+
const { url, query, variables, fetchFn } = this.options;
|
39816
|
+
const response = await fetchFn(`${url}-sub`, {
|
39817
|
+
method: "POST",
|
39818
|
+
body: JSON.stringify({
|
39819
|
+
query: print(query),
|
39820
|
+
variables
|
39821
|
+
}),
|
39822
|
+
headers: {
|
39823
|
+
"Content-Type": "application/json",
|
39824
|
+
Accept: "text/event-stream"
|
39675
39825
|
}
|
39676
39826
|
});
|
39827
|
+
this.stream = response.body.getReader();
|
39677
39828
|
}
|
39678
|
-
|
39679
|
-
|
39680
|
-
|
39681
|
-
async function* fuelGraphQLSubscriber({
|
39682
|
-
url,
|
39683
|
-
variables,
|
39684
|
-
query,
|
39685
|
-
fetchFn
|
39686
|
-
}) {
|
39687
|
-
const response = await fetchFn(`${url}-sub`, {
|
39688
|
-
method: "POST",
|
39689
|
-
body: JSON.stringify({
|
39690
|
-
query: print(query),
|
39691
|
-
variables
|
39692
|
-
}),
|
39693
|
-
headers: {
|
39694
|
-
"Content-Type": "application/json",
|
39695
|
-
Accept: "text/event-stream"
|
39696
|
-
}
|
39697
|
-
});
|
39698
|
-
const subscriptionStreamReader = response.body.pipeThrough(new FuelSubscriptionStream()).getReader();
|
39699
|
-
while (true) {
|
39700
|
-
const { value, done } = await subscriptionStreamReader.read();
|
39701
|
-
if (value instanceof FuelError) {
|
39702
|
-
throw value;
|
39829
|
+
async next() {
|
39830
|
+
if (!this.stream) {
|
39831
|
+
await this.setStream();
|
39703
39832
|
}
|
39704
|
-
|
39705
|
-
|
39706
|
-
|
39833
|
+
while (true) {
|
39834
|
+
const { value, done } = await this.stream.read();
|
39835
|
+
if (done) {
|
39836
|
+
return { value, done };
|
39837
|
+
}
|
39838
|
+
const text = _FuelGraphqlSubscriber.textDecoder.decode(value);
|
39839
|
+
if (!text.startsWith("data:")) {
|
39840
|
+
continue;
|
39841
|
+
}
|
39842
|
+
const { data, errors } = JSON.parse(text.split("data:")[1]);
|
39843
|
+
if (Array.isArray(errors)) {
|
39844
|
+
throw new FuelError(
|
39845
|
+
FuelError.CODES.INVALID_REQUEST,
|
39846
|
+
errors.map((err) => err.message).join("\n\n")
|
39847
|
+
);
|
39848
|
+
}
|
39849
|
+
return { value: data, done: false };
|
39707
39850
|
}
|
39708
39851
|
}
|
39709
|
-
|
39852
|
+
/**
|
39853
|
+
* Gets called when `break` is called in a `for-await-of` loop.
|
39854
|
+
*/
|
39855
|
+
async return() {
|
39856
|
+
await this.stream.cancel();
|
39857
|
+
this.stream.releaseLock();
|
39858
|
+
return { done: true, value: void 0 };
|
39859
|
+
}
|
39860
|
+
[Symbol.asyncIterator]() {
|
39861
|
+
return this;
|
39862
|
+
}
|
39863
|
+
};
|
39864
|
+
var FuelGraphqlSubscriber = _FuelGraphqlSubscriber;
|
39865
|
+
__publicField(FuelGraphqlSubscriber, "textDecoder", new TextDecoder());
|
39710
39866
|
|
39711
39867
|
// src/providers/memory-cache.ts
|
39712
39868
|
var cache = {};
|
@@ -40777,8 +40933,6 @@ ${MessageCoinFragmentFragmentDoc}`;
|
|
40777
40933
|
this.inputs.forEach((i) => {
|
40778
40934
|
let correspondingInput;
|
40779
40935
|
switch (i.type) {
|
40780
|
-
case InputType.Contract:
|
40781
|
-
return;
|
40782
40936
|
case InputType.Coin:
|
40783
40937
|
correspondingInput = inputs.find((x) => x.type === InputType.Coin && x.owner === i.owner);
|
40784
40938
|
break;
|
@@ -40788,7 +40942,7 @@ ${MessageCoinFragmentFragmentDoc}`;
|
|
40788
40942
|
);
|
40789
40943
|
break;
|
40790
40944
|
default:
|
40791
|
-
|
40945
|
+
return;
|
40792
40946
|
}
|
40793
40947
|
if (correspondingInput && "predicateGasUsed" in correspondingInput && bn(correspondingInput.predicateGasUsed).gt(0)) {
|
40794
40948
|
i.predicate = correspondingInput.predicate;
|
@@ -41421,7 +41575,6 @@ ${MessageCoinFragmentFragmentDoc}`;
|
|
41421
41575
|
OperationName2["contractCreated"] = "Contract created";
|
41422
41576
|
OperationName2["transfer"] = "Transfer asset";
|
41423
41577
|
OperationName2["contractCall"] = "Contract call";
|
41424
|
-
OperationName2["contractTransfer"] = "Contract transfer";
|
41425
41578
|
OperationName2["receive"] = "Receive asset";
|
41426
41579
|
OperationName2["mint"] = "Mint asset";
|
41427
41580
|
OperationName2["predicatecall"] = "Predicate call";
|
@@ -41521,33 +41674,6 @@ ${MessageCoinFragmentFragmentDoc}`;
|
|
41521
41674
|
function getReceiptsTransferOut(receipts) {
|
41522
41675
|
return getReceiptsByType(receipts, ReceiptType.TransferOut);
|
41523
41676
|
}
|
41524
|
-
function getContractTransferOperations({ receipts }) {
|
41525
|
-
const transferOutReceipts = getReceiptsTransferOut(receipts);
|
41526
|
-
const contractTransferOperations = transferOutReceipts.reduce(
|
41527
|
-
(prevContractTransferOps, receipt) => {
|
41528
|
-
const newContractTransferOps = addOperation(prevContractTransferOps, {
|
41529
|
-
name: "Contract transfer" /* contractTransfer */,
|
41530
|
-
from: {
|
41531
|
-
type: 0 /* contract */,
|
41532
|
-
address: receipt.from
|
41533
|
-
},
|
41534
|
-
to: {
|
41535
|
-
type: 1 /* account */,
|
41536
|
-
address: receipt.to
|
41537
|
-
},
|
41538
|
-
assetsSent: [
|
41539
|
-
{
|
41540
|
-
amount: receipt.amount,
|
41541
|
-
assetId: receipt.assetId
|
41542
|
-
}
|
41543
|
-
]
|
41544
|
-
});
|
41545
|
-
return newContractTransferOps;
|
41546
|
-
},
|
41547
|
-
[]
|
41548
|
-
);
|
41549
|
-
return contractTransferOperations;
|
41550
|
-
}
|
41551
41677
|
function getWithdrawFromFuelOperations({
|
41552
41678
|
inputs,
|
41553
41679
|
receipts
|
@@ -41645,70 +41771,77 @@ ${MessageCoinFragmentFragmentDoc}`;
|
|
41645
41771
|
}, []);
|
41646
41772
|
return contractCallOperations;
|
41647
41773
|
}
|
41774
|
+
function extractTransferOperationFromReceipt(receipt, contractInputs, changeOutputs) {
|
41775
|
+
const { to: toAddress, assetId, amount } = receipt;
|
41776
|
+
let { from: fromAddress } = receipt;
|
41777
|
+
const toType = contractInputs.some((input) => input.contractID === toAddress) ? 0 /* contract */ : 1 /* account */;
|
41778
|
+
if (ZeroBytes32 === fromAddress) {
|
41779
|
+
const change = changeOutputs.find((output4) => output4.assetId === assetId);
|
41780
|
+
fromAddress = change?.to || fromAddress;
|
41781
|
+
}
|
41782
|
+
const fromType = contractInputs.some((input) => input.contractID === fromAddress) ? 0 /* contract */ : 1 /* account */;
|
41783
|
+
return {
|
41784
|
+
name: "Transfer asset" /* transfer */,
|
41785
|
+
from: {
|
41786
|
+
type: fromType,
|
41787
|
+
address: fromAddress
|
41788
|
+
},
|
41789
|
+
to: {
|
41790
|
+
type: toType,
|
41791
|
+
address: toAddress
|
41792
|
+
},
|
41793
|
+
assetsSent: [
|
41794
|
+
{
|
41795
|
+
assetId: assetId.toString(),
|
41796
|
+
amount
|
41797
|
+
}
|
41798
|
+
]
|
41799
|
+
};
|
41800
|
+
}
|
41648
41801
|
function getTransferOperations({
|
41649
41802
|
inputs,
|
41650
41803
|
outputs,
|
41651
41804
|
receipts
|
41652
41805
|
}) {
|
41806
|
+
let operations = [];
|
41653
41807
|
const coinOutputs = getOutputsCoin(outputs);
|
41654
|
-
const
|
41808
|
+
const contractInputs = getInputsContract(inputs);
|
41809
|
+
const changeOutputs = getOutputsChange(outputs);
|
41810
|
+
coinOutputs.forEach((output4) => {
|
41811
|
+
const { amount, assetId, to } = output4;
|
41812
|
+
const changeOutput = changeOutputs.find((change) => change.assetId === assetId);
|
41813
|
+
if (changeOutput) {
|
41814
|
+
operations = addOperation(operations, {
|
41815
|
+
name: "Transfer asset" /* transfer */,
|
41816
|
+
from: {
|
41817
|
+
type: 1 /* account */,
|
41818
|
+
address: changeOutput.to
|
41819
|
+
},
|
41820
|
+
to: {
|
41821
|
+
type: 1 /* account */,
|
41822
|
+
address: to
|
41823
|
+
},
|
41824
|
+
assetsSent: [
|
41825
|
+
{
|
41826
|
+
assetId,
|
41827
|
+
amount
|
41828
|
+
}
|
41829
|
+
]
|
41830
|
+
});
|
41831
|
+
}
|
41832
|
+
});
|
41833
|
+
const transferReceipts = getReceiptsByType(
|
41655
41834
|
receipts,
|
41656
41835
|
ReceiptType.Transfer
|
41657
41836
|
);
|
41658
|
-
|
41659
|
-
|
41660
|
-
|
41661
|
-
|
41662
|
-
|
41663
|
-
|
41664
|
-
|
41665
|
-
|
41666
|
-
const inputAddress = getInputAccountAddress(utxo);
|
41667
|
-
operations = addOperation(operations, {
|
41668
|
-
name: "Transfer asset" /* transfer */,
|
41669
|
-
from: {
|
41670
|
-
type: 1 /* account */,
|
41671
|
-
address: inputAddress
|
41672
|
-
},
|
41673
|
-
to: {
|
41674
|
-
type: 0 /* contract */,
|
41675
|
-
address: contractInput.contractID
|
41676
|
-
},
|
41677
|
-
assetsSent: [
|
41678
|
-
{
|
41679
|
-
assetId: assetId.toString(),
|
41680
|
-
amount: transferReceipt.amount
|
41681
|
-
}
|
41682
|
-
]
|
41683
|
-
});
|
41684
|
-
}
|
41685
|
-
});
|
41686
|
-
} else {
|
41687
|
-
coinOutputs.forEach((output4) => {
|
41688
|
-
const input = getInputFromAssetId(inputs, output4.assetId);
|
41689
|
-
if (input) {
|
41690
|
-
const inputAddress = getInputAccountAddress(input);
|
41691
|
-
const operationToAdd = {
|
41692
|
-
name: "Transfer asset" /* transfer */,
|
41693
|
-
from: {
|
41694
|
-
type: 1 /* account */,
|
41695
|
-
address: inputAddress
|
41696
|
-
},
|
41697
|
-
to: {
|
41698
|
-
type: 1 /* account */,
|
41699
|
-
address: output4.to.toString()
|
41700
|
-
},
|
41701
|
-
assetsSent: [
|
41702
|
-
{
|
41703
|
-
assetId: output4.assetId.toString(),
|
41704
|
-
amount: output4.amount
|
41705
|
-
}
|
41706
|
-
]
|
41707
|
-
};
|
41708
|
-
operations = addOperation(operations, operationToAdd);
|
41709
|
-
}
|
41710
|
-
});
|
41711
|
-
}
|
41837
|
+
const transferOutReceipts = getReceiptsByType(
|
41838
|
+
receipts,
|
41839
|
+
ReceiptType.TransferOut
|
41840
|
+
);
|
41841
|
+
[...transferReceipts, ...transferOutReceipts].forEach((receipt) => {
|
41842
|
+
const operation = extractTransferOperationFromReceipt(receipt, contractInputs, changeOutputs);
|
41843
|
+
operations = addOperation(operations, operation);
|
41844
|
+
});
|
41712
41845
|
return operations;
|
41713
41846
|
}
|
41714
41847
|
function getPayProducerOperations(outputs) {
|
@@ -41781,7 +41914,6 @@ ${MessageCoinFragmentFragmentDoc}`;
|
|
41781
41914
|
rawPayload,
|
41782
41915
|
maxInputs
|
41783
41916
|
}),
|
41784
|
-
...getContractTransferOperations({ receipts }),
|
41785
41917
|
...getWithdrawFromFuelOperations({ inputs, receipts })
|
41786
41918
|
];
|
41787
41919
|
}
|
@@ -42350,7 +42482,7 @@ ${MessageCoinFragmentFragmentDoc}`;
|
|
42350
42482
|
const opDefinition = query.definitions.find((x) => x.kind === "OperationDefinition");
|
42351
42483
|
const isSubscription = opDefinition?.operation === "subscription";
|
42352
42484
|
if (isSubscription) {
|
42353
|
-
return
|
42485
|
+
return new FuelGraphqlSubscriber({
|
42354
42486
|
url: this.url,
|
42355
42487
|
query,
|
42356
42488
|
fetchFn: (url, requestInit) => fetchFn(url, requestInit, this.options),
|
@@ -42542,11 +42674,15 @@ ${MessageCoinFragmentFragmentDoc}`;
|
|
42542
42674
|
async estimateTxDependencies(transactionRequest) {
|
42543
42675
|
if (transactionRequest.type === TransactionType.Create) {
|
42544
42676
|
return {
|
42545
|
-
receipts: []
|
42677
|
+
receipts: [],
|
42678
|
+
outputVariables: 0,
|
42679
|
+
missingContractIds: []
|
42546
42680
|
};
|
42547
42681
|
}
|
42548
42682
|
await this.estimatePredicates(transactionRequest);
|
42549
42683
|
let receipts = [];
|
42684
|
+
const missingContractIds = [];
|
42685
|
+
let outputVariables = 0;
|
42550
42686
|
for (let attempt = 0; attempt < MAX_RETRIES; attempt++) {
|
42551
42687
|
const { dryRun: gqlReceipts } = await this.operations.dryRun({
|
42552
42688
|
encodedTransaction: hexlify(transactionRequest.toTransactionBytes()),
|
@@ -42556,16 +42692,20 @@ ${MessageCoinFragmentFragmentDoc}`;
|
|
42556
42692
|
const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(receipts);
|
42557
42693
|
const hasMissingOutputs = missingOutputVariables.length !== 0 || missingOutputContractIds.length !== 0;
|
42558
42694
|
if (hasMissingOutputs) {
|
42695
|
+
outputVariables += missingOutputVariables.length;
|
42559
42696
|
transactionRequest.addVariableOutputs(missingOutputVariables.length);
|
42560
42697
|
missingOutputContractIds.forEach(({ contractId }) => {
|
42561
42698
|
transactionRequest.addContractInputAndOutput(Address.fromString(contractId));
|
42699
|
+
missingContractIds.push(contractId);
|
42562
42700
|
});
|
42563
42701
|
} else {
|
42564
42702
|
break;
|
42565
42703
|
}
|
42566
42704
|
}
|
42567
42705
|
return {
|
42568
|
-
receipts
|
42706
|
+
receipts,
|
42707
|
+
outputVariables,
|
42708
|
+
missingContractIds
|
42569
42709
|
};
|
42570
42710
|
}
|
42571
42711
|
/**
|
@@ -42633,11 +42773,15 @@ ${MessageCoinFragmentFragmentDoc}`;
|
|
42633
42773
|
const minGas = txRequestClone.calculateMinGas(chainInfo);
|
42634
42774
|
const maxGas = txRequestClone.calculateMaxGas(chainInfo, minGas);
|
42635
42775
|
let receipts = [];
|
42776
|
+
let missingContractIds = [];
|
42777
|
+
let outputVariables = 0;
|
42636
42778
|
if (isScriptTransaction && estimateTxDependencies) {
|
42637
42779
|
txRequestClone.gasPrice = bn(0);
|
42638
42780
|
txRequestClone.gasLimit = bn(maxGasPerTx.sub(maxGas).toNumber() * 0.9);
|
42639
42781
|
const result = await this.estimateTxDependencies(txRequestClone);
|
42640
42782
|
receipts = result.receipts;
|
42783
|
+
outputVariables = result.outputVariables;
|
42784
|
+
missingContractIds = result.missingContractIds;
|
42641
42785
|
}
|
42642
42786
|
const gasUsed = isScriptTransaction ? getGasUsedFromReceipts(receipts) : minGas;
|
42643
42787
|
const usedFee = calculatePriceWithFactor(
|
@@ -42659,7 +42803,8 @@ ${MessageCoinFragmentFragmentDoc}`;
|
|
42659
42803
|
minFee,
|
42660
42804
|
maxFee,
|
42661
42805
|
estimatedInputs: txRequestClone.inputs,
|
42662
|
-
|
42806
|
+
outputVariables,
|
42807
|
+
missingContractIds
|
42663
42808
|
};
|
42664
42809
|
}
|
42665
42810
|
async getResourcesForTransaction(owner, transactionRequestLike, forwardingQuantities = []) {
|
@@ -49143,17 +49288,6 @@ ${MessageCoinFragmentFragmentDoc}`;
|
|
49143
49288
|
})(FuelConnectorEventTypes || {});
|
49144
49289
|
var FuelConnectorEventType = "FuelConnector";
|
49145
49290
|
|
49146
|
-
// src/connectors/types/data-type.ts
|
49147
|
-
var MessageTypes = /* @__PURE__ */ ((MessageTypes2) => {
|
49148
|
-
MessageTypes2["ping"] = "ping";
|
49149
|
-
MessageTypes2["uiEvent"] = "uiEvent";
|
49150
|
-
MessageTypes2["event"] = "event";
|
49151
|
-
MessageTypes2["request"] = "request";
|
49152
|
-
MessageTypes2["response"] = "response";
|
49153
|
-
MessageTypes2["removeConnection"] = "removeConnection";
|
49154
|
-
return MessageTypes2;
|
49155
|
-
})(MessageTypes || {});
|
49156
|
-
|
49157
49291
|
// src/connectors/types/local-storage.ts
|
49158
49292
|
var LocalStorage = class {
|
49159
49293
|
storage;
|