Skip to content
This repository was archived by the owner on Mar 23, 2021. It is now read-only.

Commit 771ed51

Browse files
Merge ethereum_support into cnd crate
1 parent 2b5370c commit 771ed51

39 files changed

+365
-389
lines changed

Cargo.lock

Lines changed: 6 additions & 22 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
@@ -1,2 +1,2 @@
11
[workspace]
2-
members = ["cnd", "libp2p-comit", "internal/*"]
2+
members = ["cnd", "libp2p-comit"]

cnd/Cargo.toml

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@ description = "Reference implementation of a COMIT network daemon."
99
anyhow = "1"
1010
async-std = "1"
1111
async-trait = "0.1"
12+
bigdecimal = "0.1.0"
1213
binary_macros = "0.6"
1314
bitcoin = "0.19.1"
1415
blockchain_contracts = "0.1"
16+
byteorder = "1.3"
1517
chrono = { version = "0.4", features = ["serde"] }
1618
config = { version = "0.9", features = ["toml"] }
1719
debug_stub_derive = "0.3"
@@ -23,7 +25,6 @@ directories = "2.0"
2325
either = "1.5"
2426
enum-display-derive = "0.1"
2527
ethbloom = "0.6.4"
26-
ethereum_support = { path = "../internal/ethereum_support" }
2728
fern = { version = "0.5", features = ["colored"] }
2829
futures = { version = "0.1" }
2930
futures-core = { version = "=0.3.0-alpha.19", features = ["alloc", "compat", "async-await"], package = "futures-preview" }
@@ -40,11 +41,12 @@ log = { version = "0.4", features = ["serde"] }
4041
maplit = "1"
4142
mime = "0.3"
4243
mime_guess = "2.0"
44+
num = "0.2"
4345
paste = "0.1"
4446
pem = "0.7"
4547
rand = "0.7"
48+
regex = "1.3"
4649
reqwest = { version = "0.9", default-features = false }
47-
rlp = "0.4"
4850
rust-crypto = "0.2"
4951
rustic_hal = "0.2"
5052
serde = { version = "1", features = ["derive"] }
@@ -56,13 +58,29 @@ strum = "0.16"
5658
strum_macros = "0.16"
5759
testcontainers = "0.8"
5860
thiserror = "1"
61+
tiny-keccak = { version = "2.0", features = ["keccak"] }
5962
tokio = "0.1"
6063
toml = "0.5"
6164
url_serde = "0.2.0"
6265
uuid = { version = "0.8", features = ["serde", "v4"] }
6366
void = "1.0.2"
6467
warp = { version = "0.1", default-features = false }
6568

69+
# These versions need to be "in sync".
70+
# web3 0.8 gives us primitive-types 0.3.0
71+
# primitive-types 0.3.0 with the "rlp" feature gives us "rlp" version 0.4.2
72+
[dependencies.web3]
73+
default-features = false
74+
features = ["http"]
75+
version = "0.8"
76+
77+
[dependencies.primitive-types]
78+
features = ["rlp"]
79+
version = "0.3.0"
80+
81+
[dependencies.rlp]
82+
version = "0.4.2"
83+
6684
[dev-dependencies]
6785
base64 = "0.11"
6886
bitcoincore-rpc = "0.8.0-rc1"
@@ -71,7 +89,6 @@ matches = "0.1.8"
7189
memsocket = "0.1"
7290
pretty_env_logger = "0.3"
7391
quickcheck = "0.9.0"
74-
regex = "1.3.1"
7592
serde_urlencoded = "0.6"
7693
spectral = "0.6"
7794
tempfile = "3.1.0"

