Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: re-introduce a section from provider docs #2716

Merged
merged 46 commits into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
ac0313b
docs: re-introduce a section from provider docs
mvares Jul 6, 2024
c2a07a8
add getMessageProof
mvares Jul 6, 2024
b9ca250
fix name of snippet
mvares Jul 6, 2024
e993e90
remove nits
mvares Jul 6, 2024
3200928
use withdrawToBaseLayer method for transfering
mvares Jul 7, 2024
8b4b5b3
add comments
mvares Jul 7, 2024
9d88d1d
Merge branch 'master' into mv/docs/reintroduce-docs
mvares Jul 8, 2024
73ddcb3
add blockHeight and blockId examples
mvares Jul 8, 2024
9ee8021
nits
mvares Jul 8, 2024
3c7632e
fix docs
mvares Jul 8, 2024
280702b
nits
mvares Jul 8, 2024
b5fd9b7
formating
mvares Jul 8, 2024
5fcce74
Merge branch 'master' into mv/docs/reintroduce-docs
mvares Jul 10, 2024
cf67d9b
refining
mvares Jul 10, 2024
c8deeb7
fix comment
mvares Jul 10, 2024
2efaeec
Merge branch 'master' into mv/docs/reintroduce-docs
mvares Jul 10, 2024
31817f1
Merge branch 'master' into mv/docs/reintroduce-docs
mvares Jul 10, 2024
c1097ad
fix
mvares Jul 10, 2024
1b3b98f
Merge branch 'master' into mv/docs/reintroduce-docs
mvares Jul 10, 2024
d152ca4
Merge branch 'master' into mv/docs/reintroduce-docs
mvares Jul 10, 2024
103a11f
Merge branch 'master' into mv/docs/reintroduce-docs
mvares Jul 11, 2024
610c053
refactoring
mvares Jul 11, 2024
a994911
more refactors
mvares Jul 11, 2024
1878287
improving comments
mvares Jul 11, 2024
f5b97d1
Merge branch 'master' into mv/docs/reintroduce-docs
mvares Jul 11, 2024
06b4d3e
Merge branch 'master' into mv/docs/reintroduce-docs
mvares Jul 11, 2024
4b34fa7
Merge branch 'master' into mv/docs/reintroduce-docs
mvares Jul 12, 2024
55b38f3
Merge branch 'master' into mv/docs/reintroduce-docs
mvares Jul 15, 2024
9ed094b
Merge branch 'master' into mv/docs/reintroduce-docs
mvares Jul 15, 2024
270b272
change the way that launches nodes
mvares Jul 15, 2024
360f321
Merge branch 'master' into mv/docs/reintroduce-docs
mvares Jul 16, 2024
35642be
Merge remote-tracking branch 'origin' into mv/docs/reintroduce-docs
mvares Jul 16, 2024
c7c23f0
Merge branch 'master' into mv/docs/reintroduce-docs
mvares Jul 17, 2024
350d70e
Merge branch 'master' into mv/docs/reintroduce-docs
mvares Jul 18, 2024
3ad3c17
Merge branch 'master' into mv/docs/reintroduce-docs
mvares Jul 18, 2024
01e1653
Merge branch 'master' into mv/docs/reintroduce-docs
danielbate Jul 19, 2024
ad70be7
Merge branch 'master' into mv/docs/reintroduce-docs
mvares Jul 19, 2024
61d0a80
Merge branch 'master' into mv/docs/reintroduce-docs
mvares Jul 19, 2024
c150fb1
Merge branch 'master' into mv/docs/reintroduce-docs
danielbate Jul 22, 2024
23d7c5a
Merge branch 'master' into mv/docs/reintroduce-docs
petertonysmith94 Jul 22, 2024
a219e16
fix name of topics
mvares Jul 22, 2024
b692cbe
add marking
mvares Jul 22, 2024
4f53a7e
Merge branch 'master' into mv/docs/reintroduce-docs
mvares Jul 22, 2024
ce5a378
Merge branch 'master' into mv/docs/reintroduce-docs
maschad Jul 22, 2024
3f1a09e
Merge branch 'master' into mv/docs/reintroduce-docs
petertonysmith94 Jul 23, 2024
9e9a20a
Merge branch 'master' into mv/docs/reintroduce-docs
petertonysmith94 Jul 23, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .changeset/three-moles-drop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
---

docs: re-introduce a section from provider docs
119 changes: 117 additions & 2 deletions apps/docs-snippets/src/guide/provider/querying-the-chain.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import type { CoinQuantityLike, ExcludeResourcesOption } from 'fuels';
import type {
TransactionResultMessageOutReceipt,
CoinQuantityLike,
ExcludeResourcesOption,
} from 'fuels';
import { FUEL_NETWORK_URL, Provider, ScriptTransactionRequest } from 'fuels';
import { generateTestWallet } from 'fuels/test-utils';
import { TestMessage, generateTestWallet, launchTestNode } from 'fuels/test-utils';

