Skip to content

Commit 065a41f

Browse files
committed
the rest of todos
1 parent ce03230 commit 065a41f

File tree

11 files changed

+172
-72
lines changed

11 files changed

+172
-72
lines changed

Cargo.lock

Lines changed: 8 additions & 41 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

adapter/src/ethereum/client.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use ethsign::{KeyFile, Signature};
1010
use primitives::{Address, BigNum, Chain, ChainId, ChainOf, Channel, Config, ValidatorId};
1111

1212
use super::{
13-
error::{Error, EwtSigningError, KeystoreError, VerifyError},
13+
error::{Error, KeystoreError, VerifyError, OutpaceError},
1414
ewt::{self, Payload},
1515
to_ethereum_signed, Electrum, LockedWallet, UnlockedWallet, WalletState, IDENTITY_ABI,
1616
OUTPACE_ABI,
@@ -282,8 +282,7 @@ impl Unlocked for Ethereum<UnlockedWallet> {
282282
.state
283283
.wallet
284284
.sign(&message)
285-
// TODO: This is not entirely true, we do not sign an Ethereum Web Token but Outpace state_root
286-
.map_err(|err| EwtSigningError::SigningMessage(err.to_string()))?;
285+
.map_err(|err| OutpaceError::SignStateroot(err.to_string()))?;
287286

288287
Ok(format!("0x{}", hex::encode(wallet_sign.to_electrum())))
289288
}

adapter/src/ethereum/error.rs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ impl From<Error> for AdapterError {
2222
err @ Error::ContractInitialization(..) => AdapterError::adapter(err),
2323
err @ Error::ContractQuerying(..) => AdapterError::adapter(err),
2424
err @ Error::VerifyAddress(..) => AdapterError::adapter(err),
25+
err @ Error::OutpaceError( .. ) => AdapterError::adapter(err),
2526
err @ Error::AuthenticationTokenNotIntendedForUs { .. } => {
2627
AdapterError::authentication(err)
2728
}
@@ -74,6 +75,8 @@ pub enum Error {
7475
},
7576
#[error("Insufficient privilege")]
7677
InsufficientAuthorizationPrivilege,
78+
#[error("Outpace contract error: {0}")]
79+
OutpaceError(#[from] OutpaceError),
7780
}
7881

7982
#[derive(Debug, Error)]
@@ -123,6 +126,12 @@ pub enum EwtSigningError {
123126
DecodingHexSignature(#[from] hex::FromHexError),
124127
}
125128

129+
#[derive(Debug, Error)]
130+
pub enum OutpaceError {
131+
#[error("Error while signing outpace contract: {0}")]
132+
SignStateroot(String),
133+
}
134+
126135
#[derive(Debug, Error)]
127136
pub enum EwtVerifyError {
128137
#[error("The Ethereum Web Token header is invalid")]
@@ -142,12 +151,18 @@ pub enum EwtVerifyError {
142151
/// or if Signature V component is not in "Electrum" notation (`< 27`).
143152
#[error("Error when decoding token signature")]
144153
InvalidSignature,
154+
#[error("Payload error: {0}")]
155+
Payload(#[from] PayloadError)
156+
}
157+
158+
#[derive(Debug, Error)]
159+
pub enum PayloadError {
145160
#[error("Payload decoding: {0}")]
146-
PayloadDecoding(#[source] base64::DecodeError),
161+
Decoding(#[source] base64::DecodeError),
147162
#[error("Payload deserialization: {0}")]
148-
PayloadDeserialization(#[from] serde_json::Error),
163+
Deserialization(#[from] serde_json::Error),
149164
#[error("Payload is not a valid UTF-8 string: {0}")]
150-
PayloadUtf8(#[from] std::str::Utf8Error),
165+
Utf8(#[from] std::str::Utf8Error),
151166
}
152167

153168
#[cfg(test)]

adapter/src/ethereum/ewt.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use serde::{Deserialize, Serialize};
77
use web3::signing::keccak256;
88

99
use super::{
10-
error::{EwtSigningError, EwtVerifyError},
10+
error::{EwtSigningError, EwtVerifyError, PayloadError},
1111
to_ethereum_signed, Electrum,
1212
};
1313

@@ -54,14 +54,13 @@ pub struct Payload {
5454

5555
impl Payload {
5656
/// Decodes the [`Payload`] from a base64 encoded json string
57-
// TODO: replace with own error?
58-
pub fn base64_decode(encoded_json: &str) -> Result<Self, EwtVerifyError> {
57+
pub fn base64_decode(encoded_json: &str) -> Result<Self, PayloadError> {
5958
let base64_decode = base64::decode_config(encoded_json, base64::URL_SAFE_NO_PAD)
60-
.map_err(EwtVerifyError::PayloadDecoding)?;
59+
.map_err(PayloadError::Decoding)?;
6160

62-
let json = std::str::from_utf8(&base64_decode).map_err(EwtVerifyError::PayloadUtf8)?;
61+
let json = std::str::from_utf8(&base64_decode).map_err(PayloadError::Utf8)?;
6362

64-
serde_json::from_str(json).map_err(EwtVerifyError::PayloadDeserialization)
63+
serde_json::from_str(json).map_err(PayloadError::Deserialization)
6564
}
6665
}
6766

adview-manager/src/helpers.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,6 @@ pub fn get_unit_html_with_events(
156156
let body =
157157
serde_json::to_string(&events_body).expect("It should always serialize EventBody");
158158

159-
// TODO: check whether the JSON body with `''` quotes executes correctly!
160159
let fetch_opts = format!("var fetchOpts = {{ method: 'POST', headers: {{ 'content-type': 'application/json' }}, body: {body} }};");
161160

162161
let validators: String = validators

primitives/Cargo.toml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,6 @@ required-features = ["test-util"]
8383
# (De)Serialization
8484
serde = { version = "1.0", features = ["derive"] }
8585
serde_json = "1.0"
86-
# TODO: Remove once we change `ChannelId` Serialize impl
87-
serde-hex = "0.1"
8886
serde_millis = "0.1"
8987
# Used prefixes on field for targeting::Input, and `campaign::Active`
9088
serde_with = "2"
@@ -106,7 +104,7 @@ ethereum-types = "0.13"
106104
parse-display = "0.5"
107105
# CID & multihash / multibase
108106
cid = "0.8"
109-
hex = "0.4"
107+
hex = { version = "0.4", features = ["serde"] }
110108
merkletree = "0.10"
111109
tiny-keccak = { version = "2", features = ["keccak"] }
112110
url = { version = "2", features = ["serde"] }

primitives/src/analytics/query.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@ pub struct Time {
9999
/// - a timestamp in milliseconds
100100
/// **Note:** [`DateHour`] rules should be uphold, this means that passed values should always be rounded to hours
101101
/// And it should not contain **minutes**, **seconds** or **nanoseconds**
102-
// TODO: Either Timestamp (number) or DateTime (string) de/serialization
103102
pub start: DateHour<Utc>,
104103
/// The End [`DateHour`] which will fetch `analytics_time <= end` and should be after Start [`DateHour`]!
105104
pub end: Option<DateHour<Utc>>,

primitives/src/channel.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,17 @@ use std::{fmt, ops::Deref, str::FromStr};
22

33
use ethereum_types::U256;
44

5-
use serde::{Deserialize, Deserializer, Serialize};
6-
use serde_hex::{SerHex, StrictPfx};
5+
use serde::{Deserialize, Deserializer, Serialize, Serializer};
76

87
use hex::{FromHex, FromHexError};
98

10-
use crate::{Address, Validator, ValidatorId};
9+
use crate::{Address, Validator, ValidatorId, ToHex};
1110

12-
#[derive(Serialize, Deserialize, PartialEq, Eq, Copy, Clone, Hash)]
11+
#[derive(Deserialize, PartialEq, Eq, Copy, Clone, Hash)]
1312
#[serde(transparent)]
1413
pub struct ChannelId(
1514
#[serde(
1615
deserialize_with = "deserialize_channel_id",
17-
serialize_with = "SerHex::<StrictPfx>::serialize"
1816
)]
1917
[u8; 32],
2018
);
@@ -39,6 +37,15 @@ where
3937
validate_channel_id(&channel_id).map_err(serde::de::Error::custom)
4038
}
4139

40+
impl Serialize for ChannelId {
41+
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
42+
where
43+
S: Serializer,
44+
{
45+
serializer.serialize_str(&self.0.to_hex_prefixed())
46+
}
47+
}
48+
4249
fn validate_channel_id(s: &str) -> Result<[u8; 32], FromHexError> {
4350
// strip `0x` prefix
4451
let hex = s.strip_prefix("0x").unwrap_or(s);

sentry/src/db.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,6 @@ pub mod tests_postgres {
347347
let manager =
348348
deadpool_postgres::Manager::from_config(config, NoTls, self.manager_config.clone());
349349

350-
// TODO: Fix error mapping
351350
let pool = deadpool_postgres::Pool::builder(manager)
352351
.max_size(15)
353352
.build()

0 commit comments

Comments
 (0)