Syntax
Runbooks contain a series of code blocks that look something like this:variable, action, and
output), a reference name ("query_path", "http_query", and
"status_code"), and the inner data of the block (everything between the
{ ... }). Some command types also require that a command is specified
("std::send_http_request"). The inner data of the block is dictated by the
command type and command that are specified.
Command References
One command can reference the outputs of another command to build a chain of dependent commands. When you execute a Runbook, Surfpool creates a graph of all the commands to ensure they are always executed in the correct order. This does mean that dependency cycles need to be avoided when creating a Runbook. Another command’s output can be referenced in a block usingcommand_type.ref_name.output_name. Here are some examples:
Functions
The standard library provides some functions that can be written in-line, as opposed to writing full command blocks with named arguments. These functions can be extended via addons. These functions can look like explicit function calls (e.g.add(1, 3)),
or they can look like in-line arithmetic operations (e.g. 1 + 3). Functions
can reference other command outputs, or they can be stored in new command
outputs. Here’s an example using a few functions:
Manifest & CLI Inputs
Inputs can be provided to the Runbook by passing them in as a CLI input, or by specifying them in atxtx.yml manifest file. If the same input is provided
both in the CLI and in a manifest, the CLI input will take precedence. To see
information on how to use the CLI, check out the
CLI documentation. In the manifest, these
inputs can be grouped by an environment key, making it easy to use the same
Runbook across multiple environments.
Here is an example config with environment variables:
.tx files loaded by this runbook, the inputs input.network_id
and input.rpc_api_url will be available in the global scope. When the Web UI
loads this runbook, the first action item will allow you to select which
environment to load. Selecting a new environment will reload the current runbook
with the new environment variables being injected into the execution.
State Management
Surfpool can manage state across Runbook executions. When running contract deployments, the state management can be used to detect any changes to the contract code and Runbook inputs to determine if the Runbook needs to be re-executed. Surfpool will prevent a re-execution of a Runbook if there aren’t any changes to the contract code or Runbook inputs. To enable state management, provide thestate value and a location to store
the state file in the txtx.yml:
Variables
Variables can be used to store values that can be used by other constructs and that can be edited by users in the Web UI. If the variables’seditable field
is unspecified or set to false, the variable will appear on the Web UI in the
Variables Review section as a readonly value that can be verified. If the
editable field is set to true, however, the variable will appear as an
editable field in the Web UI. The optional description field can be provided
to add additional context to the variable. Here is an example variable:
Addons & Defaults
Addon blocks allow you to specify what addons will be used by the Runbook. Any fields declared inside the addon block can be referenced by any actions that are part of that addon. This will allow you to omit fields when using custom actions from that addon. The following example declares thesvm addon and sets the
network_id and rpc_api_url fields as defaults:
.tx file, any actions from the SVM addon can omit
both the network_id and rpc_api_url fields.
Flows
Flows allow you to execute a Runbook multiple times with different inputs for each execution. Any fields specified in the flow block can be referenced by any actions that are part of that flow viaflow.field_name. This can be used in
conjunction with the addon block in helpful ways:
Signers
Addons can define signers that provide various ways to sign transactions when using surfpool. These signers can be used to sign transactions via a mnemonic or secret key, to prompt users to connect their web wallet and sign in the Surfpool Web UI, to sign transactions asynchronously via secure enclave, to define multisig wallets, and more. Each addon signer implementation will have its own use cases and documentation. Here is an example of a signer in use:alice, which uses the svm::web_wallet
signer. This signer definition will generate a prompt in the Web UI to connect a
wallet, provide a public key via message signature, and to sign all transactions
using this wallet as a signer.