/**
* @group node
Expand Down Expand Up @@ -142,4 +146,115 @@ describe('querying the chain', () => {
expect(message).toBeDefined();
expect(message?.nonce).toEqual(nonce);
});

it('can getMessage', async () => {
// #region Message-getMessages
// #import { TestMessage, launchTestNode };

// Creates a test message with an amount of 100
const testMessage = new TestMessage({ amount: 100 });

// Launches a test node with the test message configured
using launched = await launchTestNode({ walletsConfig: { messages: [testMessage] } });
const {
wallets: [wallet],
} = launched;

// Retrieves messages from the wallet
const { messages } = await wallet.getMessages();
// #endregion Message-getMessages

expect(messages[0].nonce).toEqual(testMessage.nonce);
});

it('can getMessageProof with blockId', async () => {
// #region Message-getMessageProof-blockId
// #import { launchTestNode, TransactionResultMessageOutReceipt };

// Launches a test node
using launched = await launchTestNode({
nodeOptions: {
args: ['--poa-instant', 'false', '--poa-interval-period', '1s'],
},
});

const {
mvares marked this conversation as resolved.
Show resolved Hide resolved
wallets: [sender, recipient],
provider,
} = launched;

// Performs a withdrawal transaction from sender to recipient, thus generating a message
const withdrawTx = await sender.withdrawToBaseLayer(recipient.address.toB256(), 100);
const result = await withdrawTx.waitForResult();

// Waiting for a new block to be commited (1 confirmation block)
await new Promise((resolve) => {
setTimeout(() => {
resolve(true);
}, 1000);
});

// Retrives the latest block
const latestBlock = await provider.getBlock('latest');

// Retrieves the `nonce` via message out receipt from the initial transaction result
const { nonce } = result.receipts[0] as TransactionResultMessageOutReceipt;

// Retrieves the message proof for the transaction ID and nonce using the next block Id
const messageProof = await provider.getMessageProof(
result.gqlTransaction.id,
nonce,
latestBlock?.id
);
// #endregion Message-getMessageProof-blockId

expect(messageProof?.amount.toNumber()).toEqual(100);
expect(messageProof?.sender.toHexString()).toEqual(result.id);
});

it('can getMessageProof with blockHeight', async () => {
// #region Message-getMessageProof-blockHeight
// #import { launchTestNode, TransactionResultMessageOutReceipt };

// Launches a test node
using launched = await launchTestNode({
nodeOptions: {
args: ['--poa-instant', 'false', '--poa-interval-period', '1s'],
},
});

const {
wallets: [sender, recipient],
provider,
} = launched;

// Performs a withdrawal transaction from sender to recipient, thus generating a message
const withdrawTx = await sender.withdrawToBaseLayer(recipient.address.toB256(), 100);
const result = await withdrawTx.waitForResult();

// Waiting for a new block to be commited (1 confirmation block)
await new Promise((resolve) => {
setTimeout(() => {
resolve(true);
}, 1000);
});

// Retrieves the `nonce` via message out receipt from the initial transaction result
const { nonce } = result.receipts[0] as TransactionResultMessageOutReceipt;

// Retrives the latest block
const latestBlock = await provider.getBlock('latest');

// Retrieves the message proof for the transaction ID and nonce using the block height
const messageProof = await provider.getMessageProof(
result.gqlTransaction.id,
nonce,
undefined,
latestBlock?.height
);
// #endregion Message-getMessageProof-blockHeight

expect(messageProof?.amount.toNumber()).toEqual(100);
expect(messageProof?.sender.toHexString()).toEqual(result.id);
});
});
19 changes: 7 additions & 12 deletions apps/docs/src/guide/provider/querying-the-chain.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,25 +57,20 @@ You can use the `getMessageByNonce` method to retrieve a message by its nonce.

<<< @/../../docs-snippets/src/guide/provider/querying-the-chain.test.ts#get-message-by-nonce-1{ts:line-numbers}

<!-- TODO: fix these examples to not reference hardcoded values after #1356 which introduces message generation tools
### Get messages
## `getMessages`

You can use the `getMessages` method to retrieve a list of messages from the blockchain.

<<< @/../../docs-snippets/src/guide/provider/querying-the-chain.test.ts#Message-getMessages{ts:line-numbers}

## Get resources

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

<<< @/../../docs-snippets/src/guide/provider/querying-the-chain.test.ts#Message-getResourcesToSpend{ts:line-numbers}

## Get message proof
## `getMessageProof`

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.

<<< @/../../docs-snippets/src/guide/provider/querying-the-chain.test.ts#Message-getMessageProof{ts:line-numbers}
You can retrieve a message proof by either using it's block ID:

<<< @/../../docs-snippets/src/guide/provider/querying-the-chain.test.ts#Message-getMessageProof-blockId{ts:line-numbers}

--->
Or by it's block height:

<!-- TODO: Add docs for the two new parameters `commitBlockId` and `commitBlockHeight` -->
<<< @/../../docs-snippets/src/guide/provider/querying-the-chain.test.ts#Message-getMessageProof-blockHeight{ts:line-numbers}
Loading