Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide indexer store base on SQLite #1088

Merged
merged 8 commits into from
Nov 1, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fixup some errors when compile
baichuan3 committed Oct 31, 2023
commit 6cf18402fd54ca7890bded02a4c73e6351950b97
15 changes: 15 additions & 0 deletions Cargo.lock

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

7 changes: 7 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -224,6 +224,13 @@ diesel = { version = "2.1.0", features = [
diesel-derive-enum = { version = "2.0.1", features = ["sqlite"] }
diesel_migrations = { version = "2.0.0" }
tap = "1.0.1"
backoff = { version = "0.4.0", features = [
"futures",
"futures-core",
"pin-project-lite",
"tokio",
"tokio_1",
] }

# Note: the BEGIN and END comments below are required for external tooling. Do not remove.
# BEGIN MOVE DEPENDENCIES
6 changes: 3 additions & 3 deletions crates/rooch-config/src/indexer_config.rs
Original file line number Diff line number Diff line change
@@ -34,7 +34,7 @@ impl IndexerConfig {
}

pub fn init(&self) -> Result<()> {
let indexer_db = self.get_indexer_db();
let indexer_db = self.clone().get_indexer_db();
if !indexer_db.exists() {
std::fs::create_dir_all(indexer_db.clone())?;
}
@@ -50,10 +50,10 @@ impl IndexerConfig {
self.base().data_dir()
}

pub fn get_indexer_db(self) -> PathBuf {
pub fn get_indexer_db(&self) -> PathBuf {
self.data_dir()
.join(R_DEFAULT_DB_DIR.as_path())
.join(ROOCH_INDEXER_DB_FILENAME.as_path())
.join(ROOCH_INDEXER_DB_FILENAME)
}
}

1 change: 1 addition & 0 deletions crates/rooch-indexer/Cargo.toml
Original file line number Diff line number Diff line change
@@ -33,6 +33,7 @@ serde_json = { workspace = true }
regex = { workspace = true }
thiserror = { workspace = true }
tracing = { workspace = true }
backoff = { workspace = true }
tokio = { workspace = true, features = ["full"] }
diesel = { workspace = true }
diesel-derive-enum = { workspace = true }
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
CREATE TABLE transactions (
tx_order INTEGER NOT NULL PRIMARY KEY,
tx_order BIGINT NOT NULL PRIMARY KEY,
tx_hash VARCHAR NOT NULL,
transaction_type VARCHAR NOT NULL,
sequence_number INTEGER NOT NULL,
sequence_number BIGINT NOT NULL,
multichain_id VARCHAR NOT NULL,
multichain_raw_address BLOB NOT NULL,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Store multichain_raw_address as hex?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

sender VARCHAR NOT NULL,
action VARCHAR NOT NULL,
action_type SMALLINT NOT NULL,
action_raw BLOB NOT NULL,
auth_validator_id INTEGER NOT NULL,
auth_validator_id BIGINT NOT NULL,
authenticator_payload BLOB NOT NULL,
tx_accumulator_root VARCHAR NOT NULL,
transaction_raw BLOB NOT NULL,

state_root VARCHAR NOT NULL,
event_root VARCHAR NOT NULL,
gas_used INTEGER NOT NULL,
gas_used BIGINT NOT NULL,
status VARCHAR NOT NULL,

tx_order_auth_validator_id INTEGER NOT NULL,
tx_order_auth_validator_id BIGINT NOT NULL,
tx_order_authenticator_payload BLOB NOT NULL,

created_at INTEGER NOT NULL,
updated_at INTEGER NOT NULL,
created_at BIGINT NOT NULL,
updated_at BIGINT NOT NULL,
UNIQUE (tx_hash)
);

Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
CREATE TABLE events
(
event_handle_id VARCHAR NOT NULL,
event_seq INTEGER NOT NULL,
event_seq BIGINT NOT NULL,
type_tag VARCHAR NOT NULL,
event_data BLOB NOT NULL,
event_index INTEGER NOT NULL,
event_index BIGINT NOT NULL,

tx_hash VARCHAR NOT NULL,
tx_order INTEGER NOT NULL,
tx_order BIGINT NOT NULL,
sender VARCHAR NOT NULL,
created_at INTEGER NOT NULL,
updated_at INTEGER NOT NULL,
created_at BIGINT NOT NULL,
updated_at BIGINT NOT NULL,
-- Constraints
PRIMARY KEY (event_handle_id, event_seq)
);
13 changes: 13 additions & 0 deletions crates/rooch-indexer/src/errors.rs
Original file line number Diff line number Diff line change
@@ -58,6 +58,19 @@ pub enum IndexerError {

#[error("Invalid argument with error: `{0}`")]
InvalidArgumentError(String),

#[error("`{0}`: `{1}`")]
ErrorWithContext(String, Box<IndexerError>),
}

pub trait Context<T> {
fn context(self, context: &str) -> Result<T, IndexerError>;
}

impl<T> Context<T> for Result<T, IndexerError> {
fn context(self, context: &str) -> Result<T, IndexerError> {
self.map_err(|e| IndexerError::ErrorWithContext(context.to_string(), Box::new(e)))
}
}

impl From<tokio::task::JoinError> for IndexerError {
32 changes: 18 additions & 14 deletions crates/rooch-indexer/src/indexer.rs
Original file line number Diff line number Diff line change
@@ -9,8 +9,7 @@ use crate::{
};
use anyhow::{anyhow, Result};
use diesel::{
r2d2::ConnectionManager, ExpressionMethods, OptionalExtension, QueryDsl, RunQueryDsl,
SqliteConnection,
r2d2::ConnectionManager, Connection, ExpressionMethods, QueryDsl, RunQueryDsl, SqliteConnection,
};
use itertools::Itertools;
use rooch_types::transaction::TransactionWithInfo;
@@ -67,12 +66,15 @@ impl IndexerReader {
{
blocking_call_is_ok_or_panic();

let mut connection = self.get_connection()?;
connection
.build_transaction()
.read_only()
.run(query)
.map_err(|e| IndexerError::SQLiteReadError(e.to_string()))
// let mut connection = self.get_connection()?;
// connection
// .build_transaction()
// .read_only()
// .run(query)
// .map_err(|e| IndexerError::SQLiteReadError(e.to_string()))

//TODO implements sqlite query
Err(IndexerError::SQLiteReadError("Not implements".to_string()))
}

pub async fn spawn_blocking<F, R, E>(&self, f: F) -> Result<R, E>
@@ -130,13 +132,15 @@ fn blocking_call_is_ok_or_panic() {
impl IndexerReader {
fn multi_get_transactions(
&self,
tx_orders: Vec<u128>,
tx_orders: Vec<i64>,
) -> Result<Vec<StoredTransaction>, IndexerError> {
self.run_query(|conn| {
transactions::table
.filter(transactions::tx_order.eq_any(tx_orders))
.load::<StoredTransaction>(conn)
})
// self.run_query(|conn| {
// transactions::table
// .filter(transactions::tx_order.eq_any(tx_orders))
// .load::<StoredTransaction>(conn)
// })
//TODO
Ok(vec![])
}

fn stored_transaction_to_transaction_block(
1 change: 0 additions & 1 deletion crates/rooch-indexer/src/lib.rs
Original file line number Diff line number Diff line change
@@ -9,7 +9,6 @@
use std::time::Duration;

use anyhow::Result;
use clap::Parser;
use diesel::r2d2::ConnectionManager;
use diesel::sqlite::SqliteConnection;
use tracing::info;
14 changes: 7 additions & 7 deletions crates/rooch-indexer/src/models/events.rs
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@ pub struct StoredEvent {
#[diesel(sql_type = diesel::sql_types::Text)]
pub event_handle_id: String,
/// the number of messages that have been emitted to the path previously
#[diesel(sql_type = diesel::sql_types::Integer)]
#[diesel(sql_type = diesel::sql_types::BigInt)]
pub event_seq: i64,
/// the type of the event data
#[diesel(sql_type = diesel::sql_types::Text)]
@@ -21,22 +21,22 @@ pub struct StoredEvent {
#[diesel(sql_type = diesel::sql_types::Blob)]
pub event_data: Vec<u8>,
/// event index in the transaction events
#[diesel(sql_type = diesel::sql_types::Integer)]
#[diesel(sql_type = diesel::sql_types::BigInt)]
pub event_index: i64,

/// the hash of this transaction.
#[diesel(sql_type = diesel::sql_types::Text)]
pub tx_hash: String,
/// the tx order of this transaction.
#[diesel(sql_type = diesel::sql_types::Integer)]
pub tx_order: i128,
#[diesel(sql_type = diesel::sql_types::BigInt)]
pub tx_order: i64,
/// the rooch address of sender who emit the event
#[diesel(sql_type = diesel::sql_types::Text)]
pub sender: String,

#[diesel(sql_type = diesel::sql_types::Integer)]
#[diesel(sql_type = diesel::sql_types::BigInt)]
pub created_at: i64,
#[diesel(sql_type = diesel::sql_types::Integer)]
#[diesel(sql_type = diesel::sql_types::BigInt)]
pub updated_at: i64,
}

@@ -51,7 +51,7 @@ impl From<IndexedEvent> for StoredEvent {

// TODO use tx_hash: StrView(event.tx_hash) ?
tx_hash: event.tx_hash.to_string(),
tx_order: event.tx_order as i128,
tx_order: event.tx_order as i64,
sender: event.sender.to_string(),

created_at: event.created_at as i64,
47 changes: 29 additions & 18 deletions crates/rooch-indexer/src/models/transactions.rs
Original file line number Diff line number Diff line change
@@ -3,13 +3,16 @@

use diesel::prelude::*;
use move_core_types::vm_status::KeptVMStatus;
use moveos_types::h256::H256;
use std::str::FromStr;

use crate::schema::transactions;
use crate::types::{IndexedTransaction, IndexerResult};

use crate::errors::IndexerError;
use moveos_types::transaction::TransactionExecutionInfo;
use rooch_types::transaction::authenticator::Authenticator;
use rooch_types::transaction::TransactionWithInfo;
use rooch_types::transaction::{RawTransaction, TransactionType, TransactionWithInfo};
use rooch_types::transaction::{TransactionSequenceInfo, TypedTransaction};

#[derive(Clone, Debug, Queryable, Insertable, QueryableByName)]
@@ -20,12 +23,12 @@ pub struct StoredTransaction {
#[diesel(sql_type = diesel::sql_types::Text)]
pub tx_hash: String,
/// The tx order of this transaction.
#[diesel(sql_type = diesel::sql_types::Integer)]
pub tx_order: i128,
#[diesel(sql_type = diesel::sql_types::BigInt)]
pub tx_order: i64,

#[diesel(sql_type = diesel::sql_types::Text)]
pub transaction_type: String,
#[diesel(sql_type = diesel::sql_types::Integer)]
#[diesel(sql_type = diesel::sql_types::BigInt)]
pub sequence_number: i64,
#[diesel(sql_type = diesel::sql_types::Text)]
pub multichain_id: String,
@@ -36,11 +39,11 @@ pub struct StoredTransaction {
pub sender: String,
#[diesel(sql_type = diesel::sql_types::Text)]
pub action: String,
#[diesel(sql_type = diesel::sql_types::Integer)]
pub action_type: i8,
#[diesel(sql_type = diesel::sql_types::SmallInt)]
pub action_type: i16,
#[diesel(sql_type = diesel::sql_types::Blob)]
pub action_raw: Vec<u8>,
#[diesel(sql_type = diesel::sql_types::Integer)]
#[diesel(sql_type = diesel::sql_types::BigInt)]
pub auth_validator_id: i64,
#[diesel(sql_type = diesel::sql_types::Blob)]
pub authenticator_payload: Vec<u8>,
@@ -54,36 +57,36 @@ pub struct StoredTransaction {
#[diesel(sql_type = diesel::sql_types::Text)]
pub event_root: String,
/// The amount of gas used.
#[diesel(sql_type = diesel::sql_types::Integer)]
#[diesel(sql_type = diesel::sql_types::BigInt)]
pub gas_used: i64,
/// The vm status.
#[diesel(sql_type = diesel::sql_types::Text)]
pub status: String,

/// The tx order signature,
#[diesel(sql_type = diesel::sql_types::Integer)]
#[diesel(sql_type = diesel::sql_types::BigInt)]
pub tx_order_auth_validator_id: i64,
#[diesel(sql_type = diesel::sql_types::Blob)]
pub tx_order_authenticator_payload: Vec<u8>,

#[diesel(sql_type = diesel::sql_types::Integer)]
#[diesel(sql_type = diesel::sql_types::BigInt)]
pub created_at: i64,
#[diesel(sql_type = diesel::sql_types::Integer)]
// #[diesel(sql_type = diesel::sql_types::BigInt)]
pub updated_at: i64,
}

impl From<IndexedTransaction> for StoredTransaction {
fn from(transaction: IndexedTransaction) -> Self {
StoredTransaction {
tx_hash: transaction.tx_hash.to_string(),
tx_order: transaction.tx_order as i128,
tx_order: transaction.tx_order as i64,
transaction_type: transaction.transaction_type.transaction_type_name(),
sequence_number: transaction.sequence_number as i64,
multichain_id: transaction.multichain_id.multichain_name(),
multichain_raw_address: transaction.multichain_raw_address,
sender: transaction.sender.to_string(),
action: transaction.action.action_name(),
action_type: transaction.action.action_type() as i8,
action_type: transaction.action.action_type() as i16,
action_raw: transaction.action_raw,
auth_validator_id: transaction.auth_validator_id as i64,
authenticator_payload: transaction.authenticator_payload,
@@ -108,19 +111,27 @@ impl From<IndexedTransaction> for StoredTransaction {
impl StoredTransaction {
pub fn try_into_transaction_with_info(self) -> IndexerResult<TransactionWithInfo> {
//TODO construct TypedTransaction
let transaction = TypedTransaction {};
let raw_transaction = RawTransaction {
transaction_type: TransactionType::Rooch,
raw: self.transaction_raw,
};
let transaction = TypedTransaction::try_from(raw_transaction)?;
let sequence_info = TransactionSequenceInfo {
tx_order: self.tx_order as u128,
tx_order_signature: Authenticator {
auth_validator_id: self.tx_order_auth_validator_id as u64,
payload: self.tx_order_authenticator_payload,
},
tx_accumulator_root: self.tx_accumulator_root.into(),
tx_accumulator_root: H256::from_str(self.tx_accumulator_root.as_str())
.map_err(|e| IndexerError::DataTransformationError(e.to_string()))?,
};
let execution_info = TransactionExecutionInfo {
tx_hash: self.tx_hash.into(),
state_root: self.state_root.into(),
event_root: self.state_root.into(),
tx_hash: H256::from_str(self.tx_hash.as_str())
.map_err(|e| IndexerError::DataTransformationError(e.to_string()))?,
state_root: H256::from_str(self.state_root.as_str())
.map_err(|e| IndexerError::DataTransformationError(e.to_string()))?,
event_root: H256::from_str(self.state_root.as_str())
.map_err(|e| IndexerError::DataTransformationError(e.to_string()))?,
gas_used: self.gas_used as u64,
//TODO convert KeptVMStatus
status: KeptVMStatus::Executed,
24 changes: 12 additions & 12 deletions crates/rooch-indexer/src/schema.rs
Original file line number Diff line number Diff line change
@@ -3,15 +3,15 @@
diesel::table! {
events (event_handle_id, event_seq) {
event_handle_id -> Text,
event_seq -> Integer,
event_seq -> BigInt,
type_tag -> Text,
event_data -> Binary,
event_index -> Integer,
event_index -> BigInt,
tx_hash -> Text,
tx_order -> Integer,
tx_order -> BigInt,
sender -> Text,
created_at -> Integer,
updated_at -> Integer,
created_at -> BigInt,
updated_at -> BigInt,
}
}

@@ -26,28 +26,28 @@ diesel::table! {

diesel::table! {
transactions (tx_order) {
tx_order -> Integer,
tx_order -> BigInt,
tx_hash -> Text,
transaction_type -> Text,
sequence_number -> Integer,
sequence_number -> BigInt,
multichain_id -> Text,
multichain_raw_address -> Binary,
sender -> Text,
action -> Text,
action_type -> SmallInt,
action_raw -> Binary,
auth_validator_id -> Integer,
auth_validator_id -> BigInt,
authenticator_payload -> Binary,
tx_accumulator_root -> Text,
transaction_raw -> Binary,
state_root -> Text,
event_root -> Text,
gas_used -> Integer,
gas_used -> BigInt,
status -> Text,
tx_order_auth_validator_id -> Integer,
tx_order_auth_validator_id -> BigInt,
tx_order_authenticator_payload -> Binary,
created_at -> Integer,
updated_at -> Integer,
created_at -> BigInt,
updated_at -> BigInt,
}
}

17 changes: 6 additions & 11 deletions crates/rooch-indexer/src/store/indexer_store.rs
Original file line number Diff line number Diff line change
@@ -17,6 +17,7 @@ use crate::errors::{Context, IndexerError};

use crate::models::events::StoredEvent;
use crate::models::transactions::StoredTransaction;
use crate::schema::{events, transactions};
use crate::store::diesel_macro::transactional_blocking_with_retry;
use crate::types::{IndexedEvent, IndexedTransaction};
use crate::SqliteConnectionPool;
@@ -66,7 +67,7 @@ impl SqliteIndexerStore {
transactions: Vec<IndexedTransaction>,
) -> Result<(), IndexerError> {
let transactions = transactions
.iter()
.into_iter()
.map(StoredTransaction::from)
.collect::<Vec<_>>();

@@ -85,13 +86,7 @@ impl SqliteIndexerStore {
},
Duration::from_secs(60)
)
.tap(|_| {
info!(
elapsed,
"Persisted {} chunked transactions",
transactions.len()
)
})
.tap(|_| info!("Persisted {} chunked transactions", transactions.len()))
}

fn persist_events_chunk(&self, events: Vec<IndexedEvent>) -> Result<(), IndexerError> {
@@ -116,7 +111,7 @@ impl SqliteIndexerStore {
},
Duration::from_secs(60)
)
.tap(|_| info!(elapsed, "Persisted {} chunked events", len))
.tap(|_| info!("Persisted {} chunked events", len))
}

async fn execute_in_blocking_worker<F, R>(&self, f: F) -> Result<R, IndexerError>
@@ -186,7 +181,7 @@ impl IndexerStore for SqliteIndexerStore {
e
))
})?;
info!(elapsed, "Persisted {} transactions", len);
info!("Persisted {} transactions", len);
Ok(())
}

@@ -211,7 +206,7 @@ impl IndexerStore for SqliteIndexerStore {
e
))
})?;
info!(elapsed, "Persisted {} events", len);
info!("Persisted {} events", len);
Ok(())
}
}
44 changes: 24 additions & 20 deletions crates/rooch-indexer/src/store/mod.rs
Original file line number Diff line number Diff line change
@@ -15,7 +15,7 @@ pub(crate) mod diesel_macro {
.build_transaction()
.read_only()
.run($query)
.map_err(|e| IndexerError::PostgresReadError(e.to_string()))
.map_err(|e| IndexerError::SQLiteReadError(e.to_string()))
}};
}

@@ -27,7 +27,7 @@ pub(crate) mod diesel_macro {
.serializable()
.read_write()
.run($query)
.map_err(|e| IndexerError::PostgresWriteError(e.to_string()))
.map_err(|e| IndexerError::SQLiteWriteError(e.to_string()))
}};
}

@@ -37,24 +37,28 @@ pub(crate) mod diesel_macro {
backoff.max_elapsed_time = Some($max_elapsed);

let result = match backoff::retry(backoff, || {
let mut sqlite_pool_conn =
crate::get_sqlite_pool_connection($pool).map_err(|e| {
backoff::Error::Transient {
err: IndexerError::PostgresWriteError(e.to_string()),
retry_after: None,
}
})?;
sqlite_pool_conn
.build_transaction()
.read_write()
.run($query)
.map_err(|e| {
tracing::error!("Error with persisting data into DB: {:?}", e);
backoff::Error::Transient {
err: IndexerError::PostgresWriteError(e.to_string()),
retry_after: None,
}
})
// let mut sqlite_pool_conn =
// crate::get_sqlite_pool_connection($pool).map_err(|e| {
// backoff::Error::Transient {
// err: IndexerError::SQLiteWriteError(e.to_string()),
// retry_after: None,
// }
// })?;
// sqlite_pool_conn
// .build_transaction()
// .read_write()
// .run($query)
// .map_err(|e| {
// tracing::error!("Error with persisting data into DB: {:?}", e);
// backoff::Error::Transient {
// err: IndexerError::SQLiteWriteError(e.to_string()),
// retry_after: None,
// }
// })
//TODO
Err(backoff::Error::Permanent(IndexerError::SQLiteWriteError(
"TODO".to_string(),
)))
}) {
Ok(v) => Ok(v),
Err(backoff::Error::Transient { err, .. }) => Err(err),
21 changes: 8 additions & 13 deletions crates/rooch-indexer/src/test_utils.rs
Original file line number Diff line number Diff line change
@@ -6,27 +6,22 @@ use tokio::task::JoinHandle;

use crate::errors::IndexerError;
use crate::store::SqliteIndexerStore;
use crate::utils::reset_database;
use crate::{new_sqlite_connection_pool, Indexer, IndexerConfig};

/// Spawns an indexer thread with provided SQLite DB url
pub async fn start_test_indexer(
config: IndexerConfig,
) -> Result<(SqliteIndexerStore, JoinHandle<Result<(), IndexerError>>), anyhow::Error> {
let parsed_url = config.base_connection_url()?;
let blocking_pool = new_sqlite_connection_pool(&parsed_url)
.map_err(|e| anyhow!("unable to connect to SQLite, is it running? {e}"))?;
if config.reset_db {
reset_database(
&mut blocking_pool
.get()
.map_err(|e| anyhow!("Fail to get sqlite_connection_pool {e}"))?,
true,
)?;
}
let indexer_db = config
.get_indexer_db()
.to_str()
.ok_or_else(|| anyhow!("Indexer_db doest not exist"))?
.to_string();
let blocking_pool = new_sqlite_connection_pool(indexer_db.as_str())
.map_err(|e| anyhow!("Unable to connect to SQLite, is it running? {e}"))?;

let store = SqliteIndexerStore::new(blocking_pool);
let store_clone = store.clone();
let handle = tokio::spawn(async move { Indexer::start(&config, store_clone, None).await });
let handle = tokio::spawn(async move { Indexer::start(&config, store_clone).await });
Ok((store, handle))
}
1 change: 1 addition & 0 deletions crates/rooch-indexer/src/utils.rs
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@

use crate::SqlitePoolConnection;
use anyhow::anyhow;
use diesel::migration::MigrationSource;
use diesel::{RunQueryDsl, SqliteConnection};
use diesel_migrations::{embed_migrations, EmbeddedMigrations, MigrationHarness};
use tracing::info;
3 changes: 1 addition & 2 deletions crates/rooch-rpc-server/src/service/aggregate_service.rs
Original file line number Diff line number Diff line change
@@ -15,12 +15,11 @@ use moveos_types::moveos_std::object_ref::ObjectRef;
use moveos_types::moveos_std::tx_context::TxContext;
use moveos_types::state_resolver::resource_tag_to_key;
use moveos_types::transaction::FunctionCall;
use rooch_rpc_api::jsonrpc_types::transaction_view::TransactionWithInfo;
use rooch_types::account::BalanceInfo;
use rooch_types::framework::account_coin_store::AccountCoinStoreModule;
use rooch_types::framework::coin::{CoinInfo, CoinModule};
use rooch_types::framework::coin_store::CoinStore;
use rooch_types::transaction::TransactionSequenceInfoMapping;
use rooch_types::transaction::{TransactionSequenceInfoMapping, TransactionWithInfo};
use std::collections::HashMap;
use tokio::runtime::Handle;

11 changes: 11 additions & 0 deletions crates/rooch-types/src/transaction/mod.rs
Original file line number Diff line number Diff line change
@@ -10,6 +10,8 @@ use move_core_types::account_address::AccountAddress;
use moveos_types::transaction::TransactionExecutionInfo;
use moveos_types::{h256::H256, transaction::MoveOSTransaction};
use serde::{Deserialize, Serialize};
use std::fmt;
use std::fmt::{Display, Formatter};

pub mod authenticator;
pub mod ethereum;
@@ -27,6 +29,15 @@ impl TransactionType {
}
}

impl Display for TransactionType {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
match self {
TransactionType::Rooch => write!(f, "Rooch"),
TransactionType::Ethereum => write!(f, "Ethereum"),
}
}
}

#[derive(Clone, Debug, Eq, PartialEq, Hash, Serialize, Deserialize)]
pub struct RawTransaction {
pub transaction_type: TransactionType,
8 changes: 6 additions & 2 deletions moveos/moveos-types/src/transaction.rs
Original file line number Diff line number Diff line change
@@ -121,8 +121,12 @@ impl MoveAction {
}
}

pub fn action_name(self) -> String {
self.to_string()
pub fn action_name(&self) -> String {
match self {
MoveAction::Script(_) => "Script".to_string(),
MoveAction::Function(_) => "Function".to_string(),
MoveAction::ModuleBundle(_) => "ModuleBundle".to_string(),
}
}

pub fn new_module_bundle(modules: Vec<Vec<u8>>) -> Self {