-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
WIP: Try killing declare_id! by moving it into the #[program] macro. #868
Closed
Closed
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
37ed8e9
Try moving declare_id! within the #[program] macro.
cqfd 587f997
More robust + nicer error messages.
cqfd d865288
Whoops, stowaway logs.
cqfd 073bce8
Try to give better program_id error messages.
cqfd 2d558ab
Pass cfg provider.cluster as ANCHOR_CLUSTER env var.
cqfd a370158
Hack to get cargo build to rerun macros even if no changes.
cqfd 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 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 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 |
---|---|---|
|
@@ -25,3 +25,4 @@ serde_json = "1.0" | |
sha2 = "0.9.2" | ||
thiserror = "1.0" | ||
bs58 = "0.3.1" | ||
toml = "0.5.8" |
This file contains 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 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,17 @@ | ||
use quote::quote; | ||
|
||
use crate::Program; | ||
|
||
pub fn generate(program: &Program) -> proc_macro2::TokenStream { | ||
let anchor_toml = std::fs::read_to_string("./Anchor.toml") | ||
.map(|s| s.parse::<toml::Value>()) | ||
.unwrap() | ||
.unwrap(); | ||
let cluster = std::env::var("ANCHOR_CLUSTER").unwrap_or("localnet".to_string()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ^ This env var is WIP, I was thinking the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sgtm |
||
let program_id = anchor_toml["programs"][cluster][&program.name.to_string()].to_string(); | ||
// strip quotes, urgh | ||
let program_id = &program_id[1..program_id.len() - 1]; | ||
quote! { | ||
::anchor_lang::declare_id!(#program_id); | ||
} | ||
} |
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.
What should happen if the program id isn't in the Anchor.toml?
I think it would convenient if it looked for the default deploy key in the local filesystem. I.e.
target/deploy/<program-name>-keypair.json
, which is whatsolana program deploy
uses by default. Then everything would work by default, i.e., you can clone, test, and deploy without any modifications--since you would have the keypair locally for the deploy.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.
Yeah, was wondering about all the error handling 😬
So the desired behavior is: check for the id in Anchor.toml first, otherwise fall back to target/deploy/-keypair.json? (I realized working on this that I need to learn more about the Anchor.toml format, what each part means/entails etc.)
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.
Having an issue including
solana-sdk
as a dependency so this macro can useKeypair
, when I try to useanchor build
etc. I get a ring 0.16.20 build error. Not sure why yet (maybe becauseanchor build
uses build-bpf whereas other places that usesolana-sdk
, e.g. the cli, don't?).Will try again tomorrow.
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.
^ Have gotten around that for now by just snagging the final 32 bytes of the on-disk keypair and bs58-ing it 🙃