-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for sending signed payloads to beacon node
- Loading branch information
Showing
11 changed files
with
932 additions
and
61 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
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,44 @@ | ||
#[derive(Debug)] | ||
pub enum BeaconNodeError { | ||
InvalidBeaconNodeURI, | ||
ClientConfigurationError, | ||
NodeCommunicationError, | ||
Non200Response, | ||
} | ||
|
||
/// A trait for types that can be sent to beacon node as-is | ||
/// without transformations | ||
pub trait BeaconNodeExportable { | ||
/// Export an entity as JSON | ||
fn export(&self) -> serde_json::Value; | ||
|
||
/// The path at beacon node where to send data | ||
fn beacon_node_path(&self) -> String; | ||
|
||
/// Send the JSON payload to beacon node | ||
fn send_beacon_payload(&self, beacon_node_uri: url::Url) -> Result<(), BeaconNodeError> { | ||
let reqwc = reqwest::blocking::Client::builder() | ||
.build() | ||
.map_err(|_| BeaconNodeError::ClientConfigurationError)?; | ||
let joined_url = beacon_node_uri | ||
.join(&self.beacon_node_path()) | ||
.map_err(|_| BeaconNodeError::InvalidBeaconNodeURI)?; | ||
let resp = reqwc | ||
.post(joined_url) | ||
.header("Content-Type", "application/json") | ||
.body(self.export().to_string()) | ||
.send(); | ||
|
||
match resp { | ||
Ok(response) => { | ||
let code = response.status().as_u16(); | ||
if code != 200 { | ||
Err(BeaconNodeError::Non200Response) | ||
} else { | ||
Ok(()) | ||
} | ||
} | ||
Err(_) => Err(BeaconNodeError::NodeCommunicationError), | ||
} | ||
} | ||
} |
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
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
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
Oops, something went wrong.