Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a
forc-tx
plugin purely for constructing TXs from CLI (FuelLabs…
…#3582) This crate allows for constructing arbitrary transactions from the command line. The constructed `forc_tx::Transaction` can be converted to a `fuel_tx::Transaction` using the `TryFrom` implementation. The key difference between the `forc_tx::Transaction` type differs in that it accepts *paths* for fields like `bytecode`, `storage_slots`, `predicate_data`, etc. These are loaded during the `fuel_tx::Transaction`'s `try_from` constructor. Addresses FuelLabs#3491. Verbose Example --------------- The following isn't a valid transaction, but shows what it looks like to specify arguments including multiple inputs and outputs. ```console forc tx create \ --bytecode ./my-contract/out/debug/my-contract.bin \ --storage-slots ./my-contract/out/debug/my-contract-storage_slots.json \ --gas-limit 100 \ --gas-price 0 \ --maturity 0 \ --witness ADFD \ --witness DFDA \ input coin \ --utxo-id 0 \ --output-ix 0 \ --owner 0x0000000000000000000000000000000000000000000000000000000000000000 \ --amount 100 \ --asset-id 0x0000000000000000000000000000000000000000000000000000000000000000 \ --tx-ptr 89ACBDEFBDEF \ --witness-ix 0 \ --maturity 0 \ --predicate ./my-predicate/out/debug/my-predicate.bin \ --predicate-data ./my-predicate.dat \ input contract \ --utxo-id 1 \ --output-ix 1 \ --balance-root 0x0000000000000000000000000000000000000000000000000000000000000000 \ --state-root 0x0000000000000000000000000000000000000000000000000000000000000000 \ --tx-ptr 89ACBDEFBDEF \ --contract-id 0xCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC \ input message \ --msg-id 0xBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB \ --sender 0x1111111111111111111111111111111111111111111111111111111111111111 \ --recipient 0x2222222222222222222222222222222222222222222222222222222222222222 \ --amount 1 \ --nonce 1234 \ --witness-ix 1 \ --msg-data ./message.dat \ --predicate ./my-predicate2/out/debug/my-predicate2.bin \ --predicate-data ./my-predicate2.dat \ output coin \ --to 0x2222222222222222222222222222222222222222222222222222222222222222 \ --amount 100 \ --asset-id 0x0000000000000000000000000000000000000000000000000000000000000000 \ output contract \ --input-ix 1 \ --balance-root 0x0000000000000000000000000000000000000000000000000000000000000000 \ --state-root 0x0000000000000000000000000000000000000000000000000000000000000000 \ output message \ --recipient 0x2222222222222222222222222222222222222222222222222222222222222222 \ --amount 100 \ output change \ --to 0x2222222222222222222222222222222222222222222222222222222222222222 \ --amount 100 \ --asset-id 0x0000000000000000000000000000000000000000000000000000000000000000 \ output variable \ --to 0x2222222222222222222222222222222222222222222222222222222222222222 \ --amount 100 \ --asset-id 0x0000000000000000000000000000000000000000000000000000000000000000 \ output contract-created \ --contract-id 0xCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC \ --state-root 0x0000000000000000000000000000000000000000000000000000000000000000 ``` The output of this command dumps the entire `fuel_tx::Transaction` serialized to JSON to stdout. A `-o tx.json` argument can be provided (before the transaction type) to write the tx to a file instead. Follow-up --------- - Currently, the CLI is a bit unwieldy due to requiring a custom `try_parse` constructor which is required to parse multiple trailing input/output subcommands. This is necessary because clap doesn't appear to allow multiple trailing subcommands by default. We should see if it's possible to manually implement clap's Subcommand for some custom type in a manner that allows us the same behaviour but without breaking clap's generated CLI. - Possibly add forc-aware defaults, i.e. infer unambiguous defaults for bytecode, storage slots, etc from the project within the current or parent directory. - Base `forc-run`, `forc-deploy` transaction construction on components from `forc-tx`. - Add CI tests for `forc tx` command that actually constructs and submits a transaction to a node. This might be a lot easier to write once we have something like a `forc submit` command that allows submitting a transaction from the command line. Co-authored-by: Joshua Batty <[email protected]>
- Loading branch information