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 17, 2024
1 parent c5166de commit 4d8dc0d
Show file tree
Hide file tree
Showing 19 changed files with 657 additions and 51 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
42 changes: 41 additions & 1 deletion ecosystem/indexer-grpc/indexer-transaction-generator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,19 @@ This tool is to generate transactions for testing purpose.

## Usage

`cargo run -- --config example.yaml --output-folder /your_path_to_store_transactions/`
Under root folder, i.e., `aptos-core`, run

```
cargo run -p aptos-indexer-transaction-generator -- \
--config ecosystem/indexer-grpc/indexer-transaction-generator/template_config.yaml \
--output-folder /tmp/ --move-folder-path \
ecosystem/indexer-grpc/indexer-transaction-generator/example_scripts
```

### Config

```YAML
# Config to import transactions onchain.
import_config:
testnet:
# Transaction Stream endpoint addresss.
Expand All @@ -18,4 +26,36 @@ import_config:
# A map from versions to dump and their output names.
versions_to_import:
123: testnet_v1.json
# Config to generate the transactions via localnode.
script_transaction_generator_config:
runs:
- transactions:
- output_name: transfer_from_a_to_b
script_path: path/to/script1
fund_address: address_a
- output_name: transfer_from_b_to_c
script_path: path/to/script2
- transactions:
# Note: we've generated transactions for script1, we don't need the name anymore.
- script_path: path/to/script1
fund_address: address_a
- output_name: burn
script_path: path/to/script3


```

### Recommended file structure
```
your_testing_folder/
├─ config.yaml
├─ move_files/
│ ├─ your_first_move_script/
│ │ ├─ .aptos/
│ │ ├─ Move.toml
│ │ ├─ sources/
│ │ │ ├─ main.move
│ ├─ your_second_move_script/
...
```
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This folder hosts all the example move scripts.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
transactions:
- output_name: simple_user_script
script_path: ecosystem/indexer-grpc/indexer-transaction-generator/example_scripts/simple_user_script
fund_address: a531b7fdd7917f73ca216d89a8d9ce0cf7e7cfb9086ca6f6cbf9521532748d16
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[package]
name = "test_case"
version = "1.0.0"
authors = []

[addresses]

[dev-addresses]

[dependencies.AptosFramework]
git = "https://github.com/aptos-labs/aptos-core.git"
rev = "mainnet"
subdir = "aptos-move/framework/aptos-framework"

[dev-dependencies]
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
script {
fun main(src: &signer) {
}
}
Loading

0 comments on commit 4d8dc0d

Please sign in to comment.