diff --git a/Cargo.lock b/Cargo.lock index 9662a018635ae..fa92253a87b4b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3529,7 +3529,6 @@ version = "0.1.0" dependencies = [ "anyhow", "aptos", - "aptos-api-types", "aptos-build-info", "aptos-crypto", "aptos-framework", diff --git a/aptos-move/aptos-release-builder/Cargo.toml b/aptos-move/aptos-release-builder/Cargo.toml index 0b522e3805c15..42f02244848ab 100644 --- a/aptos-move/aptos-release-builder/Cargo.toml +++ b/aptos-move/aptos-release-builder/Cargo.toml @@ -15,7 +15,6 @@ rust-version = { workspace = true } [dependencies] anyhow = { workspace = true } aptos = { workspace = true, features = [ "no-upload-proposal" ] } -aptos-api-types = { workspace = true } aptos-build-info = { workspace = true } aptos-crypto = { workspace = true } aptos-framework = { workspace = true } diff --git a/aptos-move/aptos-release-builder/src/validate.rs b/aptos-move/aptos-release-builder/src/validate.rs index b994ef499bbc9..16e2761a6b7af 100644 --- a/aptos-move/aptos-release-builder/src/validate.rs +++ b/aptos-move/aptos-release-builder/src/validate.rs @@ -9,14 +9,11 @@ use aptos::{ move_tool::{RunFunction, RunScript}, stake::IncreaseLockup, }; -use aptos_api_types::U64; use aptos_crypto::ed25519::Ed25519PrivateKey; use aptos_genesis::keys::PrivateIdentity; -use aptos_rest_client::Client; use aptos_temppath::TempPath; use aptos_types::account_address::AccountAddress; use clap::Parser; -use serde::Deserialize; use std::{ fs, path::{Path, PathBuf}, @@ -37,11 +34,6 @@ pub struct NetworkConfig { pub framework_git_rev: Option, } -#[derive(Deserialize)] -struct CreateProposalEvent { - proposal_id: U64, -} - impl NetworkConfig { pub fn new_from_dir(endpoint: Url, test_dir: &Path) -> Result { let root_key_path = test_dir.join("mint.key"); @@ -218,33 +210,19 @@ impl NetworkConfig { let rev_string = self.framework_git_rev.clone(); let framework_path = aptos_framework_path(); - if let Some(rev) = &rev_string { + let proposal_summary = if let Some(rev) = &rev_string { args.push("--framework-git-rev"); args.push(rev.as_str()); - SubmitProposal::try_parse_from(args)?.execute().await?; + SubmitProposal::try_parse_from(args)?.execute().await? } else { args.push("--framework-local-dir"); args.push(framework_path.as_os_str().to_str().unwrap()); - SubmitProposal::try_parse_from(args)?.execute().await?; + SubmitProposal::try_parse_from(args)?.execute().await? }; - // Get proposal id. - let event = Client::new(self.endpoint.clone()) - .get_account_events( - AccountAddress::ONE, - "0x1::aptos_governance::GovernanceEvents", - "create_proposal_events", - None, - Some(1), - ) - .await? - .into_inner() - .pop() - .unwrap(); - - Ok(*serde_json::from_value::(event.data)? + Ok(proposal_summary .proposal_id - .inner()) + .expect("Failed to extract proposal id")) } pub async fn vote_proposal(&self, proposal_id: u64) -> Result<()> { diff --git a/crates/aptos/src/governance/mod.rs b/crates/aptos/src/governance/mod.rs index e5506839ff750..175ca8ccc247f 100644 --- a/crates/aptos/src/governance/mod.rs +++ b/crates/aptos/src/governance/mod.rs @@ -30,6 +30,7 @@ use aptos_rest_client::{ use aptos_sdk::move_types::language_storage::CORE_CODE_ADDRESS; use aptos_types::{ account_address::AccountAddress, + account_config::is_aptos_governance_create_proposal_event, event::EventHandle, governance::VotingRecords, stake_pool::StakePool, @@ -444,20 +445,21 @@ async fn get_metadata_from_url(metadata_url: &Url) -> CliTypedResult> { fn extract_proposal_id(txn: &Transaction) -> CliTypedResult> { if let Transaction::UserTransaction(inner) = txn { // Find event with proposal id - let proposal_id = if let Some(event) = inner.events.iter().find(|event| { - event.typ.to_string().as_str() == "0x1::aptos_governance::CreateProposalEvent" - }) { - let data: CreateProposalEvent = - serde_json::from_value(event.data.clone()).map_err(|_| { - CliError::UnexpectedError( - "Failed to parse Proposal event to get ProposalId".to_string(), - ) - })?; - Some(data.proposal_id.0) - } else { - warn!("No proposal event found to find proposal id"); - None - }; + let proposal_id = + if let Some(event) = inner.events.iter().find(|event| { + is_aptos_governance_create_proposal_event(event.typ.to_string().as_str()) + }) { + let data: CreateProposalEvent = serde_json::from_value(event.data.clone()) + .map_err(|_| { + CliError::UnexpectedError( + "Failed to parse Proposal event to get ProposalId".to_string(), + ) + })?; + Some(data.proposal_id.0) + } else { + warn!("No proposal event found to find proposal id"); + None + }; return Ok(proposal_id); } @@ -473,7 +475,7 @@ struct CreateProposalEvent { #[derive(Debug, Deserialize, Serialize)] pub struct ProposalSubmissionSummary { - proposal_id: Option, + pub proposal_id: Option, #[serde(flatten)] transaction: TransactionSummary, } diff --git a/types/src/account_config/events/mod.rs b/types/src/account_config/events/mod.rs index 6a224aaae5904..33a9ac344cb8c 100644 --- a/types/src/account_config/events/mod.rs +++ b/types/src/account_config/events/mod.rs @@ -11,3 +11,8 @@ pub use deposit::*; pub use new_block::*; pub use new_epoch::*; pub use withdraw::*; + +pub fn is_aptos_governance_create_proposal_event(event_type: &str) -> bool { + event_type == "0x1::aptos_governance::CreateProposal" + || event_type == "0x1::aptos_governance::CreateProposalEvent" +}