Skip to content

Commit

Permalink
feat: merging movement-v2 upstream.
Browse files Browse the repository at this point in the history
  • Loading branch information
l-monninger committed Jan 28, 2024
1 parent 7882ac9 commit e710c9b
Show file tree
Hide file tree
Showing 11 changed files with 754 additions and 1,070 deletions.
1 change: 1 addition & 0 deletions m1/Cargo.lock

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

2 changes: 2 additions & 0 deletions m1/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ tokio = { version = "1.21.0", features = ["full"] }
tokio-util = { version = "0.7.2", features = ["compat", "codec"] }
toml = "0.5.9"
walkdir = "2.3.2"
poem-openapi = { version = "=2.0.11", features = ["swagger-ui", "url"] }
poem-openapi-derive = "=2.0.11"

jemallocator = { version = "0.3.2", features = [
"profiling",
Expand Down
2 changes: 1 addition & 1 deletion m1/rust-toolchain
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.73.0
1.71.1
1 change: 1 addition & 0 deletions m1/subnet/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ bcs = { workspace = true }
aptos-indexer = { workspace = true }
aptos-indexer-grpc-fullnode = { workspace = true }
aptos-protos = { workspace = true }
poem-openapi = { workspace = true }

# todo: differs from workspace because of e2e tests crate I believe, need to check
clap = { version = "4.4.8", features = ["cargo", "derive"] }
121 changes: 81 additions & 40 deletions m1/subnet/src/api/chain_handlers.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
use std::io;
use std::marker::PhantomData;

use aptos_api::accept_type::AcceptType;
use aptos_api_types::U64;
use avalanche_types::proto::http::Element;
use avalanche_types::subnet::rpc::http::handle::Handle;
use bytes::Bytes;
use jsonrpc_core::{BoxFuture, Error, ErrorCode, IoHandler, Result};
use jsonrpc_derive::rpc;
use serde::{Deserialize, Serialize};
use aptos_api::accept_type::AcceptType;
use aptos_api_types::U64;

use crate::api::de_request;
use crate::util::HexParser;
use crate::vm::Vm;

#[rpc]
Expand All @@ -22,16 +23,28 @@ pub trait Rpc {
#[rpc(name = "submitTransaction", alias("aptosvm.submitTransaction"))]
fn submit_transaction(&self, args: RpcReq) -> BoxFuture<Result<RpcRes>>;

#[rpc(name = "submitTransactionBatch", alias("aptosvm.submitTransactionBatch"))]
#[rpc(
name = "submitTransactionBatch",
alias("aptosvm.submitTransactionBatch")
)]
fn submit_transaction_batch(&self, args: RpcReq) -> BoxFuture<Result<RpcRes>>;

#[rpc(name = "getTransactionByHash", alias("aptosvm.getTransactionByHash"))]
fn get_transaction_by_hash(&self, args: RpcReq) -> BoxFuture<Result<RpcRes>>;

#[rpc(name = "getTransactionByVersion", alias("aptosvm.getTransactionByVersion"))]
fn get_transaction_by_version(&self, args: GetTransactionByVersionArgs) -> BoxFuture<Result<RpcRes>>;
#[rpc(
name = "getTransactionByVersion",
alias("aptosvm.getTransactionByVersion")
)]
fn get_transaction_by_version(
&self,
args: GetTransactionByVersionArgs,
) -> BoxFuture<Result<RpcRes>>;

#[rpc(name = "getAccountsTransactions", alias("aptosvm.getAccountsTransactions"))]
#[rpc(
name = "getAccountsTransactions",
alias("aptosvm.getAccountsTransactions")
)]
fn get_accounts_transactions(&self, args: RpcReq) -> BoxFuture<Result<RpcRes>>;

