Skip to content

Commit

Permalink
fix: merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
DhananjayPurohit committed Apr 29, 2024
2 parents 549fd54 + 9660b00 commit f3198df
Show file tree
Hide file tree
Showing 41 changed files with 188 additions and 3,165 deletions.
81 changes: 40 additions & 41 deletions Cargo.lock

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

4 changes: 1 addition & 3 deletions clients/rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,4 @@ serde_json = "1.0.96"
sqlx = { version = "0.7", features = [ "runtime-tokio", "sqlite", "time", "uuid" ] }
tokio = { version = "1.27.0", features = ["full"] }
uuid = { version = "1.3.1", features = ["v4", "serde"] }

[dependencies.mercury-lib]
path = "../../lib"
mercurylib = { path = "../../lib" }
31 changes: 31 additions & 0 deletions clients/rust/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Mercury Layer Client

Mercury layer client provides a user interface to the Mercury Layer protocol, via the Mercury Layer server.

# Running

1. Run the `enclave` project on localhost
2. Run the `server` project on localhost
3. Run one of the commands below

# Some commands

`cargo run create-wallet <wallet_name>` to create a wallet

`cargo run new-token` to create a new token

`cargo run new-deposit-address <wallet_name> <token> <amount>` creates a deposit address

`cargo run list-statecoins <wallet_name>` shows wallet coins

`cargo run new-transfer-address <wallet_name>` generates a statechain address to receive statechain coins

`cargo run transfer-send <wallet_name> <statechain-id> <statechain-address> ` transfers the specified statechain coin to the specified address

`cargo run transfer-receive <wallet_name>` scans for new statechain transfers

`cargo run withdraw <wallet_name> <statechain-id> <btc-address> <optional_fee_rate>` withdraws the statechain coin to the specified bitcoin address

`cargo run broadcast-backup-transaction <wallet_name> <statechain-id> <btc-address> <optional_fee_rate>` broadcasts the backup transaction to the network

This is a work in progress. Several changes to the project are expected.
12 changes: 9 additions & 3 deletions clients/rust/src/broadcast_backup_tx.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
use crate::{client_config::ClientConfig, sqlite_manager::{get_backup_txs, get_wallet, update_wallet}};
use anyhow::{anyhow, Result};
use electrum_client::ElectrumApi;
use mercury_lib::wallet::{cpfp_tx, CoinStatus};
use mercurylib::wallet::{cpfp_tx, CoinStatus};

