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 26, 2024
2 parents f13e4c0 + 1f947b8 commit fa8bf21
Show file tree
Hide file tree
Showing 44 changed files with 201 additions and 3,218 deletions.
24 changes: 0 additions & 24 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[workspace]
members = ["clients/standalone-rust", "clients/rust", "server", "wasm", "lib", "token-server"]
members = ["clients/rust", "server", "wasm", "lib", "token-server"]
20 changes: 10 additions & 10 deletions clients/rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,24 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
anyhow = "1.0"
bech32 = { version = "0.9.1", default-features = false }
bitcoin = { version = "0.30.1", features = ["serde", "base64", "rand-std", "std", "bitcoinconsensus"], default-features = false }
bip39 = "1.2.0"
bech32 = { version = "0.9.1", default-features = false }
clap = { version = "4.2.5", features = ["derive"]}
chrono = "0.4.31"
config = "0.13.1"
electrum-client = "0.18.0"
hex = "0.4.3"
rand = "0.8.5"
reqwest = { version = "0.11.16", features = ["blocking", "json", "socks"] }
tokio = { version = "1.27.0", features = ["full"] }
sqlx = { version = "0.7", features = [ "runtime-tokio", "sqlite", "time", "uuid" ] }
schemars = { version = "0.8.12", features = ["chrono", "uuid"] }
secp256k1-zkp = { git = "https://github.com/ssantos21/rust-secp256k1-zkp.git", branch = "blinded-musig-scheme", features = [ "rand-std", "bitcoin_hashes", "std" ] }
serde = { version = "1.0.163", features = ["derive"] }
serde_json = "1.0.96"
schemars = { version = "0.8.12", features = ["chrono", "uuid"] }
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"] }
clap = { version = "4.2.5", features = ["derive"]}
rand = "0.8.5"
hex = "0.4.3"
secp256k1-zkp = { git = "https://github.com/ssantos21/rust-secp256k1-zkp.git", branch = "blinded-musig-scheme", features = [ "rand-std", "bitcoin_hashes", "std" ] }
anyhow = "1.0"
chrono = "0.4.31"