#[rpc(name = "simulateTransaction", alias("aptosvm.simulateTransaction"))]
Expand All @@ -44,17 +57,18 @@ pub trait Rpc {
fn estimate_gas_price(&self) -> BoxFuture<Result<RpcRes>>;
/*******************************TRANSACTION END***************************************/


/*******************************HELPER API START***************************************/
#[rpc(name = "faucet", alias("aptosvm.faucet"))]
fn faucet_apt(&self, args: RpcReq) -> BoxFuture<Result<RpcRes>>;

#[rpc(name = "faucetWithCli")]
fn faucet_with_cli(&self, args: RpcReq) -> BoxFuture<Result<RpcRes>>;

#[rpc(name = "createAccount", alias("aptosvm.createAccount"))]
fn create_account(&self, args: RpcReq) -> BoxFuture<Result<RpcRes>>;

/*******************************HELPER API END***************************************/


/******************************* ACCOUNT START ***************************************/

#[rpc(name = "getAccount", alias("aptosvm.getAccount"))]
Expand All @@ -66,14 +80,19 @@ pub trait Rpc {
#[rpc(name = "getAccountModules", alias("aptosvm.getAccountModules"))]
fn get_account_modules(&self, args: RpcReq) -> BoxFuture<Result<RpcRes>>;

#[rpc(name = "getAccountResourcesState", alias("aptosvm.getAccountResourcesState"))]
#[rpc(
name = "getAccountResourcesState",
alias("aptosvm.getAccountResourcesState")
)]
fn get_account_resources_state(&self, args: AccountStateArgs) -> BoxFuture<Result<RpcRes>>;

#[rpc(name = "getAccountModulesState", alias("aptosvm.getAccountModulesState"))]
#[rpc(
name = "getAccountModulesState",
alias("aptosvm.getAccountModulesState")
)]
fn get_account_modules_state(&self, args: AccountStateArgs) -> BoxFuture<Result<RpcRes>>;
/******************************* ACCOUNT END ***************************************/


/*******************************BLOCK START***************************************/
#[rpc(name = "getBlockByHeight", alias("aptosvm.getBlockByHeight"))]
fn get_block_by_height(&self, args: BlockArgs) -> BoxFuture<Result<RpcRes>>;
Expand All @@ -91,24 +110,29 @@ pub trait Rpc {
#[rpc(name = "getRawTableItem", alias("aptosvm.getRawTableItem"))]
fn get_raw_table_item(&self, args: RpcTableReq) -> BoxFuture<Result<RpcRes>>;

#[rpc(name = "getEventsByCreationNumber", alias("aptosvm.getEventsByCreationNumber"))]
#[rpc(
name = "getEventsByCreationNumber",
alias("aptosvm.getEventsByCreationNumber")
)]
fn get_events_by_creation_number(&self, args: RpcEventNumReq) -> BoxFuture<Result<RpcRes>>;

#[rpc(name = "getEventsByEventHandle", alias("aptosvm.getEventsByEventHandle"))]
#[rpc(
name = "getEventsByEventHandle",
alias("aptosvm.getEventsByEventHandle")
)]
fn get_events_by_event_handle(&self, args: RpcEventHandleReq) -> BoxFuture<Result<RpcRes>>;

#[rpc(name = "getLedgerInfo", alias("aptosvm.getLedgerInfo"))]
fn get_ledger_info(&self) -> BoxFuture<Result<RpcRes>>;
}


#[derive(Deserialize, Serialize, Debug, Clone)]
pub struct GetTableItemArgs {
pub table_handle: String,
pub key_type: String,
pub value_type: String,
pub key: String,
pub is_bsc_format: Option<bool>,
pub is_bcs_format: Option<bool>,
}

#[derive(Deserialize, Serialize, Debug, Clone)]
Expand All @@ -117,22 +141,22 @@ pub struct RpcReq {
pub ledger_version: Option<U64>,
pub start: Option<String>,
pub limit: Option<u16>,
pub is_bsc_format: Option<bool>,
pub is_bcs_format: Option<bool>,
}

#[derive(Deserialize, Serialize, Debug, Clone)]
pub struct RpcRes {
pub data: String,
pub header: String,
pub error: Option<String>,
}


