-
Notifications
You must be signed in to change notification settings - Fork 1.4k
feat!: add support for assemble tx #1634
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
base: master
Are you sure you want to change the base?
Changes from all commits
5a8cba6
723eb55
93eaebe
648d5ff
658a928
b3d1c7f
2069cdb
d179a2a
b5bdbc6
dba5782
342dd59
b6c4be2
8a82538
72b010d
4c16920
3a1d523
ca880ac
d971704
c6bd94e
494ac3a
6b0cc1c
2478f48
f0e32f6
aa289f0
575af13
f45e499
30ab40a
b2bc3ea
43a8079
c30fb8a
81b557e
8d4af88
dc841ea
6e2d9e0
b85f8e2
0d52722
cd6c12b
ed99330
e2096da
c364488
26d45d4
d1a83ec
56f379f
08e8ee8
d5c0aac
323da72
8186383
95a80d2
5cdc2f4
cbcfad9
7cccd9b
18caac7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,13 @@ | ||
# Calling other contracts | ||
|
||
If your contract method is calling other contracts you will have to add the appropriate `Inputs` and `Outputs` to your transaction. For your convenience, the `CallHandler` provides methods that prepare those inputs and outputs for you. You have two methods that you can use: `with_contracts(&[&contract_instance, ...])` and `with_contract_ids(&[&contract_id, ...])`. | ||
|
||
`with_contracts(&[&contract_instance, ...])` requires contract instances that were created using the `abigen` macro. When setting the external contracts with this method, logs and require revert errors originating from the external contract can be propagated and decoded by the calling contract. | ||
If your contract method is calling other contracts you will have to add the appropriate `Inputs` and `Outputs` to your transaction. For your convenience, the `CallHandler` will fill in all missing `Inputs`/`Outputs` before sending the transaction. | ||
|
||
```rust,ignore | ||
{{#include ../../../e2e/tests/contracts.rs:external_contract}} | ||
``` | ||
|
||
If however, you do not need to decode logs or you do not have a contract instance that was generated using the `abigen` macro you can use `with_contract_ids(&[&contract_id, ...])` and provide the required contract ids. | ||
If you need to decode logs and require revert errors originating from the external contract you will need to pass the `LogDecoder` from the external contract to the contract instance making the call. | ||
|
||
```rust,ignore | ||
{{#include ../../../e2e/tests/contracts.rs:external_contract_ids}} | ||
{{#include ../../../e2e/tests/contracts.rs:external_contract_logs}} | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,9 @@ | ||
# Transaction dependency estimation | ||
|
||
Previously, we mentioned that a contract call might require you to manually specify external contracts, variable outputs, or output messages. The SDK can also attempt to estimate and set these dependencies for you at the cost of running multiple simulated calls in the background. | ||
Previously, we mentioned that a contract call might require you to manually specify external contracts, variable outputs, or output messages. The SDK will estimate and set these dependencies for you. | ||
|
||
The following example uses a contract call that calls an external contract and later mints assets to a specified address. Calling it without including the dependencies will result in a revert: | ||
|
||
```rust,ignore | ||
{{#include ../../../examples/contracts/src/lib.rs:dependency_estimation_fail}} | ||
``` | ||
|
||
As mentioned in previous chapters, you can specify the external contract and add an output variable to resolve this: | ||
|
||
```rust,ignore | ||
{{#include ../../../examples/contracts/src/lib.rs:dependency_estimation_manual}} | ||
``` | ||
|
||
But this requires you to know the contract ID of the external contract and the needed number of output variables. Alternatively, by chaining | ||
|
||
- `.with_variable_output_policy(VariableOutputPolicy::EstimateMinimum)` and | ||
- `.determine_missing_contracts()` | ||
|
||
the dependencies will be estimated by the SDK and set automatically. | ||
The following example uses a contract call that calls an external contract and later mints assets to a specified address. | ||
|
||
```rust,ignore | ||
{{#include ../../../examples/contracts/src/lib.rs:dependency_estimation}} | ||
``` | ||
|
||
> **Note:** Both `with_variable_output_policy` and `determine_missing_contracts` can also be used when working with script calls or multi calls. `determine_missing_contracts()` will not enable logging from an external contract. For more information, see [here](./other-contracts.md). |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# Assemble Transactions | ||
|
||
Assemble transactions makes it possible to create a minimal `TransactionBuilder` and let the fuel node fill in the missing details. The node will add missing inputs, outputs, set transactions limits etc. Below is an example how the assemble strategy can be used to create a transfer. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Along the lines of previous question, when is the tx signed? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see in the snippet code: tb.add_signer(wallet.signer().clone())?; I assume this happens on the client side. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The transaction is signed at the end after receiving the assembled tx. This happens in the |
||
|
||
Let's first launch a local node with a funded wallet and create a random wallet that will receive some base asset. | ||
|
||
```rust,ignore | ||
{{#include ../../../e2e/tests/providers.rs:assemble_wallets}} | ||
``` | ||
|
||
Next, we create an base asset output to the receiver wallet. | ||
|
||
```rust,ignore | ||
{{#include ../../../e2e/tests/providers.rs:assemble_output}} | ||
``` | ||
|
||
Now we tell the node what kind of inputs do we require. Note that we do not specify any inputs just the amount, asset id and which require balance should be used to pay for the fees. | ||
|
||
```rust,ignore | ||
{{#include ../../../e2e/tests/providers.rs:assemble_req_balance}} | ||
``` | ||
|
||
We can now build the transaction using the assemble strategy. | ||
|
||
```rust,ignore | ||
{{#include ../../../e2e/tests/providers.rs:assemble_tb}} | ||
``` | ||
|
||
> **Note** The assemble strategy will make sure that we have enough base asset coins in the inputs to cover the transfer and the fee. Also a change output is added to the transaction. | ||
At the end, we send the transaction and make sure that the receiver balance matches the sent amount. | ||
|
||
```rust,ignore | ||
{{#include ../../../e2e/tests/providers.rs:assemble_response}} | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not super familiar with the bounds of this "fill in all missing
Inputs
/Outputs
". How much of this is communicated back to the sender before they click "send"?