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

forge(verify): OKLink support #7586

Closed
wants to merge 17 commits into from
Closed

forge(verify): OKLink support #7586

wants to merge 17 commits into from

Conversation

bixia
Copy link
Contributor

@bixia bixia commented Apr 7, 2024

Motivation

To add support for the OKLink explorer contract verification. since the OKLink use almost the same API as the etherscan does for the contract verification part. the only difference is that the OKLink requires the Ok-Access-Key pass in the header, while etherscan requires the x-apiKey pass in the header.

Solution

So, basically i reuse lots of code from etherscan part, and modify accordingly, by adding the specific header.

Reference

Closes #7724

Copy link
Member

@Evalir Evalir left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should #7373 be closed in favor of this?

@bixia
Copy link
Contributor Author

bixia commented Apr 9, 2024

Should #7373 be closed in favor of this?

already closed, as request

@bixia bixia requested a review from Evalir April 10, 2024 01:46
Copy link
Member

@mattsse mattsse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how is the oklink API different from etherscan?

if it's the same, we can likely reuse a lot of code

@bixia
Copy link
Contributor Author

bixia commented Apr 19, 2024

how is the oklink API different from etherscan?

if it's the same, we can likely reuse a lot of code

yes, it is almost the same, except for the headers

@bixia
Copy link
Contributor Author

bixia commented Apr 19, 2024

but for the headers, i find that the function i needed is from another crate. so i decide to copy it inside the verify function.

@mattsse
Copy link
Member

mattsse commented Apr 20, 2024

are the headers strictly required?

if the API is compatible we can drastically simplify this, starting with a match here:

match s {
"e" | "etherscan" => Ok(VerificationProviderType::Etherscan),
"s" | "sourcify" => Ok(VerificationProviderType::Sourcify),
"b" | "blockscout" => Ok(VerificationProviderType::Blockscout),
_ => Err(format!("Unknown provider: {s}")),
}

if we need the headers then we can also add support for this by configuring the EtherscanVerificationProvider

here

impl VerificationProviderType {
/// Returns the corresponding `VerificationProvider` for the key
pub fn client(&self, key: &Option<String>) -> Result<Box<dyn VerificationProvider>> {
match self {

@bixia
Copy link
Contributor Author

bixia commented Apr 22, 2024

are the headers strictly required?

if the API is compatible we can drastically simplify this, starting with a match here:

match s {
"e" | "etherscan" => Ok(VerificationProviderType::Etherscan),
"s" | "sourcify" => Ok(VerificationProviderType::Sourcify),
"b" | "blockscout" => Ok(VerificationProviderType::Blockscout),
_ => Err(format!("Unknown provider: {s}")),
}

if we need the headers then we can also add support for this by configuring the EtherscanVerificationProvider

here

impl VerificationProviderType {
/// Returns the corresponding `VerificationProvider` for the key
pub fn client(&self, key: &Option<String>) -> Result<Box<dyn VerificationProvider>> {
match self {

yes, header is strictly required. and the headers' field name is changed to Ok-Access-Key

the main problem is that:

  • most etherscan function is private, and can not be accessed out of the etherscan folder.
  • the way etherscan post the request is handled over to foundry_block_explorers crate. which means i must modify the foundry_block_explorers part to add support for our specific header requirement.

to avoid this problem, inside this PR, i reuse some function from etherscan folder, and not use foundry_block_explorers as etherscan does, but rewrite in raw reqwest function.

by doing this, the modification to ur original code is minimal. all the modification is located in my oklink.rs file.

@mattsse
Copy link
Member

mattsse commented Apr 22, 2024

by doing this, the modification to ur original code is minimal

I don't want to have effectively have the same code twice, if all we need is a few additional headers.

this can easily be supported by:

adding helper functions to set default headers here:

https://github.com/foundry-rs/block-explorers/blob/30a0476a712721b583c85e0b98a9680105e56a91/crates/block-explorers/src/lib.rs#L275

install default headers to the client here:

https://github.com/foundry-rs/block-explorers/blob/30a0476a712721b583c85e0b98a9680105e56a91/crates/block-explorers/src/lib.rs#L377

then the

pub struct EtherscanVerificationProvider {

can have an additional map of headers that are then installed via the builder here:

let mut builder = Client::builder();

@DaniPopes
Copy link
Member

Can you also please look at #7733, should the API URL just be https://www.oklink.com/api here https://github.com/alloy-rs/chains/blob/14af647606c6945f433252ed96cd47397771e6ba/src/named.rs#L783 ?

@bixia
Copy link
Contributor Author

bixia commented Apr 23, 2024

@bixia
Copy link
Contributor Author

bixia commented Apr 23, 2024

by doing this, the modification to ur original code is minimal

I don't want to have effectively have the same code twice, if all we need is a few additional headers.

this can easily be supported by:

adding helper functions to set default headers here:

https://github.com/foundry-rs/block-explorers/blob/30a0476a712721b583c85e0b98a9680105e56a91/crates/block-explorers/src/lib.rs#L275

install default headers to the client here:

https://github.com/foundry-rs/block-explorers/blob/30a0476a712721b583c85e0b98a9680105e56a91/crates/block-explorers/src/lib.rs#L377

then the

pub struct EtherscanVerificationProvider {

can have an additional map of headers that are then installed via the builder here:

let mut builder = Client::builder();

i have discussed with our team member. the oklink API is not 100% compactable with etherscan API. since the etherscan API will change from time to time, oklink API may not keep up with it.
to help user who utilize foundry to verify contracts on oklink, we prefer to keep it separate and simple, and not tight to etherscan too much.

@bixia
Copy link
Contributor Author

bixia commented Apr 28, 2024

hi @mattsse the block_explore code layout has been transformed a lot.
image
should i just add another crate like the blob-explore?
i mean: it will be three explore: blob-explore, block-explore and oklink-explore.
since not only the headers, but also the url is totally different from each other between oklink and etherscan

@bixia
Copy link
Contributor Author

bixia commented May 13, 2024

close this PR in favor of #7915

@bixia bixia closed this May 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for OKLink verification
5 participants