Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
202 commits
Select commit Hold shift + click to select a range
a51de51
👩‍🏫 Reorganize bridge modules
justin-elementlabs Jun 3, 2024
50d613f
🤓 Stub out more of implementation components
justin-elementlabs Jun 3, 2024
95f2af7
Fix compilation error
aristotleee Jun 4, 2024
d8fb953
remove invalid secret and use existing unspendable pubkey
aristotleee Jun 4, 2024
32ab0b7
🫣 Progress
justin-elementlabs Jun 5, 2024
edd7a2f
🏏 Fix errors, create alts
justin-elementlabs Jun 6, 2024
e997f2e
🎱 Cargo fix
justin-elementlabs Jun 6, 2024
abb2997
✊ Progress
justin-elementlabs Jun 10, 2024
e71b3d9
👐 Cargo fix
justin-elementlabs Jun 10, 2024
499c1d5
🏅 Post meeting
justin-elementlabs Jun 11, 2024
5d8ad9b
😻 Complete txns
justin-elementlabs Jun 11, 2024
68a9f47
😼 Work of refactoring
justin-elementlabs Jun 11, 2024
222b7ae
📦 Cargo fix
justin-elementlabs Jun 11, 2024
50c1546
😵 Progress
justin-elementlabs Jun 11, 2024
372ef21
😐 Progress
justin-elementlabs Jun 12, 2024
7257f71
📦 Cargo fix
justin-elementlabs Jun 12, 2024
9c76f7b
🚀 Progress
justin-elementlabs Jun 12, 2024
3bf1ef2
🤓 Progress
justin-elementlabs Jun 12, 2024
d75d53b
👨‍🚀 Progress
justin-elementlabs Jun 12, 2024
bce0e5d
✂️ Cargo clippy
justin-elementlabs Jun 12, 2024
6f52b36
🥍 rustfmt
justin-elementlabs Jun 12, 2024
204d6ac
🐙 Progress
justin-elementlabs Jun 13, 2024
6b1d7be
👨‍🍳 rustfmt
justin-elementlabs Jun 13, 2024
3d9202b
👩‍⚖️ Progress
justin-elementlabs Jun 13, 2024
de827f5
🔥 Fix output amounts
justin-elementlabs Jun 13, 2024
8aa9dc1
🧼 Fix op code
justin-elementlabs Jun 13, 2024
1c1749b
🤡 fmt
justin-elementlabs Jun 13, 2024
afb48de
❓ Added questions
justin-elementlabs Jun 13, 2024
f362d3f
Add `peg_in_confirm` and `peg_in_refund` tests
StarDumpling Jun 13, 2024
77f88f7
Merge branch 'impl01-02' into add-unit-tests
StarDumpling Jun 13, 2024
10b707b
finish assert tx and add unit test
aristotleee Jun 14, 2024
2bb2e9b
fixed bugs and added test cases to disprove tx and burn tx
timesaved12345 Jun 17, 2024
d31eaeb
fix control block error
timesaved12345 Jun 17, 2024
75436f2
peg in confirm & test
aristotleee Jun 17, 2024
babcd5c
Refactor `Input` into a struct
Jun 17, 2024
1124526
😼 Fix pub key error by adding new Bitcoin PubKey
justin-elementlabs Jun 17, 2024
84f3b8f
Merge pull request #6 from elementlabs42/input-refactor
justin-elementlabs Jun 17, 2024
581dd23
pub key compressed or uncompressed error
aristotleee Jun 18, 2024
3d8fc86
fixed burn tx test case for timelock and added more test cases
timesaved12345 Jun 18, 2024
2444fdc
Merge remote-tracking branch 'origin/rc' into disprove_burn_tx
timesaved12345 Jun 18, 2024
d00a224
take1 timelock fix & unit test
aristotleee Jun 18, 2024
f91b3e8
clean up
timesaved12345 Jun 18, 2024
eb4d264
fixed import
timesaved12345 Jun 18, 2024
37cef1a
`peg_in_refund` and `connector_a` fixes
StarDumpling Jun 18, 2024
8442168
Merge branch 'add-unit-tests02-fix-pubkey-for-p2wsh' into add-unit-tests
StarDumpling Jun 18, 2024
dbadb9a
Add `challenge` tx test
StarDumpling Jun 18, 2024
b8e8ba0
🤕 Refactor context
justin-elementlabs Jun 18, 2024
5ed8c37
🫣 Fix
justin-elementlabs Jun 18, 2024
1ddf9db
🧼 Fix formatting
justin-elementlabs Jun 18, 2024
b138b28
Merge branch 'rc' into add-unit-tests02-fix-pubkey-for-p2wsh
justin-elementlabs Jun 18, 2024
d09e7a5
Fix formatting
justin-elementlabs Jun 18, 2024
13f9d2d
Merge pull request #7 from elementlabs42/add-unit-tests02-fix-pubkey-…
justin-elementlabs Jun 18, 2024
efc14f0
Add todo
justin-elementlabs Jun 18, 2024
d357d4d
Merge branch 'rc' into disprove_burn_tx
justin-elementlabs Jun 18, 2024
445e96d
Fix function call
justin-elementlabs Jun 18, 2024
46e04ae
Fix type
justin-elementlabs Jun 18, 2024
0854bc2
Fix formatting
justin-elementlabs Jun 18, 2024
5931cd9
Update unspendable
justin-elementlabs Jun 18, 2024
8ee4f65
Format
justin-elementlabs Jun 18, 2024
99e921d
Merge branch 'rc' into disprove_burn_tx
justin-elementlabs Jun 18, 2024
2dfc0f9
Fix burn
justin-elementlabs Jun 18, 2024
95a0418
Merge branch 'rc' into impl01-02-assert-unit-test
aristotleee Jun 19, 2024
0134e8d
move tests in tests folder
aristotleee Jun 19, 2024
903b27f
prettier
aristotleee Jun 19, 2024
9eaa655
Fixed compilation errors and moved test cases to tests/
timesaved12345 Jun 19, 2024
411e633
refactoring
timesaved12345 Jun 19, 2024
36b2faa
refactoring connector b
timesaved12345 Jun 19, 2024
1ca71e3
Merge branch 'rc' into add-unit-tests
StarDumpling Jun 19, 2024
5279686
Update messages
justin-elementlabs Jun 19, 2024
21b0c24
Merge pull request #5 from elementlabs42/impl01-02-assert-unit-test
justin-elementlabs Jun 19, 2024
009f782
Merge branch 'rc' into add-unit-tests
justin-elementlabs Jun 19, 2024
d991f2c
Rust fmt
justin-elementlabs Jun 19, 2024
3b03079
Merge branch 'rc' into disprove_burn_tx
justin-elementlabs Jun 19, 2024
ecc7568
Merge pull request #9 from elementlabs42/disprove_burn_tx
justin-elementlabs Jun 19, 2024
8e6b09c
Refactor connectors
justin-elementlabs Jun 20, 2024
b7517d1
Format
justin-elementlabs Jun 20, 2024
bcfefb1
Start updating tests
justin-elementlabs Jun 20, 2024
61290db
Extract network setting from lower level functions
franklynot Jun 20, 2024
25ad58f
continue refactoring
timesaved12345 Jun 20, 2024
aab3876
Merge pull request #12 from elementlabs42/network-refactor
justin-elementlabs Jun 20, 2024
b7ea6e8
Reorder network param
justin-elementlabs Jun 20, 2024
451aac2
Fix tests
justin-elementlabs Jun 20, 2024
69e68a2
Refactor tests
justin-elementlabs Jun 20, 2024
57c4261
Fix formatting
justin-elementlabs Jun 20, 2024
c76a175
Format tests
justin-elementlabs Jun 20, 2024
534bba8
Merge pull request #10 from elementlabs42/rc-flow
justin-elementlabs Jun 20, 2024
0c5c7c3
Fix up a few items
justin-elementlabs Jun 20, 2024
f2826bd
Merge branch 'rc-flow' into rc
justin-elementlabs Jun 20, 2024
65475fd
Implement trait for connectors
justin-elementlabs Jun 20, 2024
52a0078
Merge pull request #15 from elementlabs42/rc-traits
justin-elementlabs Jun 20, 2024
90c0af2
Always use the network provided in context
franklynot Jun 20, 2024
9bc7d52
Merge pull request #16 from elementlabs42/remove-hardcoded-network
justin-elementlabs Jun 20, 2024
304eed6
Finalize the kick-off tx
franklynot Jun 20, 2024
9c3cdd6
fixed compilation erros
timesaved12345 Jun 21, 2024
4c9ee3a
fix lint
timesaved12345 Jun 21, 2024
95f8267
merged rc
timesaved12345 Jun 21, 2024
a09f822
refactoring tests
timesaved12345 Jun 21, 2024
f2cd351
fix lint
timesaved12345 Jun 21, 2024
c6af2e6
Rename variables
justin-elementlabs Jun 21, 2024
cbfa60e
Merge branch 'kick-off' into rc
justin-elementlabs Jun 21, 2024
b07e8b2
Merge pull request #18 from elementlabs42/refactor_connectors
justin-elementlabs Jun 21, 2024
ad85f92
COmment out incomplete signing code
justin-elementlabs Jun 21, 2024
7a601c8
Refactor signing
justin-elementlabs Jun 21, 2024
04e685b
Restructure components into transactions and connectors
justin-elementlabs Jun 21, 2024
461d51a
Rename p2wpkh
justin-elementlabs Jun 21, 2024
e3652d5
Merge pull request #19 from elementlabs42/refactor-signing
justin-elementlabs Jun 21, 2024
c988f73
Merge branch 'rc' into restructure-components
justin-elementlabs Jun 21, 2024
21bd30a
Format
justin-elementlabs Jun 21, 2024
5581f1e
Merge pull request #20 from elementlabs42/restructure-components
justin-elementlabs Jun 21, 2024
42f0335
Replace connector 2 pub key with operator pub key
justin-elementlabs Jun 21, 2024
3414dc9
Fixes (#23)
justin-elementlabs Jun 24, 2024
79fea70
Add codeowners (#24)
justin-elementlabs Jun 24, 2024
649a45d
Txn Serialization (#11)
aristotleee Jun 24, 2024
dcc97a6
[WIP] Refactor pre-signing functions (#22)
franklynot Jun 25, 2024
2583300
Refactor contexts
justin-elementlabs Jun 25, 2024
d479266
Refactor signing flow
justin-elementlabs Jun 25, 2024
df21ea1
Fix some compile time issues
justin-elementlabs Jun 26, 2024
f277d10
Fix mutable borrow
justin-elementlabs Jun 26, 2024
1d6471a
Update test setup
justin-elementlabs Jun 26, 2024
295da6c
Finish fixing all compile errors
justin-elementlabs Jun 26, 2024
b64cef6
Refactor contexts (#26)
justin-elementlabs Jun 27, 2024
dccf325
Rename assert leaf to disprove leaf
justin-elementlabs Jun 27, 2024
17e9304
Merge branch 'rc-start-flow' into rc
justin-elementlabs Jun 27, 2024
7ffc1b4
Add integration tests (#21)
StarDumpling Jul 3, 2024
9d0750e
Allow adding inputs only once in `challenge` tx (#28)
StarDumpling Jul 4, 2024
8bd8f8e
Start on graphs (#27)
justin-elementlabs Jul 4, 2024
c1d3b19
Merge remote-tracking branch 'upstream/main' into rc
justin-elementlabs Jul 5, 2024
e58c7c2
Update code to be compatible with Script changes
justin-elementlabs Jul 5, 2024
5bd5449
Small changes to client
justin-elementlabs Jul 8, 2024
181942b
[WIP] Rc create graph - implementation (#29)
StarDumpling Jul 9, 2024
fe8a287
Add serialization and deserialization to graphs
justin-elementlabs Jul 9, 2024
c73eb14
Refactor tests to use helper outpoint method (#32)
justin-elementlabs Jul 9, 2024
854a623
Remove unused variables
justin-elementlabs Jul 9, 2024
7471162
Add peg-in statuses and peg-out statuses (#34)
StarDumpling Jul 10, 2024
34b6360
Work on client syncing (#33)
justin-elementlabs Jul 11, 2024
a8580dc
Delete obsolete files
justin-elementlabs Jul 11, 2024
59cb5d8
Refactor and clean up unused variables
justin-elementlabs Jul 11, 2024
cb6c9d7
Remove unused variables
justin-elementlabs Jul 11, 2024
1fa5000
Try to implement formatter for statuses (#35)
justin-elementlabs Jul 11, 2024
c2a2e80
Merge remote-tracking branch 'upstream/main' into rc
justin-elementlabs Jul 11, 2024
ef49ee7
Delete codeowners
justin-elementlabs Jul 11, 2024
6715e17
Add peg out graph methods to client
justin-elementlabs Jul 15, 2024
98eea0d
Implement `peg-in` graph tx functions (#36)
StarDumpling Jul 15, 2024
de53623
Verify funding inputs at the beginnin of every integration test (#38)
StarDumpling Jul 16, 2024
3c6c60b
Add human-readable statuses (#39)
StarDumpling Jul 16, 2024
210a12f
Merge branch 'main' into rc
justin-elementlabs Jul 17, 2024
27204b3
feat: refine evm address encode (#40)
stardustPandora Jul 24, 2024
89d47d2
Add merge + validation POC (#37)
justin-elementlabs Jul 30, 2024
3a004b0
Add ftp and ftps support (#42)
justin-elementlabs Jul 30, 2024
1db0e30
Add debug message to transaction verification
justin-elementlabs Jul 31, 2024
c43c205
Ftp tests (#45)
justin-elementlabs Aug 1, 2024
9aa6ae3
Peg out test (#43)
aristotleee Aug 6, 2024
8c53b8f
Add `validate()` test cases (#47)
StarDumpling Aug 6, 2024
8d1bb4e
Add `merge()` test cases (#48)
StarDumpling Aug 6, 2024
45ce1dc
Add ftp tests (#52)
justin-elementlabs Aug 13, 2024
c932852
update test values (#53)
aristotleee Aug 14, 2024
03d9832
add evm address for depositor (#54)
aristotleee Aug 15, 2024
88117c8
Add MuSig2 (#41)
franklynot Aug 16, 2024
07fd8f5
Add client peg-out tests (#57)
StarDumpling Aug 21, 2024
4ae641c
Read private data from local file (#56)
franklynot Aug 21, 2024
5c09afe
Add directories to data stores, add `destination_network` (#60)
StarDumpling Aug 27, 2024
b7bc61d
Add public nonce verification (#63)
franklynot Aug 30, 2024
8d1cebb
L2 chain adaptors (#58)
aristotleee Aug 30, 2024
19b6349
Graph v3 merged (#59)
justin-elementlabs Sep 2, 2024
872834e
Nonce signature tests (#67)
franklynot Sep 4, 2024
86ba553
Merge branch 'BitVM:main' into rc
justin-elementlabs Sep 10, 2024
e389ead
Sync with BitVM codebase (#70)
justin-elementlabs Sep 10, 2024
01a7b11
Merge branch 'rc' into rc-updates
justin-elementlabs Sep 10, 2024
b2ef156
Merge pull request #1 from elementlabs42/rc-updates
justin-elementlabs Sep 10, 2024
1fa08ea
Merge branch 'BitVM:main' into rc
justin-elementlabs Sep 12, 2024
e5ceed8
Start on CLI (#65)
justin-elementlabs Sep 23, 2024
7bfec34
Add commits testing (#69)
justin-elementlabs Sep 24, 2024
a016c8c
Implement peg out flow (#64)
justin-elementlabs Sep 24, 2024
90aa7d0
Add peg out confirm (#62)
justin-elementlabs Oct 8, 2024
a02977e
Infrastructure for Winternitz secrets + superblock commit (#73)
franklynot Oct 15, 2024
c355110
Query CLI (#75)
aristotleee Oct 17, 2024
2bed58d
Reduce compiler warnings (#68)
franklynot Oct 23, 2024
e102f23
Enforce one commitment message per Winternitz key (#78)
franklynot Oct 28, 2024
20e9355
Pull out connectors (#76)
StarDumpling Oct 29, 2024
2d5d854
Fix start_time_timeout test (#79)
StarDumpling Oct 29, 2024
e68508b
Winternitz signing refactor: Pass only required commitment secrets (#80)
franklynot Nov 7, 2024
ec86271
feat: more precise pegin verifier status & state machine (#83)
sander2 Nov 7, 2024
8e8a8dd
Cli query commands for UI signing (#77)
aristotleee Nov 8, 2024
2297b8b
Merge branch 'BitVM:main' into rc
justin-elementlabs Nov 8, 2024
4ddc6a9
Merge remote-tracking branch 'fork/rc' into rc
justin-elementlabs Nov 8, 2024
eb761ea
Format
justin-elementlabs Nov 8, 2024
8de2b9f
Merge remote-tracking branch 'fork/rc' into rc
justin-elementlabs Nov 8, 2024
28f31ab
Remove obsolete methods
justin-elementlabs Nov 8, 2024
2e60b8c
Add missing dep
justin-elementlabs Nov 8, 2024
38e29ee
Clean up Winternitz signing code and use `execute_script` to get pass…
franklynot Nov 8, 2024
d3e1ba8
Fix sftp threading issue (#85)
justin-elementlabs Nov 10, 2024
6a05837
Sync from BitVM (#84)
justin-elementlabs Nov 10, 2024
d6c9fed
Merge branch 'main' into rc
lucidLuckylee Nov 18, 2024
2458443
Fix `sign_digit` Witness push format
lucidLuckylee Nov 19, 2024
9edf548
Update Cargo.lock
lucidLuckylee Nov 19, 2024
02cb6fe
Specify message sizes in secret generation
lucidLuckylee Nov 19, 2024
833dde9
feat: initiate pegin (#86)
sander2 Nov 20, 2024
2117b5d
Merge remote-tracking branch 'fork/rc-fix131' into rc-fix131
justin-elementlabs Nov 20, 2024
b551474
No longer hash small messages
lucidLuckylee Nov 21, 2024
8adf280
Do not hash tx IDs in commitments (#91)
franklynot Nov 27, 2024
7311518
Merge branch 'main' into rc-fix131-push
justin-elementlabs Nov 27, 2024
b7591f1
Merge branch 'fix/131' into rc-fix131-push
justin-elementlabs Nov 27, 2024
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
53 changes: 53 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,16 @@ suppaftp = { version = "6.0.1", features = ["async", "async-native-tls"] }
openssh-sftp-client = { version = "0.14.6", features = ["openssh"] }
openssh = { version = "0.10.4", features = ["native-mux"] }
alloy = { version = "0.2.1", features = ["full"] }
clap = { version = "4.5.16", features = ["derive", "cargo", "env"] }
toml = "0.5.11"
colored = "2.0.0"

[dev-dependencies]
num-bigint = { version = "0.4.4", features = ["rand"] }
ark-std = { version = "0.4.0", default-features = false, features = ["print-trace"] }
ark-crypto-primitives = { git = "https://github.com/arkworks-rs/crypto-primitives", features = ["snark", "sponge"] }
ark-relations = { git = "https://github.com/arkworks-rs/snark/" }
serial_test = "*"
tqdm = "0.7"

[profile.dev]
Expand Down Expand Up @@ -75,3 +79,10 @@ ark-crypto-primitives = { git = "https://github.com/arkworks-rs/crypto-primitive
ark-relations = { git = "https://github.com/arkworks-rs/snark/" }
ark-snark = { git = "https://github.com/arkworks-rs/snark/" }
ark-groth16 = { git = "https://github.com/arkworks-rs/groth16" }

[[bin]]
name = "cli"

[[bin]]
name = "cli-query"
path = "src/bin/cli_query/main.rs"
76 changes: 76 additions & 0 deletions src/bin/cli/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
use bitcoin::PublicKey;
use bitvm::bridge::client::cli::client_command::{ClientCommand, CommonArgs};
use bitvm::bridge::client::cli::key_command::KeysCommand;
use clap::{arg, command};
use std::error::Error;

#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
let command = command!() // requires `cargo` feature
.propagate_version(true)
.subcommand_required(true)
.arg_required_else_help(true)
.arg(
arg!(--"key-dir" <DIRECTORY> "The directory containing the private keys").required(false).env("KEY_DIR"),
)
.arg(
arg!(-r --verifiers [VERIFIER_PUBKEYS] "Pubkeys of the verifiers")
.required(false)
.num_args(0..1000)
.value_delimiter(',')
.value_parser(clap::value_parser!(PublicKey))
.env("VERIFIERS"),
)
.arg(arg!(-e --environment <ENVIRONMENT> "Specify the Bitcoin network environment (mainnet, testnet). Defaults to mainnet.").required(false).default_value("mainnet").env("ENVIRONMENT"))
.subcommand(KeysCommand::get_command())
.subcommand(ClientCommand::get_depositor_address_command())
.subcommand(ClientCommand::get_depositor_utxos_command())
.subcommand(ClientCommand::get_initiate_peg_in_command())
.subcommand(ClientCommand::get_status_command())
.subcommand(ClientCommand::get_broadcast_command())
.subcommand(ClientCommand::get_automatic_command())
.subcommand(ClientCommand::get_interactive_command());

let matches = command.clone().get_matches();

let global_args = CommonArgs {
key_dir: matches.get_one::<String>("key-dir").cloned(),
verifiers: matches
.get_many::<PublicKey>("verifiers")
.map(|x| x.cloned().collect::<Vec<PublicKey>>()),
environment: matches.get_one::<String>("environment").cloned(),
};

if let Some(sub_matches) = matches.subcommand_matches("keys") {
let keys_command = KeysCommand::new(global_args.key_dir);
keys_command.handle_command(sub_matches)?;
} else if matches
.subcommand_matches("get-depositor-address")
.is_some()
{
let mut client_command = ClientCommand::new(global_args).await;
let _ = client_command.handle_get_depositor_address().await;
} else if matches.subcommand_matches("get-depositor-utxos").is_some() {
let mut client_command = ClientCommand::new(global_args).await;
let _ = client_command.handle_get_depositor_utxos().await;
} else if let Some(sub_matches) = matches.subcommand_matches("initiate-peg-in") {
let mut client_command = ClientCommand::new(global_args).await;
let _ = client_command
.handle_initiate_peg_in_command(sub_matches)
.await;
} else if matches.subcommand_matches("status").is_some() {
let mut client_command = ClientCommand::new(global_args).await;
let _ = client_command.handle_status_command().await;
} else if let Some(sub_matches) = matches.subcommand_matches("broadcast") {
let mut client_command = ClientCommand::new(global_args).await;
let _ = client_command.handle_broadcast_command(sub_matches).await;
} else if matches.subcommand_matches("automatic").is_some() {
let mut client_command = ClientCommand::new(global_args).await;
let _ = client_command.handle_automatic_command().await;
} else if matches.subcommand_matches("interactive").is_some() {
let mut client_command = ClientCommand::new(global_args).await;
let _ = client_command.handle_interactive_command(&command).await;
}

Ok(())
}
49 changes: 49 additions & 0 deletions src/bin/cli_query/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
use bitcoin::Network;
use bitvm::bridge::{client::cli::query_command::QueryCommand, constants::DestinationNetwork};
use clap::{arg, command};
use std::error::Error;

#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
let command = command!() // requires `cargo` feature
.propagate_version(true)
.subcommand_required(true)
.arg_required_else_help(true)
.subcommand(QueryCommand::depositor_command())
.subcommand(QueryCommand::withdrawer_command())
.subcommand(QueryCommand::history_command())
.subcommand(QueryCommand::transactions_command())
.subcommand(QueryCommand::signatures_command())
.subcommand(QueryCommand::broadcast_command())
.subcommand(QueryCommand::peg_in_graphs_command())
.arg(arg!(-e --environment <ENVIRONMENT> "Specify the Bitcoin and L2 network environment (mainnet, testnet)").required(false)
.default_value("mainnet"))
.arg(arg!(-p --prefix <PREFIX> "Prefix for local file cache path").required(false));

let matches = command.clone().get_matches();
let (source_network, destination_network) =
match matches.get_one::<String>("environment").unwrap().as_str() {
"mainnet" => (Network::Bitcoin, DestinationNetwork::Ethereum),
"testnet" => (Network::Testnet, DestinationNetwork::EthereumSepolia),
_ => {
eprintln!("Invalid environment. Use mainnet, testnet.");
std::process::exit(1);
}
};
let prefix = matches.get_one::<String>("prefix").map(|s| s.as_str());

let mut query = QueryCommand::new(source_network, destination_network, prefix).await;
let resp = match matches.subcommand() {
Some(("depositor", sub)) => query.handle_depositor(sub).await,
Some(("withdrawer", sub)) => query.handle_withdrawer(sub, destination_network).await,
Some(("history", sub)) => query.handle_history(sub, destination_network).await,
Some(("transactions", sub)) => query.handle_transactions(sub, destination_network).await,
Some(("signatures", sub)) => query.handle_signatures(sub, destination_network).await,
Some(("broadcast", sub)) => query.handle_broadcast(sub).await,
Some(("pegins", _)) => query.handle_peg_in_graphs().await,
_ => unreachable!(),
};

resp.flush();
Ok(())
}
22 changes: 16 additions & 6 deletions src/bridge/client/chain/chain.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
use std::borrow::Borrow;

use bitcoin::{Amount, OutPoint, PubkeyHash, PublicKey};
use serde::{Deserialize, Serialize};

use super::{
base::ChainAdaptor,
ethereum::{EthereumAdaptor, EthereumInitConfig},
};

#[derive(Debug)]
#[derive(Serialize, Deserialize, Eq, PartialEq, Clone, Debug)]
pub struct PegOutEvent {
pub withdrawer_chain_address: String,
pub withdrawer_public_key_hash: PubkeyHash,
pub source_outpoint: OutPoint,
pub amount: Amount,
pub operator_public_key: PublicKey,
pub timestamp: u32,
pub tx_hash: Vec<u8>,
}

#[derive(Debug)]
#[derive(Serialize, Deserialize, Eq, PartialEq, Clone, Debug)]
pub struct PegOutBurntEvent {
pub withdrawer_chain_address: String,
pub source_outpoint: OutPoint,
Expand All @@ -24,26 +28,30 @@ pub struct PegOutBurntEvent {
pub timestamp: u32,
}

#[derive(Debug)]
#[derive(Serialize, Deserialize, Eq, PartialEq, Clone, Debug)]
pub struct PegInEvent {
pub depositor: String,
pub amount: Amount,
pub depositor_pubkey: PublicKey,
}

static CLIENT_MISSING_ORACLE_DRIVER_ERROR: &str = "Bridge client is missing chain adaptor";
static CLIENT_MISSING_CHAIN_DRIVER_ERROR: &str = "Bridge client is missing chain adaptor";

pub struct Chain {
ethereum: Option<EthereumAdaptor>,
default: Option<Box<dyn ChainAdaptor>>,
}

impl Chain {
pub fn new() -> Self {
Self {
ethereum: EthereumAdaptor::new(),
default: None,
}
}

pub fn init_default(&mut self, adaptor: Box<dyn ChainAdaptor>) { self.default = Some(adaptor); }

pub fn init_ethereum(&mut self, conf: EthereumInitConfig) {
self.ethereum = Some(EthereumAdaptor::from_config(conf));
}
Expand All @@ -66,10 +74,12 @@ impl Chain {
}

fn get_driver(&self) -> Result<&dyn ChainAdaptor, &str> {
if self.ethereum.is_some() {
if self.default.is_some() {
return Ok((*self.default.as_ref().unwrap()).borrow());
} else if self.ethereum.is_some() {
return Ok(self.ethereum.as_ref().unwrap());
} else {
Err(CLIENT_MISSING_ORACLE_DRIVER_ERROR)
Err(CLIENT_MISSING_CHAIN_DRIVER_ERROR)
}
}
}
15 changes: 14 additions & 1 deletion src/bridge/client/chain/ethereum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,23 +51,29 @@ pub struct EthereumAdaptor {
bridge_address: EvmAddress,
bridge_creation_block: u64,
provider: RootProvider<Http<Client>>,
to_block: Option<BlockNumberOrTag>,
}

pub struct EthereumInitConfig {
pub rpc_url: Url,
pub bridge_address: EvmAddress,
pub bridge_creation_block: u64,
pub to_block: Option<BlockNumberOrTag>,
}

impl EthereumAdaptor {
async fn get_sol_events<T>(&self) -> Result<Vec<Log<T>>, String>
where
T: SolEvent,
{
let filter = Filter::new()
let mut filter = Filter::new()
.from_block(BlockNumberOrTag::Number(self.bridge_creation_block))
.address(self.bridge_address)
.event(T::SIGNATURE);
filter = match self.to_block.is_none() {
true => filter.to_block(BlockNumberOrTag::Finalized),
false => filter.to_block(self.to_block.unwrap()),
};

let results = self.provider.get_logs(&filter).await;
if results.is_err() {
Expand Down Expand Up @@ -119,6 +125,7 @@ impl ChainAdaptor for EthereumAdaptor {
.unwrap(),
operator_public_key,
timestamp: u32::try_from(e.block_timestamp.unwrap()).unwrap(),
tx_hash: e.transaction_hash.unwrap().to_vec(),
}
})
.collect();
Expand Down Expand Up @@ -190,6 +197,7 @@ impl EthereumAdaptor {
let rpc_url_str = dotenv::var("BRIDGE_CHAIN_ADAPTOR_ETHEREUM_RPC_URL");
let bridge_address_str = dotenv::var("BRIDGE_CHAIN_ADAPTOR_ETHEREUM_BRIDGE_ADDRESS");
let bridge_creation = dotenv::var("BRIDGE_CHAIN_ADAPTOR_ETHEREUM_BRIDGE_CREATION");
let to_block = dotenv::var("BRIDGE_CHAIN_ADAPTOR_ETHEREUM_TO_BLOCK");
if bridge_address_str.is_err() || bridge_creation.is_err() {
return None;
}
Expand All @@ -203,6 +211,10 @@ impl EthereumAdaptor {
rpc_url: rpc_url.unwrap(),
bridge_address: bridge_address.unwrap(),
bridge_creation_block: bridge_creation.unwrap().parse::<u64>().unwrap(),
to_block: match to_block {
Ok(block) => Some(BlockNumberOrTag::from_str(block.as_str()).unwrap()),
Err(_) => Some(BlockNumberOrTag::Finalized),
},
}))
}

Expand All @@ -211,6 +223,7 @@ impl EthereumAdaptor {
bridge_address: conf.bridge_address,
bridge_creation_block: conf.bridge_creation_block,
provider: ProviderBuilder::new().on_http(conf.rpc_url),
to_block: conf.to_block,
}
}
}
Loading