cnd/src/btsieve/ethereum/mod.rs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ pub use self::{
55
transaction_pattern::{Event, Topic, TransactionPattern},
66
web3_connector::Web3Connector,
77
};
8-
use crate::btsieve::{BlockByHash, LatestBlock, MatchingTransactions, ReceiptByHash};
9-
use ethereum_support::TransactionAndReceipt;
8+
use crate::{
9+
btsieve::{BlockByHash, LatestBlock, MatchingTransactions, ReceiptByHash},
10+
ethereum::TransactionAndReceipt,
11+
};
1012
use futures_core::{compat::Future01CompatExt, TryFutureExt};
1113
use std::ops::Add;
1214
use tokio::{
@@ -16,11 +18,11 @@ use tokio::{
1618

1719
impl<C> MatchingTransactions<TransactionPattern> for C
1820
where
19-
C: LatestBlock<Block = Option<ethereum_support::Block<ethereum_support::Transaction>>>
20-
+ BlockByHash<Block = Option<ethereum_support::Block<ethereum_support::Transaction>>>
21+
C: LatestBlock<Block = Option<crate::ethereum::Block<crate::ethereum::Transaction>>>
22+
+ BlockByHash<Block = Option<crate::ethereum::Block<crate::ethereum::Transaction>>>
2123
+ ReceiptByHash<
22-
Receipt = Option<ethereum_support::TransactionReceipt>,
23-
TransactionHash = ethereum_support::H256,
24+
Receipt = Option<crate::ethereum::TransactionReceipt>,
25+
TransactionHash = crate::ethereum::H256,
2426
> + Clone,
2527
{
2628
type Transaction = TransactionAndReceipt;
@@ -40,11 +42,11 @@ async fn matching_transaction<C>(
4042
pattern: TransactionPattern,
4143
) -> Result<TransactionAndReceipt, ()>
4244
where
43-
C: LatestBlock<Block = Option<ethereum_support::Block<ethereum_support::Transaction>>>
44-
+ BlockByHash<Block = Option<ethereum_support::Block<ethereum_support::Transaction>>>
45+
C: LatestBlock<Block = Option<crate::ethereum::Block<crate::ethereum::Transaction>>>
46+
+ BlockByHash<Block = Option<crate::ethereum::Block<crate::ethereum::Transaction>>>
4547
+ ReceiptByHash<
46-
Receipt = Option<ethereum_support::TransactionReceipt>,
47-
TransactionHash = ethereum_support::H256,
48+
Receipt = Option<crate::ethereum::TransactionReceipt>,
49+
TransactionHash = crate::ethereum::H256,
4850
> + Clone,
4951
{
5052
loop {

cnd/src/btsieve/ethereum/transaction_pattern.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1+
use crate::ethereum::{Address, Block, Bytes, Transaction, TransactionReceipt, H256};
12
use ethbloom::Input;
2-
use ethereum_support::{
3-
web3::types::{TransactionReceipt, H256},
4-
Address, Block, Bytes, Transaction,
5-
};
63

74
#[derive(Clone, Default, Debug, Eq, PartialEq)]
85
/// If the field is set to Some(foo) then only transactions matching foo are
@@ -165,9 +162,11 @@ pub struct Event {
165162
#[cfg(test)]
166163
mod tests {
167164
use super::*;
168-
use crate::quickcheck::Quickcheck;
169-
use ethereum_support::web3::types::{
170-
Address, Block, Bytes, Log, Transaction, TransactionReceipt, H160, H2048, H256,
165+
use crate::{
166+
ethereum::{
167+
Address, Block, Bytes, Log, Transaction, TransactionReceipt, H160, H2048, H256,
168+
},
169+
quickcheck::Quickcheck,
171170
};
172171
use spectral::prelude::*;
173172
use std::str::FromStr;

cnd/src/btsieve/ethereum/web3_connector.rs

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
use crate::btsieve::{BlockByHash, LatestBlock, ReceiptByHash};
2-
use ethereum_support::{
3-
web3::{
4-
self,
5-
futures::Future,
6-
transports::{EventLoopHandle, Http},
7-
types::BlockId,
8-
Web3,
1+
use crate::{
2+
btsieve::{BlockByHash, LatestBlock, ReceiptByHash},
3+
ethereum::{
4+
web3::{
5+
self,
6+
transports::{EventLoopHandle, Http},
7+
Web3,
8+
},
9+
BlockId, BlockNumber,
910
},
10-
BlockNumber,
1111
};
12+
use futures::Future;
1213
use reqwest::Url;
1314
use std::sync::Arc;
1415

@@ -30,9 +31,9 @@ impl Web3Connector {
3031
}
3132

3233
impl LatestBlock for Web3Connector {
33-
type Error = web3::Error;
34-
type Block = Option<ethereum_support::Block<ethereum_support::Transaction>>;
35-
type BlockHash = ethereum_support::H256;
34+
type Error = crate::ethereum::web3::Error;
35+
type Block = Option<crate::ethereum::Block<crate::ethereum::Transaction>>;
36+
type BlockHash = crate::ethereum::H256;
3637

3738
fn latest_block(
3839
&mut self,
@@ -46,9 +47,9 @@ impl LatestBlock for Web3Connector {
4647
}
4748

4849
impl BlockByHash for Web3Connector {
49-
type Error = web3::Error;
50-
type Block = Option<ethereum_support::Block<ethereum_support::Transaction>>;
51-
type BlockHash = ethereum_support::H256;
50+
type Error = crate::ethereum::web3::Error;
51+
type Block = Option<crate::ethereum::Block<crate::ethereum::Transaction>>;
52+
type BlockHash = crate::ethereum::H256;
5253

5354
fn block_by_hash(
5455
&self,
@@ -60,9 +61,9 @@ impl BlockByHash for Web3Connector {
6061
}
6162

6263
impl ReceiptByHash for Web3Connector {
63-
type Receipt = Option<ethereum_support::TransactionReceipt>;
64-
type TransactionHash = ethereum_support::H256;
65-
type Error = web3::Error;
64+
type Receipt = Option<crate::ethereum::TransactionReceipt>;
65+
type TransactionHash = crate::ethereum::H256;
66+
type Error = crate::ethereum::web3::Error;
6667

6768
fn receipt_by_hash(
6869
&self,

cnd/src/comit_api/mod.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use crate::{
2+
ethereum::Erc20Token,
23
libp2p_comit_ext::{FromHeader, ToHeader},
34
swap_protocols::{
45
asset::AssetKind,
@@ -8,7 +9,6 @@ use crate::{
89
},
910
};
1011
use bitcoin::util::amount::Denomination;
11-
use ethereum_support::Erc20Token;
1212
use libp2p_comit::frame::Header;
1313
use serde::de::Error;
1414
use std::fmt;
@@ -146,9 +146,11 @@ impl FromHeader for Decision {
146146
#[cfg(test)]
147147
mod tests {
148148
use super::*;
149-
use crate::swap_protocols::{ledger::ethereum, HashFunction};
149+
use crate::{
150+
ethereum::{Address, Erc20Quantity, U256},
151+
swap_protocols::{ledger::ethereum, HashFunction},
152+
};
150153
use bitcoin::Amount;
151-
use ethereum_support::{Address, Erc20Quantity, U256};
152154
use spectral::prelude::*;
153155

154156
#[test]

cnd/src/db/integration_tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ use crate::{
44
swap_types::{DetermineTypes, SwapTypes},
55
AssetKind, LedgerKind, Retrieve, Save, Sqlite, Swap,
66
},
7+
ethereum::{Erc20Token, EtherQuantity},
78
quickcheck::Quickcheck,
89
swap_protocols::{
910
ledger::{Bitcoin, Ethereum},
1011
rfc003::{Accept, Request},
1112
},
1213
};
1314
use bitcoin::Amount as BitcoinAmount;
14-
use ethereum_support::{Erc20Token, EtherQuantity};
1515
use std::path::Path;
1616

1717
macro_rules! db_roundtrip_test {

cnd/src/db/load_swaps.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use crate::{
44
new_types::{DecimalU256, EthereumAddress, Satoshis},
55
schema, Sqlite,
66
},
7+
ethereum::{Erc20Quantity, Erc20Token, EtherQuantity, U256},
78
swap_protocols::{
89
asset::Asset,
910
ledger::{ethereum::ChainId, Bitcoin, Ethereum},
@@ -16,7 +17,6 @@ use crate::{
1617
};
1718
use async_trait::async_trait;
1819
use diesel::{self, prelude::*, RunQueryDsl};
19-
use ethereum_support::{Erc20Quantity, Erc20Token, EtherQuantity, U256};
2020

2121
pub type AcceptedSwap<AL, BL, AA, BA> = (Request<AL, BL, AA, BA>, Accept<AL, BL>);
2222

@@ -53,7 +53,7 @@ impl LoadAcceptedSwap<Bitcoin, Ethereum, bitcoin::Amount, EtherQuantity> for Sql
5353
&self,
5454
key: SwapId,
5555
) -> anyhow::Result<
56-
AcceptedSwap<Bitcoin, Ethereum, bitcoin::Amount, ethereum_support::EtherQuantity>,
56+
AcceptedSwap<Bitcoin, Ethereum, bitcoin::Amount, crate::ethereum::EtherQuantity>,
5757
> {
5858
use schema::{
5959
rfc003_bitcoin_ethereum_accept_messages as accept_messages,

cnd/src/db/new_types.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use ethereum_support::{FromDecimalStr, U256};
1+
use crate::ethereum::{FromDecimalStr, U256};
22
use std::{fmt, str::FromStr};
33

44
/// A new type for representing satoshis
@@ -29,7 +29,7 @@ impl From<DecimalU256> for U256 {
2929
}
3030

3131
impl FromStr for DecimalU256 {
32-
type Err = <ethereum_support::U256 as FromDecimalStr>::Err;
32+
type Err = <crate::ethereum::U256 as FromDecimalStr>::Err;
3333

3434
fn from_str(s: &str) -> Result<Self, Self::Err> {
3535
U256::from_decimal_str(s).map(DecimalU256)
@@ -47,10 +47,10 @@ impl fmt::Display for DecimalU256 {
4747
/// Together with the `Text` sql type, this will store an ethereum address in
4848
/// hex encoding.
4949
#[derive(Debug, Clone, Copy, PartialEq)]
50-
pub struct EthereumAddress(pub ethereum_support::Address);
50+
pub struct EthereumAddress(pub crate::ethereum::Address);
5151

5252
impl FromStr for EthereumAddress {
53-
type Err = <ethereum_support::Address as FromStr>::Err;
53+
type Err = <crate::ethereum::Address as FromStr>::Err;
5454

5555
fn from_str(s: &str) -> Result<Self, Self::Err> {
5656
s.parse().map(EthereumAddress)

0 commit comments

Comments
 (0)