@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/test-utils.mjs
CHANGED
@@ -25,7 +25,7 @@ import { hexlify as hexlify15 } from "@fuel-ts/utils";
|
|
25
25
|
// src/account.ts
|
26
26
|
import { Address as Address3 } from "@fuel-ts/address";
|
27
27
|
import { BaseAssetId as BaseAssetId3 } from "@fuel-ts/address/configs";
|
28
|
-
import { ErrorCode as
|
28
|
+
import { ErrorCode as ErrorCode14, FuelError as FuelError14 } from "@fuel-ts/errors";
|
29
29
|
import { AbstractAccount } from "@fuel-ts/interfaces";
|
30
30
|
import { bn as bn16 } from "@fuel-ts/math";
|
31
31
|
import { arrayify as arrayify14 } from "@fuel-ts/utils";
|
@@ -68,7 +68,7 @@ var addAmountToAsset = (params) => {
|
|
68
68
|
|
69
69
|
// src/providers/provider.ts
|
70
70
|
import { Address as Address2 } from "@fuel-ts/address";
|
71
|
-
import { ErrorCode as
|
71
|
+
import { ErrorCode as ErrorCode12, FuelError as FuelError12 } from "@fuel-ts/errors";
|
72
72
|
import { BN, bn as bn14, max } from "@fuel-ts/math";
|
73
73
|
import {
|
74
74
|
InputType as InputType6,
|
@@ -76,7 +76,7 @@ import {
|
|
76
76
|
InputMessageCoder,
|
77
77
|
TransactionCoder as TransactionCoder5
|
78
78
|
} from "@fuel-ts/transactions";
|
79
|
-
import { arrayify as arrayify11, hexlify as hexlify12 } from "@fuel-ts/utils";
|
79
|
+
import { arrayify as arrayify11, hexlify as hexlify12, DateTime as DateTime2 } from "@fuel-ts/utils";
|
80
80
|
import { checkFuelCoreVersionCompatibility } from "@fuel-ts/versions";
|
81
81
|
import { equalBytes } from "@noble/curves/abstract/utils";
|
82
82
|
import { Network } from "ethers";
|
@@ -144,6 +144,9 @@ var TransactionStatusFragmentFragmentDoc = gql`
|
|
144
144
|
time
|
145
145
|
reason
|
146
146
|
}
|
147
|
+
... on SqueezedOutStatus {
|
148
|
+
reason
|
149
|
+
}
|
147
150
|
}
|
148
151
|
`;
|
149
152
|
var TransactionFragmentFragmentDoc = gql`
|
@@ -886,72 +889,77 @@ function getSdk(requester) {
|
|
886
889
|
}
|
887
890
|
|
888
891
|
// src/providers/fuel-graphql-subscriber.ts
|
889
|
-
import { FuelError } from "@fuel-ts/errors";
|
892
|
+
import { ErrorCode, FuelError } from "@fuel-ts/errors";
|
890
893
|
import { print } from "graphql";
|
891
|
-
var
|
892
|
-
|
893
|
-
|
894
|
-
|
895
|
-
|
896
|
-
|
897
|
-
|
898
|
-
|
899
|
-
|
900
|
-
|
901
|
-
|
902
|
-
|
903
|
-
|
904
|
-
|
905
|
-
|
906
|
-
|
907
|
-
this.readableStreamController.enqueue(
|
908
|
-
new FuelError(
|
909
|
-
FuelError.CODES.INVALID_REQUEST,
|
910
|
-
errors.map((err) => err.message).join("\n\n")
|
911
|
-
)
|
912
|
-
);
|
913
|
-
} else {
|
914
|
-
this.readableStreamController.enqueue(data);
|
915
|
-
}
|
916
|
-
}
|
894
|
+
var _FuelGraphqlSubscriber = class {
|
895
|
+
constructor(options) {
|
896
|
+
this.options = options;
|
897
|
+
}
|
898
|
+
stream;
|
899
|
+
async setStream() {
|
900
|
+
const { url, query, variables, fetchFn } = this.options;
|
901
|
+
const response = await fetchFn(`${url}-sub`, {
|
902
|
+
method: "POST",
|
903
|
+
body: JSON.stringify({
|
904
|
+
query: print(query),
|
905
|
+
variables
|
906
|
+
}),
|
907
|
+
headers: {
|
908
|
+
"Content-Type": "application/json",
|
909
|
+
Accept: "text/event-stream"
|
917
910
|
}
|
918
911
|
});
|
912
|
+
this.stream = response.body.getReader();
|
919
913
|
}
|
920
|
-
|
921
|
-
|
922
|
-
|
923
|
-
async function* fuelGraphQLSubscriber({
|
924
|
-
url,
|
925
|
-
variables,
|
926
|
-
query,
|
927
|
-
fetchFn
|
928
|
-
}) {
|
929
|
-
const response = await fetchFn(`${url}-sub`, {
|
930
|
-
method: "POST",
|
931
|
-
body: JSON.stringify({
|
932
|
-
query: print(query),
|
933
|
-
variables
|
934
|
-
}),
|
935
|
-
headers: {
|
936
|
-
"Content-Type": "application/json",
|
937
|
-
Accept: "text/event-stream"
|
938
|
-
}
|
939
|
-
});
|
940
|
-
const subscriptionStreamReader = response.body.pipeThrough(new FuelSubscriptionStream()).getReader();
|
941
|
-
while (true) {
|
942
|
-
const { value, done } = await subscriptionStreamReader.read();
|
943
|
-
if (value instanceof FuelError) {
|
944
|
-
throw value;
|
914
|
+
async next() {
|
915
|
+
if (!this.stream) {
|
916
|
+
await this.setStream();
|
945
917
|
}
|
946
|
-
|
947
|
-
|
948
|
-
|
918
|
+
while (true) {
|
919
|
+
const { value, done } = await this.stream.read();
|
920
|
+
if (done) {
|
921
|
+
return { value, done };
|
922
|
+
}
|
923
|
+
const text = _FuelGraphqlSubscriber.textDecoder.decode(value);
|
924
|
+
if (!text.startsWith("data:")) {
|
925
|
+
continue;
|
926
|
+
}
|
927
|
+
let data;
|
928
|
+
let errors;
|
929
|
+
try {
|
930
|
+
({ data, errors } = JSON.parse(text.replace(/^data:/, "")));
|
931
|
+
} catch (e) {
|
932
|
+
throw new FuelError(
|
933
|
+
ErrorCode.STREAM_PARSING_ERROR,
|
934
|
+
`Error while parsing stream data response: ${text}`
|
935
|
+
);
|
936
|
+
}
|
937
|
+
if (Array.isArray(errors)) {
|
938
|
+
throw new FuelError(
|
939
|
+
FuelError.CODES.INVALID_REQUEST,
|
940
|
+
errors.map((err) => err.message).join("\n\n")
|
941
|
+
);
|
942
|
+
}
|
943
|
+
return { value: data, done: false };
|
949
944
|
}
|
950
945
|
}
|
951
|
-
|
946
|
+
/**
|
947
|
+
* Gets called when `break` is called in a `for-await-of` loop.
|
948
|
+
*/
|
949
|
+
async return() {
|
950
|
+
await this.stream.cancel();
|
951
|
+
this.stream.releaseLock();
|
952
|
+
return { done: true, value: void 0 };
|
953
|
+
}
|
954
|
+
[Symbol.asyncIterator]() {
|
955
|
+
return this;
|
956
|
+
}
|
957
|
+
};
|
958
|
+
var FuelGraphqlSubscriber = _FuelGraphqlSubscriber;
|
959
|
+
__publicField(FuelGraphqlSubscriber, "textDecoder", new TextDecoder());
|
952
960
|
|
953
961
|
// src/providers/memory-cache.ts
|
954
|
-
import { ErrorCode, FuelError as FuelError2 } from "@fuel-ts/errors";
|
962
|
+
import { ErrorCode as ErrorCode2, FuelError as FuelError2 } from "@fuel-ts/errors";
|
955
963
|
import { hexlify as hexlify2 } from "@fuel-ts/utils";
|
956
964
|
var cache = {};
|
957
965
|
var DEFAULT_TTL_IN_MS = 30 * 1e3;
|
@@ -961,7 +969,7 @@ var MemoryCache = class {
|
|
961
969
|
this.ttl = ttlInMs;
|
962
970
|
if (typeof ttlInMs !== "number" || this.ttl <= 0) {
|
963
971
|
throw new FuelError2(
|
964
|
-
|
972
|
+
ErrorCode2.INVALID_TTL,
|
965
973
|
`Invalid TTL: ${this.ttl}. Use a value greater than zero.`
|
966
974
|
);
|
967
975
|
}
|
@@ -1011,7 +1019,7 @@ var MemoryCache = class {
|
|
1011
1019
|
|
1012
1020
|
// src/providers/transaction-request/input.ts
|
1013
1021
|
import { ZeroBytes32 } from "@fuel-ts/address/configs";
|
1014
|
-
import { ErrorCode as
|
1022
|
+
import { ErrorCode as ErrorCode3, FuelError as FuelError3 } from "@fuel-ts/errors";
|
1015
1023
|
import { bn as bn2, toNumber } from "@fuel-ts/math";
|
1016
1024
|
import { InputType } from "@fuel-ts/transactions";
|
1017
1025
|
import { arrayify, hexlify as hexlify3 } from "@fuel-ts/utils";
|
@@ -1077,7 +1085,7 @@ var inputify = (value) => {
|
|
1077
1085
|
}
|
1078
1086
|
default: {
|
1079
1087
|
throw new FuelError3(
|
1080
|
-
|
1088
|
+
ErrorCode3.INVALID_TRANSACTION_INPUT,
|
1081
1089
|
`Invalid transaction input type: ${type}.`
|
1082
1090
|
);
|
1083
1091
|
}
|
@@ -1086,7 +1094,7 @@ var inputify = (value) => {
|
|
1086
1094
|
|
1087
1095
|
// src/providers/transaction-request/output.ts
|
1088
1096
|
import { ZeroBytes32 as ZeroBytes322 } from "@fuel-ts/address/configs";
|
1089
|
-
import { ErrorCode as
|
1097
|
+
import { ErrorCode as ErrorCode4, FuelError as FuelError4 } from "@fuel-ts/errors";
|
1090
1098
|
import { bn as bn3 } from "@fuel-ts/math";
|
1091
1099
|
import { OutputType } from "@fuel-ts/transactions";
|
1092
1100
|
import { hexlify as hexlify4 } from "@fuel-ts/utils";
|
@@ -1134,7 +1142,7 @@ var outputify = (value) => {
|
|
1134
1142
|
}
|
1135
1143
|
default: {
|
1136
1144
|
throw new FuelError4(
|
1137
|
-
|
1145
|
+
ErrorCode4.INVALID_TRANSACTION_INPUT,
|
1138
1146
|
`Invalid transaction output type: ${type}.`
|
1139
1147
|
);
|
1140
1148
|
}
|
@@ -1159,7 +1167,7 @@ var isCoin = (resource) => "id" in resource;
|
|
1159
1167
|
|
1160
1168
|
// src/providers/utils/receipts.ts
|
1161
1169
|
import { ZeroBytes32 as ZeroBytes323 } from "@fuel-ts/address/configs";
|
1162
|
-
import { ErrorCode as
|
1170
|
+
import { ErrorCode as ErrorCode5, FuelError as FuelError5 } from "@fuel-ts/errors";
|
1163
1171
|
import { bn as bn4 } from "@fuel-ts/math";
|
1164
1172
|
import {
|
1165
1173
|
ReceiptBurnCoder,
|
@@ -1364,12 +1372,12 @@ function assembleReceiptByType(receipt) {
|
|
1364
1372
|
return burnReceipt;
|
1365
1373
|
}
|
1366
1374
|
default:
|
1367
|
-
throw new FuelError5(
|
1375
|
+
throw new FuelError5(ErrorCode5.INVALID_RECEIPT_TYPE, `Invalid receipt type: ${receiptType}.`);
|
1368
1376
|
}
|
1369
1377
|
}
|
1370
1378
|
|
1371
1379
|
// src/providers/utils/block-explorer.ts
|
1372
|
-
import { ErrorCode as
|
1380
|
+
import { ErrorCode as ErrorCode6, FuelError as FuelError6 } from "@fuel-ts/errors";
|
1373
1381
|
|
1374
1382
|
// src/providers/utils/gas.ts
|
1375
1383
|
import { bn as bn5 } from "@fuel-ts/math";
|
@@ -1487,9 +1495,6 @@ function sleep(time) {
|
|
1487
1495
|
});
|
1488
1496
|
}
|
1489
1497
|
|
1490
|
-
// src/providers/utils/time.ts
|
1491
|
-
var fromUnixToTai64 = (unixTimestampMs) => (BigInt(unixTimestampMs) + BigInt(2 ** 62) + BigInt(10)).toString();
|
1492
|
-
|
1493
1498
|
// src/providers/transaction-request/errors.ts
|
1494
1499
|
var NoWitnessAtIndexError = class extends Error {
|
1495
1500
|
constructor(index) {
|
@@ -1731,7 +1736,7 @@ var BaseTransactionRequest = class {
|
|
1731
1736
|
txPointer: "0x00000000000000000000000000000000",
|
1732
1737
|
witnessIndex,
|
1733
1738
|
predicate: predicate?.bytes,
|
1734
|
-
predicateData: predicate?.
|
1739
|
+
predicateData: predicate?.predicateDataBytes
|
1735
1740
|
};
|
1736
1741
|
this.pushInput(input);
|
1737
1742
|
this.addChangeOutput(owner, assetId);
|
@@ -1764,7 +1769,7 @@ var BaseTransactionRequest = class {
|
|
1764
1769
|
amount,
|
1765
1770
|
witnessIndex,
|
1766
1771
|
predicate: predicate?.bytes,
|
1767
|
-
predicateData: predicate?.
|
1772
|
+
predicateData: predicate?.predicateDataBytes
|
1768
1773
|
};
|
1769
1774
|
this.pushInput(input);
|
1770
1775
|
this.addChangeOutput(recipient, assetId);
|
@@ -1979,8 +1984,6 @@ var BaseTransactionRequest = class {
|
|
1979
1984
|
this.inputs.forEach((i) => {
|
1980
1985
|
let correspondingInput;
|
1981
1986
|
switch (i.type) {
|
1982
|
-
case InputType2.Contract:
|
1983
|
-
return;
|
1984
1987
|
case InputType2.Coin:
|
1985
1988
|
correspondingInput = inputs.find((x) => x.type === InputType2.Coin && x.owner === i.owner);
|
1986
1989
|
break;
|
@@ -1990,7 +1993,7 @@ var BaseTransactionRequest = class {
|
|
1990
1993
|
);
|
1991
1994
|
break;
|
1992
1995
|
default:
|
1993
|
-
|
1996
|
+
return;
|
1994
1997
|
}
|
1995
1998
|
if (correspondingInput && "predicateGasUsed" in correspondingInput && bn6(correspondingInput.predicateGasUsed).gt(0)) {
|
1996
1999
|
i.predicate = correspondingInput.predicate;
|
@@ -2009,11 +2012,10 @@ import { arrayify as arrayify6, hexlify as hexlify9 } from "@fuel-ts/utils";
|
|
2009
2012
|
|
2010
2013
|
// src/providers/transaction-request/hash-transaction.ts
|
2011
2014
|
import { ZeroBytes32 as ZeroBytes325 } from "@fuel-ts/address/configs";
|
2012
|
-
import { uint64ToBytesBE } from "@fuel-ts/hasher";
|
2015
|
+
import { uint64ToBytesBE, sha256 } from "@fuel-ts/hasher";
|
2013
2016
|
import { bn as bn7 } from "@fuel-ts/math";
|
2014
2017
|
import { TransactionType as TransactionType2, InputType as InputType3, OutputType as OutputType3, TransactionCoder as TransactionCoder2 } from "@fuel-ts/transactions";
|
2015
2018
|
import { concat as concat2 } from "@fuel-ts/utils";
|
2016
|
-
import { sha256 } from "ethers";
|
2017
2019
|
import { clone as clone2 } from "ramda";
|
2018
2020
|
function hashTransaction(transactionRequest, chainId) {
|
2019
2021
|
const transaction = transactionRequest.toTransaction();
|
@@ -2400,7 +2402,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2400
2402
|
};
|
2401
2403
|
|
2402
2404
|
// src/providers/transaction-request/utils.ts
|
2403
|
-
import { ErrorCode as
|
2405
|
+
import { ErrorCode as ErrorCode7, FuelError as FuelError7 } from "@fuel-ts/errors";
|
2404
2406
|
import { TransactionType as TransactionType5 } from "@fuel-ts/transactions";
|
2405
2407
|
var transactionRequestify = (obj) => {
|
2406
2408
|
if (obj instanceof ScriptTransactionRequest || obj instanceof CreateTransactionRequest) {
|
@@ -2415,19 +2417,19 @@ var transactionRequestify = (obj) => {
|
|
2415
2417
|
return CreateTransactionRequest.from(obj);
|
2416
2418
|
}
|
2417
2419
|
default: {
|
2418
|
-
throw new FuelError7(
|
2420
|
+
throw new FuelError7(ErrorCode7.INVALID_TRANSACTION_TYPE, `Invalid transaction type: ${type}.`);
|
2419
2421
|
}
|
2420
2422
|
}
|
2421
2423
|
};
|
2422
2424
|
|
2423
2425
|
// src/providers/transaction-response/transaction-response.ts
|
2424
|
-
import { ErrorCode as
|
2426
|
+
import { ErrorCode as ErrorCode11, FuelError as FuelError11 } from "@fuel-ts/errors";
|
2425
2427
|
import { bn as bn13 } from "@fuel-ts/math";
|
2426
2428
|
import { TransactionCoder as TransactionCoder4 } from "@fuel-ts/transactions";
|
2427
2429
|
import { arrayify as arrayify10 } from "@fuel-ts/utils";
|
2428
2430
|
|
2429
2431
|
// src/providers/transaction-summary/assemble-transaction-summary.ts
|
2430
|
-
import { hexlify as hexlify11 } from "@fuel-ts/utils";
|
2432
|
+
import { DateTime, hexlify as hexlify11 } from "@fuel-ts/utils";
|
2431
2433
|
|
2432
2434
|
// src/providers/transaction-summary/calculate-transaction-fee.ts
|
2433
2435
|
import { bn as bn10 } from "@fuel-ts/math";
|
@@ -2502,15 +2504,9 @@ var calculateTransactionFee = (params) => {
|
|
2502
2504
|
};
|
2503
2505
|
};
|
2504
2506
|
|
2505
|
-
// src/providers/transaction-summary/date.ts
|
2506
|
-
import { TAI64 } from "tai64";
|
2507
|
-
var fromTai64ToDate = (tai64Timestamp) => {
|
2508
|
-
const timestamp = TAI64.fromString(tai64Timestamp, 10).toUnix();
|
2509
|
-
return new Date(timestamp * 1e3);
|
2510
|
-
};
|
2511
|
-
|
2512
2507
|
// src/providers/transaction-summary/operations.ts
|
2513
|
-
import {
|
2508
|
+
import { ZeroBytes32 as ZeroBytes328 } from "@fuel-ts/address/configs";
|
2509
|
+
import { ErrorCode as ErrorCode9, FuelError as FuelError9 } from "@fuel-ts/errors";
|
2514
2510
|
import { bn as bn12 } from "@fuel-ts/math";
|
2515
2511
|
import { ReceiptType as ReceiptType3, TransactionType as TransactionType7 } from "@fuel-ts/transactions";
|
2516
2512
|
|
@@ -2559,7 +2555,7 @@ var getFunctionCall = ({ abi, receipt, rawPayload, maxInputs }) => {
|
|
2559
2555
|
};
|
2560
2556
|
|
2561
2557
|
// src/providers/transaction-summary/input.ts
|
2562
|
-
import { ErrorCode as
|
2558
|
+
import { ErrorCode as ErrorCode8, FuelError as FuelError8 } from "@fuel-ts/errors";
|
2563
2559
|
import { InputType as InputType5 } from "@fuel-ts/transactions";
|
2564
2560
|
function getInputsByTypes(inputs, types) {
|
2565
2561
|
return inputs.filter((i) => types.includes(i.type));
|
@@ -2598,7 +2594,7 @@ function getInputContractFromIndex(inputs, inputIndex) {
|
|
2598
2594
|
}
|
2599
2595
|
if (contractInput.type !== InputType5.Contract) {
|
2600
2596
|
throw new FuelError8(
|
2601
|
-
|
2597
|
+
ErrorCode8.INVALID_TRANSACTION_INPUT,
|
2602
2598
|
`Contract input should be of type 'contract'.`
|
2603
2599
|
);
|
2604
2600
|
}
|
@@ -2646,7 +2642,7 @@ function getTransactionTypeName(transactionType) {
|
|
2646
2642
|
return "Script" /* Script */;
|
2647
2643
|
default:
|
2648
2644
|
throw new FuelError9(
|
2649
|
-
|
2645
|
+
ErrorCode9.INVALID_TRANSACTION_TYPE,
|
2650
2646
|
`Invalid transaction type: ${transactionType}.`
|
2651
2647
|
);
|
2652
2648
|
}
|
@@ -2706,36 +2702,6 @@ function addOperation(operations, toAdd) {
|
|
2706
2702
|
}
|
2707
2703
|
return allOperations;
|
2708
2704
|
}
|
2709
|
-
function getReceiptsTransferOut(receipts) {
|
2710
|
-
return getReceiptsByType(receipts, ReceiptType3.TransferOut);
|
2711
|
-
}
|
2712
|
-
function getContractTransferOperations({ receipts }) {
|
2713
|
-
const transferOutReceipts = getReceiptsTransferOut(receipts);
|
2714
|
-
const contractTransferOperations = transferOutReceipts.reduce(
|
2715
|
-
(prevContractTransferOps, receipt) => {
|
2716
|
-
const newContractTransferOps = addOperation(prevContractTransferOps, {
|
2717
|
-
name: "Contract transfer" /* contractTransfer */,
|
2718
|
-
from: {
|
2719
|
-
type: 0 /* contract */,
|
2720
|
-
address: receipt.from
|
2721
|
-
},
|
2722
|
-
to: {
|
2723
|
-
type: 1 /* account */,
|
2724
|
-
address: receipt.to
|
2725
|
-
},
|
2726
|
-
assetsSent: [
|
2727
|
-
{
|
2728
|
-
amount: receipt.amount,
|
2729
|
-
assetId: receipt.assetId
|
2730
|
-
}
|
2731
|
-
]
|
2732
|
-
});
|
2733
|
-
return newContractTransferOps;
|
2734
|
-
},
|
2735
|
-
[]
|
2736
|
-
);
|
2737
|
-
return contractTransferOperations;
|
2738
|
-
}
|
2739
2705
|
function getWithdrawFromFuelOperations({
|
2740
2706
|
inputs,
|
2741
2707
|
receipts
|
@@ -2833,70 +2799,77 @@ function getContractCallOperations({
|
|
2833
2799
|
}, []);
|
2834
2800
|
return contractCallOperations;
|
2835
2801
|
}
|
2802
|
+
function extractTransferOperationFromReceipt(receipt, contractInputs, changeOutputs) {
|
2803
|
+
const { to: toAddress, assetId, amount } = receipt;
|
2804
|
+
let { from: fromAddress } = receipt;
|
2805
|
+
const toType = contractInputs.some((input) => input.contractID === toAddress) ? 0 /* contract */ : 1 /* account */;
|
2806
|
+
if (ZeroBytes328 === fromAddress) {
|
2807
|
+
const change = changeOutputs.find((output) => output.assetId === assetId);
|
2808
|
+
fromAddress = change?.to || fromAddress;
|
2809
|
+
}
|
2810
|
+
const fromType = contractInputs.some((input) => input.contractID === fromAddress) ? 0 /* contract */ : 1 /* account */;
|
2811
|
+
return {
|
2812
|
+
name: "Transfer asset" /* transfer */,
|
2813
|
+
from: {
|
2814
|
+
type: fromType,
|
2815
|
+
address: fromAddress
|
2816
|
+
},
|
2817
|
+
to: {
|
2818
|
+
type: toType,
|
2819
|
+
address: toAddress
|
2820
|
+
},
|
2821
|
+
assetsSent: [
|
2822
|
+
{
|
2823
|
+
assetId: assetId.toString(),
|
2824
|
+
amount
|
2825
|
+
}
|
2826
|
+
]
|
2827
|
+
};
|
2828
|
+
}
|
2836
2829
|
function getTransferOperations({
|
2837
2830
|
inputs,
|
2838
2831
|
outputs,
|
2839
2832
|
receipts
|
2840
2833
|
}) {
|
2834
|
+
let operations = [];
|
2841
2835
|
const coinOutputs = getOutputsCoin(outputs);
|
2842
|
-
const
|
2836
|
+
const contractInputs = getInputsContract(inputs);
|
2837
|
+
const changeOutputs = getOutputsChange(outputs);
|
2838
|
+
coinOutputs.forEach((output) => {
|
2839
|
+
const { amount, assetId, to } = output;
|
2840
|
+
const changeOutput = changeOutputs.find((change) => change.assetId === assetId);
|
2841
|
+
if (changeOutput) {
|
2842
|
+
operations = addOperation(operations, {
|
2843
|
+
name: "Transfer asset" /* transfer */,
|
2844
|
+
from: {
|
2845
|
+
type: 1 /* account */,
|
2846
|
+
address: changeOutput.to
|
2847
|
+
},
|
2848
|
+
to: {
|
2849
|
+
type: 1 /* account */,
|
2850
|
+
address: to
|
2851
|
+
},
|
2852
|
+
assetsSent: [
|
2853
|
+
{
|
2854
|
+
assetId,
|
2855
|
+
amount
|
2856
|
+
}
|
2857
|
+
]
|
2858
|
+
});
|
2859
|
+
}
|
2860
|
+
});
|
2861
|
+
const transferReceipts = getReceiptsByType(
|
2843
2862
|
receipts,
|
2844
2863
|
ReceiptType3.Transfer
|
2845
2864
|
);
|
2846
|
-
|
2847
|
-
|
2848
|
-
|
2849
|
-
|
2850
|
-
|
2851
|
-
|
2852
|
-
|
2853
|
-
|
2854
|
-
const inputAddress = getInputAccountAddress(utxo);
|
2855
|
-
operations = addOperation(operations, {
|
2856
|
-
name: "Transfer asset" /* transfer */,
|
2857
|
-
from: {
|
2858
|
-
type: 1 /* account */,
|
2859
|
-
address: inputAddress
|
2860
|
-
},
|
2861
|
-
to: {
|
2862
|
-
type: 0 /* contract */,
|
2863
|
-
address: contractInput.contractID
|
2864
|
-
},
|
2865
|
-
assetsSent: [
|
2866
|
-
{
|
2867
|
-
assetId: assetId.toString(),
|
2868
|
-
amount: transferReceipt.amount
|
2869
|
-
}
|
2870
|
-
]
|
2871
|
-
});
|
2872
|
-
}
|
2873
|
-
});
|
2874
|
-
} else {
|
2875
|
-
coinOutputs.forEach((output) => {
|
2876
|
-
const input = getInputFromAssetId(inputs, output.assetId);
|
2877
|
-
if (input) {
|
2878
|
-
const inputAddress = getInputAccountAddress(input);
|
2879
|
-
const operationToAdd = {
|
2880
|
-
name: "Transfer asset" /* transfer */,
|
2881
|
-
from: {
|
2882
|
-
type: 1 /* account */,
|
2883
|
-
address: inputAddress
|
2884
|
-
},
|
2885
|
-
to: {
|
2886
|
-
type: 1 /* account */,
|
2887
|
-
address: output.to.toString()
|
2888
|
-
},
|
2889
|
-
assetsSent: [
|
2890
|
-
{
|
2891
|
-
assetId: output.assetId.toString(),
|
2892
|
-
amount: output.amount
|
2893
|
-
}
|
2894
|
-
]
|
2895
|
-
};
|
2896
|
-
operations = addOperation(operations, operationToAdd);
|
2897
|
-
}
|
2898
|
-
});
|
2899
|
-
}
|
2865
|
+
const transferOutReceipts = getReceiptsByType(
|
2866
|
+
receipts,
|
2867
|
+
ReceiptType3.TransferOut
|
2868
|
+
);
|
2869
|
+
[...transferReceipts, ...transferOutReceipts].forEach((receipt) => {
|
2870
|
+
const operation = extractTransferOperationFromReceipt(receipt, contractInputs, changeOutputs);
|
2871
|
+
operations = addOperation(operations, operation);
|
2872
|
+
});
|
2900
2873
|
return operations;
|
2901
2874
|
}
|
2902
2875
|
function getPayProducerOperations(outputs) {
|
@@ -2969,7 +2942,6 @@ function getOperations({
|
|
2969
2942
|
rawPayload,
|
2970
2943
|
maxInputs
|
2971
2944
|
}),
|
2972
|
-
...getContractTransferOperations({ receipts }),
|
2973
2945
|
...getWithdrawFromFuelOperations({ inputs, receipts })
|
2974
2946
|
];
|
2975
2947
|
}
|
@@ -3027,7 +2999,7 @@ var extractBurnedAssetsFromReceipts = (receipts) => {
|
|
3027
2999
|
};
|
3028
3000
|
|
3029
3001
|
// src/providers/transaction-summary/status.ts
|
3030
|
-
import { ErrorCode as
|
3002
|
+
import { ErrorCode as ErrorCode10, FuelError as FuelError10 } from "@fuel-ts/errors";
|
3031
3003
|
var getTransactionStatusName = (gqlStatus) => {
|
3032
3004
|
switch (gqlStatus) {
|
3033
3005
|
case "FailureStatus":
|
@@ -3040,7 +3012,7 @@ var getTransactionStatusName = (gqlStatus) => {
|
|
3040
3012
|
return "squeezedout" /* squeezedout */;
|
3041
3013
|
default:
|
3042
3014
|
throw new FuelError10(
|
3043
|
-
|
3015
|
+
ErrorCode10.INVALID_TRANSACTION_STATUS,
|
3044
3016
|
`Invalid transaction status: ${gqlStatus}.`
|
3045
3017
|
);
|
3046
3018
|
}
|
@@ -3125,7 +3097,7 @@ function assembleTransactionSummary(params) {
|
|
3125
3097
|
const burnedAssets = extractBurnedAssetsFromReceipts(receipts);
|
3126
3098
|
let date;
|
3127
3099
|
if (time) {
|
3128
|
-
date =
|
3100
|
+
date = DateTime.fromTai64(time);
|
3129
3101
|
}
|
3130
3102
|
const transactionSummary = {
|
3131
3103
|
id,
|
@@ -3260,6 +3232,12 @@ var TransactionResponse = class {
|
|
3260
3232
|
transactionId: this.id
|
3261
3233
|
});
|
3262
3234
|
for await (const { statusChange } of subscription) {
|
3235
|
+
if (statusChange.type === "SqueezedOutStatus") {
|
3236
|
+
throw new FuelError11(
|
3237
|
+
ErrorCode11.TRANSACTION_SQUEEZED_OUT,
|
3238
|
+
`Transaction Squeezed Out with reason: ${statusChange.reason}`
|
3239
|
+
);
|
3240
|
+
}
|
3263
3241
|
if (statusChange.type !== "SubmittedStatus") {
|
3264
3242
|
break;
|
3265
3243
|
}
|
@@ -3289,7 +3267,7 @@ var TransactionResponse = class {
|
|
3289
3267
|
const result = await this.waitForResult(contractsAbiMap);
|
3290
3268
|
if (result.isStatusFailure) {
|
3291
3269
|
throw new FuelError11(
|
3292
|
-
|
3270
|
+
ErrorCode11.TRANSACTION_FAILED,
|
3293
3271
|
`Transaction failed: ${result.gqlTransaction.status.reason}`
|
3294
3272
|
);
|
3295
3273
|
}
|
@@ -3298,7 +3276,7 @@ var TransactionResponse = class {
|
|
3298
3276
|
};
|
3299
3277
|
|
3300
3278
|
// src/providers/transaction-response/getDecodedLogs.ts
|
3301
|
-
import {
|
3279
|
+
import { BigNumberCoder } from "@fuel-ts/abi-coder";
|
3302
3280
|
import { ReceiptType as ReceiptType5 } from "@fuel-ts/transactions";
|
3303
3281
|
|
3304
3282
|
// src/providers/utils/auto-retry-fetch.ts
|
@@ -3424,14 +3402,15 @@ var _Provider = class {
|
|
3424
3402
|
}
|
3425
3403
|
static getFetchFn(options) {
|
3426
3404
|
const { retryOptions, timeout } = options;
|
3427
|
-
return autoRetryFetch((...args) => {
|
3428
|
-
if (options.fetch) {
|
3429
|
-
return options.fetch(...args);
|
3430
|
-
}
|
3405
|
+
return autoRetryFetch(async (...args) => {
|
3431
3406
|
const url = args[0];
|
3432
3407
|
const request = args[1];
|
3433
3408
|
const signal = timeout ? AbortSignal.timeout(timeout) : void 0;
|
3434
|
-
|
3409
|
+
let fullRequest = { ...request, signal };
|
3410
|
+
if (options.requestMiddleware) {
|
3411
|
+
fullRequest = await options.requestMiddleware(fullRequest);
|
3412
|
+
}
|
3413
|
+
return options.fetch ? options.fetch(url, fullRequest, options) : fetch(url, fullRequest);
|
3435
3414
|
}, retryOptions);
|
3436
3415
|
}
|
3437
3416
|
/**
|
@@ -3451,7 +3430,7 @@ var _Provider = class {
|
|
3451
3430
|
const chain = _Provider.chainInfoCache[this.url];
|
3452
3431
|
if (!chain) {
|
3453
3432
|
throw new FuelError12(
|
3454
|
-
|
3433
|
+
ErrorCode12.CHAIN_INFO_CACHE_EMPTY,
|
3455
3434
|
"Chain info cache is empty. Make sure you have called `Provider.create` to initialize the provider."
|
3456
3435
|
);
|
3457
3436
|
}
|
@@ -3464,7 +3443,7 @@ var _Provider = class {
|
|
3464
3443
|
const node = _Provider.nodeInfoCache[this.url];
|
3465
3444
|
if (!node) {
|
3466
3445
|
throw new FuelError12(
|
3467
|
-
|
3446
|
+
ErrorCode12.NODE_INFO_CACHE_EMPTY,
|
3468
3447
|
"Node info cache is empty. Make sure you have called `Provider.create` to initialize the provider."
|
3469
3448
|
);
|
3470
3449
|
}
|
@@ -3531,7 +3510,7 @@ var _Provider = class {
|
|
3531
3510
|
const opDefinition = query.definitions.find((x) => x.kind === "OperationDefinition");
|
3532
3511
|
const isSubscription = opDefinition?.operation === "subscription";
|
3533
3512
|
if (isSubscription) {
|
3534
|
-
return
|
3513
|
+
return new FuelGraphqlSubscriber({
|
3535
3514
|
url: this.url,
|
3536
3515
|
query,
|
3537
3516
|
fetchFn: (url, requestInit) => fetchFn(url, requestInit, this.options),
|
@@ -3637,6 +3616,12 @@ var _Provider = class {
|
|
3637
3616
|
if (awaitExecution) {
|
3638
3617
|
const subscription = this.operations.submitAndAwait({ encodedTransaction });
|
3639
3618
|
for await (const { submitAndAwait } of subscription) {
|
3619
|
+
if (submitAndAwait.type === "SqueezedOutStatus") {
|
3620
|
+
throw new FuelError12(
|
3621
|
+
ErrorCode12.TRANSACTION_SQUEEZED_OUT,
|
3622
|
+
`Transaction Squeezed Out with reason: ${submitAndAwait.reason}`
|
3623
|
+
);
|
3624
|
+
}
|
3640
3625
|
if (submitAndAwait.type !== "SubmittedStatus") {
|
3641
3626
|
break;
|
3642
3627
|
}
|
@@ -3723,11 +3708,15 @@ var _Provider = class {
|
|
3723
3708
|
async estimateTxDependencies(transactionRequest) {
|
3724
3709
|
if (transactionRequest.type === TransactionType8.Create) {
|
3725
3710
|
return {
|
3726
|
-
receipts: []
|
3711
|
+
receipts: [],
|
3712
|
+
outputVariables: 0,
|
3713
|
+
missingContractIds: []
|
3727
3714
|
};
|
3728
3715
|
}
|
3729
3716
|
await this.estimatePredicates(transactionRequest);
|
3730
3717
|
let receipts = [];
|
3718
|
+
const missingContractIds = [];
|
3719
|
+
let outputVariables = 0;
|
3731
3720
|
for (let attempt = 0; attempt < MAX_RETRIES; attempt++) {
|
3732
3721
|
const { dryRun: gqlReceipts } = await this.operations.dryRun({
|
3733
3722
|
encodedTransaction: hexlify12(transactionRequest.toTransactionBytes()),
|
@@ -3737,16 +3726,20 @@ var _Provider = class {
|
|
3737
3726
|
const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(receipts);
|
3738
3727
|
const hasMissingOutputs = missingOutputVariables.length !== 0 || missingOutputContractIds.length !== 0;
|
3739
3728
|
if (hasMissingOutputs) {
|
3729
|
+
outputVariables += missingOutputVariables.length;
|
3740
3730
|
transactionRequest.addVariableOutputs(missingOutputVariables.length);
|
3741
3731
|
missingOutputContractIds.forEach(({ contractId }) => {
|
3742
3732
|
transactionRequest.addContractInputAndOutput(Address2.fromString(contractId));
|
3733
|
+
missingContractIds.push(contractId);
|
3743
3734
|
});
|
3744
3735
|
} else {
|
3745
3736
|
break;
|
3746
3737
|
}
|
3747
3738
|
}
|
3748
3739
|
return {
|
3749
|
-
receipts
|
3740
|
+
receipts,
|
3741
|
+
outputVariables,
|
3742
|
+
missingContractIds
|
3750
3743
|
};
|
3751
3744
|
}
|
3752
3745
|
/**
|
@@ -3814,11 +3807,15 @@ var _Provider = class {
|
|
3814
3807
|
const minGas = txRequestClone.calculateMinGas(chainInfo);
|
3815
3808
|
const maxGas = txRequestClone.calculateMaxGas(chainInfo, minGas);
|
3816
3809
|
let receipts = [];
|
3810
|
+
let missingContractIds = [];
|
3811
|
+
let outputVariables = 0;
|
3817
3812
|
if (isScriptTransaction && estimateTxDependencies) {
|
3818
3813
|
txRequestClone.gasPrice = bn14(0);
|
3819
3814
|
txRequestClone.gasLimit = bn14(maxGasPerTx.sub(maxGas).toNumber() * 0.9);
|
3820
3815
|
const result = await this.estimateTxDependencies(txRequestClone);
|
3821
3816
|
receipts = result.receipts;
|
3817
|
+
outputVariables = result.outputVariables;
|
3818
|
+
missingContractIds = result.missingContractIds;
|
3822
3819
|
}
|
3823
3820
|
const gasUsed = isScriptTransaction ? getGasUsedFromReceipts(receipts) : minGas;
|
3824
3821
|
const usedFee = calculatePriceWithFactor(
|
@@ -3840,7 +3837,8 @@ var _Provider = class {
|
|
3840
3837
|
minFee,
|
3841
3838
|
maxFee,
|
3842
3839
|
estimatedInputs: txRequestClone.inputs,
|
3843
|
-
|
3840
|
+
outputVariables,
|
3841
|
+
missingContractIds
|
3844
3842
|
};
|
3845
3843
|
}
|
3846
3844
|
async getResourcesForTransaction(owner, transactionRequestLike, forwardingQuantities = []) {
|
@@ -4134,7 +4132,7 @@ var _Provider = class {
|
|
4134
4132
|
};
|
4135
4133
|
if (commitBlockId && commitBlockHeight) {
|
4136
4134
|
throw new FuelError12(
|
4137
|
-
|
4135
|
+
ErrorCode12.INVALID_INPUT_PARAMETERS,
|
4138
4136
|
"commitBlockId and commitBlockHeight cannot be used together"
|
4139
4137
|
);
|
4140
4138
|
}
|
@@ -4220,13 +4218,13 @@ var _Provider = class {
|
|
4220
4218
|
* Lets you produce blocks with custom timestamps and the block number of the last block produced.
|
4221
4219
|
*
|
4222
4220
|
* @param amount - The amount of blocks to produce
|
4223
|
-
* @param startTime - The UNIX timestamp to set for the first produced block
|
4221
|
+
* @param startTime - The UNIX timestamp (milliseconds) to set for the first produced block
|
4224
4222
|
* @returns A promise that resolves to the block number of the last produced block.
|
4225
4223
|
*/
|
4226
4224
|
async produceBlocks(amount, startTime) {
|
4227
4225
|
const { produceBlocks: latestBlockHeight } = await this.operations.produceBlocks({
|
4228
4226
|
blocksToProduce: bn14(amount).toString(10),
|
4229
|
-
startTimestamp: startTime ?
|
4227
|
+
startTimestamp: startTime ? DateTime2.fromUnixMilliseconds(startTime).toTai64() : void 0
|
4230
4228
|
});
|
4231
4229
|
return bn14(latestBlockHeight);
|
4232
4230
|
}
|
@@ -4251,7 +4249,7 @@ __publicField(Provider, "chainInfoCache", {});
|
|
4251
4249
|
__publicField(Provider, "nodeInfoCache", {});
|
4252
4250
|
|
4253
4251
|
// src/providers/transaction-summary/get-transaction-summary.ts
|
4254
|
-
import { ErrorCode as
|
4252
|
+
import { ErrorCode as ErrorCode13, FuelError as FuelError13 } from "@fuel-ts/errors";
|
4255
4253
|
import { bn as bn15 } from "@fuel-ts/math";
|
4256
4254
|
import { TransactionCoder as TransactionCoder6 } from "@fuel-ts/transactions";
|
4257
4255
|
import { arrayify as arrayify12 } from "@fuel-ts/utils";
|
@@ -4302,13 +4300,13 @@ var assets = [
|
|
4302
4300
|
];
|
4303
4301
|
|
4304
4302
|
// src/utils/formatTransferToContractScriptData.ts
|
4305
|
-
import {
|
4303
|
+
import { BigNumberCoder as BigNumberCoder2 } from "@fuel-ts/abi-coder";
|
4306
4304
|
import { BN as BN2 } from "@fuel-ts/math";
|
4307
4305
|
import { arrayify as arrayify13 } from "@fuel-ts/utils";
|
4308
4306
|
import * as asm from "@fuels/vm-asm";
|
4309
4307
|
var formatTransferToContractScriptData = (params) => {
|
4310
4308
|
const { assetId, amountToTransfer, hexlifiedContractId } = params;
|
4311
|
-
const numberCoder = new
|
4309
|
+
const numberCoder = new BigNumberCoder2("u64");
|
4312
4310
|
const encoded = numberCoder.encode(new BN2(amountToTransfer).toNumber());
|
4313
4311
|
const scriptData = Uint8Array.from([
|
4314
4312
|
...arrayify13(hexlifiedContractId),
|
@@ -4369,7 +4367,7 @@ var Account = class extends AbstractAccount {
|
|
4369
4367
|
*/
|
4370
4368
|
get provider() {
|
4371
4369
|
if (!this._provider) {
|
4372
|
-
throw new FuelError14(
|
4370
|
+
throw new FuelError14(ErrorCode14.MISSING_PROVIDER, "Provider not set");
|
4373
4371
|
}
|
4374
4372
|
return this._provider;
|
4375
4373
|
}
|
@@ -4422,7 +4420,7 @@ var Account = class extends AbstractAccount {
|
|
4422
4420
|
break;
|
4423
4421
|
}
|
4424
4422
|
throw new FuelError14(
|
4425
|
-
|
4423
|
+
ErrorCode14.NOT_SUPPORTED,
|
4426
4424
|
`Wallets containing more than ${pageSize} coins exceed the current supported limit.`
|
4427
4425
|
);
|
4428
4426
|
}
|
@@ -4448,7 +4446,7 @@ var Account = class extends AbstractAccount {
|
|
4448
4446
|
break;
|
4449
4447
|
}
|
4450
4448
|
throw new FuelError14(
|
4451
|
-
|
4449
|
+
ErrorCode14.NOT_SUPPORTED,
|
4452
4450
|
`Wallets containing more than ${pageSize} messages exceed the current supported limit.`
|
4453
4451
|
);
|
4454
4452
|
}
|
@@ -4484,7 +4482,7 @@ var Account = class extends AbstractAccount {
|
|
4484
4482
|
break;
|
4485
4483
|
}
|
4486
4484
|
throw new FuelError14(
|
4487
|
-
|
4485
|
+
ErrorCode14.NOT_SUPPORTED,
|
4488
4486
|
`Wallets containing more than ${pageSize} balances exceed the current supported limit.`
|
4489
4487
|
);
|
4490
4488
|
}
|
@@ -4589,6 +4587,12 @@ var Account = class extends AbstractAccount {
|
|
4589
4587
|
* @returns A promise that resolves to the transaction response.
|
4590
4588
|
*/
|
4591
4589
|
async transfer(destination, amount, assetId = BaseAssetId3, txParams = {}) {
|
4590
|
+
if (bn16(amount).lte(0)) {
|
4591
|
+
throw new FuelError14(
|
4592
|
+
ErrorCode14.INVALID_TRANSFER_AMOUNT,
|
4593
|
+
"Transfer amount must be a positive number."
|
4594
|
+
);
|
4595
|
+
}
|
4592
4596
|
const request = await this.createTransfer(destination, amount, assetId, txParams);
|
4593
4597
|
return this.sendTransaction(request, { estimateTxDependencies: false });
|
4594
4598
|
}
|
@@ -4602,6 +4606,12 @@ var Account = class extends AbstractAccount {
|
|
4602
4606
|
* @returns A promise that resolves to the transaction response.
|
4603
4607
|
*/
|
4604
4608
|
async transferToContract(contractId, amount, assetId = BaseAssetId3, txParams = {}) {
|
4609
|
+
if (bn16(amount).lte(0)) {
|
4610
|
+
throw new FuelError14(
|
4611
|
+
ErrorCode14.INVALID_TRANSFER_AMOUNT,
|
4612
|
+
"Transfer amount must be a positive number."
|
4613
|
+
);
|
4614
|
+
}
|
4605
4615
|
const contractAddress = Address3.fromAddressOrString(contractId);
|
4606
4616
|
const { minGasPrice } = this.provider.getGasConfig();
|
4607
4617
|
const params = { gasPrice: minGasPrice, ...txParams };
|
@@ -4671,7 +4681,7 @@ var Account = class extends AbstractAccount {
|
|
4671
4681
|
}
|
4672
4682
|
async signMessage(message) {
|
4673
4683
|
if (!this._connector) {
|
4674
|
-
throw new FuelError14(
|
4684
|
+
throw new FuelError14(ErrorCode14.MISSING_CONNECTOR, "A connector is required to sign messages.");
|
4675
4685
|
}
|
4676
4686
|
return this._connector.signMessage(this.address.toString(), message);
|
4677
4687
|
}
|
@@ -4717,13 +4727,13 @@ var Account = class extends AbstractAccount {
|
|
4717
4727
|
}) {
|
4718
4728
|
if (minGasPrice.gt(gasPrice)) {
|
4719
4729
|
throw new FuelError14(
|
4720
|
-
|
4730
|
+
ErrorCode14.GAS_PRICE_TOO_LOW,
|
4721
4731
|
`Gas price '${gasPrice}' is lower than the required: '${minGasPrice}'.`
|
4722
4732
|
);
|
4723
4733
|
}
|
4724
4734
|
if (gasUsed.gt(gasLimit)) {
|
4725
4735
|
throw new FuelError14(
|
4726
|
-
|
4736
|
+
ErrorCode14.GAS_LIMIT_TOO_LOW,
|
4727
4737
|
`Gas limit '${gasLimit}' is lower than the required: '${gasUsed}'.`
|
4728
4738
|
);
|
4729
4739
|
}
|
@@ -4850,7 +4860,7 @@ import {
|
|
4850
4860
|
decryptJsonWalletData,
|
4851
4861
|
encryptJsonWalletData
|
4852
4862
|
} from "@fuel-ts/crypto";
|
4853
|
-
import { ErrorCode as
|
4863
|
+
import { ErrorCode as ErrorCode15, FuelError as FuelError15 } from "@fuel-ts/errors";
|
4854
4864
|
import { hexlify as hexlify14 } from "@fuel-ts/utils";
|
4855
4865
|
import { v4 as uuidv4 } from "uuid";
|
4856
4866
|
var DEFAULT_KDF_PARAMS_LOG_N = 13;
|
@@ -4929,7 +4939,7 @@ async function decryptKeystoreWallet(jsonWallet, password) {
|
|
4929
4939
|
const macHash = stringFromBuffer(macHashUint8Array, "hex");
|
4930
4940
|
if (mac !== macHash) {
|
4931
4941
|
throw new FuelError15(
|
4932
|
-
|
4942
|
+
ErrorCode15.INVALID_PASSWORD,
|
4933
4943
|
"Failed to decrypt the keystore wallet, the provided password is incorrect."
|
4934
4944
|
);
|
4935
4945
|
}
|
@@ -5051,24 +5061,18 @@ var BaseWalletUnlocked = class extends Account {
|
|
5051
5061
|
__publicField(BaseWalletUnlocked, "defaultPath", "m/44'/1179993420'/0'/0/0");
|
5052
5062
|
|
5053
5063
|
// src/hdwallet/hdwallet.ts
|
5054
|
-
import { ErrorCode as
|
5064
|
+
import { ErrorCode as ErrorCode18, FuelError as FuelError18 } from "@fuel-ts/errors";
|
5065
|
+
import { sha256 as sha2564 } from "@fuel-ts/hasher";
|
5055
5066
|
import { bn as bn17, toBytes as toBytes2, toHex } from "@fuel-ts/math";
|
5056
5067
|
import { arrayify as arrayify18, hexlify as hexlify17, concat as concat5 } from "@fuel-ts/utils";
|
5057
|
-
import {
|
5058
|
-
toBeHex,
|
5059
|
-
dataSlice as dataSlice2,
|
5060
|
-
encodeBase58 as encodeBase582,
|
5061
|
-
decodeBase58,
|
5062
|
-
sha256 as sha2564,
|
5063
|
-
computeHmac as computeHmac2,
|
5064
|
-
ripemd160
|
5065
|
-
} from "ethers";
|
5068
|
+
import { toBeHex, dataSlice as dataSlice2, encodeBase58 as encodeBase582, decodeBase58, computeHmac as computeHmac2, ripemd160 } from "ethers";
|
5066
5069
|
|
5067
5070
|
// src/mnemonic/mnemonic.ts
|
5068
5071
|
import { randomBytes as randomBytes3 } from "@fuel-ts/crypto";
|
5069
|
-
import { ErrorCode as
|
5072
|
+
import { ErrorCode as ErrorCode17, FuelError as FuelError17 } from "@fuel-ts/errors";
|
5073
|
+
import { sha256 as sha2563 } from "@fuel-ts/hasher";
|
5070
5074
|
import { arrayify as arrayify17, hexlify as hexlify16, concat as concat4 } from "@fuel-ts/utils";
|
5071
|
-
import { dataSlice, pbkdf2,
|
5075
|
+
import { dataSlice, pbkdf2, computeHmac, encodeBase58 } from "ethers";
|
5072
5076
|
|
5073
5077
|
// src/wordlists/words/english.ts
|
5074
5078
|
var english = [
|
@@ -7123,9 +7127,9 @@ var english = [
|
|
7123
7127
|
];
|
7124
7128
|
|
7125
7129
|
// src/mnemonic/utils.ts
|
7126
|
-
import { ErrorCode as
|
7130
|
+
import { ErrorCode as ErrorCode16, FuelError as FuelError16 } from "@fuel-ts/errors";
|
7131
|
+
import { sha256 as sha2562 } from "@fuel-ts/hasher";
|
7127
7132
|
import { arrayify as arrayify16 } from "@fuel-ts/utils";
|
7128
|
-
import { sha256 as sha2562 } from "ethers";
|
7129
7133
|
function toUtf8Bytes(stri) {
|
7130
7134
|
const str = stri.normalize("NFKD");
|
7131
7135
|
const result = [];
|
@@ -7141,7 +7145,7 @@ function toUtf8Bytes(stri) {
|
|
7141
7145
|
const c2 = str.charCodeAt(i);
|
7142
7146
|
if (i >= str.length || (c2 & 64512) !== 56320) {
|
7143
7147
|
throw new FuelError16(
|
7144
|
-
|
7148
|
+
ErrorCode16.INVALID_INPUT_PARAMETERS,
|
7145
7149
|
"Invalid UTF-8 in the input string."
|
7146
7150
|
);
|
7147
7151
|
}
|
@@ -7205,7 +7209,7 @@ function mnemonicWordsToEntropy(words, wordlist) {
|
|
7205
7209
|
const index = wordlist.indexOf(words[i].normalize("NFKD"));
|
7206
7210
|
if (index === -1) {
|
7207
7211
|
throw new FuelError16(
|
7208
|
-
|
7212
|
+
ErrorCode16.INVALID_MNEMONIC,
|
7209
7213
|
`Invalid mnemonic: the word '${words[i]}' is not found in the provided wordlist.`
|
7210
7214
|
);
|
7211
7215
|
}
|
@@ -7222,7 +7226,7 @@ function mnemonicWordsToEntropy(words, wordlist) {
|
|
7222
7226
|
const checksum = arrayify16(sha2562(entropy.slice(0, entropyBits / 8)))[0] & checksumMask;
|
7223
7227
|
if (checksum !== (entropy[entropy.length - 1] & checksumMask)) {
|
7224
7228
|
throw new FuelError16(
|
7225
|
-
|
7229
|
+
ErrorCode16.INVALID_CHECKSUM,
|
7226
7230
|
"Checksum validation failed for the provided mnemonic."
|
7227
7231
|
);
|
7228
7232
|
}
|
@@ -7237,7 +7241,7 @@ var MNEMONIC_SIZES = [12, 15, 18, 21, 24];
|
|
7237
7241
|
function assertWordList(wordlist) {
|
7238
7242
|
if (wordlist.length !== 2048) {
|
7239
7243
|
throw new FuelError17(
|
7240
|
-
|
7244
|
+
ErrorCode17.INVALID_WORD_LIST,
|
7241
7245
|
`Expected word list length of 2048, but got ${wordlist.length}.`
|
7242
7246
|
);
|
7243
7247
|
}
|
@@ -7245,7 +7249,7 @@ function assertWordList(wordlist) {
|
|
7245
7249
|
function assertEntropy(entropy) {
|
7246
7250
|
if (entropy.length % 4 !== 0 || entropy.length < 16 || entropy.length > 32) {
|
7247
7251
|
throw new FuelError17(
|
7248
|
-
|
7252
|
+
ErrorCode17.INVALID_ENTROPY,
|
7249
7253
|
`Entropy should be between 16 and 32 bytes and a multiple of 4, but got ${entropy.length} bytes.`
|
7250
7254
|
);
|
7251
7255
|
}
|
@@ -7255,7 +7259,7 @@ function assertMnemonic(words) {
|
|
7255
7259
|
const errorMsg = `Invalid mnemonic size. Expected one of [${MNEMONIC_SIZES.join(
|
7256
7260
|
", "
|
7257
7261
|
)}] words, but got ${words.length}.`;
|
7258
|
-
throw new FuelError17(
|
7262
|
+
throw new FuelError17(ErrorCode17.INVALID_MNEMONIC, errorMsg);
|
7259
7263
|
}
|
7260
7264
|
}
|
7261
7265
|
var Mnemonic = class {
|
@@ -7374,7 +7378,7 @@ var Mnemonic = class {
|
|
7374
7378
|
const seedArray = arrayify17(seed);
|
7375
7379
|
if (seedArray.length < 16 || seedArray.length > 64) {
|
7376
7380
|
throw new FuelError17(
|
7377
|
-
|
7381
|
+
ErrorCode17.INVALID_SEED,
|
7378
7382
|
`Seed length should be between 16 and 64 bytes, but received ${seedArray.length} bytes.`
|
7379
7383
|
);
|
7380
7384
|
}
|
@@ -7451,7 +7455,7 @@ function isValidExtendedKey(extendedKey) {
|
|
7451
7455
|
function parsePath(path2, depth = 0) {
|
7452
7456
|
const components = path2.split("/");
|
7453
7457
|
if (components.length === 0 || components[0] === "m" && depth !== 0) {
|
7454
|
-
throw new FuelError18(
|
7458
|
+
throw new FuelError18(ErrorCode18.HD_WALLET_ERROR, `invalid path - ${path2}`);
|
7455
7459
|
}
|
7456
7460
|
if (components[0] === "m") {
|
7457
7461
|
components.shift();
|
@@ -7481,7 +7485,7 @@ var HDWallet = class {
|
|
7481
7485
|
} else {
|
7482
7486
|
if (!config.publicKey) {
|
7483
7487
|
throw new FuelError18(
|
7484
|
-
|
7488
|
+
ErrorCode18.HD_WALLET_ERROR,
|
7485
7489
|
"Both public and private Key cannot be missing. At least one should be provided."
|
7486
7490
|
);
|
7487
7491
|
}
|
@@ -7511,7 +7515,7 @@ var HDWallet = class {
|
|
7511
7515
|
if (index & HARDENED_INDEX) {
|
7512
7516
|
if (!privateKey) {
|
7513
7517
|
throw new FuelError18(
|
7514
|
-
|
7518
|
+
ErrorCode18.HD_WALLET_ERROR,
|
7515
7519
|
"Cannot derive a hardened index without a private Key."
|
7516
7520
|
);
|
7517
7521
|
}
|
@@ -7564,7 +7568,7 @@ var HDWallet = class {
|
|
7564
7568
|
toExtendedKey(isPublic = false, testnet = false) {
|
7565
7569
|
if (this.depth >= 256) {
|
7566
7570
|
throw new FuelError18(
|
7567
|
-
|
7571
|
+
ErrorCode18.HD_WALLET_ERROR,
|
7568
7572
|
`Exceeded max depth of 255. Current depth: ${this.depth}.`
|
7569
7573
|
);
|
7570
7574
|
}
|
@@ -7595,10 +7599,10 @@ var HDWallet = class {
|
|
7595
7599
|
const bytes = arrayify18(decoded);
|
7596
7600
|
const validChecksum = base58check(bytes.slice(0, 78)) === extendedKey;
|
7597
7601
|
if (bytes.length !== 82 || !isValidExtendedKey(bytes)) {
|
7598
|
-
throw new FuelError18(
|
7602
|
+
throw new FuelError18(ErrorCode18.HD_WALLET_ERROR, "Provided key is not a valid extended key.");
|
7599
7603
|
}
|
7600
7604
|
if (!validChecksum) {
|
7601
|
-
throw new FuelError18(
|
7605
|
+
throw new FuelError18(ErrorCode18.HD_WALLET_ERROR, "Provided key has an invalid checksum.");
|
7602
7606
|
}
|
7603
7607
|
const depth = bytes[4];
|
7604
7608
|
const parentFingerprint = hexlify17(bytes.slice(5, 9));
|
@@ -7607,13 +7611,13 @@ var HDWallet = class {
|
|
7607
7611
|
const key = bytes.slice(45, 78);
|
7608
7612
|
if (depth === 0 && parentFingerprint !== "0x00000000" || depth === 0 && index !== 0) {
|
7609
7613
|
throw new FuelError18(
|
7610
|
-
|
7614
|
+
ErrorCode18.HD_WALLET_ERROR,
|
7611
7615
|
"Inconsistency detected: Depth is zero but fingerprint/index is non-zero."
|
7612
7616
|
);
|
7613
7617
|
}
|
7614
7618
|
if (isPublicExtendedKey(bytes)) {
|
7615
7619
|
if (key[0] !== 3) {
|
7616
|
-
throw new FuelError18(
|
7620
|
+
throw new FuelError18(ErrorCode18.HD_WALLET_ERROR, "Invalid public extended key.");
|
7617
7621
|
}
|
7618
7622
|
return new HDWallet({
|
7619
7623
|
publicKey: key,
|
@@ -7624,7 +7628,7 @@ var HDWallet = class {
|
|
7624
7628
|
});
|
7625
7629
|
}
|
7626
7630
|
if (key[0] !== 0) {
|
7627
|
-
throw new FuelError18(
|
7631
|
+
throw new FuelError18(ErrorCode18.HD_WALLET_ERROR, "Invalid private extended key.");
|
7628
7632
|
}
|
7629
7633
|
return new HDWallet({
|
7630
7634
|
privateKey: key.slice(1),
|