Skip to content

Commit

Permalink
[rooch-networkgh-2471] add tx build command.
Browse files Browse the repository at this point in the history
  • Loading branch information
Feliciss committed Aug 21, 2024
1 parent e13f6d3 commit 8370c5f
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 2 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions crates/rooch-rpc-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ serde = { workspace = true }
jsonrpsee = { workspace = true }
serde_json = { workspace = true }
log = { workspace = true }
hex = { workspace = true }

move-core-types = { workspace = true }

Expand Down
5 changes: 4 additions & 1 deletion crates/rooch-rpc-client/src/rooch_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
// SPDX-License-Identifier: Apache-2.0

use anyhow::{Ok, Result};
use hex::ToHex;
use jsonrpsee::http_client::HttpClient;
use moveos_types::h256::H256;
use moveos_types::moveos_std::account::Account;
use moveos_types::transaction::MoveAction;
use moveos_types::{access_path::AccessPath, state::ObjectState, transaction::FunctionCall};
use rooch_rpc_api::api::rooch_api::RoochAPIClient;
use rooch_rpc_api::jsonrpc_types::{
Expand All @@ -13,7 +15,8 @@ use rooch_rpc_api::jsonrpc_types::{
};
use rooch_rpc_api::jsonrpc_types::{
AccessPathView, AnnotatedFunctionResultView, BalanceInfoPageView, EventOptions, EventPageView,
FieldKeyView, ObjectIDView, RoochAddressView, StateOptions, StatePageView, StructTagView,
FieldKeyView, ObjectIDView, RoochAddressView, StateOptions, StatePageView, StrView,
StructTagView,
};
use rooch_rpc_api::jsonrpc_types::{ExecuteTransactionResponseView, ObjectStateView};
use rooch_rpc_api::jsonrpc_types::{
Expand Down
59 changes: 59 additions & 0 deletions crates/rooch/src/commands/transaction/commands/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// Copyright (c) RoochNetwork
// SPDX-License-Identifier: Apache-2.0

use crate::cli_types::{CommandAction, TransactionOptions, WalletContextOptions};
use async_trait::async_trait;
use move_core_types::{identifier::Identifier, language_storage::ModuleId};
use moveos_types::{move_types::FunctionId, transaction::MoveAction};
use rooch_framework::MOVEOS_STD_ADDRESS;
use rooch_rpc_api::jsonrpc_types::TransactionWithInfoPageView;
use rooch_rpc_client::wallet_context;
use rooch_types::{error::RoochResult, transaction::RoochTransactionData};

/// Get transactions by order
#[derive(Debug, clap::Parser)]
pub struct BuildCommand {
/// Transaction's hash
#[clap(long)]
pub cursor: Option<u64>,

#[clap(long)]
pub limit: Option<u64>,

/// descending order
#[clap(short = 'd', long)]
descending_order: Option<bool>,

#[clap(flatten)]
tx_options: TransactionOptions,

#[clap(flatten)]
context: WalletContextOptions,
}

#[async_trait]
impl CommandAction<RoochTransactionData> for BuildCommand {
async fn execute(self) -> RoochResult<RoochTransactionData> {
let context = self.context.build()?;
let sender = context.resolve_address(self.tx_options.sender)?.into();
let max_gas_amount = self.tx_options.max_gas_amount;

// TODO: actions for building a tx data
let mut bundles: Vec<Vec<u8>> = vec![];
let args = bcs::to_bytes(&bundles).unwrap();
let action = MoveAction::new_function_call(
FunctionId::new(
ModuleId::new(
MOVEOS_STD_ADDRESS,
Identifier::new("module_store".to_owned()).unwrap(),
),
Identifier::new("publish_modules_entry".to_owned()).unwrap(),
),
vec![],
vec![args],
);

let tx_data = context.build_tx_data(sender, action, max_gas_amount);
Ok(tx_data)
}
}
1 change: 1 addition & 0 deletions crates/rooch/src/commands/transaction/commands/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright (c) RoochNetwork
// SPDX-License-Identifier: Apache-2.0

pub mod build;
pub mod get_transactions_by_hash;
pub mod get_transactions_by_order;
4 changes: 3 additions & 1 deletion crates/rooch/src/commands/transaction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

use crate::cli_types::CommandAction;
use crate::commands::transaction::commands::{
get_transactions_by_hash::GetTransactionsByHashCommand,
build::BuildCommand, get_transactions_by_hash::GetTransactionsByHashCommand,
get_transactions_by_order::GetTransactionsByOrderCommand,
};
use async_trait::async_trait;
Expand All @@ -25,12 +25,14 @@ impl CommandAction<String> for Transaction {
match self.cmd {
TransactionCommand::GetTransactionsByOrder(cmd) => cmd.execute_serialized().await,
TransactionCommand::GetTransactionsByHash(cmd) => cmd.execute_serialized().await,
TransactionCommand::Build(cmd) => cmd.execute_serialized().await,
}
}
}

#[derive(Subcommand)]
pub enum TransactionCommand {
Build(BuildCommand),
GetTransactionsByOrder(GetTransactionsByOrderCommand),
GetTransactionsByHash(GetTransactionsByHashCommand),
}

0 comments on commit 8370c5f

Please sign in to comment.