Skip to content

Commit

Permalink
chore!: restructure Account related packages (FuelLabs#1675)
Browse files Browse the repository at this point in the history
  • Loading branch information
Torres-ssf authored Feb 10, 2024
1 parent 89b5157 commit 357c253
Show file tree
Hide file tree
Showing 313 changed files with 972 additions and 7,062 deletions.
2 changes: 1 addition & 1 deletion .changeset/swift-chefs-battle.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
"@fuel-ts/wallet-manager": minor
"@fuel-ts/account": minor
---

remove provider from WalletManager specific types
11 changes: 11 additions & 0 deletions .changeset/young-impalas-explain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
"@fuel-ts/account": minor
"@fuel-ts/contract": minor
"@fuel-ts/errors": minor
"fuels": minor
"@fuel-ts/interfaces": minor
"@fuel-ts/program": minor
"@fuel-ts/script": minor
---

restructure Account related packages
4 changes: 2 additions & 2 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ apps/demo-react-cra
apps/demo-react-vite

packages/fuels/test/fixtures/project
packages/providers/src/__generated__
packages/account/src/providers/__generated__

out
CHANGELOG.md

*.hbs

templates/nextjs
templates/nextjs
4 changes: 2 additions & 2 deletions .github/actions/ci-setup/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ runs:
path: |
apps/docs/.typedoc
apps/docs/src/api
packages/providers/src/__generated__
packages/account/src/providers/__generated__
templates/src/sway-api
key: ${{ runner.os }}-generated-${{ github.sha }}

Expand All @@ -37,7 +37,7 @@ runs:
path: |
apps/docs/.typedoc
apps/docs/src/api
packages/providers/src/__generated__
packages/account/src/providers/__generated__
templates/src/sway-api
key: ${{ runner.os }}-generated-${{ github.sha }}

Expand Down
4 changes: 2 additions & 2 deletions .github/actions/test-setup/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ runs:
path: |
apps/docs/.typedoc
apps/docs/src/api
packages/providers/src/__generated__
packages/account/src/providers/__generated__
key: ${{ runner.os }}-generated-${{ github.sha }}

- name: Cache Build
Expand All @@ -36,7 +36,7 @@ runs:
path: |
apps/docs/.typedoc
apps/docs/src/api
packages/providers/src/__generated__
packages/account/src/providers/__generated__
key: ${{ runner.os }}-generated-${{ github.sha }}

- name: Setup Node.js
Expand Down
2 changes: 1 addition & 1 deletion apps/demo-fuels/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"license": "Apache-2.0",
"dependencies": {
"@fuel-ts/errors": "workspace:^",
"@fuel-ts/wallet": "workspace:^",
"@fuel-ts/account": "workspace:^",
"fuels": "workspace:*"
},
"version": null
Expand Down
2 changes: 1 addition & 1 deletion apps/demo-fuels/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
* It ensures that built code is fully working.
*/

import { generateTestWallet } from '@fuel-ts/account/test-utils';
import { safeExec } from '@fuel-ts/errors/test-utils';
import { generateTestWallet } from '@fuel-ts/wallet/test-utils';
import type { BN } from 'fuels';
import { ContractFactory, Provider, toHex, BaseAssetId, Wallet, FUEL_NETWORK_URL } from 'fuels';

Expand Down
2 changes: 1 addition & 1 deletion apps/demo-typegen/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
},
"devDependencies": {
"@fuel-ts/forc": "workspace:*",
"@fuel-ts/wallet": "workspace:*",
"@fuel-ts/account": "workspace:*",
"@fuel-ts/errors": "workspace:*",
"@fuel-ts/utils": "workspace:*"
},
Expand Down
2 changes: 1 addition & 1 deletion apps/demo-typegen/src/demo.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// #region Testing-in-ts-ts
import { generateTestWallet } from '@fuel-ts/account/test-utils';
import { safeExec } from '@fuel-ts/errors/test-utils';
import { generateTestWallet } from '@fuel-ts/wallet/test-utils';
import type { BN } from 'fuels';
import {
ContractFactory,
Expand Down
3 changes: 1 addition & 2 deletions apps/docs-snippets/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
"fuels": "workspace:*",
"@fuel-ts/utils": "workspace:*",
"@fuel-ts/errors": "workspace:*",
"@fuel-ts/wallet-manager": "workspace:*",
"@fuel-ts/wallet": "workspace:*"
"@fuel-ts/account": "workspace:*"
},
"keywords": [],
"author": "",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { WalletManager } from '@fuel-ts/wallet-manager';
import { WalletManager } from '@fuel-ts/account';
import { FUEL_NETWORK_URL, Provider, Wallet } from 'fuels';

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { WalletManager } from '@fuel-ts/wallet-manager';
import { WalletManager } from '@fuel-ts/account';

