@fuel-ts/account 0.0.0-pr-1788-20240222094224 → 0.0.0-pr-1864-20240312141036
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of @fuel-ts/account might be problematic. Click here for more details.
- package/dist/account.d.ts.map +1 -1
- package/dist/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/hdwallet/hdwallet.d.ts.map +1 -1
- package/dist/index.global.js +1524 -2888
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +234 -243
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +287 -298
- package/dist/index.mjs.map +1 -1
- package/dist/mnemonic/mnemonic.d.ts.map +1 -1
- package/dist/mnemonic/utils.d.ts.map +1 -1
- package/dist/predicate/predicate.d.ts +16 -15
- package/dist/predicate/predicate.d.ts.map +1 -1
- package/dist/providers/__generated__/operations.d.ts +47 -38
- package/dist/providers/__generated__/operations.d.ts.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 +28 -12
- package/dist/providers/provider.d.ts.map +1 -1
- package/dist/providers/transaction-request/hash-transaction.d.ts.map +1 -1
- package/dist/providers/transaction-request/transaction-request.d.ts.map +1 -1
- package/dist/providers/transaction-response/getDecodedLogs.d.ts.map +1 -1
- package/dist/providers/transaction-response/transaction-response.d.ts.map +1 -1
- package/dist/providers/transaction-summary/assemble-transaction-summary.d.ts.map +1 -1
- package/dist/providers/transaction-summary/index.d.ts +0 -1
- package/dist/providers/transaction-summary/index.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/providers/utils/index.d.ts +0 -1
- package/dist/providers/utils/index.d.ts.map +1 -1
- package/dist/test-utils.global.js +1498 -2850
- package/dist/test-utils.global.js.map +1 -1
- package/dist/test-utils.js +211 -199
- package/dist/test-utils.js.map +1 -1
- package/dist/test-utils.mjs +244 -240
- 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/providers/transaction-summary/date.d.ts +0 -3
- package/dist/providers/transaction-summary/date.d.ts.map +0 -1
- package/dist/providers/utils/time.d.ts +0 -40
- package/dist/providers/utils/time.d.ts.map +0 -1
package/dist/index.mjs
CHANGED
@@ -30,7 +30,7 @@ var __privateMethod = (obj, member, method) => {
|
|
30
30
|
// src/account.ts
|
31
31
|
import { Address as Address3 } from "@fuel-ts/address";
|
32
32
|
import { BaseAssetId as BaseAssetId3 } from "@fuel-ts/address/configs";
|
33
|
-
import { ErrorCode as
|
33
|
+
import { ErrorCode as ErrorCode14, FuelError as FuelError14 } from "@fuel-ts/errors";
|
34
34
|
import { AbstractAccount } from "@fuel-ts/interfaces";
|
35
35
|
import { bn as bn16 } from "@fuel-ts/math";
|
36
36
|
import { arrayify as arrayify14 } from "@fuel-ts/utils";
|
@@ -73,7 +73,7 @@ var addAmountToAsset = (params) => {
|
|
73
73
|
|
74
74
|
// src/providers/provider.ts
|
75
75
|
import { Address as Address2 } from "@fuel-ts/address";
|
76
|
-
import { ErrorCode as
|
76
|
+
import { ErrorCode as ErrorCode12, FuelError as FuelError12 } from "@fuel-ts/errors";
|
77
77
|
import { BN, bn as bn14, max } from "@fuel-ts/math";
|
78
78
|
import {
|
79
79
|
InputType as InputType6,
|
@@ -81,7 +81,7 @@ import {
|
|
81
81
|
InputMessageCoder,
|
82
82
|
TransactionCoder as TransactionCoder5
|
83
83
|
} from "@fuel-ts/transactions";
|
84
|
-
import { arrayify as arrayify11, hexlify as hexlify12 } from "@fuel-ts/utils";
|
84
|
+
import { arrayify as arrayify11, hexlify as hexlify12, DateTime as DateTime2 } from "@fuel-ts/utils";
|
85
85
|
import { checkFuelCoreVersionCompatibility } from "@fuel-ts/versions";
|
86
86
|
import { equalBytes } from "@noble/curves/abstract/utils";
|
87
87
|
import { Network } from "ethers";
|
@@ -149,6 +149,9 @@ var TransactionStatusFragmentFragmentDoc = gql`
|
|
149
149
|
time
|
150
150
|
reason
|
151
151
|
}
|
152
|
+
... on SqueezedOutStatus {
|
153
|
+
reason
|
154
|
+
}
|
152
155
|
}
|
153
156
|
`;
|
154
157
|
var TransactionFragmentFragmentDoc = gql`
|
@@ -891,72 +894,77 @@ function getSdk(requester) {
|
|
891
894
|
}
|
892
895
|
|
893
896
|
// src/providers/fuel-graphql-subscriber.ts
|
894
|
-
import { FuelError } from "@fuel-ts/errors";
|
897
|
+
import { ErrorCode, FuelError } from "@fuel-ts/errors";
|
895
898
|
import { print } from "graphql";
|
896
|
-
var
|
897
|
-
|
898
|
-
|
899
|
-
|
900
|
-
|
901
|
-
|
902
|
-
|
903
|
-
|
904
|
-
|
905
|
-
|
906
|
-
|
907
|
-
|
908
|
-
|
909
|
-
|
910
|
-
|
911
|
-
|
912
|
-
this.readableStreamController.enqueue(
|
913
|
-
new FuelError(
|
914
|
-
FuelError.CODES.INVALID_REQUEST,
|
915
|
-
errors.map((err) => err.message).join("\n\n")
|
916
|
-
)
|
917
|
-
);
|
918
|
-
} else {
|
919
|
-
this.readableStreamController.enqueue(data);
|
920
|
-
}
|
921
|
-
}
|
899
|
+
var _FuelGraphqlSubscriber = class {
|
900
|
+
constructor(options) {
|
901
|
+
this.options = options;
|
902
|
+
}
|
903
|
+
stream;
|
904
|
+
async setStream() {
|
905
|
+
const { url, query, variables, fetchFn } = this.options;
|
906
|
+
const response = await fetchFn(`${url}-sub`, {
|
907
|
+
method: "POST",
|
908
|
+
body: JSON.stringify({
|
909
|
+
query: print(query),
|
910
|
+
variables
|
911
|
+
}),
|
912
|
+
headers: {
|
913
|
+
"Content-Type": "application/json",
|
914
|
+
Accept: "text/event-stream"
|
922
915
|
}
|
923
916
|
});
|
917
|
+
this.stream = response.body.getReader();
|
924
918
|
}
|
925
|
-
|
926
|
-
|
927
|
-
|
928
|
-
async function* fuelGraphQLSubscriber({
|
929
|
-
url,
|
930
|
-
variables,
|
931
|
-
query,
|
932
|
-
fetchFn
|
933
|
-
}) {
|
934
|
-
const response = await fetchFn(`${url}-sub`, {
|
935
|
-
method: "POST",
|
936
|
-
body: JSON.stringify({
|
937
|
-
query: print(query),
|
938
|
-
variables
|
939
|
-
}),
|
940
|
-
headers: {
|
941
|
-
"Content-Type": "application/json",
|
942
|
-
Accept: "text/event-stream"
|
943
|
-
}
|
944
|
-
});
|
945
|
-
const subscriptionStreamReader = response.body.pipeThrough(new FuelSubscriptionStream()).getReader();
|
946
|
-
while (true) {
|
947
|
-
const { value, done } = await subscriptionStreamReader.read();
|
948
|
-
if (value instanceof FuelError) {
|
949
|
-
throw value;
|
919
|
+
async next() {
|
920
|
+
if (!this.stream) {
|
921
|
+
await this.setStream();
|
950
922
|
}
|
951
|
-
|
952
|
-
|
953
|
-
|
923
|
+
while (true) {
|
924
|
+
const { value, done } = await this.stream.read();
|
925
|
+
if (done) {
|
926
|
+
return { value, done };
|
927
|
+
}
|
928
|
+
const text = _FuelGraphqlSubscriber.textDecoder.decode(value);
|
929
|
+
if (!text.startsWith("data:")) {
|
930
|
+
continue;
|
931
|
+
}
|
932
|
+
let data;
|
933
|
+
let errors;
|
934
|
+
try {
|
935
|
+
({ data, errors } = JSON.parse(text.replace(/^data:/, "")));
|
936
|
+
} catch (e) {
|
937
|
+
throw new FuelError(
|
938
|
+
ErrorCode.STREAM_PARSING_ERROR,
|
939
|
+
`Error while parsing stream data response: ${text}`
|
940
|
+
);
|
941
|
+
}
|
942
|
+
if (Array.isArray(errors)) {
|
943
|
+
throw new FuelError(
|
944
|
+
FuelError.CODES.INVALID_REQUEST,
|
945
|
+
errors.map((err) => err.message).join("\n\n")
|
946
|
+
);
|
947
|
+
}
|
948
|
+
return { value: data, done: false };
|
954
949
|
}
|
955
950
|
}
|
956
|
-
|
951
|
+
/**
|
952
|
+
* Gets called when `break` is called in a `for-await-of` loop.
|
953
|
+
*/
|
954
|
+
async return() {
|
955
|
+
await this.stream.cancel();
|
956
|
+
this.stream.releaseLock();
|
957
|
+
return { done: true, value: void 0 };
|
958
|
+
}
|
959
|
+
[Symbol.asyncIterator]() {
|
960
|
+
return this;
|
961
|
+
}
|
962
|
+
};
|
963
|
+
var FuelGraphqlSubscriber = _FuelGraphqlSubscriber;
|
964
|
+
__publicField(FuelGraphqlSubscriber, "textDecoder", new TextDecoder());
|
957
965
|
|
958
966
|
// src/providers/memory-cache.ts
|
959
|
-
import { ErrorCode, FuelError as FuelError2 } from "@fuel-ts/errors";
|
967
|
+
import { ErrorCode as ErrorCode2, FuelError as FuelError2 } from "@fuel-ts/errors";
|
960
968
|
import { hexlify as hexlify2 } from "@fuel-ts/utils";
|
961
969
|
var cache = {};
|
962
970
|
var DEFAULT_TTL_IN_MS = 30 * 1e3;
|
@@ -966,7 +974,7 @@ var MemoryCache = class {
|
|
966
974
|
this.ttl = ttlInMs;
|
967
975
|
if (typeof ttlInMs !== "number" || this.ttl <= 0) {
|
968
976
|
throw new FuelError2(
|
969
|
-
|
977
|
+
ErrorCode2.INVALID_TTL,
|
970
978
|
`Invalid TTL: ${this.ttl}. Use a value greater than zero.`
|
971
979
|
);
|
972
980
|
}
|
@@ -1016,7 +1024,7 @@ var MemoryCache = class {
|
|
1016
1024
|
|
1017
1025
|
// src/providers/transaction-request/input.ts
|
1018
1026
|
import { ZeroBytes32 } from "@fuel-ts/address/configs";
|
1019
|
-
import { ErrorCode as
|
1027
|
+
import { ErrorCode as ErrorCode3, FuelError as FuelError3 } from "@fuel-ts/errors";
|
1020
1028
|
import { bn as bn2, toNumber } from "@fuel-ts/math";
|
1021
1029
|
import { InputType } from "@fuel-ts/transactions";
|
1022
1030
|
import { arrayify, hexlify as hexlify3 } from "@fuel-ts/utils";
|
@@ -1082,7 +1090,7 @@ var inputify = (value) => {
|
|
1082
1090
|
}
|
1083
1091
|
default: {
|
1084
1092
|
throw new FuelError3(
|
1085
|
-
|
1093
|
+
ErrorCode3.INVALID_TRANSACTION_INPUT,
|
1086
1094
|
`Invalid transaction input type: ${type}.`
|
1087
1095
|
);
|
1088
1096
|
}
|
@@ -1091,7 +1099,7 @@ var inputify = (value) => {
|
|
1091
1099
|
|
1092
1100
|
// src/providers/transaction-request/output.ts
|
1093
1101
|
import { ZeroBytes32 as ZeroBytes322 } from "@fuel-ts/address/configs";
|
1094
|
-
import { ErrorCode as
|
1102
|
+
import { ErrorCode as ErrorCode4, FuelError as FuelError4 } from "@fuel-ts/errors";
|
1095
1103
|
import { bn as bn3 } from "@fuel-ts/math";
|
1096
1104
|
import { OutputType } from "@fuel-ts/transactions";
|
1097
1105
|
import { hexlify as hexlify4 } from "@fuel-ts/utils";
|
@@ -1139,7 +1147,7 @@ var outputify = (value) => {
|
|
1139
1147
|
}
|
1140
1148
|
default: {
|
1141
1149
|
throw new FuelError4(
|
1142
|
-
|
1150
|
+
ErrorCode4.INVALID_TRANSACTION_INPUT,
|
1143
1151
|
`Invalid transaction output type: ${type}.`
|
1144
1152
|
);
|
1145
1153
|
}
|
@@ -1167,7 +1175,7 @@ var isMessage = (resource) => "recipient" in resource;
|
|
1167
1175
|
|
1168
1176
|
// src/providers/utils/receipts.ts
|
1169
1177
|
import { ZeroBytes32 as ZeroBytes323 } from "@fuel-ts/address/configs";
|
1170
|
-
import { ErrorCode as
|
1178
|
+
import { ErrorCode as ErrorCode5, FuelError as FuelError5 } from "@fuel-ts/errors";
|
1171
1179
|
import { bn as bn4 } from "@fuel-ts/math";
|
1172
1180
|
import {
|
1173
1181
|
ReceiptBurnCoder,
|
@@ -1372,12 +1380,12 @@ function assembleReceiptByType(receipt) {
|
|
1372
1380
|
return burnReceipt;
|
1373
1381
|
}
|
1374
1382
|
default:
|
1375
|
-
throw new FuelError5(
|
1383
|
+
throw new FuelError5(ErrorCode5.INVALID_RECEIPT_TYPE, `Invalid receipt type: ${receiptType}.`);
|
1376
1384
|
}
|
1377
1385
|
}
|
1378
1386
|
|
1379
1387
|
// src/providers/utils/block-explorer.ts
|
1380
|
-
import { ErrorCode as
|
1388
|
+
import { ErrorCode as ErrorCode6, FuelError as FuelError6 } from "@fuel-ts/errors";
|
1381
1389
|
var DEFAULT_BLOCK_EXPLORER_URL = "https://fuellabs.github.io/block-explorer-v2";
|
1382
1390
|
var getPathFromInput = (key, value) => {
|
1383
1391
|
const pathMap = {
|
@@ -1412,14 +1420,14 @@ var buildBlockExplorerUrl = (options = {}) => {
|
|
1412
1420
|
const hasAnyDefinedValues = definedValues.length > 0;
|
1413
1421
|
if (definedValues.length > 1) {
|
1414
1422
|
throw new FuelError6(
|
1415
|
-
|
1423
|
+
ErrorCode6.ERROR_BUILDING_BLOCK_EXPLORER_URL,
|
1416
1424
|
`Only one of the following can be passed in to buildBlockExplorerUrl: ${customInputParams.map((param) => param.key).join(", ")}.`
|
1417
1425
|
);
|
1418
1426
|
}
|
1419
1427
|
if (path && definedValues.length > 0) {
|
1420
1428
|
const inputKeys = customInputParams.map(({ key }) => key).join(", ");
|
1421
1429
|
throw new FuelError6(
|
1422
|
-
|
1430
|
+
ErrorCode6.ERROR_BUILDING_BLOCK_EXPLORER_URL,
|
1423
1431
|
`You cannot pass in a path to 'buildBlockExplorerUrl' along with any of the following: ${inputKeys}.`
|
1424
1432
|
);
|
1425
1433
|
}
|
@@ -1554,10 +1562,6 @@ function sleep(time) {
|
|
1554
1562
|
});
|
1555
1563
|
}
|
1556
1564
|
|
1557
|
-
// src/providers/utils/time.ts
|
1558
|
-
var fromTai64ToUnix = (tai64Timestamp) => Number(BigInt(tai64Timestamp) - BigInt(2 ** 62) - BigInt(10));
|
1559
|
-
var fromUnixToTai64 = (unixTimestampMs) => (BigInt(unixTimestampMs) + BigInt(2 ** 62) + BigInt(10)).toString();
|
1560
|
-
|
1561
1565
|
// src/providers/transaction-request/errors.ts
|
1562
1566
|
var ChangeOutputCollisionError = class extends Error {
|
1563
1567
|
name = "ChangeOutputCollisionError";
|
@@ -1811,7 +1815,7 @@ var BaseTransactionRequest = class {
|
|
1811
1815
|
txPointer: "0x00000000000000000000000000000000",
|
1812
1816
|
witnessIndex,
|
1813
1817
|
predicate: predicate?.bytes,
|
1814
|
-
predicateData: predicate?.
|
1818
|
+
predicateData: predicate?.predicateDataBytes
|
1815
1819
|
};
|
1816
1820
|
this.pushInput(input);
|
1817
1821
|
this.addChangeOutput(owner, assetId);
|
@@ -1844,7 +1848,7 @@ var BaseTransactionRequest = class {
|
|
1844
1848
|
amount,
|
1845
1849
|
witnessIndex,
|
1846
1850
|
predicate: predicate?.bytes,
|
1847
|
-
predicateData: predicate?.
|
1851
|
+
predicateData: predicate?.predicateDataBytes
|
1848
1852
|
};
|
1849
1853
|
this.pushInput(input);
|
1850
1854
|
this.addChangeOutput(recipient, assetId);
|
@@ -2059,8 +2063,6 @@ var BaseTransactionRequest = class {
|
|
2059
2063
|
this.inputs.forEach((i) => {
|
2060
2064
|
let correspondingInput;
|
2061
2065
|
switch (i.type) {
|
2062
|
-
case InputType2.Contract:
|
2063
|
-
return;
|
2064
2066
|
case InputType2.Coin:
|
2065
2067
|
correspondingInput = inputs.find((x) => x.type === InputType2.Coin && x.owner === i.owner);
|
2066
2068
|
break;
|
@@ -2070,7 +2072,7 @@ var BaseTransactionRequest = class {
|
|
2070
2072
|
);
|
2071
2073
|
break;
|
2072
2074
|
default:
|
2073
|
-
|
2075
|
+
return;
|
2074
2076
|
}
|
2075
2077
|
if (correspondingInput && "predicateGasUsed" in correspondingInput && bn6(correspondingInput.predicateGasUsed).gt(0)) {
|
2076
2078
|
i.predicate = correspondingInput.predicate;
|
@@ -2089,11 +2091,10 @@ import { arrayify as arrayify6, hexlify as hexlify9 } from "@fuel-ts/utils";
|
|
2089
2091
|
|
2090
2092
|
// src/providers/transaction-request/hash-transaction.ts
|
2091
2093
|
import { ZeroBytes32 as ZeroBytes325 } from "@fuel-ts/address/configs";
|
2092
|
-
import { uint64ToBytesBE } from "@fuel-ts/hasher";
|
2094
|
+
import { uint64ToBytesBE, sha256 } from "@fuel-ts/hasher";
|
2093
2095
|
import { bn as bn7 } from "@fuel-ts/math";
|
2094
2096
|
import { TransactionType as TransactionType2, InputType as InputType3, OutputType as OutputType3, TransactionCoder as TransactionCoder2 } from "@fuel-ts/transactions";
|
2095
2097
|
import { concat as concat2 } from "@fuel-ts/utils";
|
2096
|
-
import { sha256 } from "ethers";
|
2097
2098
|
import { clone as clone2 } from "ramda";
|
2098
2099
|
function hashTransaction(transactionRequest, chainId) {
|
2099
2100
|
const transaction = transactionRequest.toTransaction();
|
@@ -2480,7 +2481,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2480
2481
|
};
|
2481
2482
|
|
2482
2483
|
// src/providers/transaction-request/utils.ts
|
2483
|
-
import { ErrorCode as
|
2484
|
+
import { ErrorCode as ErrorCode7, FuelError as FuelError7 } from "@fuel-ts/errors";
|
2484
2485
|
import { TransactionType as TransactionType5 } from "@fuel-ts/transactions";
|
2485
2486
|
var transactionRequestify = (obj) => {
|
2486
2487
|
if (obj instanceof ScriptTransactionRequest || obj instanceof CreateTransactionRequest) {
|
@@ -2495,19 +2496,19 @@ var transactionRequestify = (obj) => {
|
|
2495
2496
|
return CreateTransactionRequest.from(obj);
|
2496
2497
|
}
|
2497
2498
|
default: {
|
2498
|
-
throw new FuelError7(
|
2499
|
+
throw new FuelError7(ErrorCode7.INVALID_TRANSACTION_TYPE, `Invalid transaction type: ${type}.`);
|
2499
2500
|
}
|
2500
2501
|
}
|
2501
2502
|
};
|
2502
2503
|
|
2503
2504
|
// src/providers/transaction-response/transaction-response.ts
|
2504
|
-
import { ErrorCode as
|
2505
|
+
import { ErrorCode as ErrorCode11, FuelError as FuelError11 } from "@fuel-ts/errors";
|
2505
2506
|
import { bn as bn13 } from "@fuel-ts/math";
|
2506
2507
|
import { TransactionCoder as TransactionCoder4 } from "@fuel-ts/transactions";
|
2507
2508
|
import { arrayify as arrayify10 } from "@fuel-ts/utils";
|
2508
2509
|
|
2509
2510
|
// src/providers/transaction-summary/assemble-transaction-summary.ts
|
2510
|
-
import { hexlify as hexlify11 } from "@fuel-ts/utils";
|
2511
|
+
import { DateTime, hexlify as hexlify11 } from "@fuel-ts/utils";
|
2511
2512
|
|
2512
2513
|
// src/providers/transaction-summary/calculate-transaction-fee.ts
|
2513
2514
|
import { bn as bn10 } from "@fuel-ts/math";
|
@@ -2582,16 +2583,9 @@ var calculateTransactionFee = (params) => {
|
|
2582
2583
|
};
|
2583
2584
|
};
|
2584
2585
|
|
2585
|
-
// src/providers/transaction-summary/date.ts
|
2586
|
-
import { TAI64 } from "tai64";
|
2587
|
-
var fromTai64ToDate = (tai64Timestamp) => {
|
2588
|
-
const timestamp = TAI64.fromString(tai64Timestamp, 10).toUnix();
|
2589
|
-
return new Date(timestamp * 1e3);
|
2590
|
-
};
|
2591
|
-
var fromDateToTai64 = (date) => TAI64.fromUnix(Math.floor(date.getTime() / 1e3)).toString(10);
|
2592
|
-
|
2593
2586
|
// src/providers/transaction-summary/operations.ts
|
2594
|
-
import {
|
2587
|
+
import { ZeroBytes32 as ZeroBytes328 } from "@fuel-ts/address/configs";
|
2588
|
+
import { ErrorCode as ErrorCode9, FuelError as FuelError9 } from "@fuel-ts/errors";
|
2595
2589
|
import { bn as bn12 } from "@fuel-ts/math";
|
2596
2590
|
import { ReceiptType as ReceiptType3, TransactionType as TransactionType7 } from "@fuel-ts/transactions";
|
2597
2591
|
|
@@ -2640,7 +2634,7 @@ var getFunctionCall = ({ abi, receipt, rawPayload, maxInputs }) => {
|
|
2640
2634
|
};
|
2641
2635
|
|
2642
2636
|
// src/providers/transaction-summary/input.ts
|
2643
|
-
import { ErrorCode as
|
2637
|
+
import { ErrorCode as ErrorCode8, FuelError as FuelError8 } from "@fuel-ts/errors";
|
2644
2638
|
import { InputType as InputType5 } from "@fuel-ts/transactions";
|
2645
2639
|
function getInputsByTypes(inputs, types) {
|
2646
2640
|
return inputs.filter((i) => types.includes(i.type));
|
@@ -2679,7 +2673,7 @@ function getInputContractFromIndex(inputs, inputIndex) {
|
|
2679
2673
|
}
|
2680
2674
|
if (contractInput.type !== InputType5.Contract) {
|
2681
2675
|
throw new FuelError8(
|
2682
|
-
|
2676
|
+
ErrorCode8.INVALID_TRANSACTION_INPUT,
|
2683
2677
|
`Contract input should be of type 'contract'.`
|
2684
2678
|
);
|
2685
2679
|
}
|
@@ -2735,7 +2729,6 @@ var OperationName = /* @__PURE__ */ ((OperationName2) => {
|
|
2735
2729
|
OperationName2["contractCreated"] = "Contract created";
|
2736
2730
|
OperationName2["transfer"] = "Transfer asset";
|
2737
2731
|
OperationName2["contractCall"] = "Contract call";
|
2738
|
-
OperationName2["contractTransfer"] = "Contract transfer";
|
2739
2732
|
OperationName2["receive"] = "Receive asset";
|
2740
2733
|
OperationName2["mint"] = "Mint asset";
|
2741
2734
|
OperationName2["predicatecall"] = "Predicate call";
|
@@ -2769,7 +2762,7 @@ function getTransactionTypeName(transactionType) {
|
|
2769
2762
|
return "Script" /* Script */;
|
2770
2763
|
default:
|
2771
2764
|
throw new FuelError9(
|
2772
|
-
|
2765
|
+
ErrorCode9.INVALID_TRANSACTION_TYPE,
|
2773
2766
|
`Invalid transaction type: ${transactionType}.`
|
2774
2767
|
);
|
2775
2768
|
}
|
@@ -2835,33 +2828,6 @@ function addOperation(operations, toAdd) {
|
|
2835
2828
|
function getReceiptsTransferOut(receipts) {
|
2836
2829
|
return getReceiptsByType(receipts, ReceiptType3.TransferOut);
|
2837
2830
|
}
|
2838
|
-
function getContractTransferOperations({ receipts }) {
|
2839
|
-
const transferOutReceipts = getReceiptsTransferOut(receipts);
|
2840
|
-
const contractTransferOperations = transferOutReceipts.reduce(
|
2841
|
-
(prevContractTransferOps, receipt) => {
|
2842
|
-
const newContractTransferOps = addOperation(prevContractTransferOps, {
|
2843
|
-
name: "Contract transfer" /* contractTransfer */,
|
2844
|
-
from: {
|
2845
|
-
type: 0 /* contract */,
|
2846
|
-
address: receipt.from
|
2847
|
-
},
|
2848
|
-
to: {
|
2849
|
-
type: 1 /* account */,
|
2850
|
-
address: receipt.to
|
2851
|
-
},
|
2852
|
-
assetsSent: [
|
2853
|
-
{
|
2854
|
-
amount: receipt.amount,
|
2855
|
-
assetId: receipt.assetId
|
2856
|
-
}
|
2857
|
-
]
|
2858
|
-
});
|
2859
|
-
return newContractTransferOps;
|
2860
|
-
},
|
2861
|
-
[]
|
2862
|
-
);
|
2863
|
-
return contractTransferOperations;
|
2864
|
-
}
|
2865
2831
|
function getWithdrawFromFuelOperations({
|
2866
2832
|
inputs,
|
2867
2833
|
receipts
|
@@ -2959,70 +2925,77 @@ function getContractCallOperations({
|
|
2959
2925
|
}, []);
|
2960
2926
|
return contractCallOperations;
|
2961
2927
|
}
|
2928
|
+
function extractTransferOperationFromReceipt(receipt, contractInputs, changeOutputs) {
|
2929
|
+
const { to: toAddress, assetId, amount } = receipt;
|
2930
|
+
let { from: fromAddress } = receipt;
|
2931
|
+
const toType = contractInputs.some((input) => input.contractID === toAddress) ? 0 /* contract */ : 1 /* account */;
|
2932
|
+
if (ZeroBytes328 === fromAddress) {
|
2933
|
+
const change = changeOutputs.find((output) => output.assetId === assetId);
|
2934
|
+
fromAddress = change?.to || fromAddress;
|
2935
|
+
}
|
2936
|
+
const fromType = contractInputs.some((input) => input.contractID === fromAddress) ? 0 /* contract */ : 1 /* account */;
|
2937
|
+
return {
|
2938
|
+
name: "Transfer asset" /* transfer */,
|
2939
|
+
from: {
|
2940
|
+
type: fromType,
|
2941
|
+
address: fromAddress
|
2942
|
+
},
|
2943
|
+
to: {
|
2944
|
+
type: toType,
|
2945
|
+
address: toAddress
|
2946
|
+
},
|
2947
|
+
assetsSent: [
|
2948
|
+
{
|
2949
|
+
assetId: assetId.toString(),
|
2950
|
+
amount
|
2951
|
+
}
|
2952
|
+
]
|
2953
|
+
};
|
2954
|
+
}
|
2962
2955
|
function getTransferOperations({
|
2963
2956
|
inputs,
|
2964
2957
|
outputs,
|
2965
2958
|
receipts
|
2966
2959
|
}) {
|
2960
|
+
let operations = [];
|
2967
2961
|
const coinOutputs = getOutputsCoin(outputs);
|
2968
|
-
const
|
2962
|
+
const contractInputs = getInputsContract(inputs);
|
2963
|
+
const changeOutputs = getOutputsChange(outputs);
|
2964
|
+
coinOutputs.forEach((output) => {
|
2965
|
+
const { amount, assetId, to } = output;
|
2966
|
+
const changeOutput = changeOutputs.find((change) => change.assetId === assetId);
|
2967
|
+
if (changeOutput) {
|
2968
|
+
operations = addOperation(operations, {
|
2969
|
+
name: "Transfer asset" /* transfer */,
|
2970
|
+
from: {
|
2971
|
+
type: 1 /* account */,
|
2972
|
+
address: changeOutput.to
|
2973
|
+
},
|
2974
|
+
to: {
|
2975
|
+
type: 1 /* account */,
|
2976
|
+
address: to
|
2977
|
+
},
|
2978
|
+
assetsSent: [
|
2979
|
+
{
|
2980
|
+
assetId,
|
2981
|
+
amount
|
2982
|
+
}
|
2983
|
+
]
|
2984
|
+
});
|
2985
|
+
}
|
2986
|
+
});
|
2987
|
+
const transferReceipts = getReceiptsByType(
|
2969
2988
|
receipts,
|
2970
2989
|
ReceiptType3.Transfer
|
2971
2990
|
);
|
2972
|
-
|
2973
|
-
|
2974
|
-
|
2975
|
-
|
2976
|
-
|
2977
|
-
|
2978
|
-
|
2979
|
-
|
2980
|
-
const inputAddress = getInputAccountAddress(utxo);
|
2981
|
-
operations = addOperation(operations, {
|
2982
|
-
name: "Transfer asset" /* transfer */,
|
2983
|
-
from: {
|
2984
|
-
type: 1 /* account */,
|
2985
|
-
address: inputAddress
|
2986
|
-
},
|
2987
|
-
to: {
|
2988
|
-
type: 0 /* contract */,
|
2989
|
-
address: contractInput.contractID
|
2990
|
-
},
|
2991
|
-
assetsSent: [
|
2992
|
-
{
|
2993
|
-
assetId: assetId.toString(),
|
2994
|
-
amount: transferReceipt.amount
|
2995
|
-
}
|
2996
|
-
]
|
2997
|
-
});
|
2998
|
-
}
|
2999
|
-
});
|
3000
|
-
} else {
|
3001
|
-
coinOutputs.forEach((output) => {
|
3002
|
-
const input = getInputFromAssetId(inputs, output.assetId);
|
3003
|
-
if (input) {
|
3004
|
-
const inputAddress = getInputAccountAddress(input);
|
3005
|
-
const operationToAdd = {
|
3006
|
-
name: "Transfer asset" /* transfer */,
|
3007
|
-
from: {
|
3008
|
-
type: 1 /* account */,
|
3009
|
-
address: inputAddress
|
3010
|
-
},
|
3011
|
-
to: {
|
3012
|
-
type: 1 /* account */,
|
3013
|
-
address: output.to.toString()
|
3014
|
-
},
|
3015
|
-
assetsSent: [
|
3016
|
-
{
|
3017
|
-
assetId: output.assetId.toString(),
|
3018
|
-
amount: output.amount
|
3019
|
-
}
|
3020
|
-
]
|
3021
|
-
};
|
3022
|
-
operations = addOperation(operations, operationToAdd);
|
3023
|
-
}
|
3024
|
-
});
|
3025
|
-
}
|
2991
|
+
const transferOutReceipts = getReceiptsByType(
|
2992
|
+
receipts,
|
2993
|
+
ReceiptType3.TransferOut
|
2994
|
+
);
|
2995
|
+
[...transferReceipts, ...transferOutReceipts].forEach((receipt) => {
|
2996
|
+
const operation = extractTransferOperationFromReceipt(receipt, contractInputs, changeOutputs);
|
2997
|
+
operations = addOperation(operations, operation);
|
2998
|
+
});
|
3026
2999
|
return operations;
|
3027
3000
|
}
|
3028
3001
|
function getPayProducerOperations(outputs) {
|
@@ -3095,7 +3068,6 @@ function getOperations({
|
|
3095
3068
|
rawPayload,
|
3096
3069
|
maxInputs
|
3097
3070
|
}),
|
3098
|
-
...getContractTransferOperations({ receipts }),
|
3099
3071
|
...getWithdrawFromFuelOperations({ inputs, receipts })
|
3100
3072
|
];
|
3101
3073
|
}
|
@@ -3153,7 +3125,7 @@ var extractBurnedAssetsFromReceipts = (receipts) => {
|
|
3153
3125
|
};
|
3154
3126
|
|
3155
3127
|
// src/providers/transaction-summary/status.ts
|
3156
|
-
import { ErrorCode as
|
3128
|
+
import { ErrorCode as ErrorCode10, FuelError as FuelError10 } from "@fuel-ts/errors";
|
3157
3129
|
var getTransactionStatusName = (gqlStatus) => {
|
3158
3130
|
switch (gqlStatus) {
|
3159
3131
|
case "FailureStatus":
|
@@ -3166,7 +3138,7 @@ var getTransactionStatusName = (gqlStatus) => {
|
|
3166
3138
|
return "squeezedout" /* squeezedout */;
|
3167
3139
|
default:
|
3168
3140
|
throw new FuelError10(
|
3169
|
-
|
3141
|
+
ErrorCode10.INVALID_TRANSACTION_STATUS,
|
3170
3142
|
`Invalid transaction status: ${gqlStatus}.`
|
3171
3143
|
);
|
3172
3144
|
}
|
@@ -3251,7 +3223,7 @@ function assembleTransactionSummary(params) {
|
|
3251
3223
|
const burnedAssets = extractBurnedAssetsFromReceipts(receipts);
|
3252
3224
|
let date;
|
3253
3225
|
if (time) {
|
3254
|
-
date =
|
3226
|
+
date = DateTime.fromTai64(time);
|
3255
3227
|
}
|
3256
3228
|
const transactionSummary = {
|
3257
3229
|
id,
|
@@ -3386,6 +3358,12 @@ var TransactionResponse = class {
|
|
3386
3358
|
transactionId: this.id
|
3387
3359
|
});
|
3388
3360
|
for await (const { statusChange } of subscription) {
|
3361
|
+
if (statusChange.type === "SqueezedOutStatus") {
|
3362
|
+
throw new FuelError11(
|
3363
|
+
ErrorCode11.TRANSACTION_SQUEEZED_OUT,
|
3364
|
+
`Transaction Squeezed Out with reason: ${statusChange.reason}`
|
3365
|
+
);
|
3366
|
+
}
|
3389
3367
|
if (statusChange.type !== "SubmittedStatus") {
|
3390
3368
|
break;
|
3391
3369
|
}
|
@@ -3415,7 +3393,7 @@ var TransactionResponse = class {
|
|
3415
3393
|
const result = await this.waitForResult(contractsAbiMap);
|
3416
3394
|
if (result.isStatusFailure) {
|
3417
3395
|
throw new FuelError11(
|
3418
|
-
|
3396
|
+
ErrorCode11.TRANSACTION_FAILED,
|
3419
3397
|
`Transaction failed: ${result.gqlTransaction.status.reason}`
|
3420
3398
|
);
|
3421
3399
|
}
|
@@ -3424,7 +3402,7 @@ var TransactionResponse = class {
|
|
3424
3402
|
};
|
3425
3403
|
|
3426
3404
|
// src/providers/transaction-response/getDecodedLogs.ts
|
3427
|
-
import {
|
3405
|
+
import { BigNumberCoder } from "@fuel-ts/abi-coder";
|
3428
3406
|
import { ReceiptType as ReceiptType5 } from "@fuel-ts/transactions";
|
3429
3407
|
function getDecodedLogs(receipts, abiInterface) {
|
3430
3408
|
return receipts.reduce((logs, r) => {
|
@@ -3432,7 +3410,9 @@ function getDecodedLogs(receipts, abiInterface) {
|
|
3432
3410
|
logs.push(abiInterface.decodeLog(r.data, r.val1.toNumber(), r.id)[0]);
|
3433
3411
|
}
|
3434
3412
|
if (r.type === ReceiptType5.Log) {
|
3435
|
-
logs.push(
|
3413
|
+
logs.push(
|
3414
|
+
abiInterface.decodeLog(new BigNumberCoder("u64").encode(r.val0), r.val1.toNumber(), r.id)[0]
|
3415
|
+
);
|
3436
3416
|
}
|
3437
3417
|
return logs;
|
3438
3418
|
}, []);
|
@@ -3561,14 +3541,15 @@ var _Provider = class {
|
|
3561
3541
|
}
|
3562
3542
|
static getFetchFn(options) {
|
3563
3543
|
const { retryOptions, timeout } = options;
|
3564
|
-
return autoRetryFetch((...args) => {
|
3565
|
-
if (options.fetch) {
|
3566
|
-
return options.fetch(...args);
|
3567
|
-
}
|
3544
|
+
return autoRetryFetch(async (...args) => {
|
3568
3545
|
const url = args[0];
|
3569
3546
|
const request = args[1];
|
3570
3547
|
const signal = timeout ? AbortSignal.timeout(timeout) : void 0;
|
3571
|
-
|
3548
|
+
let fullRequest = { ...request, signal };
|
3549
|
+
if (options.requestMiddleware) {
|
3550
|
+
fullRequest = await options.requestMiddleware(fullRequest);
|
3551
|
+
}
|
3552
|
+
return options.fetch ? options.fetch(url, fullRequest, options) : fetch(url, fullRequest);
|
3572
3553
|
}, retryOptions);
|
3573
3554
|
}
|
3574
3555
|
/**
|
@@ -3588,7 +3569,7 @@ var _Provider = class {
|
|
3588
3569
|
const chain = _Provider.chainInfoCache[this.url];
|
3589
3570
|
if (!chain) {
|
3590
3571
|
throw new FuelError12(
|
3591
|
-
|
3572
|
+
ErrorCode12.CHAIN_INFO_CACHE_EMPTY,
|
3592
3573
|
"Chain info cache is empty. Make sure you have called `Provider.create` to initialize the provider."
|
3593
3574
|
);
|
3594
3575
|
}
|
@@ -3601,7 +3582,7 @@ var _Provider = class {
|
|
3601
3582
|
const node = _Provider.nodeInfoCache[this.url];
|
3602
3583
|
if (!node) {
|
3603
3584
|
throw new FuelError12(
|
3604
|
-
|
3585
|
+
ErrorCode12.NODE_INFO_CACHE_EMPTY,
|
3605
3586
|
"Node info cache is empty. Make sure you have called `Provider.create` to initialize the provider."
|
3606
3587
|
);
|
3607
3588
|
}
|
@@ -3668,7 +3649,7 @@ var _Provider = class {
|
|
3668
3649
|
const opDefinition = query.definitions.find((x) => x.kind === "OperationDefinition");
|
3669
3650
|
const isSubscription = opDefinition?.operation === "subscription";
|
3670
3651
|
if (isSubscription) {
|
3671
|
-
return
|
3652
|
+
return new FuelGraphqlSubscriber({
|
3672
3653
|
url: this.url,
|
3673
3654
|
query,
|
3674
3655
|
fetchFn: (url, requestInit) => fetchFn(url, requestInit, this.options),
|
@@ -3774,6 +3755,12 @@ var _Provider = class {
|
|
3774
3755
|
if (awaitExecution) {
|
3775
3756
|
const subscription = this.operations.submitAndAwait({ encodedTransaction });
|
3776
3757
|
for await (const { submitAndAwait } of subscription) {
|
3758
|
+
if (submitAndAwait.type === "SqueezedOutStatus") {
|
3759
|
+
throw new FuelError12(
|
3760
|
+
ErrorCode12.TRANSACTION_SQUEEZED_OUT,
|
3761
|
+
`Transaction Squeezed Out with reason: ${submitAndAwait.reason}`
|
3762
|
+
);
|
3763
|
+
}
|
3777
3764
|
if (submitAndAwait.type !== "SubmittedStatus") {
|
3778
3765
|
break;
|
3779
3766
|
}
|
@@ -3860,11 +3847,15 @@ var _Provider = class {
|
|
3860
3847
|
async estimateTxDependencies(transactionRequest) {
|
3861
3848
|
if (transactionRequest.type === TransactionType8.Create) {
|
3862
3849
|
return {
|
3863
|
-
receipts: []
|
3850
|
+
receipts: [],
|
3851
|
+
outputVariables: 0,
|
3852
|
+
missingContractIds: []
|
3864
3853
|
};
|
3865
3854
|
}
|
3866
3855
|
await this.estimatePredicates(transactionRequest);
|
3867
3856
|
let receipts = [];
|
3857
|
+
const missingContractIds = [];
|
3858
|
+
let outputVariables = 0;
|
3868
3859
|
for (let attempt = 0; attempt < MAX_RETRIES; attempt++) {
|
3869
3860
|
const { dryRun: gqlReceipts } = await this.operations.dryRun({
|
3870
3861
|
encodedTransaction: hexlify12(transactionRequest.toTransactionBytes()),
|
@@ -3874,16 +3865,20 @@ var _Provider = class {
|
|
3874
3865
|
const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(receipts);
|
3875
3866
|
const hasMissingOutputs = missingOutputVariables.length !== 0 || missingOutputContractIds.length !== 0;
|
3876
3867
|
if (hasMissingOutputs) {
|
3868
|
+
outputVariables += missingOutputVariables.length;
|
3877
3869
|
transactionRequest.addVariableOutputs(missingOutputVariables.length);
|
3878
3870
|
missingOutputContractIds.forEach(({ contractId }) => {
|
3879
3871
|
transactionRequest.addContractInputAndOutput(Address2.fromString(contractId));
|
3872
|
+
missingContractIds.push(contractId);
|
3880
3873
|
});
|
3881
3874
|
} else {
|
3882
3875
|
break;
|
3883
3876
|
}
|
3884
3877
|
}
|
3885
3878
|
return {
|
3886
|
-
receipts
|
3879
|
+
receipts,
|
3880
|
+
outputVariables,
|
3881
|
+
missingContractIds
|
3887
3882
|
};
|
3888
3883
|
}
|
3889
3884
|
/**
|
@@ -3951,11 +3946,15 @@ var _Provider = class {
|
|
3951
3946
|
const minGas = txRequestClone.calculateMinGas(chainInfo);
|
3952
3947
|
const maxGas = txRequestClone.calculateMaxGas(chainInfo, minGas);
|
3953
3948
|
let receipts = [];
|
3949
|
+
let missingContractIds = [];
|
3950
|
+
let outputVariables = 0;
|
3954
3951
|
if (isScriptTransaction && estimateTxDependencies) {
|
3955
3952
|
txRequestClone.gasPrice = bn14(0);
|
3956
3953
|
txRequestClone.gasLimit = bn14(maxGasPerTx.sub(maxGas).toNumber() * 0.9);
|
3957
3954
|
const result = await this.estimateTxDependencies(txRequestClone);
|
3958
3955
|
receipts = result.receipts;
|
3956
|
+
outputVariables = result.outputVariables;
|
3957
|
+
missingContractIds = result.missingContractIds;
|
3959
3958
|
}
|
3960
3959
|
const gasUsed = isScriptTransaction ? getGasUsedFromReceipts(receipts) : minGas;
|
3961
3960
|
const usedFee = calculatePriceWithFactor(
|
@@ -3977,7 +3976,8 @@ var _Provider = class {
|
|
3977
3976
|
minFee,
|
3978
3977
|
maxFee,
|
3979
3978
|
estimatedInputs: txRequestClone.inputs,
|
3980
|
-
|
3979
|
+
outputVariables,
|
3980
|
+
missingContractIds
|
3981
3981
|
};
|
3982
3982
|
}
|
3983
3983
|
async getResourcesForTransaction(owner, transactionRequestLike, forwardingQuantities = []) {
|
@@ -4271,7 +4271,7 @@ var _Provider = class {
|
|
4271
4271
|
};
|
4272
4272
|
if (commitBlockId && commitBlockHeight) {
|
4273
4273
|
throw new FuelError12(
|
4274
|
-
|
4274
|
+
ErrorCode12.INVALID_INPUT_PARAMETERS,
|
4275
4275
|
"commitBlockId and commitBlockHeight cannot be used together"
|
4276
4276
|
);
|
4277
4277
|
}
|
@@ -4357,13 +4357,13 @@ var _Provider = class {
|
|
4357
4357
|
* Lets you produce blocks with custom timestamps and the block number of the last block produced.
|
4358
4358
|
*
|
4359
4359
|
* @param amount - The amount of blocks to produce
|
4360
|
-
* @param startTime - The UNIX timestamp to set for the first produced block
|
4360
|
+
* @param startTime - The UNIX timestamp (milliseconds) to set for the first produced block
|
4361
4361
|
* @returns A promise that resolves to the block number of the last produced block.
|
4362
4362
|
*/
|
4363
4363
|
async produceBlocks(amount, startTime) {
|
4364
4364
|
const { produceBlocks: latestBlockHeight } = await this.operations.produceBlocks({
|
4365
4365
|
blocksToProduce: bn14(amount).toString(10),
|
4366
|
-
startTimestamp: startTime ?
|
4366
|
+
startTimestamp: startTime ? DateTime2.fromUnixMilliseconds(startTime).toTai64() : void 0
|
4367
4367
|
});
|
4368
4368
|
return bn14(latestBlockHeight);
|
4369
4369
|
}
|
@@ -4388,7 +4388,7 @@ __publicField(Provider, "chainInfoCache", {});
|
|
4388
4388
|
__publicField(Provider, "nodeInfoCache", {});
|
4389
4389
|
|
4390
4390
|
// src/providers/transaction-summary/get-transaction-summary.ts
|
4391
|
-
import { ErrorCode as
|
4391
|
+
import { ErrorCode as ErrorCode13, FuelError as FuelError13 } from "@fuel-ts/errors";
|
4392
4392
|
import { bn as bn15 } from "@fuel-ts/math";
|
4393
4393
|
import { TransactionCoder as TransactionCoder6 } from "@fuel-ts/transactions";
|
4394
4394
|
import { arrayify as arrayify12 } from "@fuel-ts/utils";
|
@@ -4399,7 +4399,7 @@ async function getTransactionSummary(params) {
|
|
4399
4399
|
});
|
4400
4400
|
if (!gqlTransaction) {
|
4401
4401
|
throw new FuelError13(
|
4402
|
-
|
4402
|
+
ErrorCode13.TRANSACTION_NOT_FOUND,
|
4403
4403
|
`Transaction not found for given id: ${id}.`
|
4404
4404
|
);
|
4405
4405
|
}
|
@@ -4605,13 +4605,13 @@ var assets = [
|
|
4605
4605
|
];
|
4606
4606
|
|
4607
4607
|
// src/utils/formatTransferToContractScriptData.ts
|
4608
|
-
import {
|
4608
|
+
import { BigNumberCoder as BigNumberCoder2 } from "@fuel-ts/abi-coder";
|
4609
4609
|
import { BN as BN2 } from "@fuel-ts/math";
|
4610
4610
|
import { arrayify as arrayify13 } from "@fuel-ts/utils";
|
4611
4611
|
import * as asm from "@fuels/vm-asm";
|
4612
4612
|
var formatTransferToContractScriptData = (params) => {
|
4613
4613
|
const { assetId, amountToTransfer, hexlifiedContractId } = params;
|
4614
|
-
const numberCoder = new
|
4614
|
+
const numberCoder = new BigNumberCoder2("u64");
|
4615
4615
|
const encoded = numberCoder.encode(new BN2(amountToTransfer).toNumber());
|
4616
4616
|
const scriptData = Uint8Array.from([
|
4617
4617
|
...arrayify13(hexlifiedContractId),
|
@@ -4672,7 +4672,7 @@ var Account = class extends AbstractAccount {
|
|
4672
4672
|
*/
|
4673
4673
|
get provider() {
|
4674
4674
|
if (!this._provider) {
|
4675
|
-
throw new FuelError14(
|
4675
|
+
throw new FuelError14(ErrorCode14.MISSING_PROVIDER, "Provider not set");
|
4676
4676
|
}
|
4677
4677
|
return this._provider;
|
4678
4678
|
}
|
@@ -4725,7 +4725,7 @@ var Account = class extends AbstractAccount {
|
|
4725
4725
|
break;
|
4726
4726
|
}
|
4727
4727
|
throw new FuelError14(
|
4728
|
-
|
4728
|
+
ErrorCode14.NOT_SUPPORTED,
|
4729
4729
|
`Wallets containing more than ${pageSize} coins exceed the current supported limit.`
|
4730
4730
|
);
|
4731
4731
|
}
|
@@ -4751,7 +4751,7 @@ var Account = class extends AbstractAccount {
|
|
4751
4751
|
break;
|
4752
4752
|
}
|
4753
4753
|
throw new FuelError14(
|
4754
|
-
|
4754
|
+
ErrorCode14.NOT_SUPPORTED,
|
4755
4755
|
`Wallets containing more than ${pageSize} messages exceed the current supported limit.`
|
4756
4756
|
);
|
4757
4757
|
}
|
@@ -4787,7 +4787,7 @@ var Account = class extends AbstractAccount {
|
|
4787
4787
|
break;
|
4788
4788
|
}
|
4789
4789
|
throw new FuelError14(
|
4790
|
-
|
4790
|
+
ErrorCode14.NOT_SUPPORTED,
|
4791
4791
|
`Wallets containing more than ${pageSize} balances exceed the current supported limit.`
|
4792
4792
|
);
|
4793
4793
|
}
|
@@ -4892,6 +4892,12 @@ var Account = class extends AbstractAccount {
|
|
4892
4892
|
* @returns A promise that resolves to the transaction response.
|
4893
4893
|
*/
|
4894
4894
|
async transfer(destination, amount, assetId = BaseAssetId3, txParams = {}) {
|
4895
|
+
if (bn16(amount).lte(0)) {
|
4896
|
+
throw new FuelError14(
|
4897
|
+
ErrorCode14.INVALID_TRANSFER_AMOUNT,
|
4898
|
+
"Transfer amount must be a positive number."
|
4899
|
+
);
|
4900
|
+
}
|
4895
4901
|
const request = await this.createTransfer(destination, amount, assetId, txParams);
|
4896
4902
|
return this.sendTransaction(request, { estimateTxDependencies: false });
|
4897
4903
|
}
|
@@ -4905,6 +4911,12 @@ var Account = class extends AbstractAccount {
|
|
4905
4911
|
* @returns A promise that resolves to the transaction response.
|
4906
4912
|
*/
|
4907
4913
|
async transferToContract(contractId, amount, assetId = BaseAssetId3, txParams = {}) {
|
4914
|
+
if (bn16(amount).lte(0)) {
|
4915
|
+
throw new FuelError14(
|
4916
|
+
ErrorCode14.INVALID_TRANSFER_AMOUNT,
|
4917
|
+
"Transfer amount must be a positive number."
|
4918
|
+
);
|
4919
|
+
}
|
4908
4920
|
const contractAddress = Address3.fromAddressOrString(contractId);
|
4909
4921
|
const { minGasPrice } = this.provider.getGasConfig();
|
4910
4922
|
const params = { gasPrice: minGasPrice, ...txParams };
|
@@ -4974,7 +4986,7 @@ var Account = class extends AbstractAccount {
|
|
4974
4986
|
}
|
4975
4987
|
async signMessage(message) {
|
4976
4988
|
if (!this._connector) {
|
4977
|
-
throw new FuelError14(
|
4989
|
+
throw new FuelError14(ErrorCode14.MISSING_CONNECTOR, "A connector is required to sign messages.");
|
4978
4990
|
}
|
4979
4991
|
return this._connector.signMessage(this.address.toString(), message);
|
4980
4992
|
}
|
@@ -5020,13 +5032,13 @@ var Account = class extends AbstractAccount {
|
|
5020
5032
|
}) {
|
5021
5033
|
if (minGasPrice.gt(gasPrice)) {
|
5022
5034
|
throw new FuelError14(
|
5023
|
-
|
5035
|
+
ErrorCode14.GAS_PRICE_TOO_LOW,
|
5024
5036
|
`Gas price '${gasPrice}' is lower than the required: '${minGasPrice}'.`
|
5025
5037
|
);
|
5026
5038
|
}
|
5027
5039
|
if (gasUsed.gt(gasLimit)) {
|
5028
5040
|
throw new FuelError14(
|
5029
|
-
|
5041
|
+
ErrorCode14.GAS_LIMIT_TOO_LOW,
|
5030
5042
|
`Gas limit '${gasLimit}' is lower than the required: '${gasUsed}'.`
|
5031
5043
|
);
|
5032
5044
|
}
|
@@ -5157,7 +5169,7 @@ import {
|
|
5157
5169
|
decryptJsonWalletData,
|
5158
5170
|
encryptJsonWalletData
|
5159
5171
|
} from "@fuel-ts/crypto";
|
5160
|
-
import { ErrorCode as
|
5172
|
+
import { ErrorCode as ErrorCode15, FuelError as FuelError15 } from "@fuel-ts/errors";
|
5161
5173
|
import { hexlify as hexlify14 } from "@fuel-ts/utils";
|
5162
5174
|
import { v4 as uuidv4 } from "uuid";
|
5163
5175
|
var DEFAULT_KDF_PARAMS_LOG_N = 13;
|
@@ -5236,7 +5248,7 @@ async function decryptKeystoreWallet(jsonWallet, password) {
|
|
5236
5248
|
const macHash = stringFromBuffer(macHashUint8Array, "hex");
|
5237
5249
|
if (mac !== macHash) {
|
5238
5250
|
throw new FuelError15(
|
5239
|
-
|
5251
|
+
ErrorCode15.INVALID_PASSWORD,
|
5240
5252
|
"Failed to decrypt the keystore wallet, the provided password is incorrect."
|
5241
5253
|
);
|
5242
5254
|
}
|
@@ -5358,24 +5370,18 @@ var BaseWalletUnlocked = class extends Account {
|
|
5358
5370
|
__publicField(BaseWalletUnlocked, "defaultPath", "m/44'/1179993420'/0'/0/0");
|
5359
5371
|
|
5360
5372
|
// src/hdwallet/hdwallet.ts
|
5361
|
-
import { ErrorCode as
|
5373
|
+
import { ErrorCode as ErrorCode18, FuelError as FuelError18 } from "@fuel-ts/errors";
|
5374
|
+
import { sha256 as sha2564 } from "@fuel-ts/hasher";
|
5362
5375
|
import { bn as bn17, toBytes as toBytes2, toHex } from "@fuel-ts/math";
|
5363
5376
|
import { arrayify as arrayify18, hexlify as hexlify17, concat as concat5 } from "@fuel-ts/utils";
|
5364
|
-
import {
|
5365
|
-
toBeHex,
|
5366
|
-
dataSlice as dataSlice2,
|
5367
|
-
encodeBase58 as encodeBase582,
|
5368
|
-
decodeBase58,
|
5369
|
-
sha256 as sha2564,
|
5370
|
-
computeHmac as computeHmac2,
|
5371
|
-
ripemd160
|
5372
|
-
} from "ethers";
|
5377
|
+
import { toBeHex, dataSlice as dataSlice2, encodeBase58 as encodeBase582, decodeBase58, computeHmac as computeHmac2, ripemd160 } from "ethers";
|
5373
5378
|
|
5374
5379
|
// src/mnemonic/mnemonic.ts
|
5375
5380
|
import { randomBytes as randomBytes3 } from "@fuel-ts/crypto";
|
5376
|
-
import { ErrorCode as
|
5381
|
+
import { ErrorCode as ErrorCode17, FuelError as FuelError17 } from "@fuel-ts/errors";
|
5382
|
+
import { sha256 as sha2563 } from "@fuel-ts/hasher";
|
5377
5383
|
import { arrayify as arrayify17, hexlify as hexlify16, concat as concat4 } from "@fuel-ts/utils";
|
5378
|
-
import { dataSlice, pbkdf2,
|
5384
|
+
import { dataSlice, pbkdf2, computeHmac, encodeBase58 } from "ethers";
|
5379
5385
|
|
5380
5386
|
// src/wordlists/words/english.ts
|
5381
5387
|
var english = [
|
@@ -7436,9 +7442,9 @@ var Language = /* @__PURE__ */ ((Language2) => {
|
|
7436
7442
|
})(Language || {});
|
7437
7443
|
|
7438
7444
|
// src/mnemonic/utils.ts
|
7439
|
-
import { ErrorCode as
|
7445
|
+
import { ErrorCode as ErrorCode16, FuelError as FuelError16 } from "@fuel-ts/errors";
|
7446
|
+
import { sha256 as sha2562 } from "@fuel-ts/hasher";
|
7440
7447
|
import { arrayify as arrayify16 } from "@fuel-ts/utils";
|
7441
|
-
import { sha256 as sha2562 } from "ethers";
|
7442
7448
|
function toUtf8Bytes(stri) {
|
7443
7449
|
const str = stri.normalize("NFKD");
|
7444
7450
|
const result = [];
|
@@ -7454,7 +7460,7 @@ function toUtf8Bytes(stri) {
|
|
7454
7460
|
const c2 = str.charCodeAt(i);
|
7455
7461
|
if (i >= str.length || (c2 & 64512) !== 56320) {
|
7456
7462
|
throw new FuelError16(
|
7457
|
-
|
7463
|
+
ErrorCode16.INVALID_INPUT_PARAMETERS,
|
7458
7464
|
"Invalid UTF-8 in the input string."
|
7459
7465
|
);
|
7460
7466
|
}
|
@@ -7518,7 +7524,7 @@ function mnemonicWordsToEntropy(words, wordlist) {
|
|
7518
7524
|
const index = wordlist.indexOf(words[i].normalize("NFKD"));
|
7519
7525
|
if (index === -1) {
|
7520
7526
|
throw new FuelError16(
|
7521
|
-
|
7527
|
+
ErrorCode16.INVALID_MNEMONIC,
|
7522
7528
|
`Invalid mnemonic: the word '${words[i]}' is not found in the provided wordlist.`
|
7523
7529
|
);
|
7524
7530
|
}
|
@@ -7535,7 +7541,7 @@ function mnemonicWordsToEntropy(words, wordlist) {
|
|
7535
7541
|
const checksum = arrayify16(sha2562(entropy.slice(0, entropyBits / 8)))[0] & checksumMask;
|
7536
7542
|
if (checksum !== (entropy[entropy.length - 1] & checksumMask)) {
|
7537
7543
|
throw new FuelError16(
|
7538
|
-
|
7544
|
+
ErrorCode16.INVALID_CHECKSUM,
|
7539
7545
|
"Checksum validation failed for the provided mnemonic."
|
7540
7546
|
);
|
7541
7547
|
}
|
@@ -7550,7 +7556,7 @@ var MNEMONIC_SIZES = [12, 15, 18, 21, 24];
|
|
7550
7556
|
function assertWordList(wordlist) {
|
7551
7557
|
if (wordlist.length !== 2048) {
|
7552
7558
|
throw new FuelError17(
|
7553
|
-
|
7559
|
+
ErrorCode17.INVALID_WORD_LIST,
|
7554
7560
|
`Expected word list length of 2048, but got ${wordlist.length}.`
|
7555
7561
|
);
|
7556
7562
|
}
|
@@ -7558,7 +7564,7 @@ function assertWordList(wordlist) {
|
|
7558
7564
|
function assertEntropy(entropy) {
|
7559
7565
|
if (entropy.length % 4 !== 0 || entropy.length < 16 || entropy.length > 32) {
|
7560
7566
|
throw new FuelError17(
|
7561
|
-
|
7567
|
+
ErrorCode17.INVALID_ENTROPY,
|
7562
7568
|
`Entropy should be between 16 and 32 bytes and a multiple of 4, but got ${entropy.length} bytes.`
|
7563
7569
|
);
|
7564
7570
|
}
|
@@ -7568,7 +7574,7 @@ function assertMnemonic(words) {
|
|
7568
7574
|
const errorMsg = `Invalid mnemonic size. Expected one of [${MNEMONIC_SIZES.join(
|
7569
7575
|
", "
|
7570
7576
|
)}] words, but got ${words.length}.`;
|
7571
|
-
throw new FuelError17(
|
7577
|
+
throw new FuelError17(ErrorCode17.INVALID_MNEMONIC, errorMsg);
|
7572
7578
|
}
|
7573
7579
|
}
|
7574
7580
|
var Mnemonic = class {
|
@@ -7687,7 +7693,7 @@ var Mnemonic = class {
|
|
7687
7693
|
const seedArray = arrayify17(seed);
|
7688
7694
|
if (seedArray.length < 16 || seedArray.length > 64) {
|
7689
7695
|
throw new FuelError17(
|
7690
|
-
|
7696
|
+
ErrorCode17.INVALID_SEED,
|
7691
7697
|
`Seed length should be between 16 and 64 bytes, but received ${seedArray.length} bytes.`
|
7692
7698
|
);
|
7693
7699
|
}
|
@@ -7764,7 +7770,7 @@ function isValidExtendedKey(extendedKey) {
|
|
7764
7770
|
function parsePath(path, depth = 0) {
|
7765
7771
|
const components = path.split("/");
|
7766
7772
|
if (components.length === 0 || components[0] === "m" && depth !== 0) {
|
7767
|
-
throw new FuelError18(
|
7773
|
+
throw new FuelError18(ErrorCode18.HD_WALLET_ERROR, `invalid path - ${path}`);
|
7768
7774
|
}
|
7769
7775
|
if (components[0] === "m") {
|
7770
7776
|
components.shift();
|
@@ -7794,7 +7800,7 @@ var HDWallet = class {
|
|
7794
7800
|
} else {
|
7795
7801
|
if (!config.publicKey) {
|
7796
7802
|
throw new FuelError18(
|
7797
|
-
|
7803
|
+
ErrorCode18.HD_WALLET_ERROR,
|
7798
7804
|
"Both public and private Key cannot be missing. At least one should be provided."
|
7799
7805
|
);
|
7800
7806
|
}
|
@@ -7824,7 +7830,7 @@ var HDWallet = class {
|
|
7824
7830
|
if (index & HARDENED_INDEX) {
|
7825
7831
|
if (!privateKey) {
|
7826
7832
|
throw new FuelError18(
|
7827
|
-
|
7833
|
+
ErrorCode18.HD_WALLET_ERROR,
|
7828
7834
|
"Cannot derive a hardened index without a private Key."
|
7829
7835
|
);
|
7830
7836
|
}
|
@@ -7877,7 +7883,7 @@ var HDWallet = class {
|
|
7877
7883
|
toExtendedKey(isPublic = false, testnet = false) {
|
7878
7884
|
if (this.depth >= 256) {
|
7879
7885
|
throw new FuelError18(
|
7880
|
-
|
7886
|
+
ErrorCode18.HD_WALLET_ERROR,
|
7881
7887
|
`Exceeded max depth of 255. Current depth: ${this.depth}.`
|
7882
7888
|
);
|
7883
7889
|
}
|
@@ -7908,10 +7914,10 @@ var HDWallet = class {
|
|
7908
7914
|
const bytes = arrayify18(decoded);
|
7909
7915
|
const validChecksum = base58check(bytes.slice(0, 78)) === extendedKey;
|
7910
7916
|
if (bytes.length !== 82 || !isValidExtendedKey(bytes)) {
|
7911
|
-
throw new FuelError18(
|
7917
|
+
throw new FuelError18(ErrorCode18.HD_WALLET_ERROR, "Provided key is not a valid extended key.");
|
7912
7918
|
}
|
7913
7919
|
if (!validChecksum) {
|
7914
|
-
throw new FuelError18(
|
7920
|
+
throw new FuelError18(ErrorCode18.HD_WALLET_ERROR, "Provided key has an invalid checksum.");
|
7915
7921
|
}
|
7916
7922
|
const depth = bytes[4];
|
7917
7923
|
const parentFingerprint = hexlify17(bytes.slice(5, 9));
|
@@ -7920,13 +7926,13 @@ var HDWallet = class {
|
|
7920
7926
|
const key = bytes.slice(45, 78);
|
7921
7927
|
if (depth === 0 && parentFingerprint !== "0x00000000" || depth === 0 && index !== 0) {
|
7922
7928
|
throw new FuelError18(
|
7923
|
-
|
7929
|
+
ErrorCode18.HD_WALLET_ERROR,
|
7924
7930
|
"Inconsistency detected: Depth is zero but fingerprint/index is non-zero."
|
7925
7931
|
);
|
7926
7932
|
}
|
7927
7933
|
if (isPublicExtendedKey(bytes)) {
|
7928
7934
|
if (key[0] !== 3) {
|
7929
|
-
throw new FuelError18(
|
7935
|
+
throw new FuelError18(ErrorCode18.HD_WALLET_ERROR, "Invalid public extended key.");
|
7930
7936
|
}
|
7931
7937
|
return new HDWallet({
|
7932
7938
|
publicKey: key,
|
@@ -7937,7 +7943,7 @@ var HDWallet = class {
|
|
7937
7943
|
});
|
7938
7944
|
}
|
7939
7945
|
if (key[0] !== 0) {
|
7940
|
-
throw new FuelError18(
|
7946
|
+
throw new FuelError18(ErrorCode18.HD_WALLET_ERROR, "Invalid private extended key.");
|
7941
7947
|
}
|
7942
7948
|
return new HDWallet({
|
7943
7949
|
privateKey: key.slice(1),
|
@@ -8105,7 +8111,7 @@ __publicField(Wallet, "fromEncryptedJson", WalletUnlocked.fromEncryptedJson);
|
|
8105
8111
|
// src/wallet-manager/wallet-manager.ts
|
8106
8112
|
import { Address as Address8 } from "@fuel-ts/address";
|
8107
8113
|
import { encrypt, decrypt } from "@fuel-ts/crypto";
|
8108
|
-
import { ErrorCode as
|
8114
|
+
import { ErrorCode as ErrorCode21, FuelError as FuelError21 } from "@fuel-ts/errors";
|
8109
8115
|
import { EventEmitter } from "events";
|
8110
8116
|
|
8111
8117
|
// src/wallet-manager/storages/memory-storage.ts
|
@@ -8128,7 +8134,7 @@ var MemoryStorage = class {
|
|
8128
8134
|
|
8129
8135
|
// src/wallet-manager/vaults/mnemonic-vault.ts
|
8130
8136
|
import { Address as Address6 } from "@fuel-ts/address";
|
8131
|
-
import { ErrorCode as
|
8137
|
+
import { ErrorCode as ErrorCode19, FuelError as FuelError19 } from "@fuel-ts/errors";
|
8132
8138
|
var _secret;
|
8133
8139
|
var MnemonicVault = class {
|
8134
8140
|
constructor(options) {
|
@@ -8185,7 +8191,7 @@ var MnemonicVault = class {
|
|
8185
8191
|
numberOfAccounts += 1;
|
8186
8192
|
} while (numberOfAccounts < this.numberOfAccounts);
|
8187
8193
|
throw new FuelError19(
|
8188
|
-
|
8194
|
+
ErrorCode19.WALLET_MANAGER_ERROR,
|
8189
8195
|
`Account with address '${address}' not found in derived wallets.`
|
8190
8196
|
);
|
8191
8197
|
}
|
@@ -8199,7 +8205,7 @@ __publicField(MnemonicVault, "type", "mnemonic");
|
|
8199
8205
|
|
8200
8206
|
// src/wallet-manager/vaults/privatekey-vault.ts
|
8201
8207
|
import { Address as Address7 } from "@fuel-ts/address";
|
8202
|
-
import { ErrorCode as
|
8208
|
+
import { ErrorCode as ErrorCode20, FuelError as FuelError20 } from "@fuel-ts/errors";
|
8203
8209
|
var _privateKeys;
|
8204
8210
|
var PrivateKeyVault = class {
|
8205
8211
|
/**
|
@@ -8241,7 +8247,7 @@ var PrivateKeyVault = class {
|
|
8241
8247
|
);
|
8242
8248
|
if (!privateKey) {
|
8243
8249
|
throw new FuelError20(
|
8244
|
-
|
8250
|
+
ErrorCode20.WALLET_MANAGER_ERROR,
|
8245
8251
|
`No private key found for address '${address}'.`
|
8246
8252
|
);
|
8247
8253
|
}
|
@@ -8265,7 +8271,7 @@ var ERROR_MESSAGES = {
|
|
8265
8271
|
};
|
8266
8272
|
function assert(condition, message) {
|
8267
8273
|
if (!condition) {
|
8268
|
-
throw new FuelError21(
|
8274
|
+
throw new FuelError21(ErrorCode21.WALLET_MANAGER_ERROR, message);
|
8269
8275
|
}
|
8270
8276
|
}
|
8271
8277
|
var _vaults, _passphrase, _isLocked, _serializeVaults, serializeVaults_fn, _deserializeVaults, deserializeVaults_fn;
|
@@ -8491,25 +8497,25 @@ deserializeVaults_fn = function(vaults) {
|
|
8491
8497
|
__publicField(WalletManager, "Vaults", [MnemonicVault, PrivateKeyVault]);
|
8492
8498
|
|
8493
8499
|
// src/wallet-manager/types.ts
|
8494
|
-
import { ErrorCode as
|
8500
|
+
import { ErrorCode as ErrorCode22, FuelError as FuelError22 } from "@fuel-ts/errors";
|
8495
8501
|
var Vault = class {
|
8496
8502
|
constructor(_options) {
|
8497
|
-
throw new FuelError22(
|
8503
|
+
throw new FuelError22(ErrorCode22.NOT_IMPLEMENTED, "Not implemented.");
|
8498
8504
|
}
|
8499
8505
|
serialize() {
|
8500
|
-
throw new FuelError22(
|
8506
|
+
throw new FuelError22(ErrorCode22.NOT_IMPLEMENTED, "Not implemented.");
|
8501
8507
|
}
|
8502
8508
|
getAccounts() {
|
8503
|
-
throw new FuelError22(
|
8509
|
+
throw new FuelError22(ErrorCode22.NOT_IMPLEMENTED, "Not implemented.");
|
8504
8510
|
}
|
8505
8511
|
addAccount() {
|
8506
|
-
throw new FuelError22(
|
8512
|
+
throw new FuelError22(ErrorCode22.NOT_IMPLEMENTED, "Not implemented.");
|
8507
8513
|
}
|
8508
8514
|
exportAccount(_address) {
|
8509
|
-
throw new FuelError22(
|
8515
|
+
throw new FuelError22(ErrorCode22.NOT_IMPLEMENTED, "Not implemented.");
|
8510
8516
|
}
|
8511
8517
|
getWallet(_address) {
|
8512
|
-
throw new FuelError22(
|
8518
|
+
throw new FuelError22(ErrorCode22.NOT_IMPLEMENTED, "Not implemented.");
|
8513
8519
|
}
|
8514
8520
|
};
|
8515
8521
|
__publicField(Vault, "type");
|
@@ -8526,7 +8532,7 @@ import {
|
|
8526
8532
|
} from "@fuel-ts/abi-coder";
|
8527
8533
|
import { Address as Address9 } from "@fuel-ts/address";
|
8528
8534
|
import { BaseAssetId as BaseAssetId4 } from "@fuel-ts/address/configs";
|
8529
|
-
import { ErrorCode as
|
8535
|
+
import { ErrorCode as ErrorCode23, FuelError as FuelError23 } from "@fuel-ts/errors";
|
8530
8536
|
import { ByteArrayCoder, InputType as InputType7 } from "@fuel-ts/transactions";
|
8531
8537
|
import { arrayify as arrayify20, hexlify as hexlify19 } from "@fuel-ts/utils";
|
8532
8538
|
|
@@ -8546,27 +8552,37 @@ var getPredicateRoot = (bytecode) => {
|
|
8546
8552
|
// src/predicate/predicate.ts
|
8547
8553
|
var Predicate = class extends Account {
|
8548
8554
|
bytes;
|
8549
|
-
|
8550
|
-
|
8555
|
+
predicateDataBytes = Uint8Array.from([]);
|
8556
|
+
predicateData = [];
|
8551
8557
|
interface;
|
8552
8558
|
/**
|
8553
8559
|
* Creates an instance of the Predicate class.
|
8554
8560
|
*
|
8555
|
-
* @param
|
8561
|
+
* @param bytecode - The bytecode of the predicate.
|
8562
|
+
* @param abi - The JSON ABI of the predicate.
|
8556
8563
|
* @param provider - The provider used to interact with the blockchain.
|
8557
|
-
* @param
|
8564
|
+
* @param inputData - The predicate input data (optional).
|
8558
8565
|
* @param configurableConstants - Optional configurable constants for the predicate.
|
8559
8566
|
*/
|
8560
|
-
constructor(
|
8567
|
+
constructor({
|
8568
|
+
bytecode,
|
8569
|
+
abi,
|
8570
|
+
provider,
|
8571
|
+
inputData,
|
8572
|
+
configurableConstants
|
8573
|
+
}) {
|
8561
8574
|
const { predicateBytes, predicateInterface } = Predicate.processPredicateData(
|
8562
|
-
|
8563
|
-
|
8575
|
+
bytecode,
|
8576
|
+
abi,
|
8564
8577
|
configurableConstants
|
8565
8578
|
);
|
8566
8579
|
const address = Address9.fromB256(getPredicateRoot(predicateBytes));
|
8567
8580
|
super(address, provider);
|
8568
8581
|
this.bytes = predicateBytes;
|
8569
8582
|
this.interface = predicateInterface;
|
8583
|
+
if (inputData !== void 0 && inputData.length > 0) {
|
8584
|
+
this.predicateData = inputData;
|
8585
|
+
}
|
8570
8586
|
}
|
8571
8587
|
/**
|
8572
8588
|
* Populates the transaction data with predicate data.
|
@@ -8618,18 +8634,8 @@ var Predicate = class extends Account {
|
|
8618
8634
|
const transactionRequest = this.populateTransactionPredicateData(transactionRequestLike);
|
8619
8635
|
return super.simulateTransaction(transactionRequest);
|
8620
8636
|
}
|
8621
|
-
/**
|
8622
|
-
* Sets data for the predicate.
|
8623
|
-
*
|
8624
|
-
* @param args - Arguments for the predicate function.
|
8625
|
-
* @returns The Predicate instance with updated predicate data.
|
8626
|
-
*/
|
8627
|
-
setData(...args) {
|
8628
|
-
this.predicateArgs = args;
|
8629
|
-
return this;
|
8630
|
-
}
|
8631
8637
|
getPredicateData(policiesLength) {
|
8632
|
-
if (!this.
|
8638
|
+
if (!this.predicateData.length) {
|
8633
8639
|
return new Uint8Array();
|
8634
8640
|
}
|
8635
8641
|
const mainFn = this.interface?.functions.main;
|
@@ -8638,7 +8644,7 @@ var Predicate = class extends Account {
|
|
8638
8644
|
maxInputs: this.provider.getChain().consensusParameters.maxInputs.toNumber()
|
8639
8645
|
});
|
8640
8646
|
const OFFSET = VM_TX_MEMORY + SCRIPT_FIXED_SIZE + INPUT_COIN_FIXED_SIZE + WORD_SIZE + paddedCode.byteLength + policiesLength * WORD_SIZE;
|
8641
|
-
return mainFn?.encodeArguments(this.
|
8647
|
+
return mainFn?.encodeArguments(this.predicateData, OFFSET) || new Uint8Array();
|
8642
8648
|
}
|
8643
8649
|
/**
|
8644
8650
|
* Processes the predicate data and returns the altered bytecode and interface.
|
@@ -8655,7 +8661,7 @@ var Predicate = class extends Account {
|
|
8655
8661
|
abiInterface = new Interface3(jsonAbi);
|
8656
8662
|
if (abiInterface.functions.main === void 0) {
|
8657
8663
|
throw new FuelError23(
|
8658
|
-
|
8664
|
+
ErrorCode23.ABI_MAIN_METHOD_MISSING,
|
8659
8665
|
'Cannot use ABI without "main" function.'
|
8660
8666
|
);
|
8661
8667
|
}
|
@@ -8701,7 +8707,7 @@ var Predicate = class extends Account {
|
|
8701
8707
|
});
|
8702
8708
|
} catch (err) {
|
8703
8709
|
throw new FuelError23(
|
8704
|
-
|
8710
|
+
ErrorCode23.INVALID_CONFIGURABLE_CONSTANTS,
|
8705
8711
|
`Error setting configurable constants: ${err.message}.`
|
8706
8712
|
);
|
8707
8713
|
}
|
@@ -8710,7 +8716,7 @@ var Predicate = class extends Account {
|
|
8710
8716
|
};
|
8711
8717
|
|
8712
8718
|
// src/connectors/fuel.ts
|
8713
|
-
import { ErrorCode as
|
8719
|
+
import { ErrorCode as ErrorCode24, FuelError as FuelError24 } from "@fuel-ts/errors";
|
8714
8720
|
|
8715
8721
|
// src/connectors/fuel-connector.ts
|
8716
8722
|
import { EventEmitter as EventEmitter2 } from "events";
|
@@ -8752,17 +8758,6 @@ var FuelConnectorEventTypes = /* @__PURE__ */ ((FuelConnectorEventTypes2) => {
|
|
8752
8758
|
})(FuelConnectorEventTypes || {});
|
8753
8759
|
var FuelConnectorEventType = "FuelConnector";
|
8754
8760
|
|
8755
|
-
// src/connectors/types/data-type.ts
|
8756
|
-
var MessageTypes = /* @__PURE__ */ ((MessageTypes2) => {
|
8757
|
-
MessageTypes2["ping"] = "ping";
|
8758
|
-
MessageTypes2["uiEvent"] = "uiEvent";
|
8759
|
-
MessageTypes2["event"] = "event";
|
8760
|
-
MessageTypes2["request"] = "request";
|
8761
|
-
MessageTypes2["response"] = "response";
|
8762
|
-
MessageTypes2["removeConnection"] = "removeConnection";
|
8763
|
-
return MessageTypes2;
|
8764
|
-
})(MessageTypes || {});
|
8765
|
-
|
8766
8761
|
// src/connectors/types/local-storage.ts
|
8767
8762
|
var LocalStorage = class {
|
8768
8763
|
storage;
|
@@ -9342,7 +9337,7 @@ var _Fuel = class extends FuelConnector {
|
|
9342
9337
|
const currentNetwork = await this.currentNetwork();
|
9343
9338
|
provider = await Provider.create(currentNetwork.url);
|
9344
9339
|
} else {
|
9345
|
-
throw new FuelError24(
|
9340
|
+
throw new FuelError24(ErrorCode24.INVALID_PROVIDER, "Provider is not valid.");
|
9346
9341
|
}
|
9347
9342
|
return provider;
|
9348
9343
|
}
|
@@ -9399,7 +9394,6 @@ export {
|
|
9399
9394
|
LocalStorage,
|
9400
9395
|
MNEMONIC_SIZES,
|
9401
9396
|
MemoryStorage,
|
9402
|
-
MessageTypes,
|
9403
9397
|
mnemonic_default as Mnemonic,
|
9404
9398
|
MnemonicVault,
|
9405
9399
|
NoWitnessAtIndexError,
|
@@ -9437,10 +9431,6 @@ export {
|
|
9437
9431
|
english,
|
9438
9432
|
extractBurnedAssetsFromReceipts,
|
9439
9433
|
extractMintedAssetsFromReceipts,
|
9440
|
-
fromDateToTai64,
|
9441
|
-
fromTai64ToDate,
|
9442
|
-
fromTai64ToUnix,
|
9443
|
-
fromUnixToTai64,
|
9444
9434
|
gasUsedByInputs,
|
9445
9435
|
getAssetEth,
|
9446
9436
|
getAssetFuel,
|
@@ -9448,7 +9438,6 @@ export {
|
|
9448
9438
|
getAssetWithNetwork,
|
9449
9439
|
getContractCallOperations,
|
9450
9440
|
getContractCreatedOperations,
|
9451
|
-
getContractTransferOperations,
|
9452
9441
|
getDecodedLogs,
|
9453
9442
|
getDefaultChainId,
|
9454
9443
|
getGasUsedFromReceipts,
|