Skip to content

Commit b044a04

Browse files
committed
feature: test deposit command
1 parent 2342328 commit b044a04

6 files changed

Lines changed: 64 additions & 8 deletions

File tree

bin/utxo-spend/src/main.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,17 @@ use node::wallet::SimpleWallet;
44
use protocol::oracle::Oracle;
55
use std::str::FromStr;
66

7-
const FEE_SATS: u64 = 200;
8-
97
#[tokio::main]
108
async fn main() {
119
dotenvy::dotenv().ok();
1210

1311
// Get command line arguments
1412
let args: Vec<String> = std::env::args().collect();
15-
if args.len() != 3 {
16-
println!("Usage: {} <destination_address> <amount_in_sats>", args[0]);
13+
if args.len() != 4 {
14+
println!(
15+
"Usage: {} <destination_address> <amount_in_sats> [fee_in_sats]",
16+
args[0]
17+
);
1718
std::process::exit(1);
1819
}
1920

@@ -24,14 +25,18 @@ async fn main() {
2425
.parse::<u64>()
2526
.expect("Amount must be a valid number");
2627

28+
let fee = args[3]
29+
.parse::<u64>()
30+
.expect("Fee sats must be a valid number");
31+
2732
let mnemonic = std::env::var("MNEMONIC").expect("MNEMONIC env variable not set");
2833
let (address, private_key) = generate_keys_from_mnemonic(mnemonic.as_str());
2934
println!("Sender address: {}. Loading wallet utxos...", address);
3035

3136
let oracle = protocol::oracle::EsploraOracle::new(true);
3237
let mut wallet = SimpleWallet::new(&address, oracle.clone(), Some(true)).await;
3338

34-
let (tx, sighash) = wallet.create_spend(amount, FEE_SATS, &address_to).unwrap();
39+
let (tx, sighash) = wallet.create_spend(amount, fee, &address_to).unwrap();
3540
println!(
3641
"Created Transaction for amount: {} to address: {}",
3742
amount, address_to

bootstrap.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env bash
22
# -----------------------------------------------------------------------------
3-
# Bootstrap multiple TheVault nodes for local testing / development.
3+
# Bootstrap multiple threshold nodes for local testing / development.
44
#
55
# This script will:
66
# 1. Generate N node identities & config files via the CLI (`cargo run --bin cli setup`).

crates/clients/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ impl WindowedConfirmedTransactionProvider for EsploraApiClient {
163163
continue;
164164
}
165165
};
166+
tracing::info!("Current height: {}", current_height);
166167

167168
let new_confirmed_height = current_height - 6;
168169

@@ -205,8 +206,7 @@ impl WindowedConfirmedTransactionProvider for EsploraApiClient {
205206
if addresses.insert(
206207
Address::from_str(&address_str)
207208
.unwrap()
208-
.require_network(Network::Bitcoin)
209-
.unwrap(),
209+
.assume_checked()
210210
) {
211211
info!("Now polling {} addresses.", addresses.len());
212212
}

crates/node/src/handlers/deposit/handler.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ impl<N: Network, D: Db, O: Oracle> Handler<N, D, O> for DepositIntentState {
1919
message: Option<NetworkEvent>,
2020
) -> Result<(), types::errors::NodeError> {
2121
if let Ok(tx) = self.transaction_rx.try_recv() {
22+
tracing::info!("New transaction: {}", tx.compute_txid());
2223
if let Err(e) = self.update_user_balance(node, tx) {
2324
info!("Failed to update user balance: {}", e);
2425
}

docker-compose.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ services:
66
image: vault-node
77
environment:
88
- KEY_PASSWORD=
9+
- IS_TESTNET=true
910
entrypoint: "/app/cli run --key-file-path one.json --config-file-path one.yaml"
1011
ports:
1112
- "50051:50051"
@@ -22,6 +23,7 @@ services:
2223
dockerfile: Dockerfile
2324
environment:
2425
- KEY_PASSWORD=
26+
- IS_TESTNET=true
2527
entrypoint: "/app/cli run --key-file-path two.json --config-file-path two.yaml"
2628
volumes:
2729
- ./keys/two.json:/app/two.json
@@ -36,6 +38,7 @@ services:
3638
image: vault-node
3739
environment:
3840
- KEY_PASSWORD=
41+
- IS_TESTNET=true
3942
entrypoint: "/app/cli run --key-file-path three.json --config-file-path three.yaml"
4043
volumes:
4144
- ./keys/three.json:/app/three.json
@@ -50,6 +53,7 @@ services:
5053
image: vault-node
5154
environment:
5255
- KEY_PASSWORD=
56+
- IS_TESTNET=true
5357
entrypoint: "/app/cli run --key-file-path four.json --config-file-path four.yaml"
5458
volumes:
5559
- ./keys/four.json:/app/four.json
@@ -64,6 +68,7 @@ services:
6468
image: vault-node
6569
environment:
6670
- KEY_PASSWORD=
71+
- IS_TESTNET=true
6772
entrypoint: "/app/cli run --key-file-path five.json --config-file-path five.yaml"
6873
volumes:
6974
- ./keys/five.json:/app/five.json

test-deposit.sh

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/bin/bash
2+
3+
# Set the deposit amount
4+
deposit_amount=$1
5+
fee=$2
6+
7+
# Check if the deposit amount is provided
8+
if [ -z "$deposit_amount" ]; then
9+
echo "Error: Please provide a deposit amount."
10+
exit 1
11+
fi
12+
13+
# Check if the fee is provided
14+
if [ -z "$fee" ]; then
15+
fee=200
16+
echo "Fee not provided, using default value: $fee"
17+
fi
18+
19+
# Run the deposit command and extract the deposit_address
20+
deposit_output=$(cargo run --bin "cli" -- deposit "$deposit_amount" 2>&1)
21+
echo "$deposit_output"
22+
deposit_address=$(echo "$deposit_output" | grep "deposit_address" | sed 's/.*deposit_address: "\([^"]*\)".*/\1/')
23+
24+
# Check if deposit_address is empty
25+
if [ -z "$deposit_address" ]; then
26+
echo "Error: Could not extract deposit_address from deposit command output."
27+
exit 1
28+
fi
29+
30+
echo "Deposit Address: $deposit_address"
31+
32+
# Run the utxo-spend command with the extracted address and extract the transaction_id
33+
utxo_spend_output=$(cargo run --bin "utxo-spend" -- "$deposit_address" "$deposit_amount" "$fee" 2>&1)
34+
35+
echo "$utxo_spend_output"
36+
transaction_id=$(echo "$utxo_spend_output" | grep "Broadcast Transaction txid:" | sed 's/.*Broadcast Transaction txid: //')
37+
38+
# Check if transaction_id is empty
39+
if [ -z "$transaction_id" ]; then
40+
echo "Error: Could not extract transaction_id from utxo-spend command output."
41+
exit 1
42+
fi
43+
44+
# Print the transaction ID
45+
echo "Submitted Transaction ID: $transaction_id"

0 commit comments

Comments
 (0)