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(Radon): Enhance handling of hex-string, integers and binary buffers #2413

Open
wants to merge 25 commits into
base: 2.0-base
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
5bbea50
feat: implement HttpHead as new RADType
guidiaz Oct 10, 2023
3fdf8f9
chore: cargo fmt --all
guidiaz Oct 10, 2023
721347a
feat: handle repeated headers within http/head response
guidiaz Oct 11, 2023
ef30733
test: run valid http head retrieval
guidiaz Oct 11, 2023
a665397
test: try http-head data request w/ invalid request header
guidiaz Oct 11, 2023
198e5b8
chore: bump package versions
guidiaz Oct 11, 2023
9bae448
chore: cargo fmt --all
guidiaz Oct 11, 2023
af5ff86
chore: solve clippy warnings
guidiaz Oct 11, 2023
ac57ded
fix: use http::Response::headers(&self) to transform response to HTTP…
guidiaz Oct 11, 2023
5e073f9
chore: attend pr review comments
guidiaz Oct 20, 2023
6c4d1ac
feat(rad): add support to binary sources
guidiaz Oct 20, 2023
0cfd81d
chore(rad): refactor existing tests
guidiaz Oct 20, 2023
68c7648
chore: attend pr review comments
guidiaz Oct 26, 2023
184f768
chore: cargo clippy --fix
guidiaz Oct 26, 2023
cd4641c
feat(rad): add new RadonErrors::BufferIsNotValue
guidiaz Oct 26, 2023
f1314a4
fix(rad): http-head response headers can contain 'accept-ranges'
guidiaz Nov 14, 2023
1f2402b
feat(rad): implement StringReplace
guidiaz Nov 14, 2023
533c103
feat(rad): implement StringSlice
guidiaz Nov 14, 2023
b3322b1
feat(rad): implement StringSplit
guidiaz Nov 14, 2023
88c8674
feat(rad): first approach to ArrayJoin
guidiaz Nov 14, 2023
0ab36ce
chore(rad): rename asX <-> toX depending on whether conversion may fail
guidiaz Dec 13, 2023
1c7a4a2
feat(rad): implement RadonOpCodes::BytesAsInteger
guidiaz Dec 13, 2023
ae50ed8
feat(rad): support multiple encoding schemas on RadonOpCodes::BytesSt…
guidiaz Dec 13, 2023
888ef3b
feat(rad): implement RadonOpCodes::IntegerToBytes
guidiaz Dec 13, 2023
179503c
feat(rad): implement RadonOpCodes::StringAsBytes
guidiaz Dec 13, 2023
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
31 changes: 20 additions & 11 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
5 changes: 4 additions & 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 All @@ -10,6 +10,7 @@ description = "RAD component"
rocksdb-backend = ["witnet_data_structures/rocksdb-backend"]

[dependencies]
base64 = "0.21.5"
cbor-codec = { git = "https://github.com/witnet/cbor-codec.git", branch = "feat/ldexpf-shim" }
failure = "0.1.8"
futures = "0.3.4"
Expand All @@ -23,9 +24,11 @@ minidom = { git = "https://github.com/witnet/xmpp-rs", rev = "bc8a33ff5da95ee403
num_enum = "0.4.2"
ordered-float = "3.0"
rand = "0.7.3"
regex = "1.4.2"
serde = "1.0.111"
serde_cbor = "0.11.2"
serde_json = "1.0.96"
slicestring = "0.3.2"
# the url crate is used to perform additional validations before passing arguments to the surf http client
# the version of url must be kept in sync with the version used by surf in the `witnet_net` crate
url = "2.1.1"
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