/**
* @group node
Expand Down
2 changes: 1 addition & 1 deletion apps/docs/.vitepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ export default defineConfig({
},
{
text: 'Connecting to Testnet',
link: '/guide/providers/connecting-to-an-external-node',
link: '/guide/providers/connecting-to-testnet',
},
{
text: 'Querying the Chain',
Expand Down
2 changes: 1 addition & 1 deletion apps/docs/src/glossary.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ A Provider is a Class that provides an abstraction for a connection to a Fuel no

## Wallet and signer

A [`Wallet`](./api/Wallet/Wallet.md) is a Class with direct or indirect access to a private key. You can use a [`Wallet`](./api/Wallet/Wallet.md) to sign messages and transactions to authorize the network to charge your account to perform operations. The terms wallet and signer in the SDK are often used interchangeably, but, technically, a `Signer` enables the signing of transactions and messages; the [`Wallet`](./api/Wallet/Wallet.md) implements the `Signer` functionality.
A [`Wallet`](./api/Account/Wallet.md) is a Class with direct or indirect access to a private key. You can use a [`Wallet`](./api/Account/Wallet.md) to sign messages and transactions to authorize the network to charge your account to perform operations. The terms wallet and signer in the SDK are often used interchangeably, but, technically, a `Signer` enables the signing of transactions and messages; the [`Wallet`](./api/Account/Wallet.md) implements the `Signer` functionality.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Making Calls with Different Wallets or Providers

This guide demonstrates how to make contract calls using different wallets and providers by passing either an [`Account`](../../api/Wallet/Account.md) or a [`Provider`](../../api/Providers/Provider.md) to the contract on instantiation.
This guide demonstrates how to make contract calls using different wallets and providers by passing either an [`Account`](../../api/Account/Account.md) or a [`Provider`](../../api/Account/Provider.md) to the contract on instantiation.

## Changing Wallets

Expand Down
4 changes: 2 additions & 2 deletions apps/docs/src/guide/contracts/cost-estimation.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Estimating Contract Call Cost

The `getTransactionCost` function provided by the [Provider](../../api/Providers/Provider.md) allows you to estimate the cost of a specific contract call. The return type, `TransactionCost`, is an object containing relevant information for the estimation:
The `getTransactionCost` function provided by the [Provider](../../api/Account/Provider.md) allows you to estimate the cost of a specific contract call. The return type, `TransactionCost`, is an object containing relevant information for the estimation:

<<< @/../../../packages/providers/src/provider.ts#cost-estimation-1{ts:line-numbers}
<<< @/../../../packages/account/src/providers/provider.ts#cost-estimation-1{ts:line-numbers}

The following example demonstrate how to get the estimated transaction cost for:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ However, the SDK always automatically estimates these dependencies and double-ch

The SDK uses the `estimateTxDependencies` helper function to set any missing dependencies identified during the estimation process. This requires simulating the transaction a few times in the background.

<<< @/../../../packages/providers/src/provider.ts#Provider-sendTransaction{ts:line-numbers}
<<< @/../../../packages/account/src/providers/provider.ts#Provider-sendTransaction{ts:line-numbers}

While relying on the SDK's automatic estimation is a decent default behavior, we recommend manually specifying the dependencies if they are known in advance to avoid the performance impact of the estimation process.
4 changes: 2 additions & 2 deletions apps/docs/src/guide/cookbook/custom-transactions.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Custom Transactions

There may be scenarios where you need to build out transactions that involve multiple program types and assets; this can be done by instantiating a [`ScriptTransactionRequest`](../../api/Providers/ScriptTransactionRequest.md). This class allows you to a append multiple program types and assets to a single transaction.
There may be scenarios where you need to build out transactions that involve multiple program types and assets; this can be done by instantiating a [`ScriptTransactionRequest`](../../api/Account/ScriptTransactionRequest.md). This class allows you to a append multiple program types and assets to a single transaction.

Consider the following script that transfers multiple assets to a contract:

<<< @/../../docs-snippets/test/fixtures/forc-projects/script-transfer-to-contract/src/main.sw#custom-transactions-1{ts:line-numbers}

This script can be executed by creating a [`ScriptTransactionRequest`](../../api/Providers/ScriptTransactionRequest.md), appending the resource and contract inputs/outputs and then sending the transaction, as follows:
This script can be executed by creating a [`ScriptTransactionRequest`](../../api/Account/ScriptTransactionRequest.md), appending the resource and contract inputs/outputs and then sending the transaction, as follows:

<<< @/../../docs-snippets/src/guide/scripts/script-custom-transaction.test.ts#custom-transactions-2{ts:line-numbers}
2 changes: 1 addition & 1 deletion apps/docs/src/guide/messages/getting-a-message-proof.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

A message proof is a cryptographic proof that a message was included in a block. You can use the `getMessageProof` method to retrieve a message proof for a given transaction ID and message ID.

<<< @/../../../packages/wallet/src/transfer.test.ts#Message-getMessageProof{ts:line-numbers}
<<< @/../../../packages/account/src/account.test.ts#Message-getMessageProof{ts:line-numbers}

<!-- TODO: Add docs for the two new parameters `commitBlockId` and `commitBlockHeight` -->
2 changes: 1 addition & 1 deletion apps/docs/src/guide/messages/getting-all-resources.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

You can use the `getResourcesToSpend` method to retrieve a list of all the resources (coins + assets) that can be spent by a given address.

<<< @/../../../packages/wallet/src/account.test.ts#Message-getResourcesToSpend{ts:line-numbers}
<<< @/../../../packages/account/src/account.test.ts#Message-getResourcesToSpend{ts:line-numbers}
2 changes: 1 addition & 1 deletion apps/docs/src/guide/messages/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ A message is an object that contains some data that when broadcast to the networ

This is the general structure of a `Message` object:

<<< @/../../../packages/providers/src/message.ts#Message-shape{ts:line-numbers}
<<< @/../../../packages/account/src/providers/message.ts#Message-shape{ts:line-numbers}
2 changes: 1 addition & 1 deletion apps/docs/src/guide/predicates/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ After compiling, you will obtain the binary of the predicate and its JSON ABI (A

<<< @/../../docs-snippets/src/guide/predicates/index.test.ts#predicate-index-2{ts:line-numbers}

The created [`Predicate`](../../api/Predicate/Predicate.md) instance, among other things, has three important properties: the predicate `bytes` (byte code), the `chainId`, and the predicate `address`.
The created [`Predicate`](../../api/Account/Predicate.md) instance, among other things, has three important properties: the predicate `bytes` (byte code), the `chainId`, and the predicate `address`.

This address, generated from the byte code, corresponds to the Pay-to-Script-Hash (P2SH) address used in Bitcoin.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ With the predicate instantiated, we can transfer funds to its address. This requ

Now that our predicate holds funds, we can use it to validate a transaction.

First, we need to set its data. Note that the `main` function in our predicate example requires a parameter called `input_address` of type `b256`. We achieve this using the [`Predicate`](../../api/Predicate/Predicate.md) class method `setData`.
First, we need to set its data. Note that the `main` function in our predicate example requires a parameter called `input_address` of type `b256`. We achieve this using the [`Predicate`](../../api/Account/Predicate.md) class method `setData`.

<<< @/../../docs-snippets/src/guide/predicates/send-and-spend-funds-from-predicates.test.ts#send-and-spend-funds-from-predicates-4{ts:line-numbers}

Expand All @@ -40,7 +40,7 @@ Once the predicate resolves with a return value `true` based on its predefined c

---

In a similar approach, you can use the `createTransfer` method, which returns a [`ScriptTransactionRequest`](../../api/Providers/ScriptTransactionRequest.md). Then, we can submit this transaction request by calling the `sendTransaction` method.
In a similar approach, you can use the `createTransfer` method, which returns a [`ScriptTransactionRequest`](../../api/Account/ScriptTransactionRequest.md). Then, we can submit this transaction request by calling the `sendTransaction` method.

This can be useful if you need the transaction ID before actually submitting it to the node.

Expand Down
2 changes: 1 addition & 1 deletion apps/docs/src/guide/providers/connection.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ At a high level, you can use the Fuel TypeScript SDK to build applications that

For this interaction to work, the SDK must be able to communicate with a `fuel-core` node; you have two options at your disposal:

1. Use the [Testnet](../providers/connecting-to-an-external-node.md)
1. Use the [Testnet](../providers/connecting-to-testnet.md)
2. [Run a local Fuel-Core node](https://docs.fuel.network/guides/running-a-node/) and instantiate a provider that points to that node's IP and port

For application building, you should use the first option.
Expand Down
4 changes: 2 additions & 2 deletions apps/docs/src/guide/providers/index.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Providers

An instance of the [`Provider`](../../api/Providers/Provider.md) class lets you connect to a Fuel node. It provides read-only access to the blockchain state. You can use this provider as-is or through a [`Wallet`](../../api/Wallet/Wallet.md) instance.
An instance of the [`Provider`](../../api/Account/Provider.md) class lets you connect to a Fuel node. It provides read-only access to the blockchain state. You can use this provider as-is or through a [`Wallet`](../../api/Account/Wallet.md) instance.

<<< @/../../../packages/providers/test/provider.test.ts#provider-definition{ts:line-numbers}
<<< @/../../../packages/account/src/providers/provider.test.ts#provider-definition{ts:line-numbers}
4 changes: 2 additions & 2 deletions apps/docs/src/guide/providers/querying-the-chain.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Once you have set up a provider, you're ready to interact with the Fuel blockcha
We can connect to either a _*local*_ or an _*external*_ node:

> 1. _Running a [local node](https://docs.fuel.network/guides/running-a-node/)_
> 1. _Connecting to an [external node](./connecting-to-an-external-node.md)_
> 1. _Connecting to an [external node](./connecting-to-testnet.md)_
Let's look at a few examples below.

Expand All @@ -31,4 +31,4 @@ Get all the spendable balances of all assets for an address. This is different f

This method returns all the blocks from the blockchain that match the given query. The below code snippet shows how to get the last 10 blocks.

<<< @/../../../packages/providers/test/provider.test.ts#Provider-get-blocks{ts:line-numbers}
<<< @/../../../packages/account/src/providers/provider.test.ts#Provider-get-blocks{ts:line-numbers}
2 changes: 1 addition & 1 deletion apps/docs/src/guide/providers/retrying-calls.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

The default behavior of calls done via the `Provider` towards a fuel node is that they'll fail if the connection breaks. Specifying retry options allows you to customize how many additional attempts you want to make when the connection to the node breaks before ultimately throwing an error. You can also specify the back-off algorithm as well as the base delay that algorithm will use to calculate the wait time for each request.

<<< @/../../../packages/providers/test/auto-retry-fetch.test.ts#provider-retry-options{ts:line-numbers}
<<< @/../../../packages/account/test/auto-retry-fetch.test.ts#provider-retry-options{ts:line-numbers}
4 changes: 2 additions & 2 deletions apps/docs/src/guide/testing/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ For this, you can find two simple utilities on the wallet package:

- [`@fuel-ts/wallet`](https://github.com/FuelLabs/fuels-ts/tree/master/packages/wallet#test-utilities)

On top of these two utilities, if you want to quickly get up and running with a local node, you can use the `launchNodeAndGetWallets` from the `@fuel-ts/wallet/test-utils` package.
On top of these two utilities, if you want to quickly get up and running with a local node, you can use the `launchNodeAndGetWallets` from the `@fuel-ts/account/test-utils` package.

```ts
import { launchNodeAndGetWallets } from "@fuel-ts/wallet/test-utils";
import { launchNodeAndGetWallets } from "@fuel-ts/account/test-utils";

const { stop, wallets, provider } = await launchNodeAndGetWallets();

Expand Down
4 changes: 2 additions & 2 deletions apps/docs/src/guide/testing/setting-up-a-custom-chain.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ The `launchNodeAndGetWallets` method lets you launch a local Fuel node with vari

In the code snippet below, we provide a custom chain config file to the `launchNodeAndGetWallets` method. You can use a chain config file to customize things like the chain's consensus parameters or specify some initial states for the chain. Click here to see what a chain config file looks like: [`chainConfig.json`](https://github.com/FuelLabs/fuels-ts/blob/master/.fuel-core/configs/chainConfig.json)

<<< @/../../../packages/wallet/src/test-utils/launchNodeAndGetWallets.test.ts#launchNode-custom-config{ts:line-numbers}
<<< @/../../../packages/account/src/test-utils/launchNodeAndGetWallets.test.ts#launchNode-custom-config{ts:line-numbers}

## Customization options

Expand All @@ -14,6 +14,6 @@ The `walletCount` option lets you specify how many wallets you want to generate.

The `launchNodeOptions` option lets you specify some additional options for the node. The available options are:

<<< @/../../../packages/wallet/src/test-utils/launchNode.ts#launchNode-launchNodeOptions{ts:line-numbers}
<<< @/../../../packages/account/src/test-utils/launchNode.ts#launchNode-launchNodeOptions{ts:line-numbers}

> Note: You can see all the available fuel-core args by running `pnpm fuels core run -h`.
2 changes: 1 addition & 1 deletion apps/docs/src/guide/testing/tweaking-the-blockchain.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

You can force-produce blocks using the `produceBlocks` helper to achieve an arbitrary block height. This is especially useful when you want to do some testing regarding transaction maturity.

<<< @/../../../packages/providers/test/provider.test.ts#Provider-produce-blocks{ts:line-numbers}
<<< @/../../../packages/account/src/providers/provider.test.ts#Provider-produce-blocks{ts:line-numbers}

# Producing Blocks With Custom Timestamps

Expand Down
Loading

0 comments on commit 357c253

Please sign in to comment.