Skip to content

Commit

Permalink
mpl 3.1.0 (#4)
Browse files Browse the repository at this point in the history
* mpl 3.1.0

* Check for missing commands

---------

Co-authored-by: enzotar <[email protected]>
  • Loading branch information
juchiast and enzotar authored Nov 8, 2023
1 parent e14682d commit 2617d33
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 21 deletions.
13 changes: 7 additions & 6 deletions crates/cmds-solana/src/nft/candy_machine_v3/initialize.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
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;

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;

Check warning on line 21 in crates/cmds-solana/src/nft/candy_machine_v3/initialize.rs

View workflow job for this annotation

GitHub Actions / clippy

unused import: `once_cell::sync::Lazy`

warning: unused import: `once_cell::sync::Lazy` --> crates/cmds-solana/src/nft/candy_machine_v3/initialize.rs:21:9 | 21 | use once_cell::sync::Lazy; | ^^^^^^^^^^^^^^^^^^^^^

Check warning on line 21 in crates/cmds-solana/src/nft/candy_machine_v3/initialize.rs

View workflow job for this annotation

GitHub Actions / clippy

unused import: `once_cell::sync::Lazy`

warning: unused import: `once_cell::sync::Lazy` --> crates/cmds-solana/src/nft/candy_machine_v3/initialize.rs:21:9 | 21 | use once_cell::sync::Lazy; | ^^^^^^^^^^^^^^^^^^^^^
Expand Down Expand Up @@ -82,7 +83,7 @@ async fn run(mut ctx: Context, input: Input) -> Result<Output, CommandError> {

// 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(),
Expand Down
11 changes: 5 additions & 6 deletions crates/cmds-solana/src/nft/candy_machine_v3/mint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,15 @@ use solana_sdk::{compute_budget::ComputeBudgetInstruction, pubkey::Pubkey};

use mpl_token_metadata::{
accounts::{MasterEdition, Metadata},
instructions::MetadataDelegateRole,
types::MetadataDelegateRole,
};

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;

Check warning on line 20 in crates/cmds-solana/src/nft/candy_machine_v3/mint.rs

View workflow job for this annotation

GitHub Actions / clippy

unused import: `once_cell::sync::Lazy`

warning: unused import: `once_cell::sync::Lazy` --> crates/cmds-solana/src/nft/candy_machine_v3/mint.rs:20:9 | 20 | use once_cell::sync::Lazy; | ^^^^^^^^^^^^^^^^^^^^^

Check warning on line 20 in crates/cmds-solana/src/nft/candy_machine_v3/mint.rs

View workflow job for this annotation

GitHub Actions / clippy

unused import: `once_cell::sync::Lazy`

warning: unused import: `once_cell::sync::Lazy` --> crates/cmds-solana/src/nft/candy_machine_v3/mint.rs:20:9 | 20 | use once_cell::sync::Lazy; | ^^^^^^^^^^^^^^^^^^^^^
Expand Down Expand Up @@ -71,7 +70,7 @@ pub struct Output {
}

async fn run(mut ctx: Context, input: Input) -> Result<Output, CommandError> {
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();

Expand All @@ -96,15 +95,15 @@ async fn run(mut ctx: Context, input: Input) -> Result<Output, CommandError> {
);

// 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,
)
.0;

// 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,
Expand Down
2 changes: 1 addition & 1 deletion crates/cmds-solana/src/nft/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
14 changes: 14 additions & 0 deletions crates/db/src/connection/admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,20 @@ impl AdminConn {
Self { conn }
}

pub async fn get_natives_commands(self) -> crate::Result<Vec<String>> {
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::<Result<Vec<_>, _>>()
.map_err(Error::data("nodes.data->>'node_id'"))
}

pub async fn copy_in_flow_run_logs<I>(&self, rows: I) -> crate::Result<u64>
where
I: IntoIterator,
Expand Down
53 changes: 45 additions & 8 deletions crates/flow-server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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"))
Expand All @@ -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))
Expand Down

0 comments on commit 2617d33

Please sign in to comment.