pub async fn execute(client_config: &ClientConfig, wallet_name: &str, statechain_id: &str, to_address: &str, fee_rate: Option<u64>) -> Result<()> {

let mut wallet: mercury_lib::wallet::Wallet = get_wallet(&client_config.pool, &wallet_name).await?;
let mut wallet: mercurylib::wallet::Wallet = get_wallet(&client_config.pool, &wallet_name).await?;

let is_address_valid = mercury_lib::validate_address(to_address, &wallet.network)?;
let is_address_valid = mercurylib::validate_address(to_address, &wallet.network)?;

if !is_address_valid {
return Err(anyhow!("Invalid address"));
}

let is_address_valid = mercurylib::validate_address(to_address, &wallet.network)?;

if !is_address_valid {
return Err(anyhow!("Invalid address"));
Expand Down
4 changes: 2 additions & 2 deletions clients/rust/src/coin_status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::str::FromStr;

use bitcoin::Address;
use electrum_client::{ElectrumApi, ListUnspentRes};
use mercury_lib::wallet::{CoinStatus, Coin, Activity, BackupTx};
use mercurylib::wallet::{CoinStatus, Coin, Activity, BackupTx};
use anyhow::{anyhow, Result, Ok};
use serde_json::Value;

Expand Down Expand Up @@ -174,7 +174,7 @@ async fn check_withdrawal(client_config: &ClientConfig, coin: &mut Coin) -> Resu

pub async fn update_coins(client_config: &ClientConfig, wallet_name: &str) -> Result<()> {

let mut wallet: mercury_lib::wallet::Wallet = get_wallet(&client_config.pool, &wallet_name).await?;
let mut wallet: mercurylib::wallet::Wallet = get_wallet(&client_config.pool, &wallet_name).await?;

let network = wallet.network.clone();

Expand Down
8 changes: 4 additions & 4 deletions clients/rust/src/deposit.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use anyhow::{anyhow, Result, Ok};
use mercury_lib::{deposit::{create_deposit_msg1, create_aggregated_address}, wallet::{Wallet, BackupTx, CoinStatus, Coin}, transaction:: get_user_backup_address, utils::get_blockheight};
use mercurylib::{deposit::{create_deposit_msg1, create_aggregated_address}, wallet::{Wallet, BackupTx, CoinStatus, Coin}, transaction:: get_user_backup_address, utils::get_blockheight};

use crate::{sqlite_manager::update_wallet, get_wallet, client_config::ClientConfig, transaction::new_transaction};

Expand Down Expand Up @@ -98,13 +98,13 @@ pub async fn init(client_config: &ClientConfig, wallet: &Wallet, token_id: uuid:

let value = response.text().await?;

let deposit_msg_1_response: mercury_lib::deposit::DepositMsg1Response = serde_json::from_str(value.as_str())?;
let deposit_msg_1_response: mercurylib::deposit::DepositMsg1Response = serde_json::from_str(value.as_str())?;

// println!("value: {:?}", value);

// println!("response: {:?}", deposit_msg_1_response);

let deposit_init_result = mercury_lib::deposit::handle_deposit_msg_1_response(&coin, &deposit_msg_1_response)?;
let deposit_init_result = mercurylib::deposit::handle_deposit_msg_1_response(&coin, &deposit_msg_1_response)?;

let coin = wallet.coins.last_mut().unwrap();

Expand Down Expand Up @@ -134,7 +134,7 @@ pub async fn get_token(client_config: &ClientConfig) -> Result<String> {

let value = response.text().await?;

let token: mercury_lib::deposit::TokenID = serde_json::from_str(value.as_str())?;
let token: mercurylib::deposit::TokenID = serde_json::from_str(value.as_str())?;

return Ok(token.token_id);
}
2 changes: 1 addition & 1 deletion clients/rust/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ async fn main() -> Result<()> {
},
Commands::ListStatecoins { wallet_name } => {
coin_status::update_coins(&client_config, &wallet_name).await?;
let wallet: mercury_lib::wallet::Wallet = get_wallet(&client_config.pool, &wallet_name).await?;
let wallet: mercurylib::wallet::Wallet = get_wallet(&client_config.pool, &wallet_name).await?;
for coin in wallet.coins.iter() {
println!("----\ncoin.user_pubkey: {}", coin.user_pubkey);
println!("coin.aggregated_address: {}", coin.aggregated_address.as_ref().unwrap_or(&"".to_string()));
Expand Down
2 changes: 1 addition & 1 deletion clients/rust/src/sqlite_manager.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use mercury_lib::wallet::{Wallet, BackupTx};
use mercurylib::wallet::{Wallet, BackupTx};
use serde_json::json;
use sqlx::{Pool, Sqlite, Row};
use anyhow::{anyhow, Result};
Expand Down
6 changes: 3 additions & 3 deletions clients/rust/src/transaction.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use electrum_client::ElectrumApi;
use mercury_lib::{transaction::{SignFirstRequestPayload, PartialSignatureRequestPayload, PartialSignatureResponsePayload, get_partial_sig_request, create_signature, new_backup_transaction}, wallet::Coin};
use mercurylib::{transaction::{SignFirstRequestPayload, PartialSignatureRequestPayload, PartialSignatureResponsePayload, get_partial_sig_request, create_signature, new_backup_transaction}, wallet::Coin};
use anyhow::Result;
use secp256k1_zkp::musig::MusigPartialSignature;
use crate::{client_config::ClientConfig, utils::info_config};
Expand All @@ -16,7 +16,7 @@ pub async fn new_transaction(

// TODO: validate address first

let coin_nonce = mercury_lib::transaction::create_and_commit_nonces(&coin)?;
let coin_nonce = mercurylib::transaction::create_and_commit_nonces(&coin)?;
coin.secret_nonce = Some(coin_nonce.secret_nonce);
coin.public_nonce = Some(coin_nonce.public_nonce);
coin.blinding_factor = Some(coin_nonce.blinding_factor);
Expand Down Expand Up @@ -84,7 +84,7 @@ pub async fn sign_first(client_config: &ClientConfig, sign_first_request_payload

let value = request.json(&sign_first_request_payload).send().await?.text().await?;

let sign_first_response_payload: mercury_lib::transaction::SignFirstResponsePayload = serde_json::from_str(value.as_str())?;
let sign_first_response_payload: mercurylib::transaction::SignFirstResponsePayload = serde_json::from_str(value.as_str())?;

let mut server_pubnonce_hex = sign_first_response_payload.server_pubnonce.to_string();

Expand Down
Loading

0 comments on commit f3198df

Please sign in to comment.