Skip to content
Merged
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
8 changes: 5 additions & 3 deletions src/connector.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
use crate::fungible_token::*;
use crate::parameters::*;
use crate::sdk;
use crate::types::{AccountId, Balance, EthAddress, Gas, PromiseResult, Proof, ERR_FAILED_PARSE};
use crate::types::{
AccountId, Balance, EthAddress, Gas, PromiseResult, Proof, SdkUnwrap, ERR_FAILED_PARSE,
};

use crate::admin_controlled::{AdminControlled, PausedMask};
use crate::deposit_event::*;
use crate::engine::Engine;
use crate::json::parse_json;
use crate::prelude::*;
use crate::prover::validate_eth_address;
use crate::storage::{self, EthConnectorStorageId, KeyPrefix};
#[cfg(feature = "log")]
use alloc::format;
Expand Down Expand Up @@ -110,7 +111,8 @@ impl EthConnectorContract {
// Get initial contract arguments
let contract_data = EthConnector {
prover_account: args.prover_account,
eth_custodian_address: validate_eth_address(args.eth_custodian_address),
eth_custodian_address: crate::types::validate_eth_address(args.eth_custodian_address)
.sdk_unwrap(),
};
// Save eth-connector specific data
sdk::save_contract(
Expand Down
1 change: 0 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ mod fungible_token;
mod json;
mod log_entry;
mod precompiles;
mod prover;
pub mod sdk;

#[cfg(test)]
Expand Down
225 changes: 0 additions & 225 deletions src/prover.rs

This file was deleted.

42 changes: 40 additions & 2 deletions src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,33 @@ fn long_signature(name: &str, params: &[ParamType]) -> Hash {
H256::from(result)
}

#[derive(Debug)]
pub enum ValidationError {
EthAddressFailedDecode,
WrongEthAddress,
}

impl AsRef<[u8]> for ValidationError {
fn as_ref(&self) -> &[u8] {
match self {
Self::EthAddressFailedDecode => b"FAILED_DECODE_ETH_ADDRESS",
Self::WrongEthAddress => b"WRONG_ETH_ADDRESS",
}
}
}

/// Validate Etherium address from string and return EthAddress
pub fn validate_eth_address(address: String) -> Result<EthAddress, ValidationError> {
let data = hex::decode(address).map_err(|_| ValidationError::EthAddressFailedDecode)?;
if data.len() != 20 {
return Err(ValidationError::WrongEthAddress);
}
assert_eq!(data.len(), 20, "ETH_WRONG_ADDRESS_LENGTH");
let mut result = [0u8; 20];
result.copy_from_slice(&data);
Ok(result)
}

#[derive(Default, BorshDeserialize, BorshSerialize, Clone)]
#[cfg_attr(test, derive(serde::Deserialize, serde::Serialize))]
pub struct Proof {
Expand All @@ -128,6 +155,19 @@ pub struct Proof {
pub proof: Vec<Vec<u8>>,
}

impl Proof {
pub fn get_key(&self) -> String {
let mut data = self.log_index.try_to_vec().unwrap();
data.extend(self.receipt_index.try_to_vec().unwrap());
data.extend(self.header_data.clone());
sdk::sha256(&data[..])
.0
.iter()
.map(|n| n.to_string())
.collect()
}
}

/// Newtype to distinguish balances (denominated in Wei) from other U256 types.
#[derive(Debug, Eq, PartialEq, Copy, Clone, Default)]
pub struct Wei(U256);
Expand Down Expand Up @@ -226,8 +266,6 @@ pub enum ErrorKind {
InvalidEcRecoverSignature,
}

pub type Result<T> = core::result::Result<T, ErrorKind>;

#[allow(dead_code)]
pub fn u256_to_arr(value: &U256) -> [u8; 32] {
let mut result = [0u8; 32];
Expand Down