#[derive(Deserialize, Serialize, Debug, Clone)]
pub struct RpcTableReq {
pub query: String,
pub body: String,
pub ledger_version: Option<U64>,
pub is_bsc_format: Option<bool>,
pub is_bcs_format: Option<bool>,
}

#[derive(Deserialize, Serialize, Debug, Clone)]
Expand All @@ -141,7 +165,7 @@ pub struct RpcEventNumReq {
pub creation_number: U64,
pub start: Option<U64>,
pub limit: Option<u16>,
pub is_bsc_format: Option<bool>,
pub is_bcs_format: Option<bool>,
}

#[derive(Deserialize, Serialize, Debug, Clone)]
Expand All @@ -151,38 +175,37 @@ pub struct RpcEventHandleReq {
pub address: String,
pub event_handle: String,
pub field_name: String,
pub is_bsc_format: Option<bool>,
pub is_bcs_format: Option<bool>,
}

#[derive(Deserialize, Serialize, Debug, Clone)]
pub struct BlockArgs {
pub height_or_version: u64,
pub with_transactions: Option<bool>,
pub is_bsc_format: Option<bool>,
pub is_bcs_format: Option<bool>,
}

#[derive(Deserialize, Serialize, Debug, Clone)]
pub struct GetTransactionByVersionArgs {
pub version: U64,
pub is_bsc_format: Option<bool>,
pub is_bcs_format: Option<bool>,
}

#[derive(Deserialize, Serialize, Debug, Clone)]
pub struct AccountStateArgs {
pub account: String,
pub resource: String,
pub ledger_version: Option<U64>,
pub is_bsc_format: Option<bool>,
pub is_bcs_format: Option<bool>,
}

#[derive(Deserialize, Serialize, Debug, Clone)]
pub struct PageArgs {
pub start: Option<U64>,
pub limit: Option<u16>,
pub is_bsc_format: Option<bool>,
pub is_bcs_format: Option<bool>,
}


#[derive(Clone)]
pub struct ChainService {
pub vm: Vm,
Expand All @@ -194,7 +217,6 @@ impl ChainService {
}
}


