-
Notifications
You must be signed in to change notification settings - Fork 15
serviceability: add Feed catalog account and CRUD #3953
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
Open
nikw9944
wants to merge
1
commit into
main
Choose a base branch
from
nikw9944/infra-1700-1-feed-catalog
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| use clap::{Args, Subcommand}; | ||
|
|
||
| use crate::feed::{create::*, delete::*, get::*, list::*, update::*}; | ||
|
|
||
| #[derive(Args, Debug)] | ||
| pub struct FeedCliCommand { | ||
| #[command(subcommand)] | ||
| pub command: FeedCommands, | ||
| } | ||
|
|
||
| #[derive(Debug, Subcommand)] | ||
| pub enum FeedCommands { | ||
| /// Create a new feed (catalog entry) | ||
| #[clap()] | ||
| Create(CreateFeedCliCommand), | ||
| /// Update a feed's name or metro map | ||
| #[clap()] | ||
| Update(UpdateFeedCliCommand), | ||
| /// List all feeds | ||
| #[clap()] | ||
| List(ListFeedCliCommand), | ||
| /// Get details for a specific feed | ||
| #[clap()] | ||
| Get(GetFeedCliCommand), | ||
| /// Delete a feed (must have no references) | ||
| #[clap()] | ||
| Delete(DeleteFeedCliCommand), | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| use crate::{doublezerocommand::CliCommand, feed::parse_metro, validators::validate_code}; | ||
| use clap::Args; | ||
| use doublezero_cli_core::{print_signature, require, CliContext, RequirementCheck}; | ||
| use doublezero_sdk::commands::feed::create::CreateFeedCommand; | ||
| use solana_sdk::pubkey::Pubkey; | ||
| use std::io::Write; | ||
|
|
||
| #[derive(Args, Debug)] | ||
| pub struct CreateFeedCliCommand { | ||
| /// Unique code for the feed (immutable; used as the PDA seed) | ||
| #[arg(long, value_parser = validate_code)] | ||
| pub code: String, | ||
| /// Human-readable name for the feed | ||
| #[arg(long)] | ||
| pub name: String, | ||
| /// Metro mapping `EXCHANGE_PK=GROUP_PK[,GROUP_PK...]` (repeatable). Omit for a feed with no | ||
| /// metro restriction (reachable from any exchange). | ||
| #[arg(long = "metro", value_parser = parse_metro)] | ||
| pub metros: Vec<(Pubkey, Vec<Pubkey>)>, | ||
| } | ||
|
|
||
| impl CreateFeedCliCommand { | ||
| pub async fn execute<C: CliCommand, W: Write>( | ||
| self, | ||
| _ctx: &CliContext, | ||
| client: &C, | ||
| out: &mut W, | ||
| ) -> eyre::Result<()> { | ||
| require!( | ||
| client, | ||
| RequirementCheck::KEYPAIR | RequirementCheck::BALANCE | ||
| ); | ||
|
|
||
| let (signature, _pubkey) = client.create_feed(CreateFeedCommand { | ||
| code: self.code, | ||
| name: self.name, | ||
| metros: self.metros, | ||
| })?; | ||
|
|
||
| print_signature(out, &signature) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| use crate::{doublezerocommand::CliCommand, validators::validate_pubkey_or_code}; | ||
| use clap::Args; | ||
| use doublezero_cli_core::{print_signature, require, CliContext, RequirementCheck}; | ||
| use doublezero_sdk::commands::feed::{delete::DeleteFeedCommand, get::GetFeedCommand}; | ||
| use std::io::Write; | ||
|
|
||
| #[derive(Args, Debug)] | ||
| pub struct DeleteFeedCliCommand { | ||
| /// Feed pubkey or code to delete | ||
| #[arg(long, value_parser = validate_pubkey_or_code)] | ||
| pub pubkey: String, | ||
| } | ||
|
|
||
| impl DeleteFeedCliCommand { | ||
| pub async fn execute<C: CliCommand, W: Write>( | ||
| self, | ||
| _ctx: &CliContext, | ||
| client: &C, | ||
| out: &mut W, | ||
| ) -> eyre::Result<()> { | ||
| require!( | ||
| client, | ||
| RequirementCheck::KEYPAIR | RequirementCheck::BALANCE | ||
| ); | ||
|
|
||
| let (pubkey, _feed) = client.get_feed(GetFeedCommand { | ||
| pubkey_or_code: self.pubkey, | ||
| })?; | ||
|
|
||
| let signature = client.delete_feed(DeleteFeedCommand { pubkey })?; | ||
| print_signature(out, &signature) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| use crate::{doublezerocommand::CliCommand, validators::validate_pubkey_or_code}; | ||
| use clap::Args; | ||
| use doublezero_cli_core::{render_record, CliContext, OutputFormat}; | ||
| use doublezero_sdk::commands::feed::get::GetFeedCommand; | ||
| use serde::Serialize; | ||
| use std::io::Write; | ||
| use tabled::Tabled; | ||
|
|
||
| #[derive(Args, Debug)] | ||
| pub struct GetFeedCliCommand { | ||
| /// Feed pubkey or code to get details for | ||
| #[arg(long, value_parser = validate_pubkey_or_code)] | ||
| pub pubkey: String, | ||
| /// Output as JSON | ||
| #[arg(long)] | ||
| pub json: bool, | ||
| } | ||
|
|
||
| #[derive(Tabled, Serialize)] | ||
| struct FeedDisplay { | ||
| pub account: String, | ||
| pub code: String, | ||
| pub name: String, | ||
| /// Number of metros (exchanges) in the feed map. Empty ⇒ no metro restriction. | ||
| pub metros: usize, | ||
| pub reference_count: u32, | ||
| pub owner: String, | ||
| } | ||
|
|
||
| impl GetFeedCliCommand { | ||
| pub async fn execute<C: CliCommand, W: Write>( | ||
| self, | ||
| _ctx: &CliContext, | ||
| client: &C, | ||
| out: &mut W, | ||
| ) -> eyre::Result<()> { | ||
| let (pubkey, feed) = client.get_feed(GetFeedCommand { | ||
| pubkey_or_code: self.pubkey, | ||
| })?; | ||
|
|
||
| let display = FeedDisplay { | ||
| account: pubkey.to_string(), | ||
| code: feed.code, | ||
| name: feed.name, | ||
| metros: feed.metros.len(), | ||
| reference_count: feed.reference_count, | ||
| owner: feed.owner.to_string(), | ||
| }; | ||
|
|
||
| render_record(out, &display, OutputFormat::from_flags(self.json, false)) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| use crate::doublezerocommand::CliCommand; | ||
| use clap::Args; | ||
| use doublezero_cli_core::{render_collection, CliContext, OutputFormat}; | ||
| use doublezero_program_common::serializer; | ||
| use doublezero_sdk::commands::feed::list::ListFeedCommand; | ||
| use serde::Serialize; | ||
| use solana_sdk::pubkey::Pubkey; | ||
| use std::io::Write; | ||
| use tabled::Tabled; | ||
|
|
||
| #[derive(Args, Debug)] | ||
| pub struct ListFeedCliCommand { | ||
| /// Output in JSON format | ||
| #[arg(long, default_value_t = false)] | ||
| pub json: bool, | ||
| /// Output in compact JSON format | ||
| #[arg(long, default_value_t = false)] | ||
| pub json_compact: bool, | ||
| } | ||
|
|
||
| #[derive(Tabled, Serialize)] | ||
| pub struct FeedDisplay { | ||
| #[serde(serialize_with = "serializer::serialize_pubkey_as_string")] | ||
| pub account: Pubkey, | ||
| pub code: String, | ||
| pub name: String, | ||
| pub metros: usize, | ||
| pub reference_count: u32, | ||
| #[serde(serialize_with = "serializer::serialize_pubkey_as_string")] | ||
| pub owner: Pubkey, | ||
| } | ||
|
|
||
| impl ListFeedCliCommand { | ||
| pub async fn execute<C: CliCommand, W: Write>( | ||
| self, | ||
| _ctx: &CliContext, | ||
| client: &C, | ||
| out: &mut W, | ||
| ) -> eyre::Result<()> { | ||
| let feeds = client.list_feed(ListFeedCommand)?; | ||
|
|
||
| let mut displays: Vec<FeedDisplay> = feeds | ||
| .into_iter() | ||
| .map(|(pubkey, feed)| FeedDisplay { | ||
| account: pubkey, | ||
| code: feed.code, | ||
| name: feed.name, | ||
| metros: feed.metros.len(), | ||
| reference_count: feed.reference_count, | ||
| owner: feed.owner, | ||
| }) | ||
| .collect(); | ||
|
|
||
| displays.sort_by(|a, b| a.code.cmp(&b.code)); | ||
|
|
||
| render_collection( | ||
| out, | ||
| displays, | ||
| OutputFormat::from_flags(self.json, self.json_compact), | ||
| ) | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| pub mod create; | ||
| pub mod delete; | ||
| pub mod get; | ||
| pub mod list; | ||
| pub mod update; | ||
|
|
||
| use solana_sdk::pubkey::Pubkey; | ||
| use std::str::FromStr; | ||
|
|
||
| /// Parse a `--metro` argument of the form `EXCHANGE_PK=GROUP_PK[,GROUP_PK...]` into | ||
| /// `(exchange_pk, [group_pk, ...])`. An empty group list (`EXCHANGE_PK=`) is allowed. | ||
| pub fn parse_metro(s: &str) -> Result<(Pubkey, Vec<Pubkey>), String> { | ||
| let (exchange, groups) = s | ||
| .split_once('=') | ||
| .ok_or_else(|| format!("expected EXCHANGE_PK=GROUP_PK[,GROUP_PK...], got '{s}'"))?; | ||
| let exchange_pk = | ||
| Pubkey::from_str(exchange.trim()).map_err(|e| format!("invalid exchange pubkey: {e}"))?; | ||
| let group_pks = groups | ||
| .split(',') | ||
| .map(str::trim) | ||
| .filter(|g| !g.is_empty()) | ||
| .map(|g| Pubkey::from_str(g).map_err(|e| format!("invalid group pubkey '{g}': {e}"))) | ||
| .collect::<Result<Vec<_>, _>>()?; | ||
| Ok((exchange_pk, group_pks)) | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::parse_metro; | ||
| use solana_sdk::pubkey::Pubkey; | ||
|
|
||
| #[test] | ||
| fn test_parse_metro() { | ||
| let ex = Pubkey::new_unique(); | ||
| let g1 = Pubkey::new_unique(); | ||
| let g2 = Pubkey::new_unique(); | ||
| let (e, gs) = parse_metro(&format!("{ex}={g1},{g2}")).unwrap(); | ||
| assert_eq!(e, ex); | ||
| assert_eq!(gs, vec![g1, g2]); | ||
|
|
||
| // No groups is allowed. | ||
| let (e, gs) = parse_metro(&format!("{ex}=")).unwrap(); | ||
| assert_eq!(e, ex); | ||
| assert!(gs.is_empty()); | ||
|
|
||
| assert!(parse_metro("not-a-pair").is_err()); | ||
| assert!(parse_metro("bad=alsoBad").is_err()); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: prefer turbofish at the callsite over annotating the binding —
.collect::<Vec<FeedDisplay>>()(or just let the followingsort_byinfer it) rather thanlet mut displays: Vec<FeedDisplay> =.