Skip to content

Commit 8905dce

Browse files
committed
fix: fmt all
1 parent c190a2d commit 8905dce

File tree

820 files changed

+108161
-699
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

820 files changed

+108161
-699
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ members = [
44
"adapter",
55
"primitives",
66
"validator_worker",
7-
"sentry",
7+
# "sentry",
88
"adview-manager",
99
]
1010

Makefile.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
CARGO_MAKE_EXTEND_WORKSPACE_MAKEFILE = "true"
33
CARGO_MAKE_CLIPPY_ARGS = "--all-features -- -D warnings"
44

5+
[tasks.pre-test]
6+
scripts = [
7+
"./scripts/ethereum.sh"
8+
]
9+
510
[tasks.dev-test-flow]
611
dependencies = [
712
"format-flow",

adapter/src/ethereum.rs

Lines changed: 72 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use crate::EthereumChannel;
22
use chrono::Utc;
3+
use ethabi::token::Token;
34
use ethkey::Password;
45
use ethstore::SafeAccount;
56
use lazy_static::lazy_static;
@@ -24,7 +25,6 @@ use web3::{
2425
futures::Future,
2526
types::U256,
2627
};
27-
use ethabi::token::Token;
2828

2929
lazy_static! {
3030
static ref ADEXCORE_ABI: &'static [u8] =
@@ -134,7 +134,7 @@ impl Adapter for EthereumAdapter {
134134
let channel_id = eth_channel
135135
.hash_hex(&self.config.ethereum_core_address)
136136
.map_err(|_| map_error("Failed to hash the channel id"))?;
137-
137+
138138
println!("checking1");
139139
println!("checking2");
140140
let our_channel_id = format!("0x{}", hex::encode(channel.id));
@@ -156,13 +156,19 @@ impl Adapter for EthereumAdapter {
156156
.map_err(|_| map_error("failed to init core contract"))?;
157157

158158
let channel_status: U256 = contract
159-
.query("states", (Token::FixedBytes(channel.id.as_ref().to_vec()),), None, Options::default(), None)
159+
.query(
160+
"states",
161+
(Token::FixedBytes(channel.id.as_ref().to_vec()),),
162+
None,
163+
Options::default(),
164+
None,
165+
)
160166
.wait()
161167
.map_err(|e| {
162168
println!("{:?}", e);
163169
map_error("contract channel status query failed")
164170
})?;
165-
171+
166172
println!(" channel_status {}", channel_status);
167173
if channel_status != *CHANNEL_STATE_ACTIVE {
168174
return Err(AdapterError::Configuration(
@@ -377,16 +383,15 @@ pub fn ewt_verify(
377383
#[cfg(test)]
378384
mod test {
379385
use super::*;
386+
use crate::EthereumChannel;
387+
use chrono::{Duration, Utc};
388+
use ethabi::token::Token;
389+
use hex::FromHex;
380390
use primitives::adapter::KeystoreOptions;
381391
use primitives::config::configuration;
382392
use primitives::ChannelId;
383-
use primitives::{SpecValidators, ValidatorDesc, ChannelSpec, EventSubmission};
384-
use chrono::{Duration, TimeZone, Utc};
393+
use primitives::{ChannelSpec, EventSubmission, SpecValidators, ValidatorDesc};
385394
use std::convert::TryFrom;
386-
use hex::FromHex;
387-
use ethabi::token::{Token};
388-
use crate::EthereumChannel;
389-
390395

391396
fn setup_eth_adapter(contract_address: Option<[u8; 20]>) -> EthereumAdapter {
392397
let mut config = configuration("development", None).expect("failed parse config");
@@ -395,7 +400,7 @@ mod test {
395400
keystore_pwd: "adexvalidator".to_string(),
396401
};
397402

398-
if let Some(ct_address) = contract_address {
403+
if let Some(ct_address) = contract_address {
399404
config.ethereum_core_address = ct_address;
400405
}
401406

@@ -474,12 +479,17 @@ mod test {
474479

475480
#[test]
476481
fn should_validate_channel_properly() {
477-
let (eloop, http) = web3::transports::Http::new("http://localhost:8545").expect("failed to init transport");
482+
let (eloop, http) =
483+
web3::transports::Http::new("http://localhost:8545").expect("failed to init transport");
478484
eloop.into_remote();
479485

480486
let web3 = web3::Web3::new(http);
481-
let leader_account: Address = "Df08F82De32B8d460adbE8D72043E3a7e25A3B39".parse().expect("failed to parse leader account");
482-
let follower_account: Address = "6704Fbfcd5Ef766B287262fA2281C105d57246a6".parse().expect("failed to parse leader account");
487+
let leader_account: Address = "Df08F82De32B8d460adbE8D72043E3a7e25A3B39"
488+
.parse()
489+
.expect("failed to parse leader account");
490+
let _follower_account: Address = "6704Fbfcd5Ef766B287262fA2281C105d57246a6"
491+
.parse()
492+
.expect("failed to parse leader account");
483493

484494
// tokenbytecode.json
485495
let token_bytecode = include_str!("../test/resources/tokenbytecode.json");
@@ -494,62 +504,62 @@ mod test {
494504
let token_contract = Contract::deploy(web3.eth(), token_abi)
495505
.expect("invalid token token contract")
496506
.confirmations(0)
497-
.options(
498-
Options::with(|opt| {
499-
opt.gas_price = Some(1.into());
500-
opt.gas = Some(6_721_975.into());
501-
})
502-
)
503-
.execute(
504-
token_bytecode,
505-
(),
506-
leader_account,
507-
)
507+
.options(Options::with(|opt| {
508+
opt.gas_price = Some(1.into());
509+
opt.gas = Some(6_721_975.into());
510+
}))
511+
.execute(token_bytecode, (), leader_account)
508512
.expect("Correct parameters are passed to the constructor.")
509513
.wait()
510514
.expect("failed to wait");
511-
515+
512516
let adex_contract = Contract::deploy(web3.eth(), adex_abi)
513517
.expect("invalid adex contract")
514518
.confirmations(0)
515-
.options(
516-
Options::with(|opt| {
517-
opt.gas_price = Some(1.into());
518-
opt.gas = Some(6_721_975.into());
519-
})
520-
)
521-
.execute(
522-
adex_bytecode,
523-
(),
524-
leader_account,
525-
)
519+
.options(Options::with(|opt| {
520+
opt.gas_price = Some(1.into());
521+
opt.gas = Some(6_721_975.into());
522+
}))
523+
.execute(adex_bytecode, (), leader_account)
526524
.expect("Correct parameters are passed to the constructor.")
527525
.wait()
528526
.expect("failed to init adex contract");
529-
527+
530528
println!("adex_contract address {:?}", adex_contract.address());
531-
// contract call set balance
532-
token_contract.call("setBalanceTo", (Token::Address(leader_account), Token::Uint(2000.into())), leader_account, Options::default()).wait()
529+
// contract call set balance
530+
token_contract
531+
.call(
532+
"setBalanceTo",
533+
(Token::Address(leader_account), Token::Uint(2000.into())),
534+
leader_account,
535+
Options::default(),
536+
)
537+
.wait()
533538
.expect("Failed to set balance");
534539
println!("token address {}", token_contract.address());
535540

536541
let leader_validator_desc = ValidatorDesc {
537542
// keystore.json addresss (same with js)
538-
id: ValidatorId::try_from("2bdeafae53940669daa6f519373f686c1f3d3393").expect("failed to create id"),
543+
id: ValidatorId::try_from("2bdeafae53940669daa6f519373f686c1f3d3393")
544+
.expect("failed to create id"),
539545
url: "http://localhost:8005".to_string(),
540546
fee: 100.into(),
541547
};
542548

543549
let follower_validator_desc = ValidatorDesc {
544550
// keystore2.json addresss (same with js)
545-
id: ValidatorId::try_from("6704Fbfcd5Ef766B287262fA2281C105d57246a6").expect("failed to create id"),
551+
id: ValidatorId::try_from("6704Fbfcd5Ef766B287262fA2281C105d57246a6")
552+
.expect("failed to create id"),
546553
url: "http://localhost:8006".to_string(),
547554
fee: 100.into(),
548555
};
549556

550557
let mut valid_channel = Channel {
551558
// to be replace with the proper id
552-
id: ChannelId::from_hex("061d5e2a67d0a9a10f1c732bca12a676d83f79663a396f7d87b3e30b9b411088").expect("prep_db: failed to deserialize channel id"),
559+
id: ChannelId::from_hex(
560+
"061d5e2a67d0a9a10f1c732bca12a676d83f79663a396f7d87b3e30b9b411088",
561+
)
562+
.expect("prep_db: failed to deserialize channel id"),
553563
// leader_account
554564
creator: "0xDf08F82De32B8d460adbE8D72043E3a7e25A3B39".to_string(),
555565
deposit_asset: eth_checksum::checksum(&format!("{:?}", token_contract.address())),
@@ -572,24 +582,36 @@ mod test {
572582
};
573583

574584
// convert to eth channel
575-
let eth_channel = EthereumChannel::try_from(&valid_channel).expect("failed to create eth channel");
585+
let eth_channel =
586+
EthereumChannel::try_from(&valid_channel).expect("failed to create eth channel");
576587
let sol_tuple = eth_channel.to_solidity_tuple();
577588

578-
// contract call open channel
579-
adex_contract.call("channelOpen", (sol_tuple,), leader_account, Options::default()).wait()
589+
// contract call open channel
590+
adex_contract
591+
.call(
592+
"channelOpen",
593+
(sol_tuple,),
594+
leader_account,
595+
Options::default(),
596+
)
597+
.wait()
580598
.expect("open channel");
581599

582-
let contract_addr = <[u8; 20]>::from_hex(&format!("{:?}", adex_contract.address())[2..]).expect("failed to deserialise contract addr");
600+
let contract_addr = <[u8; 20]>::from_hex(&format!("{:?}", adex_contract.address())[2..])
601+
.expect("failed to deserialise contract addr");
583602

584603
let channel_id = eth_channel.hash(&contract_addr).expect("hash hex");
585604
println!("channel_id {}", hex::encode(channel_id));
586605
// set id to proper id
587-
valid_channel.id = ChannelId::from_hex(hex::encode(channel_id)).expect("prep_db: failed to deserialize channel id");
606+
valid_channel.id = ChannelId::from_hex(hex::encode(channel_id))
607+
.expect("prep_db: failed to deserialize channel id");
588608

589609
// eth adapter
590610
let mut eth_adapter = setup_eth_adapter(Some(contract_addr));
591611
eth_adapter.unlock().expect("should unlock eth adapter");
592612
// validate channel
593-
eth_adapter.validate_channel(&valid_channel).expect("failed to validate channel");
613+
eth_adapter
614+
.validate_channel(&valid_channel)
615+
.expect("failed to validate channel");
594616
}
595-
}
617+
}

adapter/src/lib.rs

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use std::error::Error;
77
use chrono::{DateTime, Utc};
88
use ethabi::encode;
99
use ethabi::param_type::ParamType;
10-
use ethabi::token::{LenientTokenizer, StrictTokenizer, Tokenizer, Token};
10+
use ethabi::token::{LenientTokenizer, StrictTokenizer, Token, Tokenizer};
1111
use hex::FromHex;
1212
use primitives::channel::ChannelError;
1313
use primitives::BigNum;
@@ -17,7 +17,6 @@ use std::convert::TryFrom;
1717
use tiny_keccak::Keccak;
1818
use web3::types::{Address, U256};
1919

20-
2120
pub use self::dummy::DummyAdapter;
2221
pub use self::ethereum::EthereumAdapter;
2322

@@ -110,9 +109,9 @@ impl TryFrom<&Channel> for EthereumChannel {
110109

111110
impl EthereumChannel {
112111
pub fn new(
113-
creator: &[u8; 20], // 0x prefixed using string helps check if valid eth address
112+
creator: &[u8; 20], // 0x prefixed using string helps check if valid eth address
114113
token_addr: &[u8; 20], // 0x prefixed using string helps check if valid eth address
115-
token_amount: &str, // big num string
114+
token_amount: &str, // big num string
116115
valid_until: DateTime<Utc>,
117116
validators: &[ValidatorId],
118117
spec: &[u8; 32],
@@ -125,10 +124,13 @@ impl EthereumChannel {
125124
let token_addr = Address::from_slice(token_addr);
126125
let token_amount = U256::from_dec_str(&token_amount)
127126
.map_err(|_| ChannelError::InvalidArgument("failed to parse token amount".into()))?;
128-
let valid_until = U256::from_dec_str(&valid_until.timestamp().to_string())
127+
let valid_until = U256::from_dec_str(&valid_until.timestamp().to_string())
129128
.map_err(|_| ChannelError::InvalidArgument("failed to parse valid until".into()))?;
130129

131-
let validators = validators.iter().map(|v| Address::from_slice(v.inner())).collect();
130+
let validators = validators
131+
.iter()
132+
.map(|v| Address::from_slice(v.inner()))
133+
.collect();
132134
// let validator1 = hex::decode("2bdeafae53940669daa6f519373f686c1f3d3393").expect("should deserialize v1");
133135
// let validator2 = hex::decode("6704Fbfcd5Ef766B287262fA2281C105d57246a6").expect("should deserialize v2");
134136

@@ -138,13 +140,13 @@ impl EthereumChannel {
138140
token_amount,
139141
valid_until,
140142
validators,
141-
spec: spec.to_owned()
143+
spec: spec.to_owned(),
142144
})
143145
}
144146

145147
pub fn hash(&self, contract_addr: &[u8; 20]) -> Result<[u8; 32], Box<dyn Error>> {
146148
// println!("hash {} {}, {} {}, {} {}",&self.creator[2..], &self.creator[2..].len(), contract_addr, contract_addr.len(), &self.token_addr[2..], &self.token_addr[2..].len());
147-
149+
148150
// println!("deposit amount 2 {}", self.token_amount);
149151
// println!("valid_until 2 {}", self.valid_until);
150152
let tokens = [
@@ -153,7 +155,12 @@ impl EthereumChannel {
153155
Token::Address(self.token_addr.to_owned()),
154156
Token::Uint(self.token_amount.to_owned()),
155157
Token::Uint(self.valid_until.to_owned()),
156-
Token::Array(self.validators.iter().map(|v| Token::Address(v.to_owned())).collect()),
158+
Token::Array(
159+
self.validators
160+
.iter()
161+
.map(|v| Token::Address(v.to_owned()))
162+
.collect(),
163+
),
157164
Token::FixedBytes(self.spec.to_vec()),
158165
];
159166

@@ -181,13 +188,18 @@ impl EthereumChannel {
181188

182189
// let validator1 = hex::decode("2bdeafae53940669daa6f519373f686c1f3d3393").expect("should deserialize v1");
183190
// let validator2 = hex::decode("6704Fbfcd5Ef766B287262fA2281C105d57246a6").expect("should deserialize v2");
184-
191+
185192
Token::Tuple(vec![
186193
Token::Address(self.creator.to_owned()),
187194
Token::Address(self.token_addr.to_owned()),
188195
Token::Uint(self.token_amount.to_owned()),
189196
Token::Uint(self.valid_until.to_owned()),
190-
Token::Array(self.validators.iter().map(|v| Token::Address(v.to_owned())).collect()),
197+
Token::Array(
198+
self.validators
199+
.iter()
200+
.map(|v| Token::Address(v.to_owned()))
201+
.collect(),
202+
),
191203
Token::FixedBytes(self.spec.to_vec()),
192204
])
193205
}
@@ -224,8 +236,8 @@ fn encode_params(params: &[(ParamType, &str)], lenient: bool) -> Result<Vec<u8>,
224236
}
225237
})
226238
.collect::<Result<Vec<_>, _>>()?;
227-
228-
println!("{:?}", tokens );
239+
240+
println!("{:?}", tokens);
229241
Ok(encode(&tokens).to_vec())
230242
}
231243

docs/config/dev.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ ip_rate_limit = {type='ip', timeframe=20000}
1919
sid_rate_limit = {type='sid', timeframe=20000}
2020

2121
ethereum_core_address = '0x333420fc6a897356e69b62417cd17ff012177d2b'
22-
ethereum_network = 'goerli'
22+
ethereum_network = 'http://localhost:8545'
2323

2424
creators_whitelist = []
2525
minimal_deposit = "0"

docs/config/prod.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ validator_tick_timeout = 10000
2020
ip_rate_limit = { type = "ip", timeframe = 20000 }
2121
sid_rate_limit = { type = "sid", timeframe = 0 }
2222
ethereum_core_address = '0x333420fc6a897356e69b62417cd17ff012177d2b'
23-
ethereum_network = 'homestead'
23+
ethereum_network = 'http://localhost:8545'
2424
token_address_whitelist = ['0x89d24A6b4CcB1B6fAA2625fE562bDD9a23260359']
2525

2626
creators_whitelist = []

node_modules/.bin/ganache-cli

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)