@fuel-ts/account 0.0.0-rc-2143-20240429105111 → 0.0.0-rc-2037-20240429115810
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/index.global.js +69 -8
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +192 -118
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +107 -39
- package/dist/index.mjs.map +1 -1
- package/dist/predicate/predicate.d.ts +9 -2
- package/dist/predicate/predicate.d.ts.map +1 -1
- package/dist/providers/transaction-request/helpers.d.ts +10 -0
- package/dist/providers/transaction-request/helpers.d.ts.map +1 -0
- package/dist/providers/transaction-request/index.d.ts +1 -0
- package/dist/providers/transaction-request/index.d.ts.map +1 -1
- package/dist/providers/transaction-request/transaction-request.d.ts +2 -0
- package/dist/providers/transaction-request/transaction-request.d.ts.map +1 -1
- package/dist/test-utils/index.d.ts +1 -0
- package/dist/test-utils/index.d.ts.map +1 -1
- package/dist/test-utils/launchNode.d.ts +2 -4
- package/dist/test-utils/launchNode.d.ts.map +1 -1
- package/dist/test-utils/resources.d.ts +4 -0
- package/dist/test-utils/resources.d.ts.map +1 -0
- package/dist/test-utils/seedTestWallet.d.ts +1 -1
- package/dist/test-utils/seedTestWallet.d.ts.map +1 -1
- package/dist/test-utils/transactionRequest.d.ts +5 -0
- package/dist/test-utils/transactionRequest.d.ts.map +1 -0
- package/dist/test-utils.global.js +63 -14
- package/dist/test-utils.global.js.map +1 -1
- package/dist/test-utils.js +180 -117
- package/dist/test-utils.js.map +1 -1
- package/dist/test-utils.mjs +104 -44
- package/dist/test-utils.mjs.map +1 -1
- package/dist/wallet/base-wallet-unlocked.d.ts +2 -2
- package/dist/wallet/base-wallet-unlocked.d.ts.map +1 -1
- package/package.json +15 -15
package/dist/test-utils.mjs
CHANGED
@@ -70,7 +70,7 @@ import { Address as Address2 } from "@fuel-ts/address";
|
|
70
70
|
import { ErrorCode as ErrorCode13, FuelError as FuelError13 } from "@fuel-ts/errors";
|
71
71
|
import { BN, bn as bn16 } from "@fuel-ts/math";
|
72
72
|
import {
|
73
|
-
InputType as
|
73
|
+
InputType as InputType8,
|
74
74
|
TransactionType as TransactionType8,
|
75
75
|
InputMessageCoder,
|
76
76
|
TransactionCoder as TransactionCoder5
|
@@ -1235,7 +1235,7 @@ import { bn as bn7 } from "@fuel-ts/math";
|
|
1235
1235
|
import {
|
1236
1236
|
PolicyType,
|
1237
1237
|
TransactionCoder,
|
1238
|
-
InputType as
|
1238
|
+
InputType as InputType3,
|
1239
1239
|
OutputType as OutputType2,
|
1240
1240
|
TransactionType
|
1241
1241
|
} from "@fuel-ts/transactions";
|
@@ -1685,6 +1685,12 @@ var NoWitnessAtIndexError = class extends Error {
|
|
1685
1685
|
name = "NoWitnessAtIndexError";
|
1686
1686
|
};
|
1687
1687
|
|
1688
|
+
// src/providers/transaction-request/helpers.ts
|
1689
|
+
import { InputType as InputType2 } from "@fuel-ts/transactions";
|
1690
|
+
var isRequestInputCoin = (input) => input.type === InputType2.Coin;
|
1691
|
+
var isRequestInputMessage = (input) => input.type === InputType2.Message;
|
1692
|
+
var isRequestInputResource = (input) => isRequestInputCoin(input) || isRequestInputMessage(input);
|
1693
|
+
|
1688
1694
|
// src/providers/transaction-request/witness.ts
|
1689
1695
|
import { arrayify as arrayify4, hexlify as hexlify6 } from "@fuel-ts/utils";
|
1690
1696
|
var witnessify = (value) => {
|
@@ -1875,7 +1881,7 @@ var BaseTransactionRequest = class {
|
|
1875
1881
|
*/
|
1876
1882
|
getCoinInputs() {
|
1877
1883
|
return this.inputs.filter(
|
1878
|
-
(input) => input.type ===
|
1884
|
+
(input) => input.type === InputType3.Coin
|
1879
1885
|
);
|
1880
1886
|
}
|
1881
1887
|
/**
|
@@ -1907,9 +1913,9 @@ var BaseTransactionRequest = class {
|
|
1907
1913
|
const ownerAddress = addressify(owner);
|
1908
1914
|
const found = this.inputs.find((input) => {
|
1909
1915
|
switch (input.type) {
|
1910
|
-
case
|
1916
|
+
case InputType3.Coin:
|
1911
1917
|
return hexlify7(input.owner) === ownerAddress.toB256();
|
1912
|
-
case
|
1918
|
+
case InputType3.Message:
|
1913
1919
|
return hexlify7(input.recipient) === ownerAddress.toB256();
|
1914
1920
|
default:
|
1915
1921
|
return false;
|
@@ -1924,7 +1930,7 @@ var BaseTransactionRequest = class {
|
|
1924
1930
|
* @param coin - Coin resource.
|
1925
1931
|
*/
|
1926
1932
|
addCoinInput(coin) {
|
1927
|
-
const { assetId, owner, amount } = coin;
|
1933
|
+
const { assetId, owner, amount, id, predicate } = coin;
|
1928
1934
|
let witnessIndex;
|
1929
1935
|
if (coin.predicate) {
|
1930
1936
|
witnessIndex = 0;
|
@@ -1935,13 +1941,14 @@ var BaseTransactionRequest = class {
|
|
1935
1941
|
}
|
1936
1942
|
}
|
1937
1943
|
const input = {
|
1938
|
-
|
1939
|
-
type:
|
1944
|
+
id,
|
1945
|
+
type: InputType3.Coin,
|
1940
1946
|
owner: owner.toB256(),
|
1941
1947
|
amount,
|
1942
1948
|
assetId,
|
1943
1949
|
txPointer: "0x00000000000000000000000000000000",
|
1944
|
-
witnessIndex
|
1950
|
+
witnessIndex,
|
1951
|
+
predicate
|
1945
1952
|
};
|
1946
1953
|
this.pushInput(input);
|
1947
1954
|
this.addChangeOutput(owner, assetId);
|
@@ -1953,7 +1960,7 @@ var BaseTransactionRequest = class {
|
|
1953
1960
|
* @param message - Message resource.
|
1954
1961
|
*/
|
1955
1962
|
addMessageInput(message) {
|
1956
|
-
const { recipient, sender, amount, assetId } = message;
|
1963
|
+
const { recipient, sender, amount, predicate, nonce, assetId } = message;
|
1957
1964
|
let witnessIndex;
|
1958
1965
|
if (message.predicate) {
|
1959
1966
|
witnessIndex = 0;
|
@@ -1964,12 +1971,13 @@ var BaseTransactionRequest = class {
|
|
1964
1971
|
}
|
1965
1972
|
}
|
1966
1973
|
const input = {
|
1967
|
-
|
1968
|
-
type:
|
1974
|
+
nonce,
|
1975
|
+
type: InputType3.Message,
|
1969
1976
|
sender: sender.toB256(),
|
1970
1977
|
recipient: recipient.toB256(),
|
1971
1978
|
amount,
|
1972
|
-
witnessIndex
|
1979
|
+
witnessIndex,
|
1980
|
+
predicate
|
1973
1981
|
};
|
1974
1982
|
this.pushInput(input);
|
1975
1983
|
this.addChangeOutput(recipient, assetId);
|
@@ -2153,16 +2161,27 @@ var BaseTransactionRequest = class {
|
|
2153
2161
|
toJSON() {
|
2154
2162
|
return normalizeJSON(this);
|
2155
2163
|
}
|
2164
|
+
removeWitness(index) {
|
2165
|
+
this.witnesses.splice(index, 1);
|
2166
|
+
this.adjustWitnessIndexes(index);
|
2167
|
+
}
|
2168
|
+
adjustWitnessIndexes(removedIndex) {
|
2169
|
+
this.inputs.filter(isRequestInputResource).forEach((input) => {
|
2170
|
+
if (input.witnessIndex > removedIndex) {
|
2171
|
+
input.witnessIndex -= 1;
|
2172
|
+
}
|
2173
|
+
});
|
2174
|
+
}
|
2156
2175
|
updatePredicateGasUsed(inputs) {
|
2157
2176
|
this.inputs.forEach((i) => {
|
2158
2177
|
let correspondingInput;
|
2159
2178
|
switch (i.type) {
|
2160
|
-
case
|
2161
|
-
correspondingInput = inputs.find((x) => x.type ===
|
2179
|
+
case InputType3.Coin:
|
2180
|
+
correspondingInput = inputs.find((x) => x.type === InputType3.Coin && x.owner === i.owner);
|
2162
2181
|
break;
|
2163
|
-
case
|
2182
|
+
case InputType3.Message:
|
2164
2183
|
correspondingInput = inputs.find(
|
2165
|
-
(x) => x.type ===
|
2184
|
+
(x) => x.type === InputType3.Message && x.sender === i.sender
|
2166
2185
|
);
|
2167
2186
|
break;
|
2168
2187
|
default:
|
@@ -2196,7 +2215,7 @@ import { arrayify as arrayify6, hexlify as hexlify9 } from "@fuel-ts/utils";
|
|
2196
2215
|
import { ZeroBytes32 as ZeroBytes325 } from "@fuel-ts/address/configs";
|
2197
2216
|
import { uint64ToBytesBE, sha256 } from "@fuel-ts/hasher";
|
2198
2217
|
import { bn as bn8 } from "@fuel-ts/math";
|
2199
|
-
import { TransactionType as TransactionType2, InputType as
|
2218
|
+
import { TransactionType as TransactionType2, InputType as InputType4, OutputType as OutputType3, TransactionCoder as TransactionCoder2 } from "@fuel-ts/transactions";
|
2200
2219
|
import { concat as concat2 } from "@fuel-ts/utils";
|
2201
2220
|
import { clone as clone2 } from "ramda";
|
2202
2221
|
function hashTransaction(transactionRequest, chainId) {
|
@@ -2207,7 +2226,7 @@ function hashTransaction(transactionRequest, chainId) {
|
|
2207
2226
|
transaction.inputs = transaction.inputs.map((input) => {
|
2208
2227
|
const inputClone = clone2(input);
|
2209
2228
|
switch (inputClone.type) {
|
2210
|
-
case
|
2229
|
+
case InputType4.Coin: {
|
2211
2230
|
inputClone.txPointer = {
|
2212
2231
|
blockHeight: 0,
|
2213
2232
|
txIndex: 0
|
@@ -2215,11 +2234,11 @@ function hashTransaction(transactionRequest, chainId) {
|
|
2215
2234
|
inputClone.predicateGasUsed = bn8(0);
|
2216
2235
|
return inputClone;
|
2217
2236
|
}
|
2218
|
-
case
|
2237
|
+
case InputType4.Message: {
|
2219
2238
|
inputClone.predicateGasUsed = bn8(0);
|
2220
2239
|
return inputClone;
|
2221
2240
|
}
|
2222
|
-
case
|
2241
|
+
case InputType4.Contract: {
|
2223
2242
|
inputClone.txPointer = {
|
2224
2243
|
blockHeight: 0,
|
2225
2244
|
txIndex: 0
|
@@ -2379,7 +2398,7 @@ import { Interface } from "@fuel-ts/abi-coder";
|
|
2379
2398
|
import { addressify as addressify2 } from "@fuel-ts/address";
|
2380
2399
|
import { ZeroBytes32 as ZeroBytes327 } from "@fuel-ts/address/configs";
|
2381
2400
|
import { bn as bn10 } from "@fuel-ts/math";
|
2382
|
-
import { InputType as
|
2401
|
+
import { InputType as InputType5, OutputType as OutputType5, TransactionType as TransactionType4 } from "@fuel-ts/transactions";
|
2383
2402
|
import { arrayify as arrayify8, hexlify as hexlify10 } from "@fuel-ts/utils";
|
2384
2403
|
|
2385
2404
|
// src/providers/transaction-request/scripts.ts
|
@@ -2463,7 +2482,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2463
2482
|
*/
|
2464
2483
|
getContractInputs() {
|
2465
2484
|
return this.inputs.filter(
|
2466
|
-
(input) => input.type ===
|
2485
|
+
(input) => input.type === InputType5.Contract
|
2467
2486
|
);
|
2468
2487
|
}
|
2469
2488
|
/**
|
@@ -2540,7 +2559,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2540
2559
|
return this;
|
2541
2560
|
}
|
2542
2561
|
const inputIndex = super.pushInput({
|
2543
|
-
type:
|
2562
|
+
type: InputType5.Contract,
|
2544
2563
|
contractId: contractAddress.toB256(),
|
2545
2564
|
txPointer: "0x00000000000000000000000000000000"
|
2546
2565
|
});
|
@@ -2582,7 +2601,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2582
2601
|
|
2583
2602
|
// src/providers/transaction-request/utils.ts
|
2584
2603
|
import { ErrorCode as ErrorCode8, FuelError as FuelError8 } from "@fuel-ts/errors";
|
2585
|
-
import { TransactionType as TransactionType5, InputType as
|
2604
|
+
import { TransactionType as TransactionType5, InputType as InputType6 } from "@fuel-ts/transactions";
|
2586
2605
|
var transactionRequestify = (obj) => {
|
2587
2606
|
if (obj instanceof ScriptTransactionRequest || obj instanceof CreateTransactionRequest) {
|
2588
2607
|
return obj;
|
@@ -2602,10 +2621,10 @@ var transactionRequestify = (obj) => {
|
|
2602
2621
|
};
|
2603
2622
|
var cacheTxInputsFromOwner = (inputs, owner) => inputs.reduce(
|
2604
2623
|
(acc, input) => {
|
2605
|
-
if (input.type ===
|
2624
|
+
if (input.type === InputType6.Coin && input.owner === owner) {
|
2606
2625
|
acc.utxos.push(input.id);
|
2607
2626
|
}
|
2608
|
-
if (input.type ===
|
2627
|
+
if (input.type === InputType6.Message && input.recipient === owner) {
|
2609
2628
|
acc.messages.push(input.nonce);
|
2610
2629
|
}
|
2611
2630
|
return acc;
|
@@ -2759,7 +2778,7 @@ var getFunctionCall = ({ abi, receipt, rawPayload, maxInputs }) => {
|
|
2759
2778
|
|
2760
2779
|
// src/providers/transaction-summary/input.ts
|
2761
2780
|
import { ErrorCode as ErrorCode9, FuelError as FuelError9 } from "@fuel-ts/errors";
|
2762
|
-
import { InputType as
|
2781
|
+
import { InputType as InputType7 } from "@fuel-ts/transactions";
|
2763
2782
|
function getInputsByTypes(inputs, types) {
|
2764
2783
|
return inputs.filter((i) => types.includes(i.type));
|
2765
2784
|
}
|
@@ -2767,16 +2786,16 @@ function getInputsByType(inputs, type) {
|
|
2767
2786
|
return inputs.filter((i) => i.type === type);
|
2768
2787
|
}
|
2769
2788
|
function getInputsCoin(inputs) {
|
2770
|
-
return getInputsByType(inputs,
|
2789
|
+
return getInputsByType(inputs, InputType7.Coin);
|
2771
2790
|
}
|
2772
2791
|
function getInputsMessage(inputs) {
|
2773
|
-
return getInputsByType(inputs,
|
2792
|
+
return getInputsByType(inputs, InputType7.Message);
|
2774
2793
|
}
|
2775
2794
|
function getInputsCoinAndMessage(inputs) {
|
2776
|
-
return getInputsByTypes(inputs, [
|
2795
|
+
return getInputsByTypes(inputs, [InputType7.Coin, InputType7.Message]);
|
2777
2796
|
}
|
2778
2797
|
function getInputsContract(inputs) {
|
2779
|
-
return getInputsByType(inputs,
|
2798
|
+
return getInputsByType(inputs, InputType7.Contract);
|
2780
2799
|
}
|
2781
2800
|
function getInputFromAssetId(inputs, assetId) {
|
2782
2801
|
const coinInputs = getInputsCoin(inputs);
|
@@ -2795,7 +2814,7 @@ function getInputContractFromIndex(inputs, inputIndex) {
|
|
2795
2814
|
if (!contractInput) {
|
2796
2815
|
return void 0;
|
2797
2816
|
}
|
2798
|
-
if (contractInput.type !==
|
2817
|
+
if (contractInput.type !== InputType7.Contract) {
|
2799
2818
|
throw new FuelError9(
|
2800
2819
|
ErrorCode9.INVALID_TRANSACTION_INPUT,
|
2801
2820
|
`Contract input should be of type 'contract'.`
|
@@ -2804,10 +2823,10 @@ function getInputContractFromIndex(inputs, inputIndex) {
|
|
2804
2823
|
return contractInput;
|
2805
2824
|
}
|
2806
2825
|
function getInputAccountAddress(input) {
|
2807
|
-
if (input.type ===
|
2826
|
+
if (input.type === InputType7.Coin) {
|
2808
2827
|
return input.owner.toString();
|
2809
2828
|
}
|
2810
|
-
if (input.type ===
|
2829
|
+
if (input.type === InputType7.Message) {
|
2811
2830
|
return input.recipient.toString();
|
2812
2831
|
}
|
2813
2832
|
return "";
|
@@ -4644,7 +4663,7 @@ cacheInputs_fn = function(inputs) {
|
|
4644
4663
|
return;
|
4645
4664
|
}
|
4646
4665
|
inputs.forEach((input) => {
|
4647
|
-
if (input.type ===
|
4666
|
+
if (input.type === InputType8.Coin) {
|
4648
4667
|
this.cache?.set(input.id);
|
4649
4668
|
}
|
4650
4669
|
});
|
@@ -8211,16 +8230,21 @@ __publicField(Wallet, "fromEncryptedJson", WalletUnlocked.fromEncryptedJson);
|
|
8211
8230
|
|
8212
8231
|
// src/test-utils/seedTestWallet.ts
|
8213
8232
|
import { randomBytes as randomBytes5 } from "@fuel-ts/crypto";
|
8214
|
-
var seedTestWallet = async (wallet, quantities) => {
|
8233
|
+
var seedTestWallet = async (wallet, quantities, utxosAmount = 1) => {
|
8234
|
+
const toFundAccounts = Array.isArray(wallet) ? wallet : [wallet];
|
8215
8235
|
const genesisWallet = new WalletUnlocked(
|
8216
8236
|
process.env.GENESIS_SECRET || randomBytes5(32),
|
8217
|
-
wallet
|
8237
|
+
// Connect to the same Provider as wallet
|
8238
|
+
toFundAccounts[0].provider
|
8218
8239
|
);
|
8219
8240
|
const request = new ScriptTransactionRequest();
|
8220
|
-
quantities.forEach(
|
8221
|
-
|
8222
|
-
|
8223
|
-
|
8241
|
+
quantities.map(coinQuantityfy).forEach(
|
8242
|
+
({ amount, assetId }) => toFundAccounts.forEach(({ address }) => {
|
8243
|
+
for (let i = 0; i < utxosAmount; i++) {
|
8244
|
+
request.addCoinOutput(address, amount.div(utxosAmount), assetId);
|
8245
|
+
}
|
8246
|
+
})
|
8247
|
+
);
|
8224
8248
|
const txCost = await genesisWallet.provider.getTransactionCost(request);
|
8225
8249
|
request.gasLimit = txCost.gasUsed;
|
8226
8250
|
request.maxFee = txCost.maxFee;
|
@@ -8284,7 +8308,6 @@ var launchNode = async ({
|
|
8284
8308
|
ip,
|
8285
8309
|
port,
|
8286
8310
|
args = [],
|
8287
|
-
fuelCorePath = void 0,
|
8288
8311
|
useSystemFuelCore = false,
|
8289
8312
|
loggingEnabled = true,
|
8290
8313
|
debugEnabled = false,
|
@@ -8305,7 +8328,7 @@ var launchNode = async ({
|
|
8305
8328
|
const poaInstantFlagValue = getFlagValueFromArgs(args, "--poa-instant");
|
8306
8329
|
const poaInstant = poaInstantFlagValue === "true" || poaInstantFlagValue === void 0;
|
8307
8330
|
const graphQLStartSubstring = "Binding GraphQL provider to";
|
8308
|
-
const binPath =
|
8331
|
+
const binPath = findBinPath("fuels-core", __dirname);
|
8309
8332
|
const command = useSystemFuelCore ? "fuel-core" : binPath;
|
8310
8333
|
const ipToUse = ip || "0.0.0.0";
|
8311
8334
|
const portToUse = port || (await getPortPromise({
|
@@ -8443,7 +8466,44 @@ var launchNodeAndGetWallets = async ({
|
|
8443
8466
|
};
|
8444
8467
|
return { wallets, stop: cleanup, provider };
|
8445
8468
|
};
|
8469
|
+
|
8470
|
+
// src/test-utils/transactionRequest.ts
|
8471
|
+
import { UTXO_ID_LEN as UTXO_ID_LEN4 } from "@fuel-ts/abi-coder";
|
8472
|
+
import { getRandomB256 } from "@fuel-ts/address";
|
8473
|
+
import { ZeroBytes32 as ZeroBytes329 } from "@fuel-ts/address/configs";
|
8474
|
+
import { randomBytes as randomBytes7 } from "@fuel-ts/crypto";
|
8475
|
+
import { bn as bn20 } from "@fuel-ts/math";
|
8476
|
+
import { InputType as InputType9 } from "@fuel-ts/transactions";
|
8477
|
+
import { hexlify as hexlify19 } from "@fuel-ts/utils";
|
8478
|
+
var generateFakeRequestInputCoin = (partial = {}) => ({
|
8479
|
+
id: hexlify19(randomBytes7(UTXO_ID_LEN4)),
|
8480
|
+
type: InputType9.Coin,
|
8481
|
+
owner: getRandomB256(),
|
8482
|
+
amount: bn20(100),
|
8483
|
+
assetId: ZeroBytes329,
|
8484
|
+
txPointer: "0x00000000000000000000000000000000",
|
8485
|
+
witnessIndex: 0,
|
8486
|
+
...partial
|
8487
|
+
});
|
8488
|
+
var generateFakeRequestInputMessage = (partial = {}) => ({
|
8489
|
+
nonce: getRandomB256(),
|
8490
|
+
type: InputType9.Message,
|
8491
|
+
sender: getRandomB256(),
|
8492
|
+
recipient: getRandomB256(),
|
8493
|
+
amount: bn20(100),
|
8494
|
+
witnessIndex: 0,
|
8495
|
+
...partial
|
8496
|
+
});
|
8497
|
+
var generateFakeRequestInputContract = (partial = {}) => ({
|
8498
|
+
contractId: getRandomB256(),
|
8499
|
+
type: InputType9.Contract,
|
8500
|
+
txPointer: "0x00000000000000000000000000000000",
|
8501
|
+
...partial
|
8502
|
+
});
|
8446
8503
|
export {
|
8504
|
+
generateFakeRequestInputCoin,
|
8505
|
+
generateFakeRequestInputContract,
|
8506
|
+
generateFakeRequestInputMessage,
|
8447
8507
|
generateTestWallet,
|
8448
8508
|
killNode,
|
8449
8509
|
launchNode,
|