This repository has been archived by the owner on Nov 6, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
private-tx: replace error_chain #10510
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ada76ce
Update to vanilla tx pool error
ascjones 62ffc13
private-tx: remove error-chain, implement Error, derive Display
ascjones 4f447a7
private-tx: replace ErrorKind and bail!
ascjones 23a3495
private-tx: add missing From impls and other compiler errors
ascjones 9961042
private-tx: use original tx-pool error
ascjones f291baf
Don't be silly cargo
ascjones File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,7 +31,7 @@ use crypto; | |
use futures::Future; | ||
use fetch::{Fetch, Client as FetchClient, Method, BodyReader, Request}; | ||
use bytes::{Bytes, ToPretty}; | ||
use error::{Error, ErrorKind}; | ||
use error::Error; | ||
use url::Url; | ||
use super::Signer; | ||
use super::key_server_keys::address_to_key; | ||
|
@@ -111,11 +111,11 @@ impl SecretStoreEncryptor { | |
return Ok(key); | ||
} | ||
let contract_address_signature = self.sign_contract_address(contract_address)?; | ||
let requester = self.config.key_server_account.ok_or_else(|| ErrorKind::KeyServerAccountNotSet)?; | ||
let requester = self.config.key_server_account.ok_or_else(|| Error::KeyServerAccountNotSet)?; | ||
|
||
// key id in SS is H256 && we have H160 here => expand with assitional zeros | ||
let contract_address_extended: H256 = contract_address.into(); | ||
let base_url = self.config.base_url.clone().ok_or_else(|| ErrorKind::KeyServerNotSet)?; | ||
let base_url = self.config.base_url.clone().ok_or_else(|| Error::KeyServerNotSet)?; | ||
|
||
// prepare request url | ||
let url = format!("{}/{}/{}{}", | ||
|
@@ -132,24 +132,24 @@ impl SecretStoreEncryptor { | |
Method::GET | ||
}; | ||
|
||
let url = Url::from_str(&url).map_err(|e| ErrorKind::Encrypt(e.to_string()))?; | ||
let url = Url::from_str(&url).map_err(|e| Error::Encrypt(e.to_string()))?; | ||
let response = self.client.fetch(Request::new(url, method), Default::default()).wait() | ||
.map_err(|e| ErrorKind::Encrypt(e.to_string()))?; | ||
.map_err(|e| Error::Encrypt(e.to_string()))?; | ||
|
||
if response.is_not_found() { | ||
bail!(ErrorKind::EncryptionKeyNotFound(*contract_address)); | ||
return Err(Error::EncryptionKeyNotFound(*contract_address)); | ||
} | ||
|
||
if !response.is_success() { | ||
bail!(ErrorKind::Encrypt(response.status().canonical_reason().unwrap_or("unknown").into())); | ||
return Err(Error::Encrypt(response.status().canonical_reason().unwrap_or("unknown").into())); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unrelated: unwrap_or_else |
||
} | ||
|
||
// read HTTP response | ||
let mut result = String::new(); | ||
BodyReader::new(response).read_to_string(&mut result)?; | ||
|
||
// response is JSON string (which is, in turn, hex-encoded, encrypted Public) | ||
let encrypted_bytes: ethjson::bytes::Bytes = result.trim_matches('\"').parse().map_err(|e| ErrorKind::Encrypt(e))?; | ||
let encrypted_bytes: ethjson::bytes::Bytes = result.trim_matches('\"').parse().map_err(|e| Error::Encrypt(e))?; | ||
|
||
// decrypt Public | ||
let decrypted_bytes = self.signer.decrypt(requester, &crypto::DEFAULT_MAC, &encrypted_bytes)?; | ||
|
@@ -189,7 +189,7 @@ impl SecretStoreEncryptor { | |
} | ||
|
||
fn sign_contract_address(&self, contract_address: &Address) -> Result<Signature, Error> { | ||
let key_server_account = self.config.key_server_account.ok_or_else(|| ErrorKind::KeyServerAccountNotSet)?; | ||
let key_server_account = self.config.key_server_account.ok_or_else(|| Error::KeyServerAccountNotSet)?; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unrelated: |
||
Ok(self.signer.sign(key_server_account, address_to_key(contract_address))?) | ||
} | ||
} | ||
|
@@ -204,7 +204,7 @@ impl Encryptor for SecretStoreEncryptor { | |
// retrieve the key, try to generate it if it doesn't exist yet | ||
let key = match self.retrieve_key("", false, contract_address) { | ||
Ok(key) => Ok(key), | ||
Err(Error(ErrorKind::EncryptionKeyNotFound(_), _)) => { | ||
Err(Error::EncryptionKeyNotFound(_)) => { | ||
trace!(target: "privatetx", "Key for account wasnt found in sstore. Creating. Address: {:?}", contract_address); | ||
self.retrieve_key(&format!("/{}", self.config.threshold), true, contract_address) | ||
} | ||
|
@@ -215,7 +215,7 @@ impl Encryptor for SecretStoreEncryptor { | |
let mut cypher = Vec::with_capacity(plain_data.len() + initialisation_vector.len()); | ||
cypher.extend(repeat(0).take(plain_data.len())); | ||
crypto::aes::encrypt_128_ctr(&key, initialisation_vector, plain_data, &mut cypher) | ||
.map_err(|e| ErrorKind::Encrypt(e.to_string()))?; | ||
.map_err(|e| Error::Encrypt(e.to_string()))?; | ||
cypher.extend_from_slice(&initialisation_vector); | ||
|
||
Ok(cypher) | ||
|
@@ -230,7 +230,7 @@ impl Encryptor for SecretStoreEncryptor { | |
// initialization vector takes INIT_VEC_LEN bytes | ||
let cypher_len = cypher.len(); | ||
if cypher_len < INIT_VEC_LEN { | ||
bail!(ErrorKind::Decrypt("Invalid cypher".into())); | ||
return Err(Error::Decrypt("Invalid cypher".into())); | ||
} | ||
|
||
// retrieve existing key | ||
|
@@ -241,7 +241,7 @@ impl Encryptor for SecretStoreEncryptor { | |
let mut plain_data = Vec::with_capacity(cypher_len - INIT_VEC_LEN); | ||
plain_data.extend(repeat(0).take(cypher_len - INIT_VEC_LEN)); | ||
crypto::aes::decrypt_128_ctr(&key, &iv, cypher, &mut plain_data) | ||
.map_err(|e| ErrorKind::Decrypt(e.to_string()))?; | ||
.map_err(|e| Error::Decrypt(e.to_string()))?; | ||
Ok(plain_data) | ||
} | ||
} | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unrelated to this PR but this is a needless closure should be
ok_or
insteadError::KeyServerAccountNotSet
is just value