Skip to content

Commit

Permalink
sike this is real release 0.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
billythedummy committed Dec 12, 2023
1 parent f78cae1 commit dbc4694
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 13 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- No longer generates `*IxArgs` struct if no instruction args.
- No longer generates `*Accounts` `*Keys` structs and `*_verify_account_keys()` function if instruction has no account inputs.
- All reference types for `*Keys` and `*Accounts` have been changed to pass by value since they impl `Copy`
- Replaced `solana-program` dependency with `bs58`

## [0.4.0] - 2023-08-07

Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ members = [

[workspace.dependencies]
borsh = "^0.10"
bs58 = ">=0.1"
bytemuck = "^1"
lazy_static = "^1"
num-derive = "^0.3"
Expand Down
2 changes: 1 addition & 1 deletion solores/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ name = "solores"
name = "solores"

[dependencies]
bs58 = { workspace = true }
clap = { version = "^4.0.29", features = ["derive"] }
env_logger = "^0.10.0"
heck = "^0.4.0"
Expand All @@ -47,7 +48,6 @@ quote = "^1.0"
serde = { version = "^1.0", features = ["derive"] }
serde_json = "^1"
sha2 = "^0.10"
solana-program = { workspace = true }
syn = { version = "^1.0", features = ["full"] }
toml = "^0.7.6"
void = "^1.0"
Expand Down
35 changes: 24 additions & 11 deletions solores/src/write_src.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,35 @@
use proc_macro2::{Ident, Span, TokenStream};
use quote::quote;
use solana_program::pubkey::Pubkey;
use std::{io::Write, path::Path, str::FromStr};
use std::{io::Write, path::Path};

use crate::{idl_format::IdlFormat, utils::open_file_create_overwrite, Args};

const DEFAULT_PROGRAM_ID_STR: &str = "TH1S1SNoTAVAL1DPUBKEYDoNoTUSE11111111111111";

const MAX_BASE58_LEN: usize = 44;
const PUBKEY_BYTES_SIZE: usize = 32;

/// Copied from solana_program::Pubkey::from_str()
/// so that we dont have to have solana_program as a dep
fn is_valid_pubkey(s: &str) -> bool {
if s.len() > MAX_BASE58_LEN {
return false;
}
let pubkey_vec = match bs58::decode(s).into_vec() {
Ok(v) => v,
Err(_) => return false,
};
if pubkey_vec.len() != PUBKEY_BYTES_SIZE {
return false;
}
true
}

pub fn write_lib(args: &Args, idl: &dyn IdlFormat) -> std::io::Result<()> {
let user_provided_id_opt = args.program_id.as_ref().and_then(|s| {
Pubkey::from_str(s)
.map_err(|e| {
log::warn!("provided pubkey {s} invalid. Error: {e}");
e
})
.ok()
.map(|_| s)
});
let user_provided_id_opt =
args.program_id
.as_ref()
.and_then(|s| if is_valid_pubkey(s) { Some(s) } else { None });
let id = user_provided_id_opt
.map(|string| string.as_ref())
.unwrap_or_else(|| {
Expand Down

0 comments on commit dbc4694

Please sign in to comment.