-
Notifications
You must be signed in to change notification settings - Fork 391
refactor(sdk): Remove NetworkArg + Make functions that accept Network methods of Network
#1598
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
Changes from all commits
f6caa0d
c221ae4
48fa154
e525096
cd58390
a86bf1e
709e130
4d04fb3
8e00949
de8237d
413aada
a98da8a
4922d46
efd4308
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,4 +24,4 @@ url = "2.5.0" | |
| hex = "0.4.3" | ||
| ciborium = "=0.2.2" | ||
| serde_repr = "0.1.19" | ||
| dialoguer = "0.11.0" | ||
| dialoguer = "0.11.0" | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -11,13 +11,20 @@ use ethers::types::transaction::eip712::Eip712; | |||||
| use ethers::types::transaction::eip712::Eip712Error; | ||||||
| use ethers::types::Address; | ||||||
| use ethers::types::Signature; | ||||||
| use ethers::types::H160; | ||||||
| use ethers::types::U256; | ||||||
| use lambdaworks_crypto::merkle_tree::{ | ||||||
| merkle::MerkleTree, proof::Proof, traits::IsMerkleTreeBackend, | ||||||
| }; | ||||||
| use serde::{Deserialize, Serialize}; | ||||||
| use sha3::{Digest, Keccak256}; | ||||||
|
|
||||||
| use super::constants::{ | ||||||
| ALIGNED_SERVICE_MANAGER_DEVNET, ALIGNED_SERVICE_MANAGER_HOLESKY, | ||||||
| ALIGNED_SERVICE_MANAGER_HOLESKY_STAGE, ALIGNED_SERVICE_MANAGER_MAINNET, | ||||||
| BATCHER_PAYMENT_SERVICE_ADDRESS_DEVNET, BATCHER_PAYMENT_SERVICE_ADDRESS_HOLESKY, | ||||||
| BATCHER_PAYMENT_SERVICE_ADDRESS_HOLESKY_STAGE, BATCHER_PAYMENT_SERVICE_ADDRESS_MAINNET, | ||||||
| }; | ||||||
| use super::errors::VerifySignatureError; | ||||||
|
|
||||||
| // VerificationData is a bytes32 instead of a VerificationData struct because in the BatcherPaymentService contract | ||||||
|
|
@@ -396,12 +403,37 @@ pub enum GetNonceResponseMessage { | |||||
| InvalidRequest(String), | ||||||
| } | ||||||
|
|
||||||
| #[derive(Debug, Clone, Copy)] | ||||||
| #[derive(Debug, Clone)] | ||||||
| pub enum Network { | ||||||
| Devnet, | ||||||
| Holesky, | ||||||
| HoleskyStage, | ||||||
| Mainnet, | ||||||
| Custom(String, String), | ||||||
| } | ||||||
|
|
||||||
| impl Network { | ||||||
| pub fn get_batcher_payment_service_address(&self) -> ethers::types::H160 { | ||||||
| match self { | ||||||
| Self::Devnet => H160::from_str(BATCHER_PAYMENT_SERVICE_ADDRESS_DEVNET).unwrap(), | ||||||
| Self::Holesky => H160::from_str(BATCHER_PAYMENT_SERVICE_ADDRESS_HOLESKY).unwrap(), | ||||||
| Self::HoleskyStage => { | ||||||
| H160::from_str(BATCHER_PAYMENT_SERVICE_ADDRESS_HOLESKY_STAGE).unwrap() | ||||||
| } | ||||||
| Self::Mainnet => H160::from_str(BATCHER_PAYMENT_SERVICE_ADDRESS_MAINNET).unwrap(), | ||||||
| Self::Custom(s, _) => H160::from_str(s.as_str()).unwrap(), | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| pub fn get_aligned_service_manager_address(&self) -> ethers::types::H160 { | ||||||
|
Contributor
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. Nit: pass by copy:
Suggested change
Contributor
Author
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. Great catch! @Oppen |
||||||
| match self { | ||||||
| Self::Devnet => H160::from_str(ALIGNED_SERVICE_MANAGER_DEVNET).unwrap(), | ||||||
| Self::Holesky => H160::from_str(ALIGNED_SERVICE_MANAGER_HOLESKY).unwrap(), | ||||||
| Self::HoleskyStage => H160::from_str(ALIGNED_SERVICE_MANAGER_HOLESKY_STAGE).unwrap(), | ||||||
| Self::Mainnet => H160::from_str(ALIGNED_SERVICE_MANAGER_MAINNET).unwrap(), | ||||||
| Self::Custom(_, s) => H160::from_str(s.as_str()).unwrap(), | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| impl FromStr for Network { | ||||||
|
|
@@ -413,10 +445,24 @@ impl FromStr for Network { | |||||
| "holesky-stage" => Ok(Network::HoleskyStage), | ||||||
| "devnet" => Ok(Network::Devnet), | ||||||
| "mainnet" => Ok(Network::Mainnet), | ||||||
| _ => Err( | ||||||
| "Invalid network, possible values are: \"holesky\", \"holesky-stage\", \"devnet\", \"mainnet\"" | ||||||
| .to_string(), | ||||||
| ), | ||||||
| s => { | ||||||
| if !s.contains("custom") { | ||||||
| return Err( | ||||||
| "Invalid network, possible values are: \"holesky\", \"holesky-stage\", \"devnet\", \"mainnet\", \"custom <BATCHER_PAYMENT_SERVICE_ADDRESS> <ALIGNED_SERVICE_MANAGER_ADDRESS>\"" | ||||||
| .to_string(), | ||||||
| ); | ||||||
| } | ||||||
| let parts: Vec<&str> = s.split_whitespace().collect(); | ||||||
|
|
||||||
| if parts.len() == 3 && parts[0].contains("custom") { | ||||||
| Ok(Network::Custom(parts[1].to_string(), parts[2].to_string())) | ||||||
| } else { | ||||||
| Err( | ||||||
| "Invalid custom network, \"custom <BATCHER_PAYMENT_SERVICE_ADDRESS, ALIGNED_SERVICE_MANAGER_ADDRESS>\"" | ||||||
| .to_string() | ||||||
| ) | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
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: pass by copy:
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.
Great catch! @Oppen
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.
Now that
Custom(String, String)it's no longer a good idea to pass by copy. That's also true foris_proof_verified.