From 432f6c387f17d56e4f9575cd8af1910c845f5a76 Mon Sep 17 00:00:00 2001 From: enzotar Date: Sun, 5 Nov 2023 21:49:42 -0800 Subject: [PATCH 1/2] mpl 3.1.0 --- .../src/nft/candy_machine_v3/initialize.rs | 13 +++++++------ crates/cmds-solana/src/nft/candy_machine_v3/mint.rs | 11 +++++------ crates/cmds-solana/src/nft/mod.rs | 2 +- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/crates/cmds-solana/src/nft/candy_machine_v3/initialize.rs b/crates/cmds-solana/src/nft/candy_machine_v3/initialize.rs index 0d944b89..2826b90e 100644 --- a/crates/cmds-solana/src/nft/candy_machine_v3/initialize.rs +++ b/crates/cmds-solana/src/nft/candy_machine_v3/initialize.rs @@ -1,4 +1,7 @@ -use crate::{nft::CandyMachineDataAlias, prelude::*}; +use crate::{ + nft::{CandyMachineDataAlias, TokenStandard}, + prelude::*, +}; use anchor_lang::{InstructionData, ToAccountMetas}; use solana_program::{instruction::Instruction, system_instruction, system_program}; use solana_sdk::pubkey::Pubkey; @@ -6,15 +9,13 @@ use solana_sdk::pubkey::Pubkey; use mpl_candy_machine_core::{instruction::InitializeV2, CandyMachineData}; use mpl_token_metadata::{ accounts::{MasterEdition, Metadata}, - instruction::MetadataDelegateRole, - state::TokenStandard, + types::MetadataDelegateRole, }; // Command Name const INITIALIZE_CANDY_MACHINE: &str = "initialize_candy_machine"; -const DEFINITION: &str = - flow_lib::node_definition!("solana/NFT/candy_machine/initialize.json"); +const DEFINITION: &str = flow_lib::node_definition!("solana/NFT/candy_machine/initialize.json"); fn build() -> BuildResult { use once_cell::sync::Lazy; @@ -82,7 +83,7 @@ async fn run(mut ctx: Context, input: Input) -> Result { // Collection Delegate Record PDA let collection_delegate_record = - mpl_token_metadata::pda::find_metadata_delegate_record_account( + mpl_token_metadata::accounts::MetadataDelegateRecord::find_pda( &input.collection_mint, MetadataDelegateRole::Collection, &input.collection_update_authority.pubkey(), diff --git a/crates/cmds-solana/src/nft/candy_machine_v3/mint.rs b/crates/cmds-solana/src/nft/candy_machine_v3/mint.rs index a8d8b2ff..45faf116 100644 --- a/crates/cmds-solana/src/nft/candy_machine_v3/mint.rs +++ b/crates/cmds-solana/src/nft/candy_machine_v3/mint.rs @@ -6,7 +6,7 @@ use solana_sdk::{compute_budget::ComputeBudgetInstruction, pubkey::Pubkey}; use mpl_token_metadata::{ accounts::{MasterEdition, Metadata}, - instructions::MetadataDelegateRole, + types::MetadataDelegateRole, }; use super::CandyGuardData; @@ -14,8 +14,7 @@ use super::CandyGuardData; // Command Name const MINT: &str = "mint"; -const DEFINITION: &str = - flow_lib::node_definition!("solana/NFT/candy_machine/mint.json"); +const DEFINITION: &str = flow_lib::node_definition!("solana/NFT/candy_machine/mint.json"); fn build() -> BuildResult { use once_cell::sync::Lazy; @@ -71,7 +70,7 @@ pub struct Output { } async fn run(mut ctx: Context, input: Input) -> Result { - let token_metadata_program = mpl_token_metadata::id(); + let token_metadata_program = mpl_token_metadata::ID; let candy_machine_program = mpl_candy_machine_core::id(); let candy_guard_program = mpl_candy_guard::id(); @@ -96,7 +95,7 @@ async fn run(mut ctx: Context, input: Input) -> Result { ); // Metadata TokenRecord Account - let nft_token_record = mpl_token_metadata::pda::find_token_record_account( + let nft_token_record = mpl_token_metadata::accounts::TokenRecord::find_pda( &input.mint_account, &nft_associated_token_account, ) @@ -104,7 +103,7 @@ async fn run(mut ctx: Context, input: Input) -> Result { // Collection Delegate Record PDA let collection_delegate_record = - mpl_token_metadata::pda::find_metadata_delegate_record_account( + mpl_token_metadata::accounts::MetadataDelegateRecord::find_pda( &input.collection_mint, MetadataDelegateRole::Collection, &input.collection_update_authority, diff --git a/crates/cmds-solana/src/nft/mod.rs b/crates/cmds-solana/src/nft/mod.rs index 1bf0ff11..fc90ac9b 100644 --- a/crates/cmds-solana/src/nft/mod.rs +++ b/crates/cmds-solana/src/nft/mod.rs @@ -7,7 +7,7 @@ use serde::{Deserialize, Serialize}; // pub mod approve_use_authority; pub mod arweave_file_upload; pub mod arweave_nft_upload; -// pub mod candy_machine_v3; +pub mod candy_machine_v3; pub mod create_master_edition; pub mod create_metadata_account; pub mod v1; From eafb1b01d7dbecddd8bbb1e058ff24c404f419bc Mon Sep 17 00:00:00 2001 From: Duy Do Date: Wed, 8 Nov 2023 23:07:02 +0700 Subject: [PATCH 2/2] Check for missing commands --- crates/db/src/connection/admin.rs | 14 ++++++++ crates/flow-server/src/main.rs | 53 ++++++++++++++++++++++++++----- 2 files changed, 59 insertions(+), 8 deletions(-) diff --git a/crates/db/src/connection/admin.rs b/crates/db/src/connection/admin.rs index eb739e7f..4f98e371 100644 --- a/crates/db/src/connection/admin.rs +++ b/crates/db/src/connection/admin.rs @@ -28,6 +28,20 @@ impl AdminConn { Self { conn } } + pub async fn get_natives_commands(self) -> crate::Result> { + self.conn + .query( + r#"SELECT data->>'node_id' FROM nodes WHERE type = 'native' AND "isPublic""#, + &[], + ) + .await + .map_err(Error::exec("get_natives_commands"))? + .into_iter() + .map(|r| r.try_get::<_, String>(0)) + .collect::, _>>() + .map_err(Error::data("nodes.data->>'node_id'")) + } + pub async fn copy_in_flow_run_logs(&self, rows: I) -> crate::Result where I: IntoIterator, diff --git a/crates/flow-server/src/main.rs b/crates/flow-server/src/main.rs index b4c4ea39..7f218d02 100644 --- a/crates/flow-server/src/main.rs +++ b/crates/flow-server/src/main.rs @@ -11,8 +11,9 @@ use flow_server::{ user::{SignatureAuth, SupabaseAuth}, wss, Config, }; -use futures_util::future::ok; -use std::convert::Infallible; +use futures_util::{future::ok, TryFutureExt}; +use hashbrown::HashSet; +use std::{borrow::Cow, convert::Infallible}; use utils::address_book::AddressBook; // avoid commands being optimized out by the compiler @@ -83,6 +84,32 @@ async fn main() { } }; + if let DbPool::Real(db) = &db { + let res = db + .get_admin_conn() + .and_then(move |conn| async move { + let names = conn.get_natives_commands().await?; + let mut missing = HashSet::new(); + for name in names { + if !natives.contains(&&Cow::Borrowed(name.as_str())) { + missing.insert(name); + } + } + Ok(missing) + }) + .await; + match res { + Ok(missing) => { + if !missing.is_empty() { + tracing::warn!("missing native commands: {:?}", missing); + } + } + Err(error) => { + tracing::error!("{}", error); + } + } + } + let db_worker = db_worker::DBWorker::new(db.clone(), config.clone(), actors).start(); let sig_auth = SignatureAuth::new(rand::random()); @@ -133,11 +160,18 @@ async fn main() { .service(api::kvstore::write_item::service(&config, db.clone())) .service(api::kvstore::delete_item::service(&config, db.clone())) .service(api::kvstore::read_item::service(&config, db.clone())); - let db_route = web::scope("/proxy") - .service(api::db_rpc::service(&config, db.clone())) - .service(api::db_push_logs::service(&config, db.clone())) - .service(api::auth_proxy::service(&config, db.clone())) - .service(api::ws_auth_proxy::service(&config, db.clone())); + + let db_proxy = if matches!(db, DbPool::Real(_)) { + Some( + web::scope("/proxy") + .service(api::db_rpc::service(&config, db.clone())) + .service(api::db_push_logs::service(&config, db.clone())) + .service(api::auth_proxy::service(&config, db.clone())) + .service(api::ws_auth_proxy::service(&config, db.clone())), + ) + } else { + None + }; let app = App::new() .wrap(Logger::new(r#""%r" %s %b %Dms"#).exclude("/healthcheck")) @@ -153,12 +187,15 @@ async fn main() { app = app.service(auth); } + if let Some(db_proxy) = db_proxy { + app = app.service(db_proxy); + } + app.service(flow) .service(signature) .service(apikeys) .service(websocket) .service(kvstore) - .service(db_route) .service(healthcheck) }) .bind((host, port))