[dependencies.mercury-lib]
path = "../../lib"
6 changes: 6 additions & 0 deletions clients/rust/src/broadcast_backup_tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ pub async fn execute(client_config: &ClientConfig, wallet_name: &str, statechain

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

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

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

let backup_txs = get_backup_txs(&client_config.pool, &statechain_id).await?;

let backup_tx = backup_txs.iter().max_by_key(|tx| tx.tx_n);
Expand Down
2 changes: 1 addition & 1 deletion clients/rust/src/deposit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ pub async fn create_tx1(client_config: &ClientConfig, coin: &mut Coin, wallet_ne

let to_address = get_user_backup_address(&coin, wallet_netwotk.to_string())?;

let signed_tx = new_transaction(&client_config, coin, &to_address, 0, false, None, wallet_netwotk).await?;
let signed_tx = new_transaction(&client_config, coin, &to_address, 0, false, None, wallet_netwotk, None).await?;

if coin.public_nonce.is_none() {
return Err(anyhow::anyhow!("coin.public_nonce is None"));
Expand Down
34 changes: 18 additions & 16 deletions clients/rust/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,33 +27,38 @@ struct Cli {
#[derive(Subcommand)]
enum Commands {
/// Create a wallet
CreateWallet { name: String },
/*
/// Create Aggregated Public Key
Deposit { wallet_name: String, token_id: String, amount: u32 },
*/
CreateWallet {
/// The name of the wallet to create
name: String
},
/// Get new token.
NewToken { },
/// Get new deposit address. Used to fund a new statecoin.
NewDepositAddress { wallet_name: String, token_id: String, amount: u32 },
/* /// Create a new statecoin from a deposit address
CreateStatecoin { wallet_name: String, deposit_address: String }, */
/// Broadcast the backup transaction to the network
BroadcastBackupTransaction { wallet_name: String, statechain_id: String, to_address: String, fee_rate: Option<u64> },
BroadcastBackupTransaction {
wallet_name: String,
statechain_id: String,
to_address: String,
/// Transaction fee rate in sats per byte
fee_rate: Option<u64>
},
/// Broadcast the backup transaction to the network
ListStatecoins { wallet_name: String },
/// Withdraw funds from a statechain coin to a bitcoin address
Withdraw { wallet_name: String, statechain_id: String, to_address: String, fee_rate: Option<u64> },
Withdraw {
wallet_name: String,
statechain_id: String,
to_address: String,
/// Transaction fee rate in sats per byte
fee_rate: Option<u64>
},
/// Generate a transfer address to receive funds
NewTransferAddress { wallet_name: String },
/// Send a statechain coin to a transfer address
TransferSend { wallet_name: String, statechain_id: String, to_address: String, },
/// Send a statechain coin to a transfer address
TransferReceive { wallet_name: String },
/*
/// Update Coins]
UpdateCoins { wallet_name: String },
*/
}

#[tokio::main(flavor = "current_thread")]
Expand Down Expand Up @@ -120,9 +125,6 @@ async fn main() -> Result<()> {
coin_status::update_coins(&client_config, &wallet_name).await?;
transfer_receiver::execute(&client_config, &wallet_name).await?;
},
/*Commands::UpdateCoins { wallet_name } => {
utils::update_coins(&client_config, &wallet_name).await?;
}*/
}

client_config.pool.close().await;
Expand Down
18 changes: 16 additions & 2 deletions clients/rust/src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,17 @@ use anyhow::Result;
use secp256k1_zkp::musig::MusigPartialSignature;
use crate::{client_config::ClientConfig, utils::info_config};

pub async fn new_transaction(client_config: &ClientConfig, coin: &mut Coin, to_address: &str, qt_backup_tx: u32, is_withdrawal: bool, block_height: Option<u32>, network: &str) -> Result<String> {
pub async fn new_transaction(
client_config: &ClientConfig,
coin: &mut Coin,
to_address: &str,
qt_backup_tx: u32,
is_withdrawal: bool,
block_height: Option<u32>,
network: &str,
fee_rate: Option<u64>) -> Result<String> {

// TODO: validate address first

let coin_nonce = mercury_lib::transaction::create_and_commit_nonces(&coin)?;
coin.secret_nonce = Some(coin_nonce.secret_nonce);
Expand All @@ -27,7 +37,11 @@ pub async fn new_transaction(client_config: &ClientConfig, coin: &mut Coin, to_a

let initlock = server_info.initlock;
let interval = server_info.interval;
let fee_rate_sats_per_byte = server_info.fee_rate_sats_per_byte as u32;

let fee_rate_sats_per_byte = match fee_rate {
Some(fee_rate) => fee_rate as u32,
None => server_info.fee_rate_sats_per_byte as u32,
};

let partial_sig_request = get_partial_sig_request(
&coin,
Expand Down
2 changes: 1 addition & 1 deletion clients/rust/src/transfer_receiver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use anyhow::{anyhow, Result};
use bitcoin::{Txid, Address};
use chrono::Utc;
use electrum_client::ElectrumApi;
use mercury_lib::{transfer::receiver::{GetMsgAddrResponsePayload, verify_transfer_signature, StatechainInfoResponsePayload, validate_tx0_output_pubkey, verify_latest_backup_tx_pays_to_user_pubkey, TxOutpoint, verify_transaction_signature, verify_blinded_musig_scheme, create_transfer_receiver_request_payload, TransferReceiverRequestPayload, get_new_key_info}, wallet::{Coin, Wallet, Activity, CoinStatus}, utils::{get_network, InfoConfig, get_blockheight}};
use mercury_lib::{transfer::receiver::{GetMsgAddrResponsePayload, verify_transfer_signature, StatechainInfoResponsePayload, validate_tx0_output_pubkey, verify_latest_backup_tx_pays_to_user_pubkey, TxOutpoint, verify_transaction_signature, verify_blinded_musig_scheme, create_transfer_receiver_request_payload, TransferReceiverRequestPayload, get_new_key_info}, wallet::{Coin, Activity, CoinStatus}, utils::{get_network, InfoConfig, get_blockheight}};
use serde_json::Value;

pub async fn new_transfer_address(client_config: &ClientConfig, wallet_name: &str) -> Result<String>{
Expand Down
8 changes: 7 additions & 1 deletion clients/rust/src/transfer_sender.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ pub async fn execute(client_config: &ClientConfig, recipient_address: &str, wall

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

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

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

let mut backup_transactions = get_backup_txs(&client_config.pool, &statechain_id).await?;

if backup_transactions.len() == 0 {
Expand Down Expand Up @@ -109,7 +115,7 @@ async fn create_backup_tx_to_receiver(client_config: &ClientConfig, coin: &mut C
let block_height = Some(get_blockheight(bkp_tx1)?);

let is_withdrawal = false;
let signed_tx = new_transaction(client_config, coin, recipient_address, qt_backup_tx, is_withdrawal, block_height, network).await?;
let signed_tx = new_transaction(client_config, coin, recipient_address, qt_backup_tx, is_withdrawal, block_height, network, None).await?;

Ok(signed_tx)
}
Expand Down
2 changes: 0 additions & 2 deletions clients/rust/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ pub async fn info_config(client_config: &ClientConfig) -> Result<InfoConfig>{

let fee_rate_sats_per_byte = (fee_rate_btc_per_kb * 100000.0) as u64;

println!("fee_rate_sats_per_byte: {}", fee_rate_sats_per_byte);

Ok(InfoConfig {
initlock,
interval,
Expand Down
8 changes: 7 additions & 1 deletion clients/rust/src/withdraw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ pub async fn execute(client_config: &ClientConfig, wallet_name: &str, statechain

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

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

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

let mut backup_txs = get_backup_txs(&client_config.pool, &statechain_id).await?;

if backup_txs.len() == 0 {
Expand Down Expand Up @@ -39,7 +45,7 @@ pub async fn execute(client_config: &ClientConfig, wallet_name: &str, statechain
return Err(anyhow::anyhow!("Coin status must be CONFIRMED to withdraw it. The current status is {}", coin.status));
}

let signed_tx = new_transaction(client_config, coin, &to_address, qt_backup_tx, true, None, &wallet.network).await?;
let signed_tx = new_transaction(client_config, coin, &to_address, qt_backup_tx, true, None, &wallet.network, fee_rate).await?;

if coin.public_nonce.is_none() {
return Err(anyhow::anyhow!("coin.public_nonce is None"));
Expand Down
3 changes: 0 additions & 3 deletions clients/standalone-rust/.gitignore

This file was deleted.

28 changes: 0 additions & 28 deletions clients/standalone-rust/Cargo.toml

This file was deleted.

30 changes: 0 additions & 30 deletions clients/standalone-rust/README.md

This file was deleted.

6 changes: 0 additions & 6 deletions clients/standalone-rust/Settings.toml

This file was deleted.

65 changes: 0 additions & 65 deletions clients/standalone-rust/migrations/0001_signer_data_table.sql

This file was deleted.

Loading

0 comments on commit fa8bf21

Please sign in to comment.