Skip to content

Commit

Permalink
script transaction
Browse files Browse the repository at this point in the history
  • Loading branch information
larry-aptos committed Sep 11, 2024
1 parent 8cf0704 commit ed6a282
Show file tree
Hide file tree
Showing 11 changed files with 444 additions and 27 deletions.
5 changes: 5 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions crates/aptos/src/common/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1501,12 +1501,12 @@ pub struct ChangeSummary {
pub struct FaucetOptions {
/// URL for the faucet endpoint e.g. `https://faucet.devnet.aptoslabs.com`
#[clap(long)]
pub faucet_url: Option<reqwest::Url>,
faucet_url: Option<reqwest::Url>,

/// Auth token to bypass faucet ratelimits. You can also set this as an environment
/// variable with FAUCET_AUTH_TOKEN.
#[clap(long, env)]
pub faucet_auth_token: Option<String>,
faucet_auth_token: Option<String>,
}

impl FaucetOptions {
Expand Down Expand Up @@ -1623,7 +1623,7 @@ pub struct TransactionOptions {
#[clap(flatten)]
pub(crate) gas_options: GasOptions,
#[clap(flatten)]
pub(crate) prompt_options: PromptOptions,
pub prompt_options: PromptOptions,

/// If this option is set, simulate the transaction locally.
#[clap(long)]
Expand Down Expand Up @@ -2037,7 +2037,7 @@ pub struct MultisigAccountWithSequenceNumber {
pub(crate) sequence_number: u64,
}

#[derive(Debug, Parser)]
#[derive(Debug, Default, Parser)]
pub struct TypeArgVec {
/// TypeTag arguments separated by spaces.
///
Expand Down Expand Up @@ -2076,7 +2076,7 @@ impl TryInto<Vec<TypeTag>> for TypeArgVec {
}
}

#[derive(Clone, Debug, Parser)]
#[derive(Clone, Debug, Default, Parser)]
pub struct ArgWithTypeVec {
/// Arguments combined with their type separated by spaces.
///
Expand Down Expand Up @@ -2242,7 +2242,7 @@ impl TryInto<ViewRequest> for EntryFunctionArguments {
}

/// Common options for constructing a script payload
#[derive(Debug, Parser)]
#[derive(Debug, Default, Parser)]
pub struct ScriptFunctionArguments {
#[clap(flatten)]
pub(crate) type_arg_vec: TypeArgVec,
Expand Down
4 changes: 2 additions & 2 deletions crates/aptos/src/governance/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -905,10 +905,10 @@ pub struct CompileScriptFunction {
pub compiled_script_path: Option<PathBuf>,

#[clap(flatten)]
pub(crate) framework_package_args: FrameworkPackageArgs,
pub framework_package_args: FrameworkPackageArgs,

#[clap(long, default_value_if("move_2", "true", "7"))]
pub(crate) bytecode_version: Option<u32>,
pub bytecode_version: Option<u32>,

#[clap(long, value_parser = clap::value_parser!(CompilerVersion),
default_value_if("move_2", "true", "2.0"))]
Expand Down
16 changes: 8 additions & 8 deletions crates/aptos/src/move_tool/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ impl MoveTool {
}
}

#[derive(Parser, Default)]
#[derive(Default, Parser)]
pub struct FrameworkPackageArgs {
/// Git revision or branch for the Aptos framework
///
Expand Down Expand Up @@ -379,12 +379,12 @@ pub struct CompilePackage {
/// If set, package metadata should be generated and stored in the package's build directory.
/// This metadata can be used to construct a transaction to publish a package.
#[clap(long)]
pub(crate) save_metadata: bool,
pub save_metadata: bool,

#[clap(flatten)]
pub(crate) included_artifacts_args: IncludedArtifactsArgs,
pub included_artifacts_args: IncludedArtifactsArgs,
#[clap(flatten)]
pub(crate) move_options: MovePackageDir,
pub move_options: MovePackageDir,
}

#[async_trait]
Expand Down Expand Up @@ -726,7 +726,7 @@ pub struct IncludedArtifactsArgs {
/// is the size of bytecode alone; `sparse` is roughly 2 times as much; and `all` 3-4
/// as much.
#[clap(long, default_value_t = IncludedArtifacts::Sparse)]
pub(crate) included_artifacts: IncludedArtifacts,
pub included_artifacts: IncludedArtifacts,
}

/// Publishes the modules in a Move package to the Aptos blockchain
Expand Down Expand Up @@ -2056,11 +2056,11 @@ impl CliCommand<Vec<serde_json::Value>> for ViewFunction {
#[derive(Parser)]
pub struct RunScript {
#[clap(flatten)]
pub(crate) txn_options: TransactionOptions,
pub txn_options: TransactionOptions,
#[clap(flatten)]
pub(crate) compile_proposal_args: CompileScriptFunction,
pub compile_proposal_args: CompileScriptFunction,
#[clap(flatten)]
pub(crate) script_function_args: ScriptFunctionArguments,
pub script_function_args: ScriptFunctionArguments,
}

#[async_trait]
Expand Down
4 changes: 2 additions & 2 deletions crates/aptos/src/node/local_testnet/faucet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ pub struct FaucetArgs {

#[derive(Clone, Debug)]
pub struct FaucetManager {
config: RunConfig,
prerequisite_health_checkers: HashSet<HealthChecker>,
pub config: RunConfig,
pub prerequisite_health_checkers: HashSet<HealthChecker>,
}

impl FaucetManager {
Expand Down
2 changes: 1 addition & 1 deletion crates/aptos/src/node/local_testnet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// SPDX-License-Identifier: Apache-2.0

mod docker;
mod health_checker;
mod indexer_api;
mod logging;
mod postgres;
Expand All @@ -12,6 +11,7 @@ mod utils;

// This is to allow external crates to use the localnode.
pub mod faucet;
pub mod health_checker;
pub mod node;
pub mod traits;

Expand Down
10 changes: 5 additions & 5 deletions ecosystem/indexer-grpc/indexer-transaction-generator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@ rust-version = { workspace = true }
[dependencies]
anyhow = { workspace = true }
# used for localnode.
# aptos = { workspace = true }
# aptos-config = { workspace = true }
aptos = { workspace = true }
aptos-config = { workspace = true }
aptos-faucet-core = { workspace = true }
aptos-indexer-grpc-utils = { workspace = true }
aptos-protos ={ workspace = true }
clap = { workspace = true }
futures = { workspace = true }
# rand = { workspace = true }
# regex = { workspace = true }
rand = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
serde_yaml = { workspace = true }
tokio = { workspace = true }
# toml = { workspace = true }
toml = { workspace = true }
tonic = { workspace = true }
url = { workspace = true }

Expand Down
55 changes: 52 additions & 3 deletions ecosystem/indexer-grpc/indexer-transaction-generator/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use std::{
use url::Url;

const IMPORTED_TRANSACTIONS_FOLDER: &str = "imported_transactions";
const SCRIPTED_TRANSACTIONS_FOLDER: &str = "scripted_transactions";

#[derive(Parser)]
pub struct IndexerCliArgs {
Expand Down Expand Up @@ -42,7 +43,10 @@ impl IndexerCliArgs {
/// Overall configuration for the transaction generator.
#[derive(Debug, Serialize, Deserialize)]
pub struct TransactionGeneratorConfig {
pub import_config: TransactionImporterConfig, // TODO: Add scripted transaction generation configuration.
// Configuration for importing transactions from multiple networks.
pub import_config: TransactionImporterConfig,
// Configuration for generating transactions from scripts.
pub script_transaction_generator_config: ScriptTransactionGeneratorConfig,
}

impl TransactionGeneratorConfig {
Expand All @@ -52,7 +56,20 @@ impl TransactionGeneratorConfig {
if !import_config_path.exists() {
tokio::fs::create_dir_all(&import_config_path).await?;
}
self.import_config.run(&import_config_path).await
self.import_config
.run(&import_config_path)
.await
.context("Importing transactions failed.")?;

let script_config_path = output_path.join(SCRIPTED_TRANSACTIONS_FOLDER);
// Check if the output folder exists.
if !script_config_path.exists() {
tokio::fs::create_dir_all(&script_config_path).await?;
}
self.script_transaction_generator_config
.run(&script_config_path)
.await
.context("Generating transactions from scripts failed.")
}
}

Expand All @@ -66,7 +83,7 @@ pub struct TransactionImporterConfig {
}

impl TransactionImporterConfig {
pub async fn run(&self, output_path: &Path) -> anyhow::Result<()> {
fn validate(&self) -> anyhow::Result<()> {
// Validate the configuration. This is to make sure that no output file shares the same name.
let mut output_files = HashSet::new();
for network_config in [
Expand All @@ -87,6 +104,13 @@ impl TransactionImporterConfig {
}
}
}
Ok(())
}

pub async fn run(&self, output_path: &Path) -> anyhow::Result<()> {
// Validate the configuration.
self.validate()?;

// Run the transaction importer for each network.
for network_config in [
self.mainnet_config.as_ref(),
Expand Down Expand Up @@ -115,6 +139,28 @@ pub struct TransactionImporterPerNetworkConfig {
pub versions_to_import: HashMap<u64, String>,
}

/// Configuration for generating transactions from scripts.
#[derive(Debug, Serialize, Deserialize)]
pub struct ScriptTransactionGeneratorConfig {
/// List of scripts to run to generate transactions.
pub scripted_transactions: Vec<ScriptTransactions>,
}

/// Configuration for generating transactions from a script.
/// `ScriptTransactions` will generate a list of transactions and output if specified.
/// A managed-node will be used to execute the scripts in sequence.
#[derive(Debug, Serialize, Deserialize)]
pub struct ScriptTransactions {
pub steps: Vec<ScriptStep>,
}

/// A step that can optionally output one transaction.
#[derive(Debug, Serialize, Deserialize)]
pub struct ScriptStep {
pub script_path: PathBuf,
pub output_name: Option<String>,
}

#[cfg(test)]
mod tests {
use super::*;
Expand All @@ -138,6 +184,9 @@ mod tests {
1: "mainnet_v1.json"
}
}
},
"script_transaction_generator_config": {
"scripted_transactions": []
}
}
"#;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@
// SPDX-License-Identifier: Apache-2.0

pub mod config;
pub mod managed_node;
pub mod script_transaction_generator;
pub mod transaction_importer;
Loading

0 comments on commit ed6a282

Please sign in to comment.