@fuel-ts/account 0.0.0-pr-1788-20240222094224 → 0.75.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of @fuel-ts/account might be problematic. Click here for more details.
- package/dist/connectors/fuel-connector.d.ts +2 -1
- package/dist/connectors/fuel-connector.d.ts.map +1 -1
- package/dist/connectors/types/data-type.d.ts +0 -8
- package/dist/connectors/types/data-type.d.ts.map +1 -1
- package/dist/connectors/types/events.d.ts +2 -36
- package/dist/connectors/types/events.d.ts.map +1 -1
- package/dist/connectors/types/index.d.ts +0 -2
- package/dist/connectors/types/index.d.ts.map +1 -1
- package/dist/index.global.js +543 -409
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +143 -172
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +132 -159
- package/dist/index.mjs.map +1 -1
- package/dist/providers/fuel-graphql-subscriber.d.ts +13 -3
- package/dist/providers/fuel-graphql-subscriber.d.ts.map +1 -1
- package/dist/providers/provider.d.ts +9 -3
- package/dist/providers/provider.d.ts.map +1 -1
- package/dist/providers/transaction-request/transaction-request.d.ts.map +1 -1
- package/dist/providers/transaction-summary/operations.d.ts +0 -2
- package/dist/providers/transaction-summary/operations.d.ts.map +1 -1
- package/dist/providers/transaction-summary/output.d.ts +2 -2
- package/dist/providers/transaction-summary/output.d.ts.map +1 -1
- package/dist/providers/transaction-summary/types.d.ts +0 -1
- package/dist/providers/transaction-summary/types.d.ts.map +1 -1
- package/dist/test-utils.global.js +543 -400
- package/dist/test-utils.global.js.map +1 -1
- package/dist/test-utils.js +144 -160
- package/dist/test-utils.js.map +1 -1
- package/dist/test-utils.mjs +132 -148
- package/dist/test-utils.mjs.map +1 -1
- package/package.json +16 -16
- package/dist/connectors/types/asset.d.ts +0 -2
- package/dist/connectors/types/asset.d.ts.map +0 -1
- package/dist/connectors/types/constants.d.ts +0 -7
- package/dist/connectors/types/constants.d.ts.map +0 -1
- package/dist/connectors/types/message.d.ts +0 -15
- package/dist/connectors/types/message.d.ts.map +0 -1
package/dist/test-utils.mjs
CHANGED
@@ -888,67 +888,63 @@ function getSdk(requester) {
|
|
888
888
|
// src/providers/fuel-graphql-subscriber.ts
|
889
889
|
import { FuelError } from "@fuel-ts/errors";
|
890
890
|
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
|
-
}
|
891
|
+
var _FuelGraphqlSubscriber = class {
|
892
|
+
constructor(options) {
|
893
|
+
this.options = options;
|
894
|
+
}
|
895
|
+
stream;
|
896
|
+
async setStream() {
|
897
|
+
const { url, query, variables, fetchFn } = this.options;
|
898
|
+
const response = await fetchFn(`${url}-sub`, {
|
899
|
+
method: "POST",
|
900
|
+
body: JSON.stringify({
|
901
|
+
query: print(query),
|
902
|
+
variables
|
903
|
+
}),
|
904
|
+
headers: {
|
905
|
+
"Content-Type": "application/json",
|
906
|
+
Accept: "text/event-stream"
|
917
907
|
}
|
918
908
|
});
|
909
|
+
this.stream = response.body.getReader();
|
919
910
|
}
|
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"
|
911
|
+
async next() {
|
912
|
+
if (!this.stream) {
|
913
|
+
await this.setStream();
|
938
914
|
}
|
939
|
-
|
940
|
-
|
941
|
-
|
942
|
-
|
943
|
-
|
944
|
-
|
945
|
-
|
946
|
-
|
947
|
-
|
948
|
-
|
915
|
+
while (true) {
|
916
|
+
const { value, done } = await this.stream.read();
|
917
|
+
if (done) {
|
918
|
+
return { value, done };
|
919
|
+
}
|
920
|
+
const text = _FuelGraphqlSubscriber.textDecoder.decode(value);
|
921
|
+
if (!text.startsWith("data:")) {
|
922
|
+
continue;
|
923
|
+
}
|
924
|
+
const { data, errors } = JSON.parse(text.split("data:")[1]);
|
925
|
+
if (Array.isArray(errors)) {
|
926
|
+
throw new FuelError(
|
927
|
+
FuelError.CODES.INVALID_REQUEST,
|
928
|
+
errors.map((err) => err.message).join("\n\n")
|
929
|
+
);
|
930
|
+
}
|
931
|
+
return { value: data, done: false };
|
949
932
|
}
|
950
933
|
}
|
951
|
-
|
934
|
+
/**
|
935
|
+
* Gets called when `break` is called in a `for-await-of` loop.
|
936
|
+
*/
|
937
|
+
async return() {
|
938
|
+
await this.stream.cancel();
|
939
|
+
this.stream.releaseLock();
|
940
|
+
return { done: true, value: void 0 };
|
941
|
+
}
|
942
|
+
[Symbol.asyncIterator]() {
|
943
|
+
return this;
|
944
|
+
}
|
945
|
+
};
|
946
|
+
var FuelGraphqlSubscriber = _FuelGraphqlSubscriber;
|
947
|
+
__publicField(FuelGraphqlSubscriber, "textDecoder", new TextDecoder());
|
952
948
|
|
953
949
|
// src/providers/memory-cache.ts
|
954
950
|
import { ErrorCode, FuelError as FuelError2 } from "@fuel-ts/errors";
|
@@ -1979,8 +1975,6 @@ var BaseTransactionRequest = class {
|
|
1979
1975
|
this.inputs.forEach((i) => {
|
1980
1976
|
let correspondingInput;
|
1981
1977
|
switch (i.type) {
|
1982
|
-
case InputType2.Contract:
|
1983
|
-
return;
|
1984
1978
|
case InputType2.Coin:
|
1985
1979
|
correspondingInput = inputs.find((x) => x.type === InputType2.Coin && x.owner === i.owner);
|
1986
1980
|
break;
|
@@ -1990,7 +1984,7 @@ var BaseTransactionRequest = class {
|
|
1990
1984
|
);
|
1991
1985
|
break;
|
1992
1986
|
default:
|
1993
|
-
|
1987
|
+
return;
|
1994
1988
|
}
|
1995
1989
|
if (correspondingInput && "predicateGasUsed" in correspondingInput && bn6(correspondingInput.predicateGasUsed).gt(0)) {
|
1996
1990
|
i.predicate = correspondingInput.predicate;
|
@@ -2510,6 +2504,7 @@ var fromTai64ToDate = (tai64Timestamp) => {
|
|
2510
2504
|
};
|
2511
2505
|
|
2512
2506
|
// src/providers/transaction-summary/operations.ts
|
2507
|
+
import { ZeroBytes32 as ZeroBytes328 } from "@fuel-ts/address/configs";
|
2513
2508
|
import { ErrorCode as ErrorCode8, FuelError as FuelError9 } from "@fuel-ts/errors";
|
2514
2509
|
import { bn as bn12 } from "@fuel-ts/math";
|
2515
2510
|
import { ReceiptType as ReceiptType3, TransactionType as TransactionType7 } from "@fuel-ts/transactions";
|
@@ -2706,36 +2701,6 @@ function addOperation(operations, toAdd) {
|
|
2706
2701
|
}
|
2707
2702
|
return allOperations;
|
2708
2703
|
}
|
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
2704
|
function getWithdrawFromFuelOperations({
|
2740
2705
|
inputs,
|
2741
2706
|
receipts
|
@@ -2833,70 +2798,77 @@ function getContractCallOperations({
|
|
2833
2798
|
}, []);
|
2834
2799
|
return contractCallOperations;
|
2835
2800
|
}
|
2801
|
+
function extractTransferOperationFromReceipt(receipt, contractInputs, changeOutputs) {
|
2802
|
+
const { to: toAddress, assetId, amount } = receipt;
|
2803
|
+
let { from: fromAddress } = receipt;
|
2804
|
+
const toType = contractInputs.some((input) => input.contractID === toAddress) ? 0 /* contract */ : 1 /* account */;
|
2805
|
+
if (ZeroBytes328 === fromAddress) {
|
2806
|
+
const change = changeOutputs.find((output) => output.assetId === assetId);
|
2807
|
+
fromAddress = change?.to || fromAddress;
|
2808
|
+
}
|
2809
|
+
const fromType = contractInputs.some((input) => input.contractID === fromAddress) ? 0 /* contract */ : 1 /* account */;
|
2810
|
+
return {
|
2811
|
+
name: "Transfer asset" /* transfer */,
|
2812
|
+
from: {
|
2813
|
+
type: fromType,
|
2814
|
+
address: fromAddress
|
2815
|
+
},
|
2816
|
+
to: {
|
2817
|
+
type: toType,
|
2818
|
+
address: toAddress
|
2819
|
+
},
|
2820
|
+
assetsSent: [
|
2821
|
+
{
|
2822
|
+
assetId: assetId.toString(),
|
2823
|
+
amount
|
2824
|
+
}
|
2825
|
+
]
|
2826
|
+
};
|
2827
|
+
}
|
2836
2828
|
function getTransferOperations({
|
2837
2829
|
inputs,
|
2838
2830
|
outputs,
|
2839
2831
|
receipts
|
2840
2832
|
}) {
|
2833
|
+
let operations = [];
|
2841
2834
|
const coinOutputs = getOutputsCoin(outputs);
|
2842
|
-
const
|
2835
|
+
const contractInputs = getInputsContract(inputs);
|
2836
|
+
const changeOutputs = getOutputsChange(outputs);
|
2837
|
+
coinOutputs.forEach((output) => {
|
2838
|
+
const { amount, assetId, to } = output;
|
2839
|
+
const changeOutput = changeOutputs.find((change) => change.assetId === assetId);
|
2840
|
+
if (changeOutput) {
|
2841
|
+
operations = addOperation(operations, {
|
2842
|
+
name: "Transfer asset" /* transfer */,
|
2843
|
+
from: {
|
2844
|
+
type: 1 /* account */,
|
2845
|
+
address: changeOutput.to
|
2846
|
+
},
|
2847
|
+
to: {
|
2848
|
+
type: 1 /* account */,
|
2849
|
+
address: to
|
2850
|
+
},
|
2851
|
+
assetsSent: [
|
2852
|
+
{
|
2853
|
+
assetId,
|
2854
|
+
amount
|
2855
|
+
}
|
2856
|
+
]
|
2857
|
+
});
|
2858
|
+
}
|
2859
|
+
});
|
2860
|
+
const transferReceipts = getReceiptsByType(
|
2843
2861
|
receipts,
|
2844
2862
|
ReceiptType3.Transfer
|
2845
2863
|
);
|
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
|
-
}
|
2864
|
+
const transferOutReceipts = getReceiptsByType(
|
2865
|
+
receipts,
|
2866
|
+
ReceiptType3.TransferOut
|
2867
|
+
);
|
2868
|
+
[...transferReceipts, ...transferOutReceipts].forEach((receipt) => {
|
2869
|
+
const operation = extractTransferOperationFromReceipt(receipt, contractInputs, changeOutputs);
|
2870
|
+
operations = addOperation(operations, operation);
|
2871
|
+
});
|
2900
2872
|
return operations;
|
2901
2873
|
}
|
2902
2874
|
function getPayProducerOperations(outputs) {
|
@@ -2969,7 +2941,6 @@ function getOperations({
|
|
2969
2941
|
rawPayload,
|
2970
2942
|
maxInputs
|
2971
2943
|
}),
|
2972
|
-
...getContractTransferOperations({ receipts }),
|
2973
2944
|
...getWithdrawFromFuelOperations({ inputs, receipts })
|
2974
2945
|
];
|
2975
2946
|
}
|
@@ -3531,7 +3502,7 @@ var _Provider = class {
|
|
3531
3502
|
const opDefinition = query.definitions.find((x) => x.kind === "OperationDefinition");
|
3532
3503
|
const isSubscription = opDefinition?.operation === "subscription";
|
3533
3504
|
if (isSubscription) {
|
3534
|
-
return
|
3505
|
+
return new FuelGraphqlSubscriber({
|
3535
3506
|
url: this.url,
|
3536
3507
|
query,
|
3537
3508
|
fetchFn: (url, requestInit) => fetchFn(url, requestInit, this.options),
|
@@ -3723,11 +3694,15 @@ var _Provider = class {
|
|
3723
3694
|
async estimateTxDependencies(transactionRequest) {
|
3724
3695
|
if (transactionRequest.type === TransactionType8.Create) {
|
3725
3696
|
return {
|
3726
|
-
receipts: []
|
3697
|
+
receipts: [],
|
3698
|
+
outputVariables: 0,
|
3699
|
+
missingContractIds: []
|
3727
3700
|
};
|
3728
3701
|
}
|
3729
3702
|
await this.estimatePredicates(transactionRequest);
|
3730
3703
|
let receipts = [];
|
3704
|
+
const missingContractIds = [];
|
3705
|
+
let outputVariables = 0;
|
3731
3706
|
for (let attempt = 0; attempt < MAX_RETRIES; attempt++) {
|
3732
3707
|
const { dryRun: gqlReceipts } = await this.operations.dryRun({
|
3733
3708
|
encodedTransaction: hexlify12(transactionRequest.toTransactionBytes()),
|
@@ -3737,16 +3712,20 @@ var _Provider = class {
|
|
3737
3712
|
const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(receipts);
|
3738
3713
|
const hasMissingOutputs = missingOutputVariables.length !== 0 || missingOutputContractIds.length !== 0;
|
3739
3714
|
if (hasMissingOutputs) {
|
3715
|
+
outputVariables += missingOutputVariables.length;
|
3740
3716
|
transactionRequest.addVariableOutputs(missingOutputVariables.length);
|
3741
3717
|
missingOutputContractIds.forEach(({ contractId }) => {
|
3742
3718
|
transactionRequest.addContractInputAndOutput(Address2.fromString(contractId));
|
3719
|
+
missingContractIds.push(contractId);
|
3743
3720
|
});
|
3744
3721
|
} else {
|
3745
3722
|
break;
|
3746
3723
|
}
|
3747
3724
|
}
|
3748
3725
|
return {
|
3749
|
-
receipts
|
3726
|
+
receipts,
|
3727
|
+
outputVariables,
|
3728
|
+
missingContractIds
|
3750
3729
|
};
|
3751
3730
|
}
|
3752
3731
|
/**
|
@@ -3814,11 +3793,15 @@ var _Provider = class {
|
|
3814
3793
|
const minGas = txRequestClone.calculateMinGas(chainInfo);
|
3815
3794
|
const maxGas = txRequestClone.calculateMaxGas(chainInfo, minGas);
|
3816
3795
|
let receipts = [];
|
3796
|
+
let missingContractIds = [];
|
3797
|
+
let outputVariables = 0;
|
3817
3798
|
if (isScriptTransaction && estimateTxDependencies) {
|
3818
3799
|
txRequestClone.gasPrice = bn14(0);
|
3819
3800
|
txRequestClone.gasLimit = bn14(maxGasPerTx.sub(maxGas).toNumber() * 0.9);
|
3820
3801
|
const result = await this.estimateTxDependencies(txRequestClone);
|
3821
3802
|
receipts = result.receipts;
|
3803
|
+
outputVariables = result.outputVariables;
|
3804
|
+
missingContractIds = result.missingContractIds;
|
3822
3805
|
}
|
3823
3806
|
const gasUsed = isScriptTransaction ? getGasUsedFromReceipts(receipts) : minGas;
|
3824
3807
|
const usedFee = calculatePriceWithFactor(
|
@@ -3840,7 +3823,8 @@ var _Provider = class {
|
|
3840
3823
|
minFee,
|
3841
3824
|
maxFee,
|
3842
3825
|
estimatedInputs: txRequestClone.inputs,
|
3843
|
-
|
3826
|
+
outputVariables,
|
3827
|
+
missingContractIds
|
3844
3828
|
};
|
3845
3829
|
}
|
3846
3830
|
async getResourcesForTransaction(owner, transactionRequestLike, forwardingQuantities = []) {
|