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

Feat: Enable Radon scripts to run on binary sources #2406

Open
wants to merge 19 commits into
base: 2.0-base
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "witnet"
version = "1.6.7"
version = "2.0.0"
authors = ["Witnet Foundation <[email protected]>"]
publish = false
repository = "witnet/witnet-rust"
Expand Down
2 changes: 1 addition & 1 deletion bridges/centralized-ethereum/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "witnet-centralized-ethereum-bridge"
version = "1.6.7"
version = "2.0.0"
authors = ["Witnet Foundation <[email protected]>"]
edition = "2018"

Expand Down
2 changes: 1 addition & 1 deletion data_structures/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ authors = ["Witnet Foundation <[email protected]>"]
description = "data structures component"
edition = "2021"
name = "witnet_data_structures"
version = "1.6.7"
version = "2.0.0"
workspace = ".."

[features]
Expand Down
17 changes: 13 additions & 4 deletions data_structures/src/chain/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1645,11 +1645,17 @@ pub enum RADType {
/// HTTP POST request
#[serde(rename = "HTTP-POST")]
HttpPost,
/// HTTP HEAD request
#[serde(rename = "HTTP-HEAD")]
HttpHead,
}

impl RADType {
pub fn is_http(&self) -> bool {
matches!(self, RADType::HttpGet | RADType::HttpPost)
matches!(
self,
RADType::HttpGet | RADType::HttpPost | RADType::HttpHead
)
}
}

Expand Down Expand Up @@ -1701,7 +1707,7 @@ pub struct RADRetrieve {
pub script: Vec<u8>,
/// Body of a HTTP-POST request
pub body: Vec<u8>,
/// Extra headers of a HTTP-GET or HTTP-POST request
/// Extra headers of a HTTP-GET, HTTP-POST or HTTP-HEAD request
pub headers: Vec<(String, String)>,
}

Expand Down Expand Up @@ -1810,6 +1816,9 @@ impl RADRetrieve {
&[Field::Body, Field::Headers],
)
}
RADType::HttpHead => {
check(&[Field::Kind, Field::Url, Field::Script], &[Field::Headers])
}
}
}

Expand Down Expand Up @@ -2681,7 +2690,7 @@ impl TransactionsPool {
for input in &vt_tx.body.inputs {
self.output_pointer_map
.entry(input.output_pointer)
.or_insert_with(Vec::new)
.or_default()
.push(vt_tx.hash());
}

Expand All @@ -2706,7 +2715,7 @@ impl TransactionsPool {
for input in &dr_tx.body.inputs {
self.output_pointer_map
.entry(input.output_pointer)
.or_insert_with(Vec::new)
.or_default()
.push(dr_tx.hash());
}

Expand Down
2 changes: 1 addition & 1 deletion data_structures/src/data_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ impl DataRequestPool {

self.data_requests_by_epoch
.entry(epoch)
.or_insert_with(HashSet::new)
.or_default()
.insert(dr_hash);
self.data_request_pool.insert(dr_hash, dr_state);

Expand Down
2 changes: 2 additions & 0 deletions data_structures/src/proto/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ impl ProtobufConvert for chain::RADType {
chain::RADType::HttpGet => witnet::DataRequestOutput_RADRequest_RADType::HttpGet,
chain::RADType::Rng => witnet::DataRequestOutput_RADRequest_RADType::Rng,
chain::RADType::HttpPost => witnet::DataRequestOutput_RADRequest_RADType::HttpPost,
chain::RADType::HttpHead => witnet::DataRequestOutput_RADRequest_RADType::HttpHead,
}
}

Expand All @@ -60,6 +61,7 @@ impl ProtobufConvert for chain::RADType {
witnet::DataRequestOutput_RADRequest_RADType::HttpGet => chain::RADType::HttpGet,
witnet::DataRequestOutput_RADRequest_RADType::Rng => chain::RADType::Rng,
witnet::DataRequestOutput_RADRequest_RADType::HttpPost => chain::RADType::HttpPost,
witnet::DataRequestOutput_RADRequest_RADType::HttpHead => chain::RADType::HttpHead,
})
}
}
Expand Down
2 changes: 2 additions & 0 deletions data_structures/src/radon_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ pub enum RadonErrors {
HTTPError = 0x30,
/// Al least one of the sources could not be retrieved, timeout reached.
RetrieveTimeout = 0x31,
/// Value cannot be extracted from binary buffer
BufferIsNotValue = 0x32,
// Math errors
/// Math operator caused an underflow.
Underflow = 0x40,
Expand Down
4 changes: 2 additions & 2 deletions data_structures/src/serialization_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ struct RADRetrieveSerializationHelperJson {
/// Body of a HTTP-POST request
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub body: Vec<u8>,
/// Extra headers of a HTTP-GET or HTTP-POST request
/// Extra headers of a HTTP-GET, HTTP-HEAD or HTTP-POST request
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub headers: Vec<(String, String)>,
}
Expand All @@ -377,7 +377,7 @@ struct RADRetrieveSerializationHelperBincode {
pub script: Vec<u8>,
/// Body of a HTTP-POST request
pub body: Vec<u8>,
/// Extra headers of a HTTP-GET or HTTP-POST request
/// Extra headers of a HTTP-GET, HTTP-HEAD or HTTP-POST request
pub headers: Vec<(String, String)>,
}

Expand Down
2 changes: 1 addition & 1 deletion net/src/client/http/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ pub struct WitnetHttpResponse {

impl WitnetHttpResponse {
#[inline]
/// Simple wrapper around `isahc::Response::status`.
/// Simple wrapper around `isahc::Response`.
pub fn inner(self) -> isahc::Response<isahc::AsyncBody> {
self.res
}
Expand Down
2 changes: 1 addition & 1 deletion node/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "witnet_node"
version = "1.6.7"
version = "2.0.0"
authors = ["Witnet Foundation <[email protected]>"]
workspace = ".."
description = "node component"
Expand Down
2 changes: 1 addition & 1 deletion rad/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "witnet_rad"
version = "0.3.2"
version = "0.3.3"
authors = ["Witnet Foundation <[email protected]>"]
edition = "2021"
workspace = ".."
Expand Down
5 changes: 5 additions & 0 deletions rad/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,10 @@ impl RadError {
}

Ok(RadonError::new(match kind {
RadonErrors::BufferIsNotValue => {
let (description,) = deserialize_args(error_args)?;
RadError::BufferIsNotValue { description }
}
RadonErrors::RequestTooManySources => RadError::RequestTooManySources,
RadonErrors::ScriptTooManyCalls => RadError::ScriptTooManyCalls,
RadonErrors::Overflow => RadError::Overflow,
Expand Down Expand Up @@ -574,6 +578,7 @@ impl RadError {
pub fn try_into_error_code(&self) -> Result<RadonErrors, RadError> {
Ok(match self {
RadError::Unknown => RadonErrors::Unknown,
RadError::BufferIsNotValue { .. } => RadonErrors::BufferIsNotValue,
RadError::SourceScriptNotCBOR => RadonErrors::SourceScriptNotCBOR,
RadError::SourceScriptNotArray => RadonErrors::SourceScriptNotArray,
RadError::SourceScriptNotRADON => RadonErrors::SourceScriptNotRADON,
Expand Down
Loading
Loading