Skip to content
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

feat: implement error parser and error lookup #137

Merged
merged 11 commits into from
Jun 19, 2022
Next Next commit
feat: added a structure for downloading errors
  • Loading branch information
sunguru98 committed May 30, 2022
commit e5fc7c7308d477cac5f82bf8ca4b43a52a811e7b
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
/temp
/binaries
.test_files
docs-src/book
docs-src/book
.error_files
54 changes: 54 additions & 0 deletions scripts/fetch-errors.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
RED() { echo $'\e[1;31m'$1$'\e[0m'; }
GRN() { echo $'\e[1;32m'$1$'\e[0m'; }
CYN() { echo $'\e[1;36m'$1$'\e[0m'; }

abort_on_error() {
if [ ! $1 -eq 0 ]; then
RED "Aborting: operation failed"
exit 1
fi
}

download_file() {
curl -L $1 --output "$2"
abort_on_error $?

SIZE=$(wc -c "$2" | grep -oE "[0-9]+" | head -n 1)

if [ $SIZE -eq 0 ]; then
RED "Aborting: could not download Sugar distribution"
exit 1
fi
}

DOWNLOAD_DIST="$PWD/src/.error_files"
mkdir $DOWNLOAD_DIST


CYN "🍬 Metaboss Error Fetching script"
echo "---------------------------------------"
echo ""

echo "$(CYN "1.") 🖥 $(CYN "Downlading error files")"
echo ""

download_file "https://raw.githubusercontent.com/project-serum/anchor/master/lang/src/error.rs" "$DOWNLOAD_DIST/anchor-error.rs"

download_file "https://raw.githubusercontent.com/metaplex-foundation/metaplex-program-library/master/candy-machine/program/src/errors.rs" "$DOWNLOAD_DIST/candy-error.rs"

download_file "https://raw.githubusercontent.com/metaplex-foundation/metaplex-program-library/master/token-metadata/program/src/error.rs" "$DOWNLOAD_DIST/metadata-error.rs"

echo ""
echo "$(CYN "2.") 📤 $(CYN "Updating Metaboss")"
echo ""
cargo install --locked --path "$PWD"

echo ""
echo "$(CYN "3.") 📤 $(CYN "Parsing errors")"
echo ""
metaboss parse-errors file -l error

# rm -Rf "$DOWNLOAD_DIST"



7 changes: 5 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ async fn main() -> Result<()> {
// Set rate limiting if the user specified a public RPC.
if PUBLIC_RPC_URLS.contains(&rpc.as_str()) {
warn!(
"Using a public RPC URL is not recommended for heavy tasks as you will be rate-limited and suffer a performance hit.
Please use a private RPC endpoint for best performance results."
"Using a public RPC URL is not recommended for heavy tasks as you will be rate-limited and suffer a performance hit"
);
warn!("Please use a private RPC endpoint for best performance results.");
*USE_RATE_LIMIT.write().unwrap() = true;
} else if RATE_LIMIT_DELAYS.contains_key(&rpc.as_str()) {
*USE_RATE_LIMIT.write().unwrap() = true;
Expand Down Expand Up @@ -85,6 +85,9 @@ async fn main() -> Result<()> {
Command::Withdraw {
withdraw_subcommands,
} => process_withdraw(rpc, withdraw_subcommands)?,
Command::ParseErrors {
parse_errors_subcommands
} => process_parse_errors(parse_errors_subcommands)?
}

println!("Done!");
Expand Down
16 changes: 16 additions & 0 deletions src/opt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ pub struct Opt {

#[derive(Debug, StructOpt)]
pub enum Command {
/// Parse Errors commands
#[structopt(name = "parse-errors")]
ParseErrors {
#[structopt(subcommand)]
parse_errors_subcommands: ParseErrorsSubCommands,
},
/// NFT collections commands
#[structopt(name = "collections")]
Collections {
Expand Down Expand Up @@ -809,3 +815,13 @@ pub enum WithdrawSubcommands {
keypair: Option<String>,
},
}

#[derive(Debug, StructOpt)]
pub enum ParseErrorsSubCommands {
#[structopt(name = "file")]
File,
Code {
/// Error code
error_code: String
}
}
4 changes: 4 additions & 0 deletions src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,10 @@ pub fn parse_cli_creators(new_creators: String, should_append: bool) -> Result<V
Ok(creators)
}

pub fn parse_errors() -> Result<()> {
Ok(())
}

// #[cfg(test)]
// mod tests {
// use super::*;
Expand Down
12 changes: 12 additions & 0 deletions src/process_subcommands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use crate::derive::{get_cmv2_pda, get_edition_pda, get_generic_pda, get_metadata
use crate::find::find_missing_editions_process;
use crate::mint::{mint_editions, mint_list, mint_missing_editions, mint_one};
use crate::opt::*;
use crate::parse::parse_errors;
use crate::sign::{sign_all, sign_one};
use crate::snapshot::{snapshot_cm_accounts, snapshot_holders, snapshot_mints};
use crate::update_metadata::*;
Expand Down Expand Up @@ -389,3 +390,14 @@ pub fn process_withdraw(rpc_url: String, commands: WithdrawSubcommands) -> Resul
}),
}
}

pub fn process_parse_errors(commands: ParseErrorsSubCommands) -> Result<()> {
match commands {
ParseErrorsSubCommands::Code { error_code} => {
Ok(())
},
ParseErrorsSubCommands::File => {
parse_errors()
}
}
}