Skip to content

Commit

Permalink
Remove Display and FromStr for OracleResponse. (#3323)
Browse files Browse the repository at this point in the history
## Motivation

The `FromStr` and `Display` implementations for `OracleResponse` are not
used anywhere, and make it a lot more complicated to add new oracle
variants, especially if they involve complex types. We will soon have to
add one for events.

## Proposal

Remove `FromStr` and `Display`.

## Test Plan

CI will tell us if it was used after all!

## Release Plan

- Nothing to do / These changes follow the usual release cycle.

## Links

- [reviewer
checklist](https://github.com/linera-io/linera-protocol/blob/main/CONTRIBUTING.md#reviewer-checklist)
  • Loading branch information
afck authored Feb 13, 2025
1 parent d2d0d07 commit db789e5
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 45 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

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

1 change: 0 additions & 1 deletion examples/Cargo.lock

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

1 change: 0 additions & 1 deletion linera-base/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ anyhow.workspace = true
async-graphql.workspace = true
async-graphql-derive.workspace = true
async-trait.workspace = true
base64.workspace = true
bcs.workspace = true
cfg-if.workspace = true
chrono.workspace = true
Expand Down
42 changes: 0 additions & 42 deletions linera-base/src/data_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ use std::{
str::FromStr,
};

use anyhow::Context as _;
use async_graphql::{InputObject, SimpleObject};
use base64::engine::{general_purpose::STANDARD_NO_PAD, Engine as _};
use custom_debug_derive::Debug;
use linera_witty::{WitLoad, WitStore, WitType};
#[cfg(with_metrics)]
Expand Down Expand Up @@ -786,46 +784,6 @@ pub enum OracleResponse {
Round(Option<u32>),
}

impl Display for OracleResponse {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
OracleResponse::Service(bytes) => {
write!(f, "Service:{}", STANDARD_NO_PAD.encode(bytes))?
}
OracleResponse::Post(bytes) => write!(f, "Post:{}", STANDARD_NO_PAD.encode(bytes))?,
OracleResponse::Blob(blob_id) => write!(f, "Blob:{}", blob_id)?,
OracleResponse::Assert => write!(f, "Assert")?,
OracleResponse::Round(Some(round)) => write!(f, "Round:{round}")?,
OracleResponse::Round(None) => write!(f, "Round:None")?,
};

Ok(())
}
}

impl FromStr for OracleResponse {
type Err = anyhow::Error;

fn from_str(s: &str) -> Result<Self, Self::Err> {
if let Some(string) = s.strip_prefix("Service:") {
return Ok(OracleResponse::Service(
STANDARD_NO_PAD.decode(string).context("Invalid base64")?,
));
}
if let Some(string) = s.strip_prefix("Post:") {
return Ok(OracleResponse::Post(
STANDARD_NO_PAD.decode(string).context("Invalid base64")?,
));
}
if let Some(string) = s.strip_prefix("Blob:") {
return Ok(OracleResponse::Blob(
BlobId::from_str(string).context("Invalid BlobId")?,
));
}
Err(anyhow::anyhow!("Invalid enum! Enum: {}", s))
}
}

impl<'de> BcsHashable<'de> for OracleResponse {}

/// Description of the necessary information to run a user application.
Expand Down

0 comments on commit db789e5

Please sign in to comment.