impl Rpc for ChainService {
fn get_transactions(&self, args: PageArgs) -> BoxFuture<Result<RpcRes>> {
let vm = self.vm.clone();
Expand All @@ -208,25 +230,29 @@ impl Rpc for ChainService {
log::debug!("submit_transaction called");
let vm = self.vm.clone();
Box::pin(async move {
let accept = if args.is_bsc_format.unwrap_or(false) {
let accept = if args.is_bcs_format.unwrap_or(false) {
AcceptType::Bcs
} else {
AcceptType::Json
};
let r = vm.submit_transaction(hex::decode(args.data).unwrap(), accept).await;
let r = vm
.submit_transaction(hex::decode(args.data).unwrap(), accept)
.await;
Ok(r)
})
}

fn submit_transaction_batch(&self, args: RpcReq) -> BoxFuture<Result<RpcRes>> {
let vm = self.vm.clone();
Box::pin(async move {
let accept = if args.is_bsc_format.unwrap_or(false) {
let accept = if args.is_bcs_format.unwrap_or(false) {
AcceptType::Bcs
} else {
AcceptType::Json
};
let r = vm.submit_transaction_batch(hex::decode(args.data).unwrap(), accept).await;
let r = vm
.submit_transaction_batch(hex::decode(args.data).unwrap(), accept)
.await;
Ok(r)
})
}
Expand All @@ -239,7 +265,10 @@ impl Rpc for ChainService {
})
}

fn get_transaction_by_version(&self, args: GetTransactionByVersionArgs) -> BoxFuture<Result<RpcRes>> {
fn get_transaction_by_version(
&self,
args: GetTransactionByVersionArgs,
) -> BoxFuture<Result<RpcRes>> {
let vm = self.vm.clone();
Box::pin(async move {
let ret = vm.get_transaction_by_version(args).await;
Expand All @@ -259,7 +288,7 @@ impl Rpc for ChainService {
let vm = self.vm.clone();
Box::pin(async move {
let data = hex::decode(args.data).unwrap();
let accept = if args.is_bsc_format.unwrap_or(false) {
let accept = if args.is_bcs_format.unwrap_or(false) {
AcceptType::Bcs
} else {
AcceptType::Json
Expand Down Expand Up @@ -288,8 +317,9 @@ impl Rpc for ChainService {
fn faucet_apt(&self, args: RpcReq) -> BoxFuture<Result<RpcRes>> {
let vm = self.vm.clone();
Box::pin(async move {
let acc = hex::decode(args.data).unwrap();
let accept = if args.is_bsc_format.unwrap_or(false) {
let s = args.data.as_str();
let acc = HexParser::parse_hex_string(s).unwrap();
let accept = if args.is_bcs_format.unwrap_or(false) {
AcceptType::Bcs
} else {
AcceptType::Json
Expand All @@ -302,12 +332,14 @@ impl Rpc for ChainService {
fn create_account(&self, args: RpcReq) -> BoxFuture<Result<RpcRes>> {
let vm = self.vm.clone();
Box::pin(async move {
let accept = if args.is_bsc_format.unwrap_or(false) {
let accept = if args.is_bcs_format.unwrap_or(false) {
AcceptType::Bcs
} else {
AcceptType::Json
};
let ret = vm.create_account(args.data.as_str(), accept).await;
let s = args.data.as_str();
let acc = HexParser::parse_hex_string(s).unwrap();
let ret = vm.create_account(acc, accept).await;
Ok(ret)
})
}
Expand Down Expand Up @@ -371,7 +403,6 @@ impl Rpc for ChainService {
fn view_function(&self, args: RpcReq) -> BoxFuture<Result<RpcRes>> {
let vm = self.vm.clone();
Box::pin(async move {
log::info!("view_function called {}",args.data.clone());
let ret = vm.view_function(args).await;
return Ok(ret);
})
Expand Down Expand Up @@ -416,6 +447,16 @@ impl Rpc for ChainService {
return Ok(ret);
})
}

fn faucet_with_cli(&self, args: RpcReq) -> BoxFuture<Result<RpcRes>> {
let vm = self.vm.clone();
Box::pin(async move {
let s = args.data.as_str();
let acc = HexParser::parse_hex_string(s).unwrap();
let ret = vm.faucet_with_cli(acc).await;
Ok(ret)
})
}
}

#[derive(Clone, Debug)]
Expand All @@ -426,8 +467,8 @@ pub struct ChainHandler<T> {

#[tonic::async_trait]
impl<T> Handle for ChainHandler<T>
where
T: Rpc + Send + Sync + Clone + 'static,
where
T: Rpc + Send + Sync + Clone + 'static,
{
async fn request(
&self,
Expand Down Expand Up @@ -455,7 +496,7 @@ impl<T: Rpc> ChainHandler<T> {
}
}


#[allow(dead_code)]
fn create_jsonrpc_error(e: std::io::Error) -> Error {
let mut error = Error::new(ErrorCode::InternalError);
error.message = format!("{}", e);
Expand Down
4 changes: 1 addition & 3 deletions m1/subnet/src/api/static_handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::api::de_request;
/// Defines static handler RPCs for this VM.
#[rpc]
pub trait Rpc {
#[rpc(name = "ping", alias("timestampvm.ping"))]
#[rpc(name = "ping")]
fn ping(&self) -> BoxFuture<Result<crate::api::PingResponse>>;
}

Expand All @@ -29,8 +29,6 @@ impl StaticService {
}
}



impl Rpc for StaticService {
fn ping(&self) -> BoxFuture<Result<crate::api::PingResponse>> {
log::debug!("ping called");
Expand Down
Loading

0 comments on commit e710c9b

Please sign in to comment.