@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
@@ -33066,7 +33066,7 @@ spurious results.`);
|
|
33066
33066
|
return {
|
33067
33067
|
FORC: "0.50.0",
|
33068
33068
|
FUEL_CORE: "0.22.1",
|
33069
|
-
FUELS: "0.
|
33069
|
+
FUELS: "0.75.0"
|
33070
33070
|
};
|
33071
33071
|
}
|
33072
33072
|
function parseVersion(version2) {
|
@@ -33132,6 +33132,7 @@ spurious results.`);
|
|
33132
33132
|
ErrorCode2["CODER_NOT_FOUND"] = "coder-not-found";
|
33133
33133
|
ErrorCode2["INVALID_DATA"] = "invalid-data";
|
33134
33134
|
ErrorCode2["FUNCTION_NOT_FOUND"] = "function-not-found";
|
33135
|
+
ErrorCode2["UNSUPPORTED_ENCODING_VERSION"] = "unsupported-encoding-version";
|
33135
33136
|
ErrorCode2["INVALID_BECH32_ADDRESS"] = "invalid-bech32-address";
|
33136
33137
|
ErrorCode2["INVALID_EVM_ADDRESS"] = "invalid-evm-address";
|
33137
33138
|
ErrorCode2["INVALID_B256_ADDRESS"] = "invalid-b256-address";
|
@@ -36160,16 +36161,28 @@ spurious results.`);
|
|
36160
36161
|
this.encodedLength = encodedLength;
|
36161
36162
|
}
|
36162
36163
|
};
|
36164
|
+
var U8_CODER_TYPE = "u8";
|
36165
|
+
var U16_CODER_TYPE = "u16";
|
36166
|
+
var U32_CODER_TYPE = "u32";
|
36167
|
+
var U64_CODER_TYPE = "u64";
|
36168
|
+
var RAW_PTR_CODER_TYPE = "raw untyped ptr";
|
36169
|
+
var RAW_SLICE_CODER_TYPE = "raw untyped slice";
|
36170
|
+
var BOOL_CODER_TYPE = "bool";
|
36171
|
+
var B256_CODER_TYPE = "b256";
|
36172
|
+
var B512_CODER_TYPE = "struct B512";
|
36163
36173
|
var OPTION_CODER_TYPE = "enum Option";
|
36164
36174
|
var VEC_CODER_TYPE = "struct Vec";
|
36165
36175
|
var BYTES_CODER_TYPE = "struct Bytes";
|
36166
36176
|
var STD_STRING_CODER_TYPE = "struct String";
|
36177
|
+
var STR_SLICE_CODER_TYPE = "str";
|
36167
36178
|
var stringRegEx = /str\[(?<length>[0-9]+)\]/;
|
36168
36179
|
var arrayRegEx = /\[(?<item>[\w\s\\[\]]+);\s*(?<length>[0-9]+)\]/;
|
36169
36180
|
var structRegEx = /^struct (?<name>\w+)$/;
|
36170
36181
|
var enumRegEx = /^enum (?<name>\w+)$/;
|
36171
36182
|
var tupleRegEx = /^\((?<items>.*)\)$/;
|
36172
36183
|
var genericRegEx = /^generic (?<name>\w+)$/;
|
36184
|
+
var ENCODING_V0 = "0";
|
36185
|
+
var ENCODING_V1 = "1";
|
36173
36186
|
var WORD_SIZE = 8;
|
36174
36187
|
var BYTES_32 = 32;
|
36175
36188
|
var ASSET_ID_LEN = BYTES_32;
|
@@ -36910,6 +36923,246 @@ spurious results.`);
|
|
36910
36923
|
];
|
36911
36924
|
}
|
36912
36925
|
};
|
36926
|
+
var ResolvedAbiType = class {
|
36927
|
+
abi;
|
36928
|
+
name;
|
36929
|
+
type;
|
36930
|
+
originalTypeArguments;
|
36931
|
+
components;
|
36932
|
+
constructor(abi, argument) {
|
36933
|
+
this.abi = abi;
|
36934
|
+
const type3 = findOrThrow(
|
36935
|
+
abi.types,
|
36936
|
+
(t) => t.typeId === argument.type,
|
36937
|
+
() => {
|
36938
|
+
throw new FuelError(
|
36939
|
+
ErrorCode.TYPE_NOT_FOUND,
|
36940
|
+
`Type does not exist in the provided abi: ${JSON.stringify({
|
36941
|
+
argument,
|
36942
|
+
abi: this.abi
|
36943
|
+
})}`
|
36944
|
+
);
|
36945
|
+
}
|
36946
|
+
);
|
36947
|
+
this.name = argument.name;
|
36948
|
+
this.type = type3.type;
|
36949
|
+
this.originalTypeArguments = argument.typeArguments;
|
36950
|
+
this.components = ResolvedAbiType.getResolvedGenericComponents(
|
36951
|
+
abi,
|
36952
|
+
argument,
|
36953
|
+
type3.components,
|
36954
|
+
type3.typeParameters ?? ResolvedAbiType.getImplicitGenericTypeParameters(abi, type3.components)
|
36955
|
+
);
|
36956
|
+
}
|
36957
|
+
static getResolvedGenericComponents(abi, arg, components, typeParameters) {
|
36958
|
+
if (components === null) {
|
36959
|
+
return null;
|
36960
|
+
}
|
36961
|
+
if (typeParameters === null || typeParameters.length === 0) {
|
36962
|
+
return components.map((c) => new ResolvedAbiType(abi, c));
|
36963
|
+
}
|
36964
|
+
const typeParametersAndArgsMap = typeParameters.reduce(
|
36965
|
+
(obj, typeParameter, typeParameterIndex) => {
|
36966
|
+
const o = { ...obj };
|
36967
|
+
o[typeParameter] = structuredClone(
|
36968
|
+
arg.typeArguments?.[typeParameterIndex]
|
36969
|
+
);
|
36970
|
+
return o;
|
36971
|
+
},
|
36972
|
+
{}
|
36973
|
+
);
|
36974
|
+
const resolvedComponents = this.resolveGenericArgTypes(
|
36975
|
+
abi,
|
36976
|
+
components,
|
36977
|
+
typeParametersAndArgsMap
|
36978
|
+
);
|
36979
|
+
return resolvedComponents.map((c) => new ResolvedAbiType(abi, c));
|
36980
|
+
}
|
36981
|
+
static resolveGenericArgTypes(abi, args, typeParametersAndArgsMap) {
|
36982
|
+
return args.map((arg) => {
|
36983
|
+
if (typeParametersAndArgsMap[arg.type] !== void 0) {
|
36984
|
+
return {
|
36985
|
+
...typeParametersAndArgsMap[arg.type],
|
36986
|
+
name: arg.name
|
36987
|
+
};
|
36988
|
+
}
|
36989
|
+
if (arg.typeArguments) {
|
36990
|
+
return {
|
36991
|
+
...structuredClone(arg),
|
36992
|
+
typeArguments: this.resolveGenericArgTypes(
|
36993
|
+
abi,
|
36994
|
+
arg.typeArguments,
|
36995
|
+
typeParametersAndArgsMap
|
36996
|
+
)
|
36997
|
+
};
|
36998
|
+
}
|
36999
|
+
const argType = findOrThrow(abi.types, (t) => t.typeId === arg.type);
|
37000
|
+
const implicitTypeParameters = this.getImplicitGenericTypeParameters(abi, argType.components);
|
37001
|
+
if (implicitTypeParameters && implicitTypeParameters.length > 0) {
|
37002
|
+
return {
|
37003
|
+
...structuredClone(arg),
|
37004
|
+
typeArguments: implicitTypeParameters.map((itp) => typeParametersAndArgsMap[itp])
|
37005
|
+
};
|
37006
|
+
}
|
37007
|
+
return arg;
|
37008
|
+
});
|
37009
|
+
}
|
37010
|
+
static getImplicitGenericTypeParameters(abi, args, implicitGenericParametersParam) {
|
37011
|
+
if (!Array.isArray(args)) {
|
37012
|
+
return null;
|
37013
|
+
}
|
37014
|
+
const implicitGenericParameters = implicitGenericParametersParam ?? [];
|
37015
|
+
args.forEach((a) => {
|
37016
|
+
const argType = findOrThrow(abi.types, (t) => t.typeId === a.type);
|
37017
|
+
if (genericRegEx.test(argType.type)) {
|
37018
|
+
implicitGenericParameters.push(argType.typeId);
|
37019
|
+
return;
|
37020
|
+
}
|
37021
|
+
if (!Array.isArray(a.typeArguments)) {
|
37022
|
+
return;
|
37023
|
+
}
|
37024
|
+
this.getImplicitGenericTypeParameters(abi, a.typeArguments, implicitGenericParameters);
|
37025
|
+
});
|
37026
|
+
return implicitGenericParameters.length > 0 ? implicitGenericParameters : null;
|
37027
|
+
}
|
37028
|
+
getSignature() {
|
37029
|
+
const prefix = this.getArgSignaturePrefix();
|
37030
|
+
const content = this.getArgSignatureContent();
|
37031
|
+
return `${prefix}${content}`;
|
37032
|
+
}
|
37033
|
+
getArgSignaturePrefix() {
|
37034
|
+
const structMatch = structRegEx.test(this.type);
|
37035
|
+
if (structMatch) {
|
37036
|
+
return "s";
|
37037
|
+
}
|
37038
|
+
const arrayMatch = arrayRegEx.test(this.type);
|
37039
|
+
if (arrayMatch) {
|
37040
|
+
return "a";
|
37041
|
+
}
|
37042
|
+
const enumMatch = enumRegEx.test(this.type);
|
37043
|
+
if (enumMatch) {
|
37044
|
+
return "e";
|
37045
|
+
}
|
37046
|
+
return "";
|
37047
|
+
}
|
37048
|
+
getArgSignatureContent() {
|
37049
|
+
if (this.type === "raw untyped ptr") {
|
37050
|
+
return "rawptr";
|
37051
|
+
}
|
37052
|
+
if (this.type === "raw untyped slice") {
|
37053
|
+
return "rawslice";
|
37054
|
+
}
|
37055
|
+
const strMatch = stringRegEx.exec(this.type)?.groups;
|
37056
|
+
if (strMatch) {
|
37057
|
+
return `str[${strMatch.length}]`;
|
37058
|
+
}
|
37059
|
+
if (this.components === null) {
|
37060
|
+
return this.type;
|
37061
|
+
}
|
37062
|
+
const arrayMatch = arrayRegEx.exec(this.type)?.groups;
|
37063
|
+
if (arrayMatch) {
|
37064
|
+
return `[${this.components[0].getSignature()};${arrayMatch.length}]`;
|
37065
|
+
}
|
37066
|
+
const typeArgumentsSignature = this.originalTypeArguments !== null ? `<${this.originalTypeArguments.map((a) => new ResolvedAbiType(this.abi, a).getSignature()).join(",")}>` : "";
|
37067
|
+
const componentsSignature = `(${this.components.map((c) => c.getSignature()).join(",")})`;
|
37068
|
+
return `${typeArgumentsSignature}${componentsSignature}`;
|
37069
|
+
}
|
37070
|
+
};
|
37071
|
+
function getCoders(components, options) {
|
37072
|
+
const { getCoder: getCoder3 } = options;
|
37073
|
+
return components.reduce((obj, component) => {
|
37074
|
+
const o = obj;
|
37075
|
+
o[component.name] = getCoder3(component, options);
|
37076
|
+
return o;
|
37077
|
+
}, {});
|
37078
|
+
}
|
37079
|
+
var getCoder = (resolvedAbiType, options) => {
|
37080
|
+
switch (resolvedAbiType.type) {
|
37081
|
+
case U8_CODER_TYPE:
|
37082
|
+
case U16_CODER_TYPE:
|
37083
|
+
case U32_CODER_TYPE:
|
37084
|
+
return new NumberCoder(resolvedAbiType.type, options);
|
37085
|
+
case U64_CODER_TYPE:
|
37086
|
+
case RAW_PTR_CODER_TYPE:
|
37087
|
+
return new U64Coder();
|
37088
|
+
case RAW_SLICE_CODER_TYPE:
|
37089
|
+
return new RawSliceCoder();
|
37090
|
+
case BOOL_CODER_TYPE:
|
37091
|
+
return new BooleanCoder(options);
|
37092
|
+
case B256_CODER_TYPE:
|
37093
|
+
return new B256Coder();
|
37094
|
+
case B512_CODER_TYPE:
|
37095
|
+
return new B512Coder();
|
37096
|
+
case BYTES_CODER_TYPE:
|
37097
|
+
return new ByteCoder();
|
37098
|
+
case STD_STRING_CODER_TYPE:
|
37099
|
+
return new StdStringCoder();
|
37100
|
+
default:
|
37101
|
+
break;
|
37102
|
+
}
|
37103
|
+
const stringMatch = stringRegEx.exec(resolvedAbiType.type)?.groups;
|
37104
|
+
if (stringMatch) {
|
37105
|
+
const length = parseInt(stringMatch.length, 10);
|
37106
|
+
return new StringCoder(length);
|
37107
|
+
}
|
37108
|
+
const components = resolvedAbiType.components;
|
37109
|
+
const arrayMatch = arrayRegEx.exec(resolvedAbiType.type)?.groups;
|
37110
|
+
if (arrayMatch) {
|
37111
|
+
const length = parseInt(arrayMatch.length, 10);
|
37112
|
+
const arg = components[0];
|
37113
|
+
if (!arg) {
|
37114
|
+
throw new FuelError(
|
37115
|
+
ErrorCode.INVALID_COMPONENT,
|
37116
|
+
`The provided Array type is missing an item of 'component'.`
|
37117
|
+
);
|
37118
|
+
}
|
37119
|
+
const arrayElementCoder = getCoder(arg, { isSmallBytes: true });
|
37120
|
+
return new ArrayCoder(arrayElementCoder, length);
|
37121
|
+
}
|
37122
|
+
if (resolvedAbiType.type === VEC_CODER_TYPE) {
|
37123
|
+
const arg = findOrThrow(components, (c) => c.name === "buf").originalTypeArguments?.[0];
|
37124
|
+
if (!arg) {
|
37125
|
+
throw new FuelError(
|
37126
|
+
ErrorCode.INVALID_COMPONENT,
|
37127
|
+
`The provided Vec type is missing the 'type argument'.`
|
37128
|
+
);
|
37129
|
+
}
|
37130
|
+
const argType = new ResolvedAbiType(resolvedAbiType.abi, arg);
|
37131
|
+
const itemCoder = getCoder(argType, { isSmallBytes: true, encoding: ENCODING_V0 });
|
37132
|
+
return new VecCoder(itemCoder);
|
37133
|
+
}
|
37134
|
+
const structMatch = structRegEx.exec(resolvedAbiType.type)?.groups;
|
37135
|
+
if (structMatch) {
|
37136
|
+
const coders = getCoders(components, { isRightPadded: true, getCoder });
|
37137
|
+
return new StructCoder(structMatch.name, coders);
|
37138
|
+
}
|
37139
|
+
const enumMatch = enumRegEx.exec(resolvedAbiType.type)?.groups;
|
37140
|
+
if (enumMatch) {
|
37141
|
+
const coders = getCoders(components, { getCoder });
|
37142
|
+
const isOptionEnum = resolvedAbiType.type === OPTION_CODER_TYPE;
|
37143
|
+
if (isOptionEnum) {
|
37144
|
+
return new OptionCoder(enumMatch.name, coders);
|
37145
|
+
}
|
37146
|
+
return new EnumCoder(enumMatch.name, coders);
|
37147
|
+
}
|
37148
|
+
const tupleMatch = tupleRegEx.exec(resolvedAbiType.type)?.groups;
|
37149
|
+
if (tupleMatch) {
|
37150
|
+
const coders = components.map(
|
37151
|
+
(component) => getCoder(component, { isRightPadded: true, encoding: ENCODING_V0 })
|
37152
|
+
);
|
37153
|
+
return new TupleCoder(coders);
|
37154
|
+
}
|
37155
|
+
if (resolvedAbiType.type === STR_SLICE_CODER_TYPE) {
|
37156
|
+
throw new FuelError(
|
37157
|
+
ErrorCode.INVALID_DATA,
|
37158
|
+
"String slices can not be decoded from logs. Convert the slice to `str[N]` with `__to_str_array`"
|
37159
|
+
);
|
37160
|
+
}
|
37161
|
+
throw new FuelError(
|
37162
|
+
ErrorCode.CODER_NOT_FOUND,
|
37163
|
+
`Coder not found: ${JSON.stringify(resolvedAbiType)}.`
|
37164
|
+
);
|
37165
|
+
};
|
36913
37166
|
var BooleanCoder2 = class extends Coder {
|
36914
37167
|
constructor() {
|
36915
37168
|
super("boolean", "boolean", 1);
|
@@ -36937,10 +37190,15 @@ spurious results.`);
|
|
36937
37190
|
};
|
36938
37191
|
var ByteCoder2 = class extends Coder {
|
36939
37192
|
constructor() {
|
36940
|
-
super("struct", "struct Bytes",
|
37193
|
+
super("struct", "struct Bytes", WORD_SIZE);
|
36941
37194
|
}
|
36942
|
-
encode(
|
36943
|
-
|
37195
|
+
encode(value) {
|
37196
|
+
if (!Array.isArray(value)) {
|
37197
|
+
throw new FuelError(ErrorCode.ENCODE_ERROR, `Expected array value.`);
|
37198
|
+
}
|
37199
|
+
const bytes4 = new Uint8Array(value);
|
37200
|
+
const lengthBytes = new U64Coder().encode(value.length);
|
37201
|
+
return new Uint8Array([...lengthBytes, ...bytes4]);
|
36944
37202
|
}
|
36945
37203
|
decode(data, offset) {
|
36946
37204
|
if (data.length < WORD_SIZE) {
|
@@ -36949,12 +37207,11 @@ spurious results.`);
|
|
36949
37207
|
const offsetAndLength = offset + WORD_SIZE;
|
36950
37208
|
const lengthBytes = data.slice(offset, offsetAndLength);
|
36951
37209
|
const length = bn(new U64Coder().decode(lengthBytes, 0)[0]).toNumber();
|
36952
|
-
const
|
36953
|
-
const dataBytes = data.slice(offsetAndLength, offsetAndLength + dataLength2);
|
37210
|
+
const dataBytes = data.slice(offsetAndLength, offsetAndLength + length);
|
36954
37211
|
if (dataBytes.length !== length) {
|
36955
37212
|
throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid bytes byte data size.`);
|
36956
37213
|
}
|
36957
|
-
return [dataBytes,
|
37214
|
+
return [dataBytes, offsetAndLength + length];
|
36958
37215
|
}
|
36959
37216
|
};
|
36960
37217
|
__publicField3(ByteCoder2, "memorySize", 1);
|
@@ -36979,8 +37236,28 @@ spurious results.`);
|
|
36979
37236
|
this.#caseIndexCoder = caseIndexCoder;
|
36980
37237
|
this.#encodedValueSize = encodedValueSize;
|
36981
37238
|
}
|
36982
|
-
|
36983
|
-
|
37239
|
+
#encodeNativeEnum(value) {
|
37240
|
+
const valueCoder = this.coders[value];
|
37241
|
+
const encodedValue = valueCoder.encode([]);
|
37242
|
+
const caseIndex = Object.keys(this.coders).indexOf(value);
|
37243
|
+
const padding = new Uint8Array(this.#encodedValueSize - valueCoder.encodedLength);
|
37244
|
+
return concat([this.#caseIndexCoder.encode(caseIndex), padding, encodedValue]);
|
37245
|
+
}
|
37246
|
+
encode(value) {
|
37247
|
+
if (typeof value === "string" && this.coders[value]) {
|
37248
|
+
return this.#encodeNativeEnum(value);
|
37249
|
+
}
|
37250
|
+
const [caseKey, ...empty] = Object.keys(value);
|
37251
|
+
if (!caseKey) {
|
37252
|
+
throw new FuelError(ErrorCode.INVALID_DECODE_VALUE, "A field for the case must be provided.");
|
37253
|
+
}
|
37254
|
+
if (empty.length !== 0) {
|
37255
|
+
throw new FuelError(ErrorCode.INVALID_DECODE_VALUE, "Only one field must be provided.");
|
37256
|
+
}
|
37257
|
+
const valueCoder = this.coders[caseKey];
|
37258
|
+
const caseIndex = Object.keys(this.coders).indexOf(caseKey);
|
37259
|
+
const encodedValue = valueCoder.encode(value[caseKey]);
|
37260
|
+
return new Uint8Array([...this.#caseIndexCoder.encode(caseIndex), ...encodedValue]);
|
36984
37261
|
}
|
36985
37262
|
#decodeNativeEnum(caseKey, newOffset) {
|
36986
37263
|
return [caseKey, newOffset];
|
@@ -37055,8 +37332,14 @@ spurious results.`);
|
|
37055
37332
|
constructor() {
|
37056
37333
|
super("raw untyped slice", "raw untyped slice", WORD_SIZE);
|
37057
37334
|
}
|
37058
|
-
encode(
|
37059
|
-
|
37335
|
+
encode(value) {
|
37336
|
+
if (!Array.isArray(value)) {
|
37337
|
+
throw new FuelError(ErrorCode.ENCODE_ERROR, `Expected array value.`);
|
37338
|
+
}
|
37339
|
+
const internalCoder = new ArrayCoder(new NumberCoder2("u8"), value.length);
|
37340
|
+
const bytes4 = internalCoder.encode(value);
|
37341
|
+
const lengthBytes = new U64Coder().encode(bytes4.length);
|
37342
|
+
return new Uint8Array([...lengthBytes, ...bytes4]);
|
37060
37343
|
}
|
37061
37344
|
decode(data, offset) {
|
37062
37345
|
if (data.length < this.encodedLength) {
|
@@ -37078,8 +37361,10 @@ spurious results.`);
|
|
37078
37361
|
constructor() {
|
37079
37362
|
super("struct", "struct String", WORD_SIZE);
|
37080
37363
|
}
|
37081
|
-
encode(
|
37082
|
-
|
37364
|
+
encode(value) {
|
37365
|
+
const bytes4 = toUtf8Bytes(value);
|
37366
|
+
const lengthBytes = new U64Coder().encode(value.length);
|
37367
|
+
return new Uint8Array([...lengthBytes, ...bytes4]);
|
37083
37368
|
}
|
37084
37369
|
decode(data, offset) {
|
37085
37370
|
if (data.length < this.encodedLength) {
|
@@ -37129,8 +37414,20 @@ spurious results.`);
|
|
37129
37414
|
this.name = name;
|
37130
37415
|
this.coders = coders;
|
37131
37416
|
}
|
37132
|
-
encode(
|
37133
|
-
|
37417
|
+
encode(value) {
|
37418
|
+
return concatBytes2(
|
37419
|
+
Object.keys(this.coders).map((fieldName) => {
|
37420
|
+
const fieldCoder = this.coders[fieldName];
|
37421
|
+
const fieldValue = value[fieldName];
|
37422
|
+
if (!(fieldCoder instanceof OptionCoder) && fieldValue == null) {
|
37423
|
+
throw new FuelError(
|
37424
|
+
ErrorCode.ENCODE_ERROR,
|
37425
|
+
`Invalid ${this.type}. Field "${fieldName}" not present.`
|
37426
|
+
);
|
37427
|
+
}
|
37428
|
+
return fieldCoder.encode(fieldValue);
|
37429
|
+
})
|
37430
|
+
);
|
37134
37431
|
}
|
37135
37432
|
decode(data, offset) {
|
37136
37433
|
if (data.length < this.encodedLength) {
|
@@ -37158,7 +37455,7 @@ spurious results.`);
|
|
37158
37455
|
if (this.coders.length !== value.length) {
|
37159
37456
|
throw new FuelError(ErrorCode.ENCODE_ERROR, `Types/values length mismatch.`);
|
37160
37457
|
}
|
37161
|
-
|
37458
|
+
return concatBytes2(this.coders.map((coder, i) => coder.encode(value[i])));
|
37162
37459
|
}
|
37163
37460
|
decode(data, offset) {
|
37164
37461
|
if (data.length < this.encodedLength) {
|
@@ -37179,8 +37476,13 @@ spurious results.`);
|
|
37179
37476
|
super("struct", `struct Vec`, coder.encodedLength + WORD_SIZE);
|
37180
37477
|
this.coder = coder;
|
37181
37478
|
}
|
37182
|
-
encode(
|
37183
|
-
|
37479
|
+
encode(value) {
|
37480
|
+
if (!Array.isArray(value)) {
|
37481
|
+
throw new FuelError(ErrorCode.ENCODE_ERROR, `Expected array value.`);
|
37482
|
+
}
|
37483
|
+
const bytes4 = value.map((v) => this.coder.encode(v));
|
37484
|
+
const lengthBytes = new U64Coder().encode(value.length);
|
37485
|
+
return new Uint8Array([...lengthBytes, ...concatBytes2(bytes4)]);
|
37184
37486
|
}
|
37185
37487
|
decode(data, offset) {
|
37186
37488
|
if (data.length < this.encodedLength || data.length > MAX_BYTES) {
|
@@ -37202,157 +37504,112 @@ spurious results.`);
|
|
37202
37504
|
];
|
37203
37505
|
}
|
37204
37506
|
};
|
37205
|
-
var
|
37206
|
-
|
37207
|
-
|
37208
|
-
|
37209
|
-
|
37210
|
-
|
37211
|
-
|
37212
|
-
|
37213
|
-
|
37214
|
-
|
37215
|
-
(
|
37216
|
-
|
37217
|
-
|
37218
|
-
|
37219
|
-
|
37220
|
-
|
37221
|
-
|
37222
|
-
|
37223
|
-
|
37224
|
-
|
37225
|
-
|
37226
|
-
|
37227
|
-
|
37228
|
-
this.originalTypeArguments = argument.typeArguments;
|
37229
|
-
this.components = ResolvedAbiType.getResolvedGenericComponents(
|
37230
|
-
abi,
|
37231
|
-
argument,
|
37232
|
-
type3.components,
|
37233
|
-
type3.typeParameters ?? ResolvedAbiType.getImplicitGenericTypeParameters(abi, type3.components)
|
37234
|
-
);
|
37507
|
+
var getCoder2 = (resolvedAbiType, _options) => {
|
37508
|
+
switch (resolvedAbiType.type) {
|
37509
|
+
case U8_CODER_TYPE:
|
37510
|
+
case U16_CODER_TYPE:
|
37511
|
+
case U32_CODER_TYPE:
|
37512
|
+
return new NumberCoder2(resolvedAbiType.type);
|
37513
|
+
case U64_CODER_TYPE:
|
37514
|
+
case RAW_PTR_CODER_TYPE:
|
37515
|
+
return new U64Coder();
|
37516
|
+
case RAW_SLICE_CODER_TYPE:
|
37517
|
+
return new RawSliceCoder2();
|
37518
|
+
case BOOL_CODER_TYPE:
|
37519
|
+
return new BooleanCoder2();
|
37520
|
+
case B256_CODER_TYPE:
|
37521
|
+
return new B256Coder();
|
37522
|
+
case B512_CODER_TYPE:
|
37523
|
+
return new B512Coder();
|
37524
|
+
case BYTES_CODER_TYPE:
|
37525
|
+
return new ByteCoder2();
|
37526
|
+
case STD_STRING_CODER_TYPE:
|
37527
|
+
return new StdStringCoder2();
|
37528
|
+
default:
|
37529
|
+
break;
|
37235
37530
|
}
|
37236
|
-
|
37237
|
-
|
37238
|
-
|
37239
|
-
|
37240
|
-
|
37241
|
-
|
37531
|
+
const stringMatch = stringRegEx.exec(resolvedAbiType.type)?.groups;
|
37532
|
+
if (stringMatch) {
|
37533
|
+
const length = parseInt(stringMatch.length, 10);
|
37534
|
+
return new StringCoder2(length);
|
37535
|
+
}
|
37536
|
+
const components = resolvedAbiType.components;
|
37537
|
+
const arrayMatch = arrayRegEx.exec(resolvedAbiType.type)?.groups;
|
37538
|
+
if (arrayMatch) {
|
37539
|
+
const length = parseInt(arrayMatch.length, 10);
|
37540
|
+
const arg = components[0];
|
37541
|
+
if (!arg) {
|
37542
|
+
throw new FuelError(
|
37543
|
+
ErrorCode.INVALID_COMPONENT,
|
37544
|
+
`The provided Array type is missing an item of 'component'.`
|
37545
|
+
);
|
37242
37546
|
}
|
37243
|
-
const
|
37244
|
-
|
37245
|
-
const o = { ...obj };
|
37246
|
-
o[typeParameter] = structuredClone(
|
37247
|
-
arg.typeArguments?.[typeParameterIndex]
|
37248
|
-
);
|
37249
|
-
return o;
|
37250
|
-
},
|
37251
|
-
{}
|
37252
|
-
);
|
37253
|
-
const resolvedComponents = this.resolveGenericArgTypes(
|
37254
|
-
abi,
|
37255
|
-
components,
|
37256
|
-
typeParametersAndArgsMap
|
37257
|
-
);
|
37258
|
-
return resolvedComponents.map((c) => new ResolvedAbiType(abi, c));
|
37547
|
+
const arrayElementCoder = getCoder2(arg, { isSmallBytes: true });
|
37548
|
+
return new ArrayCoder(arrayElementCoder, length);
|
37259
37549
|
}
|
37260
|
-
|
37261
|
-
|
37262
|
-
|
37263
|
-
|
37264
|
-
|
37265
|
-
|
37266
|
-
|
37267
|
-
}
|
37268
|
-
if (arg.typeArguments) {
|
37269
|
-
return {
|
37270
|
-
...structuredClone(arg),
|
37271
|
-
typeArguments: this.resolveGenericArgTypes(
|
37272
|
-
abi,
|
37273
|
-
arg.typeArguments,
|
37274
|
-
typeParametersAndArgsMap
|
37275
|
-
)
|
37276
|
-
};
|
37277
|
-
}
|
37278
|
-
const argType = findOrThrow(abi.types, (t) => t.typeId === arg.type);
|
37279
|
-
const implicitTypeParameters = this.getImplicitGenericTypeParameters(abi, argType.components);
|
37280
|
-
if (implicitTypeParameters && implicitTypeParameters.length > 0) {
|
37281
|
-
return {
|
37282
|
-
...structuredClone(arg),
|
37283
|
-
typeArguments: implicitTypeParameters.map((itp) => typeParametersAndArgsMap[itp])
|
37284
|
-
};
|
37285
|
-
}
|
37286
|
-
return arg;
|
37287
|
-
});
|
37288
|
-
}
|
37289
|
-
static getImplicitGenericTypeParameters(abi, args, implicitGenericParametersParam) {
|
37290
|
-
if (!Array.isArray(args)) {
|
37291
|
-
return null;
|
37550
|
+
if (resolvedAbiType.type === VEC_CODER_TYPE) {
|
37551
|
+
const arg = findOrThrow(components, (c) => c.name === "buf").originalTypeArguments?.[0];
|
37552
|
+
if (!arg) {
|
37553
|
+
throw new FuelError(
|
37554
|
+
ErrorCode.INVALID_COMPONENT,
|
37555
|
+
`The provided Vec type is missing the 'type argument'.`
|
37556
|
+
);
|
37292
37557
|
}
|
37293
|
-
const
|
37294
|
-
|
37295
|
-
|
37296
|
-
if (genericRegEx.test(argType.type)) {
|
37297
|
-
implicitGenericParameters.push(argType.typeId);
|
37298
|
-
return;
|
37299
|
-
}
|
37300
|
-
if (!Array.isArray(a.typeArguments)) {
|
37301
|
-
return;
|
37302
|
-
}
|
37303
|
-
this.getImplicitGenericTypeParameters(abi, a.typeArguments, implicitGenericParameters);
|
37304
|
-
});
|
37305
|
-
return implicitGenericParameters.length > 0 ? implicitGenericParameters : null;
|
37558
|
+
const argType = new ResolvedAbiType(resolvedAbiType.abi, arg);
|
37559
|
+
const itemCoder = getCoder2(argType, { isSmallBytes: true, encoding: ENCODING_V0 });
|
37560
|
+
return new VecCoder2(itemCoder);
|
37306
37561
|
}
|
37307
|
-
|
37308
|
-
|
37309
|
-
const
|
37310
|
-
return
|
37562
|
+
const structMatch = structRegEx.exec(resolvedAbiType.type)?.groups;
|
37563
|
+
if (structMatch) {
|
37564
|
+
const coders = getCoders(components, { isRightPadded: true, getCoder: getCoder2 });
|
37565
|
+
return new StructCoder2(structMatch.name, coders);
|
37311
37566
|
}
|
37312
|
-
|
37313
|
-
|
37314
|
-
|
37315
|
-
|
37316
|
-
|
37317
|
-
|
37318
|
-
if (arrayMatch) {
|
37319
|
-
return "a";
|
37320
|
-
}
|
37321
|
-
const enumMatch = enumRegEx.test(this.type);
|
37322
|
-
if (enumMatch) {
|
37323
|
-
return "e";
|
37567
|
+
const enumMatch = enumRegEx.exec(resolvedAbiType.type)?.groups;
|
37568
|
+
if (enumMatch) {
|
37569
|
+
const coders = getCoders(components, { getCoder: getCoder2 });
|
37570
|
+
const isOptionEnum = resolvedAbiType.type === OPTION_CODER_TYPE;
|
37571
|
+
if (isOptionEnum) {
|
37572
|
+
return new OptionCoder(enumMatch.name, coders);
|
37324
37573
|
}
|
37325
|
-
return
|
37574
|
+
return new EnumCoder2(enumMatch.name, coders);
|
37326
37575
|
}
|
37327
|
-
|
37328
|
-
|
37329
|
-
|
37330
|
-
|
37331
|
-
|
37332
|
-
|
37333
|
-
|
37334
|
-
|
37335
|
-
|
37336
|
-
|
37337
|
-
|
37338
|
-
|
37339
|
-
return this.type;
|
37340
|
-
}
|
37341
|
-
const arrayMatch = arrayRegEx.exec(this.type)?.groups;
|
37342
|
-
if (arrayMatch) {
|
37343
|
-
return `[${this.components[0].getSignature()};${arrayMatch.length}]`;
|
37344
|
-
}
|
37345
|
-
const typeArgumentsSignature = this.originalTypeArguments !== null ? `<${this.originalTypeArguments.map((a) => new ResolvedAbiType(this.abi, a).getSignature()).join(",")}>` : "";
|
37346
|
-
const componentsSignature = `(${this.components.map((c) => c.getSignature()).join(",")})`;
|
37347
|
-
return `${typeArgumentsSignature}${componentsSignature}`;
|
37576
|
+
const tupleMatch = tupleRegEx.exec(resolvedAbiType.type)?.groups;
|
37577
|
+
if (tupleMatch) {
|
37578
|
+
const coders = components.map(
|
37579
|
+
(component) => getCoder2(component, { isRightPadded: true, encoding: ENCODING_V0 })
|
37580
|
+
);
|
37581
|
+
return new TupleCoder2(coders);
|
37582
|
+
}
|
37583
|
+
if (resolvedAbiType.type === STR_SLICE_CODER_TYPE) {
|
37584
|
+
throw new FuelError(
|
37585
|
+
ErrorCode.INVALID_DATA,
|
37586
|
+
"String slices can not be decoded from logs. Convert the slice to `str[N]` with `__to_str_array`"
|
37587
|
+
);
|
37348
37588
|
}
|
37589
|
+
throw new FuelError(
|
37590
|
+
ErrorCode.CODER_NOT_FOUND,
|
37591
|
+
`Coder not found: ${JSON.stringify(resolvedAbiType)}.`
|
37592
|
+
);
|
37349
37593
|
};
|
37594
|
+
function getCoderForEncoding(encoding = ENCODING_V0) {
|
37595
|
+
switch (encoding) {
|
37596
|
+
case ENCODING_V1:
|
37597
|
+
return getCoder2;
|
37598
|
+
case ENCODING_V0:
|
37599
|
+
return getCoder;
|
37600
|
+
default:
|
37601
|
+
throw new FuelError(
|
37602
|
+
ErrorCode.UNSUPPORTED_ENCODING_VERSION,
|
37603
|
+
`Encoding version ${encoding} is unsupported.`
|
37604
|
+
);
|
37605
|
+
}
|
37606
|
+
}
|
37350
37607
|
var AbiCoder = class {
|
37351
37608
|
static getCoder(abi, argument, options = {
|
37352
37609
|
isSmallBytes: false
|
37353
37610
|
}) {
|
37354
37611
|
const resolvedAbiType = new ResolvedAbiType(abi, argument);
|
37355
|
-
return
|
37612
|
+
return getCoderForEncoding(options.encoding)(resolvedAbiType, options);
|
37356
37613
|
}
|
37357
37614
|
static encode(abi, argument, value, options) {
|
37358
37615
|
return this.getCoder(abi, argument, options).encode(value);
|
@@ -37360,103 +37617,6 @@ spurious results.`);
|
|
37360
37617
|
static decode(abi, argument, data, offset, options) {
|
37361
37618
|
return this.getCoder(abi, argument, options).decode(data, offset);
|
37362
37619
|
}
|
37363
|
-
static getCoderImpl(resolvedAbiType, options = {
|
37364
|
-
isSmallBytes: false
|
37365
|
-
}) {
|
37366
|
-
const { version: version2 } = options;
|
37367
|
-
switch (resolvedAbiType.type) {
|
37368
|
-
case "u8":
|
37369
|
-
case "u16":
|
37370
|
-
case "u32":
|
37371
|
-
return version2 ? new NumberCoder2(resolvedAbiType.type) : new NumberCoder(resolvedAbiType.type, options);
|
37372
|
-
case "u64":
|
37373
|
-
case "raw untyped ptr":
|
37374
|
-
return new U64Coder();
|
37375
|
-
case "raw untyped slice":
|
37376
|
-
return version2 ? new RawSliceCoder2() : new RawSliceCoder();
|
37377
|
-
case "bool":
|
37378
|
-
return version2 ? new BooleanCoder2() : new BooleanCoder(options);
|
37379
|
-
case "b256":
|
37380
|
-
return new B256Coder();
|
37381
|
-
case "struct B512":
|
37382
|
-
return new B512Coder();
|
37383
|
-
case BYTES_CODER_TYPE:
|
37384
|
-
return version2 ? new ByteCoder2() : new ByteCoder();
|
37385
|
-
case STD_STRING_CODER_TYPE:
|
37386
|
-
return version2 ? new StdStringCoder2() : new StdStringCoder();
|
37387
|
-
default:
|
37388
|
-
break;
|
37389
|
-
}
|
37390
|
-
const stringMatch = stringRegEx.exec(resolvedAbiType.type)?.groups;
|
37391
|
-
if (stringMatch) {
|
37392
|
-
const length = parseInt(stringMatch.length, 10);
|
37393
|
-
return version2 ? new StringCoder2(length) : new StringCoder(length);
|
37394
|
-
}
|
37395
|
-
const components = resolvedAbiType.components;
|
37396
|
-
const arrayMatch = arrayRegEx.exec(resolvedAbiType.type)?.groups;
|
37397
|
-
if (arrayMatch) {
|
37398
|
-
const length = parseInt(arrayMatch.length, 10);
|
37399
|
-
const arg = components[0];
|
37400
|
-
if (!arg) {
|
37401
|
-
throw new FuelError(
|
37402
|
-
ErrorCode.INVALID_COMPONENT,
|
37403
|
-
`The provided Array type is missing an item of 'component'.`
|
37404
|
-
);
|
37405
|
-
}
|
37406
|
-
const arrayElementCoder = AbiCoder.getCoderImpl(arg, { version: version2, isSmallBytes: true });
|
37407
|
-
return new ArrayCoder(arrayElementCoder, length);
|
37408
|
-
}
|
37409
|
-
if (resolvedAbiType.type === VEC_CODER_TYPE) {
|
37410
|
-
const arg = findOrThrow(components, (c) => c.name === "buf").originalTypeArguments?.[0];
|
37411
|
-
if (!arg) {
|
37412
|
-
throw new FuelError(
|
37413
|
-
ErrorCode.INVALID_COMPONENT,
|
37414
|
-
`The provided Vec type is missing the 'type argument'.`
|
37415
|
-
);
|
37416
|
-
}
|
37417
|
-
const argType = new ResolvedAbiType(resolvedAbiType.abi, arg);
|
37418
|
-
const itemCoder = AbiCoder.getCoderImpl(argType, { version: version2, isSmallBytes: true });
|
37419
|
-
return version2 ? new VecCoder2(itemCoder) : new VecCoder(itemCoder);
|
37420
|
-
}
|
37421
|
-
const structMatch = structRegEx.exec(resolvedAbiType.type)?.groups;
|
37422
|
-
if (structMatch) {
|
37423
|
-
const coders = AbiCoder.getCoders(components, { version: version2, isRightPadded: true });
|
37424
|
-
return version2 ? new StructCoder2(structMatch.name, coders) : new StructCoder(structMatch.name, coders);
|
37425
|
-
}
|
37426
|
-
const enumMatch = enumRegEx.exec(resolvedAbiType.type)?.groups;
|
37427
|
-
if (enumMatch) {
|
37428
|
-
const coders = AbiCoder.getCoders(components, { version: version2 });
|
37429
|
-
const isOptionEnum = resolvedAbiType.type === OPTION_CODER_TYPE;
|
37430
|
-
if (isOptionEnum) {
|
37431
|
-
return new OptionCoder(enumMatch.name, coders);
|
37432
|
-
}
|
37433
|
-
return version2 ? new EnumCoder2(enumMatch.name, coders) : new EnumCoder(enumMatch.name, coders);
|
37434
|
-
}
|
37435
|
-
const tupleMatch = tupleRegEx.exec(resolvedAbiType.type)?.groups;
|
37436
|
-
if (tupleMatch) {
|
37437
|
-
const coders = components.map(
|
37438
|
-
(component) => AbiCoder.getCoderImpl(component, { version: version2, isRightPadded: true })
|
37439
|
-
);
|
37440
|
-
return version2 ? new TupleCoder2(coders) : new TupleCoder(coders);
|
37441
|
-
}
|
37442
|
-
if (resolvedAbiType.type === "str") {
|
37443
|
-
throw new FuelError(
|
37444
|
-
ErrorCode.INVALID_DATA,
|
37445
|
-
"String slices can not be decoded from logs. Convert the slice to `str[N]` with `__to_str_array`"
|
37446
|
-
);
|
37447
|
-
}
|
37448
|
-
throw new FuelError(
|
37449
|
-
ErrorCode.CODER_NOT_FOUND,
|
37450
|
-
`Coder not found: ${JSON.stringify(resolvedAbiType)}.`
|
37451
|
-
);
|
37452
|
-
}
|
37453
|
-
static getCoders(components, options) {
|
37454
|
-
return components.reduce((obj, component) => {
|
37455
|
-
const o = obj;
|
37456
|
-
o[component.name] = AbiCoder.getCoderImpl(component, options);
|
37457
|
-
return o;
|
37458
|
-
}, {});
|
37459
|
-
}
|
37460
37620
|
};
|
37461
37621
|
var FunctionFragment = class {
|
37462
37622
|
signature;
|
@@ -37664,7 +37824,7 @@ spurious results.`);
|
|
37664
37824
|
}
|
37665
37825
|
const { loggedType } = findOrThrow(this.jsonAbi.loggedTypes, (type3) => type3.logId === logId);
|
37666
37826
|
return AbiCoder.decode(this.jsonAbi, loggedType, arrayify(data), 0, {
|
37667
|
-
|
37827
|
+
encoding: this.jsonAbi.encoding
|
37668
37828
|
});
|
37669
37829
|
}
|
37670
37830
|
updateExternalLoggedTypes(id, loggedTypes) {
|
@@ -43126,67 +43286,63 @@ ${MessageCoinFragmentFragmentDoc}`;
|
|
43126
43286
|
}
|
43127
43287
|
|
43128
43288
|
// src/providers/fuel-graphql-subscriber.ts
|
43129
|
-
var
|
43130
|
-
|
43131
|
-
|
43132
|
-
|
43133
|
-
|
43134
|
-
|
43135
|
-
|
43136
|
-
|
43137
|
-
|
43138
|
-
|
43139
|
-
|
43140
|
-
|
43141
|
-
|
43142
|
-
|
43143
|
-
|
43144
|
-
|
43145
|
-
this.readableStreamController.enqueue(
|
43146
|
-
new FuelError(
|
43147
|
-
FuelError.CODES.INVALID_REQUEST,
|
43148
|
-
errors.map((err) => err.message).join("\n\n")
|
43149
|
-
)
|
43150
|
-
);
|
43151
|
-
} else {
|
43152
|
-
this.readableStreamController.enqueue(data);
|
43153
|
-
}
|
43154
|
-
}
|
43289
|
+
var _FuelGraphqlSubscriber = class {
|
43290
|
+
constructor(options) {
|
43291
|
+
this.options = options;
|
43292
|
+
}
|
43293
|
+
stream;
|
43294
|
+
async setStream() {
|
43295
|
+
const { url, query, variables, fetchFn } = this.options;
|
43296
|
+
const response = await fetchFn(`${url}-sub`, {
|
43297
|
+
method: "POST",
|
43298
|
+
body: JSON.stringify({
|
43299
|
+
query: print(query),
|
43300
|
+
variables
|
43301
|
+
}),
|
43302
|
+
headers: {
|
43303
|
+
"Content-Type": "application/json",
|
43304
|
+
Accept: "text/event-stream"
|
43155
43305
|
}
|
43156
43306
|
});
|
43307
|
+
this.stream = response.body.getReader();
|
43157
43308
|
}
|
43158
|
-
|
43159
|
-
|
43160
|
-
|
43161
|
-
async function* fuelGraphQLSubscriber({
|
43162
|
-
url,
|
43163
|
-
variables,
|
43164
|
-
query,
|
43165
|
-
fetchFn
|
43166
|
-
}) {
|
43167
|
-
const response = await fetchFn(`${url}-sub`, {
|
43168
|
-
method: "POST",
|
43169
|
-
body: JSON.stringify({
|
43170
|
-
query: print(query),
|
43171
|
-
variables
|
43172
|
-
}),
|
43173
|
-
headers: {
|
43174
|
-
"Content-Type": "application/json",
|
43175
|
-
Accept: "text/event-stream"
|
43309
|
+
async next() {
|
43310
|
+
if (!this.stream) {
|
43311
|
+
await this.setStream();
|
43176
43312
|
}
|
43177
|
-
|
43178
|
-
|
43179
|
-
|
43180
|
-
|
43181
|
-
|
43182
|
-
|
43183
|
-
|
43184
|
-
|
43185
|
-
|
43186
|
-
|
43313
|
+
while (true) {
|
43314
|
+
const { value, done } = await this.stream.read();
|
43315
|
+
if (done) {
|
43316
|
+
return { value, done };
|
43317
|
+
}
|
43318
|
+
const text = _FuelGraphqlSubscriber.textDecoder.decode(value);
|
43319
|
+
if (!text.startsWith("data:")) {
|
43320
|
+
continue;
|
43321
|
+
}
|
43322
|
+
const { data, errors } = JSON.parse(text.split("data:")[1]);
|
43323
|
+
if (Array.isArray(errors)) {
|
43324
|
+
throw new FuelError(
|
43325
|
+
FuelError.CODES.INVALID_REQUEST,
|
43326
|
+
errors.map((err) => err.message).join("\n\n")
|
43327
|
+
);
|
43328
|
+
}
|
43329
|
+
return { value: data, done: false };
|
43187
43330
|
}
|
43188
43331
|
}
|
43189
|
-
|
43332
|
+
/**
|
43333
|
+
* Gets called when `break` is called in a `for-await-of` loop.
|
43334
|
+
*/
|
43335
|
+
async return() {
|
43336
|
+
await this.stream.cancel();
|
43337
|
+
this.stream.releaseLock();
|
43338
|
+
return { done: true, value: void 0 };
|
43339
|
+
}
|
43340
|
+
[Symbol.asyncIterator]() {
|
43341
|
+
return this;
|
43342
|
+
}
|
43343
|
+
};
|
43344
|
+
var FuelGraphqlSubscriber = _FuelGraphqlSubscriber;
|
43345
|
+
__publicField(FuelGraphqlSubscriber, "textDecoder", new TextDecoder());
|
43190
43346
|
|
43191
43347
|
// src/providers/memory-cache.ts
|
43192
43348
|
var cache = {};
|
@@ -44180,8 +44336,6 @@ ${MessageCoinFragmentFragmentDoc}`;
|
|
44180
44336
|
this.inputs.forEach((i) => {
|
44181
44337
|
let correspondingInput;
|
44182
44338
|
switch (i.type) {
|
44183
|
-
case InputType.Contract:
|
44184
|
-
return;
|
44185
44339
|
case InputType.Coin:
|
44186
44340
|
correspondingInput = inputs.find((x) => x.type === InputType.Coin && x.owner === i.owner);
|
44187
44341
|
break;
|
@@ -44191,7 +44345,7 @@ ${MessageCoinFragmentFragmentDoc}`;
|
|
44191
44345
|
);
|
44192
44346
|
break;
|
44193
44347
|
default:
|
44194
|
-
|
44348
|
+
return;
|
44195
44349
|
}
|
44196
44350
|
if (correspondingInput && "predicateGasUsed" in correspondingInput && bn(correspondingInput.predicateGasUsed).gt(0)) {
|
44197
44351
|
i.predicate = correspondingInput.predicate;
|
@@ -44860,36 +45014,6 @@ ${MessageCoinFragmentFragmentDoc}`;
|
|
44860
45014
|
}
|
44861
45015
|
return allOperations;
|
44862
45016
|
}
|
44863
|
-
function getReceiptsTransferOut(receipts) {
|
44864
|
-
return getReceiptsByType(receipts, ReceiptType.TransferOut);
|
44865
|
-
}
|
44866
|
-
function getContractTransferOperations({ receipts }) {
|
44867
|
-
const transferOutReceipts = getReceiptsTransferOut(receipts);
|
44868
|
-
const contractTransferOperations = transferOutReceipts.reduce(
|
44869
|
-
(prevContractTransferOps, receipt) => {
|
44870
|
-
const newContractTransferOps = addOperation(prevContractTransferOps, {
|
44871
|
-
name: "Contract transfer" /* contractTransfer */,
|
44872
|
-
from: {
|
44873
|
-
type: 0 /* contract */,
|
44874
|
-
address: receipt.from
|
44875
|
-
},
|
44876
|
-
to: {
|
44877
|
-
type: 1 /* account */,
|
44878
|
-
address: receipt.to
|
44879
|
-
},
|
44880
|
-
assetsSent: [
|
44881
|
-
{
|
44882
|
-
amount: receipt.amount,
|
44883
|
-
assetId: receipt.assetId
|
44884
|
-
}
|
44885
|
-
]
|
44886
|
-
});
|
44887
|
-
return newContractTransferOps;
|
44888
|
-
},
|
44889
|
-
[]
|
44890
|
-
);
|
44891
|
-
return contractTransferOperations;
|
44892
|
-
}
|
44893
45017
|
function getWithdrawFromFuelOperations({
|
44894
45018
|
inputs,
|
44895
45019
|
receipts
|
@@ -44987,70 +45111,77 @@ ${MessageCoinFragmentFragmentDoc}`;
|
|
44987
45111
|
}, []);
|
44988
45112
|
return contractCallOperations;
|
44989
45113
|
}
|
45114
|
+
function extractTransferOperationFromReceipt(receipt, contractInputs, changeOutputs) {
|
45115
|
+
const { to: toAddress, assetId, amount } = receipt;
|
45116
|
+
let { from: fromAddress } = receipt;
|
45117
|
+
const toType = contractInputs.some((input) => input.contractID === toAddress) ? 0 /* contract */ : 1 /* account */;
|
45118
|
+
if (ZeroBytes32 === fromAddress) {
|
45119
|
+
const change = changeOutputs.find((output4) => output4.assetId === assetId);
|
45120
|
+
fromAddress = change?.to || fromAddress;
|
45121
|
+
}
|
45122
|
+
const fromType = contractInputs.some((input) => input.contractID === fromAddress) ? 0 /* contract */ : 1 /* account */;
|
45123
|
+
return {
|
45124
|
+
name: "Transfer asset" /* transfer */,
|
45125
|
+
from: {
|
45126
|
+
type: fromType,
|
45127
|
+
address: fromAddress
|
45128
|
+
},
|
45129
|
+
to: {
|
45130
|
+
type: toType,
|
45131
|
+
address: toAddress
|
45132
|
+
},
|
45133
|
+
assetsSent: [
|
45134
|
+
{
|
45135
|
+
assetId: assetId.toString(),
|
45136
|
+
amount
|
45137
|
+
}
|
45138
|
+
]
|
45139
|
+
};
|
45140
|
+
}
|
44990
45141
|
function getTransferOperations({
|
44991
45142
|
inputs,
|
44992
45143
|
outputs,
|
44993
45144
|
receipts
|
44994
45145
|
}) {
|
45146
|
+
let operations = [];
|
44995
45147
|
const coinOutputs = getOutputsCoin(outputs);
|
44996
|
-
const
|
45148
|
+
const contractInputs = getInputsContract(inputs);
|
45149
|
+
const changeOutputs = getOutputsChange(outputs);
|
45150
|
+
coinOutputs.forEach((output4) => {
|
45151
|
+
const { amount, assetId, to } = output4;
|
45152
|
+
const changeOutput = changeOutputs.find((change) => change.assetId === assetId);
|
45153
|
+
if (changeOutput) {
|
45154
|
+
operations = addOperation(operations, {
|
45155
|
+
name: "Transfer asset" /* transfer */,
|
45156
|
+
from: {
|
45157
|
+
type: 1 /* account */,
|
45158
|
+
address: changeOutput.to
|
45159
|
+
},
|
45160
|
+
to: {
|
45161
|
+
type: 1 /* account */,
|
45162
|
+
address: to
|
45163
|
+
},
|
45164
|
+
assetsSent: [
|
45165
|
+
{
|
45166
|
+
assetId,
|
45167
|
+
amount
|
45168
|
+
}
|
45169
|
+
]
|
45170
|
+
});
|
45171
|
+
}
|
45172
|
+
});
|
45173
|
+
const transferReceipts = getReceiptsByType(
|
44997
45174
|
receipts,
|
44998
45175
|
ReceiptType.Transfer
|
44999
45176
|
);
|
45000
|
-
|
45001
|
-
|
45002
|
-
|
45003
|
-
|
45004
|
-
|
45005
|
-
|
45006
|
-
|
45007
|
-
|
45008
|
-
const inputAddress = getInputAccountAddress(utxo);
|
45009
|
-
operations = addOperation(operations, {
|
45010
|
-
name: "Transfer asset" /* transfer */,
|
45011
|
-
from: {
|
45012
|
-
type: 1 /* account */,
|
45013
|
-
address: inputAddress
|
45014
|
-
},
|
45015
|
-
to: {
|
45016
|
-
type: 0 /* contract */,
|
45017
|
-
address: contractInput.contractID
|
45018
|
-
},
|
45019
|
-
assetsSent: [
|
45020
|
-
{
|
45021
|
-
assetId: assetId.toString(),
|
45022
|
-
amount: transferReceipt.amount
|
45023
|
-
}
|
45024
|
-
]
|
45025
|
-
});
|
45026
|
-
}
|
45027
|
-
});
|
45028
|
-
} else {
|
45029
|
-
coinOutputs.forEach((output4) => {
|
45030
|
-
const input = getInputFromAssetId(inputs, output4.assetId);
|
45031
|
-
if (input) {
|
45032
|
-
const inputAddress = getInputAccountAddress(input);
|
45033
|
-
const operationToAdd = {
|
45034
|
-
name: "Transfer asset" /* transfer */,
|
45035
|
-
from: {
|
45036
|
-
type: 1 /* account */,
|
45037
|
-
address: inputAddress
|
45038
|
-
},
|
45039
|
-
to: {
|
45040
|
-
type: 1 /* account */,
|
45041
|
-
address: output4.to.toString()
|
45042
|
-
},
|
45043
|
-
assetsSent: [
|
45044
|
-
{
|
45045
|
-
assetId: output4.assetId.toString(),
|
45046
|
-
amount: output4.amount
|
45047
|
-
}
|
45048
|
-
]
|
45049
|
-
};
|
45050
|
-
operations = addOperation(operations, operationToAdd);
|
45051
|
-
}
|
45052
|
-
});
|
45053
|
-
}
|
45177
|
+
const transferOutReceipts = getReceiptsByType(
|
45178
|
+
receipts,
|
45179
|
+
ReceiptType.TransferOut
|
45180
|
+
);
|
45181
|
+
[...transferReceipts, ...transferOutReceipts].forEach((receipt) => {
|
45182
|
+
const operation = extractTransferOperationFromReceipt(receipt, contractInputs, changeOutputs);
|
45183
|
+
operations = addOperation(operations, operation);
|
45184
|
+
});
|
45054
45185
|
return operations;
|
45055
45186
|
}
|
45056
45187
|
function getPayProducerOperations(outputs) {
|
@@ -45123,7 +45254,6 @@ ${MessageCoinFragmentFragmentDoc}`;
|
|
45123
45254
|
rawPayload,
|
45124
45255
|
maxInputs
|
45125
45256
|
}),
|
45126
|
-
...getContractTransferOperations({ receipts }),
|
45127
45257
|
...getWithdrawFromFuelOperations({ inputs, receipts })
|
45128
45258
|
];
|
45129
45259
|
}
|
@@ -45679,7 +45809,7 @@ ${MessageCoinFragmentFragmentDoc}`;
|
|
45679
45809
|
const opDefinition = query.definitions.find((x) => x.kind === "OperationDefinition");
|
45680
45810
|
const isSubscription = opDefinition?.operation === "subscription";
|
45681
45811
|
if (isSubscription) {
|
45682
|
-
return
|
45812
|
+
return new FuelGraphqlSubscriber({
|
45683
45813
|
url: this.url,
|
45684
45814
|
query,
|
45685
45815
|
fetchFn: (url, requestInit) => fetchFn(url, requestInit, this.options),
|
@@ -45871,11 +46001,15 @@ ${MessageCoinFragmentFragmentDoc}`;
|
|
45871
46001
|
async estimateTxDependencies(transactionRequest) {
|
45872
46002
|
if (transactionRequest.type === TransactionType.Create) {
|
45873
46003
|
return {
|
45874
|
-
receipts: []
|
46004
|
+
receipts: [],
|
46005
|
+
outputVariables: 0,
|
46006
|
+
missingContractIds: []
|
45875
46007
|
};
|
45876
46008
|
}
|
45877
46009
|
await this.estimatePredicates(transactionRequest);
|
45878
46010
|
let receipts = [];
|
46011
|
+
const missingContractIds = [];
|
46012
|
+
let outputVariables = 0;
|
45879
46013
|
for (let attempt = 0; attempt < MAX_RETRIES; attempt++) {
|
45880
46014
|
const { dryRun: gqlReceipts } = await this.operations.dryRun({
|
45881
46015
|
encodedTransaction: hexlify(transactionRequest.toTransactionBytes()),
|
@@ -45885,16 +46019,20 @@ ${MessageCoinFragmentFragmentDoc}`;
|
|
45885
46019
|
const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(receipts);
|
45886
46020
|
const hasMissingOutputs = missingOutputVariables.length !== 0 || missingOutputContractIds.length !== 0;
|
45887
46021
|
if (hasMissingOutputs) {
|
46022
|
+
outputVariables += missingOutputVariables.length;
|
45888
46023
|
transactionRequest.addVariableOutputs(missingOutputVariables.length);
|
45889
46024
|
missingOutputContractIds.forEach(({ contractId }) => {
|
45890
46025
|
transactionRequest.addContractInputAndOutput(Address.fromString(contractId));
|
46026
|
+
missingContractIds.push(contractId);
|
45891
46027
|
});
|
45892
46028
|
} else {
|
45893
46029
|
break;
|
45894
46030
|
}
|
45895
46031
|
}
|
45896
46032
|
return {
|
45897
|
-
receipts
|
46033
|
+
receipts,
|
46034
|
+
outputVariables,
|
46035
|
+
missingContractIds
|
45898
46036
|
};
|
45899
46037
|
}
|
45900
46038
|
/**
|
@@ -45962,11 +46100,15 @@ ${MessageCoinFragmentFragmentDoc}`;
|
|
45962
46100
|
const minGas = txRequestClone.calculateMinGas(chainInfo);
|
45963
46101
|
const maxGas = txRequestClone.calculateMaxGas(chainInfo, minGas);
|
45964
46102
|
let receipts = [];
|
46103
|
+
let missingContractIds = [];
|
46104
|
+
let outputVariables = 0;
|
45965
46105
|
if (isScriptTransaction && estimateTxDependencies) {
|
45966
46106
|
txRequestClone.gasPrice = bn(0);
|
45967
46107
|
txRequestClone.gasLimit = bn(maxGasPerTx.sub(maxGas).toNumber() * 0.9);
|
45968
46108
|
const result = await this.estimateTxDependencies(txRequestClone);
|
45969
46109
|
receipts = result.receipts;
|
46110
|
+
outputVariables = result.outputVariables;
|
46111
|
+
missingContractIds = result.missingContractIds;
|
45970
46112
|
}
|
45971
46113
|
const gasUsed = isScriptTransaction ? getGasUsedFromReceipts(receipts) : minGas;
|
45972
46114
|
const usedFee = calculatePriceWithFactor(
|
@@ -45988,7 +46130,8 @@ ${MessageCoinFragmentFragmentDoc}`;
|
|
45988
46130
|
minFee,
|
45989
46131
|
maxFee,
|
45990
46132
|
estimatedInputs: txRequestClone.inputs,
|
45991
|
-
|
46133
|
+
outputVariables,
|
46134
|
+
missingContractIds
|
45992
46135
|
};
|
45993
46136
|
}
|
45994
46137
|
async getResourcesForTransaction(owner, transactionRequestLike, forwardingQuantities = []) {
|