send times to welist
ED25519 times signing
This commit is contained in:
parent
d937ee9364
commit
7c8ed123aa
31
README.md
31
README.md
@ -1,10 +1,11 @@
|
|||||||
# bal-server
|
# bal-server
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ git clone ....
|
$ git clone ....
|
||||||
$ cd bal-server
|
$ cd bal-server
|
||||||
|
$ openssl genpkey -algorithm ED25519 -out private_key.pem
|
||||||
|
$ openssl pkey -in private_key.pem -pubout -out public_key.pem
|
||||||
$ cargo build --release
|
$ cargo build --release
|
||||||
$ sudo cp target/release/bal-server /usr/local/bin
|
$ sudo cp target/release/bal-server /usr/local/bin
|
||||||
$ bal-server
|
$ bal-server
|
||||||
@ -20,6 +21,7 @@ The `bal-server` application can be configured using environment variables. The
|
|||||||
| `BAL_SERVER_DB_FILE` | Path to the SQLite3 database file. If the file does not exist, a new one will be created. | `bal.db` |
|
| `BAL_SERVER_DB_FILE` | Path to the SQLite3 database file. If the file does not exist, a new one will be created. | `bal.db` |
|
||||||
| `BAL_SERVER_BIND_ADDRESS` | Public address for listening to requests. | `127.0.0.1` |
|
| `BAL_SERVER_BIND_ADDRESS` | Public address for listening to requests. | `127.0.0.1` |
|
||||||
| `BAL_SERVER_BIND_PORT` | Default port for listening to requests. | `9137` |
|
| `BAL_SERVER_BIND_PORT` | Default port for listening to requests. | `9137` |
|
||||||
|
| `BAL_SERVER_PUB_KEY_PATH` | WillExecutor Ed25519 public key | `public_key.pem` |
|
||||||
| `BAL_SERVER_REGTEST_ADDRESS` | Bitcoin address for the regtest environment. | - |
|
| `BAL_SERVER_REGTEST_ADDRESS` | Bitcoin address for the regtest environment. | - |
|
||||||
| `BAL_SERVER_REGTEST_FIXED_FEE` | Fixed fee for the regtest environment. | 50000 |
|
| `BAL_SERVER_REGTEST_FIXED_FEE` | Fixed fee for the regtest environment. | 50000 |
|
||||||
| `BAL_SERVER_SIGNET_ADDRESS` | Bitcoin address for the signet environment. | - |
|
| `BAL_SERVER_SIGNET_ADDRESS` | Bitcoin address for the signet environment. | - |
|
||||||
@ -28,6 +30,8 @@ The `bal-server` application can be configured using environment variables. The
|
|||||||
| `BAL_SERVER_TESTNET_FIXED_FEE` | Fixed fee for the testnet environment. | 50000 |
|
| `BAL_SERVER_TESTNET_FIXED_FEE` | Fixed fee for the testnet environment. | 50000 |
|
||||||
| `BAL_SERVER_BITCOIN_ADDRESS` | Bitcoin address for the mainnet environment. | - |
|
| `BAL_SERVER_BITCOIN_ADDRESS` | Bitcoin address for the mainnet environment. | - |
|
||||||
| `BAL_SERVER_BITCOIN_FIXED_FEE` | Fixed fee for the mainnet environment. | 50000 |
|
| `BAL_SERVER_BITCOIN_FIXED_FEE` | Fixed fee for the mainnet environment. | 50000 |
|
||||||
|
|
||||||
|
|
||||||
# bal-pusher
|
# bal-pusher
|
||||||
|
|
||||||
`bal-pusher` is a tool that retrieves Bitcoin transactions from a database and pushes them to the Bitcoin network when their **locktime** exceeds the **median time past** (MTP). It listens for Bitcoin block updates via ZMQ.
|
`bal-pusher` is a tool that retrieves Bitcoin transactions from a database and pushes them to the Bitcoin network when their **locktime** exceeds the **median time past** (MTP). It listens for Bitcoin block updates via ZMQ.
|
||||||
@ -48,27 +52,6 @@ To use `bal-pusher`, you need to compile and install Bitcoin with ZMQ (ZeroMQ) s
|
|||||||
2. **Install Rust and Cargo**:
|
2. **Install Rust and Cargo**:
|
||||||
If you haven't already installed Rust and Cargo, you can follow the official instructions to do so: [Rust Installation](https://www.rust-lang.org/tools/install).
|
If you haven't already installed Rust and Cargo, you can follow the official instructions to do so: [Rust Installation](https://www.rust-lang.org/tools/install).
|
||||||
|
|
||||||
### Installation Steps
|
|
||||||
|
|
||||||
1. Clone the repository:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
git clone <repo-url>
|
|
||||||
cd bal-pusher
|
|
||||||
```
|
|
||||||
|
|
||||||
2. Build the project:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
cargo build --release
|
|
||||||
```
|
|
||||||
|
|
||||||
3. Install the binary:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
sudo cp target/release/bal-pusher /usr/local/bin
|
|
||||||
```
|
|
||||||
|
|
||||||
## Configuration
|
## Configuration
|
||||||
|
|
||||||
`bal-pusher` can be configured using environment variables. If no configuration file is provided, a default configuration file will be created.
|
`bal-pusher` can be configured using environment variables. If no configuration file is provided, a default configuration file will be created.
|
||||||
@ -85,6 +68,10 @@ To use `bal-pusher`, you need to compile and install Bitcoin with ZMQ (ZeroMQ) s
|
|||||||
| `BAL_PUSHER_BITCOIN_COOKIE_FILE` | Path to Bitcoin RPC cookie file. | `$HOME/.bitcoin/.cookie` |
|
| `BAL_PUSHER_BITCOIN_COOKIE_FILE` | Path to Bitcoin RPC cookie file. | `$HOME/.bitcoin/.cookie` |
|
||||||
| `BAL_PUSHER_BITCOIN_RPC_USER` | Bitcoin RPC username. | - |
|
| `BAL_PUSHER_BITCOIN_RPC_USER` | Bitcoin RPC username. | - |
|
||||||
| `BAL_PUSHER_BITCOIN_RPC_PASSWORD` | Bitcoin RPC password. | - |
|
| `BAL_PUSHER_BITCOIN_RPC_PASSWORD` | Bitcoin RPC password. | - |
|
||||||
|
| `BAL_PUSHER_SEND_STATS` | Contact welist to provide times | false |
|
||||||
|
| `WELIST_SERVER_URL` | welist server url to provide times | https://welist.bitcoin-afer.life |
|
||||||
|
| `BAL_SERVER_URL` | WillExecutor server url | - |
|
||||||
|
| `SSL_KEY_PATH` | Ed25519 private key pem file | `private_key.pem` |
|
||||||
|
|
||||||
|
|
||||||
## Running `bal-pusher`
|
## Running `bal-pusher`
|
||||||
|
|||||||
14
bal-pusher.sh
Normal file
14
bal-pusher.sh
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
RUST_LOG=trace
|
||||||
|
|
||||||
|
BAL_PUSHER_DB_FILE="$(pwd)/bal.db"
|
||||||
|
#export BAL_PUSHER_BITCOIN_COOKIE_FILE=/~/.bitcoin/.cookie
|
||||||
|
#export BAL_PUSHER_REGTEST_COOKIE_FILE=/~/.bitcoin/regtest/.cookie
|
||||||
|
#export BAL_PUSHER_TESTNET_COOKIE_FILE=/~/.bitcoin/testnet3/.cookie
|
||||||
|
#export BAL_PUSHER_SIGNET_COOKIE_FILE=/~/.bitcoin/signet/.cookie
|
||||||
|
|
||||||
|
BAL_PUSHER_ZMQ_LISTENER=tcp://127.0.0.1:28332
|
||||||
|
export BAL_PUSHER_SEND_STATS=true
|
||||||
|
export WELIST_SERVER_URL=http://localhost:8085
|
||||||
|
export BAL_SERVER_URL="http://127.0.0.1:9133"
|
||||||
|
export SSL_KEY_PATH="$(pwd)/private_key.pem"
|
||||||
|
cargo run --bin=bal-pusher regtest
|
||||||
24
bal-server.sh
Normal file
24
bal-server.sh
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
WORKING_DIR=$(pwd)
|
||||||
|
if [ ! -f "$WORKING_DIR/public_key.pem" ]; then
|
||||||
|
echo "creating keypairs"
|
||||||
|
openssl genpkey -algorithm ED25519 -out private_key.pem
|
||||||
|
openssl pkey -in private_key.pem -pubout -out public_key.pem
|
||||||
|
fi
|
||||||
|
|
||||||
|
export RUST_LOG="trace"
|
||||||
|
export BAL_SERVER_DB_FILE="$WORKING_DIR/bal.db"
|
||||||
|
export BAL_SERVER_INFO="BAL devel willexecutor server"
|
||||||
|
export BAL_SERVER_BIND_ADDRESS="127.0.0.1"
|
||||||
|
export BAL_SERVER_BIND_PORT=9133
|
||||||
|
export BAL_SERVER_PUB_KEY_PATH="$WORKING_DIR/public_key.pem"
|
||||||
|
|
||||||
|
#export BAL_SERVER_BITCOIN_ADDRESS="your bitcoin address or xpub to recive payments here"
|
||||||
|
#export BAL_SERVER_BITCOIN_FIXED_FEE=50000
|
||||||
|
|
||||||
|
export BAL_SERVER_REGTEST_ADDRESS="vpub5UhLrYG1qQjnJhvJgBdqgpznyH11mxW9hwBYxf3KhfdjiupCFPUVDvgwpeZ9Wj5YUJXjKjXjy7DSbJNBW1sXbKwARiaphm1UjHYy3mKvTG4"
|
||||||
|
export BAL_SERVER_REGTEST_FEE=5000
|
||||||
|
#export BAL_SERVER_TESTNET_ADDRESS=
|
||||||
|
#export BAL_SERVER_TESTNET_FEE=100000
|
||||||
|
#export BAL_SERVER_SIGNET_ADDRESS=
|
||||||
|
#export BAL_SERVER_SIGNET_FEE=100000
|
||||||
|
cargo run --bin=bal-server
|
||||||
@ -24,6 +24,7 @@ use reqwest::Client as rClient;
|
|||||||
use openssl::hash::MessageDigest;
|
use openssl::hash::MessageDigest;
|
||||||
use openssl::pkey::{PKey};
|
use openssl::pkey::{PKey};
|
||||||
use openssl::sign::Signer;
|
use openssl::sign::Signer;
|
||||||
|
use openssl::sign::Verifier;
|
||||||
use base64::{engine::general_purpose, Engine as _};
|
use base64::{engine::general_purpose, Engine as _};
|
||||||
use std::fs;
|
use std::fs;
|
||||||
|
|
||||||
@ -327,7 +328,7 @@ async fn send_stats_report(cfg: &MyConfig, bcinfo: GetBlockchainInfoResult) -> R
|
|||||||
}))
|
}))
|
||||||
.send().await?;
|
.send().await?;
|
||||||
let body = &(response.text().await?);
|
let body = &(response.text().await?);
|
||||||
println!("Body: {}", body);
|
trace!("Body: {}", body);
|
||||||
}else {
|
}else {
|
||||||
debug!("Not sending stats");
|
debug!("Not sending stats");
|
||||||
}
|
}
|
||||||
@ -339,16 +340,14 @@ fn sign_message(private_key_path: &str, message: &str) -> String {
|
|||||||
let key_data = fs::read(private_key_path).unwrap();
|
let key_data = fs::read(private_key_path).unwrap();
|
||||||
|
|
||||||
let private_key = PKey::private_key_from_pem(&key_data).unwrap();
|
let private_key = PKey::private_key_from_pem(&key_data).unwrap();
|
||||||
|
let mut signer = Signer::new_without_digest(&private_key).unwrap();
|
||||||
|
|
||||||
let mut signer = Signer::new(MessageDigest::sha256(), &private_key).unwrap();
|
let signature = signer.sign_oneshot_to_vec(message.as_bytes()).unwrap();
|
||||||
|
|
||||||
signer.update(message.as_bytes()).unwrap();
|
|
||||||
|
|
||||||
let firma = signer.sign_to_vec().unwrap();
|
let signature_b64 = general_purpose::STANDARD.encode(&signature);
|
||||||
|
|
||||||
let firma_b64 = general_purpose::STANDARD.encode(&firma);
|
signature_b64
|
||||||
|
|
||||||
firma_b64
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_env(cfg: &mut MyConfig){
|
fn parse_env(cfg: &mut MyConfig){
|
||||||
|
|||||||
@ -11,6 +11,7 @@ use std::net::IpAddr;
|
|||||||
use std::env;
|
use std::env;
|
||||||
|
|
||||||
//use std::time::{SystemTime,UNIX_EPOCH};
|
//use std::time::{SystemTime,UNIX_EPOCH};
|
||||||
|
use std::fs;
|
||||||
use std::sync::{ Arc, Mutex, MutexGuard };
|
use std::sync::{ Arc, Mutex, MutexGuard };
|
||||||
//use std::net::SocketAddr;
|
//use std::net::SocketAddr;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
@ -68,6 +69,7 @@ struct MyConfig {
|
|||||||
bind_address: String,
|
bind_address: String,
|
||||||
bind_port: u16, // Changed to u16 for port numbers
|
bind_port: u16, // Changed to u16 for port numbers
|
||||||
db_file: String,
|
db_file: String,
|
||||||
|
pub_key_path: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug,Serialize, Deserialize)]
|
#[derive(Debug,Serialize, Deserialize)]
|
||||||
@ -90,7 +92,8 @@ impl Default for MyConfig {
|
|||||||
bind_address: "127.0.0.1".to_string(),
|
bind_address: "127.0.0.1".to_string(),
|
||||||
bind_port: 9137,
|
bind_port: 9137,
|
||||||
db_file: "bal.db".to_string(),
|
db_file: "bal.db".to_string(),
|
||||||
info:"Will Executor Server".to_string()
|
info: "Will Executor Server".to_string(),
|
||||||
|
pub_key_path: "public_key.pem".to_string(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -109,6 +112,13 @@ async fn echo_version(
|
|||||||
) -> Result<Response<BoxBody<Bytes, hyper::Error>>, hyper::Error> {
|
) -> Result<Response<BoxBody<Bytes, hyper::Error>>, hyper::Error> {
|
||||||
Ok(Response::new(full(VERSION)))
|
Ok(Response::new(full(VERSION)))
|
||||||
}
|
}
|
||||||
|
async fn echo_pub_key(
|
||||||
|
cfg: &MyConfig,
|
||||||
|
) -> Result<Response<BoxBody<Bytes, hyper::Error>>, hyper::Error> {
|
||||||
|
let pub_key = fs::read_to_string(&cfg.pub_key_path)
|
||||||
|
.expect(format!("Failed to read public key file {}",cfg.pub_key_path).as_str());
|
||||||
|
Ok(Response::new(full(pub_key)))
|
||||||
|
}
|
||||||
async fn echo_info(
|
async fn echo_info(
|
||||||
param: &str,
|
param: &str,
|
||||||
cfg: &MyConfig,
|
cfg: &MyConfig,
|
||||||
@ -441,6 +451,9 @@ async fn echo(
|
|||||||
if uri=="/version"{
|
if uri=="/version"{
|
||||||
ret= echo_version().await;
|
ret= echo_version().await;
|
||||||
}
|
}
|
||||||
|
if uri=="/.pub_key.pem" {
|
||||||
|
ret = echo_pub_key(cfg).await;
|
||||||
|
}
|
||||||
ret
|
ret
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -480,6 +493,11 @@ fn parse_env(cfg: &Arc<Mutex<MyConfig>>){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if let Ok(value) = env::var("BAL_SERVER_PUB_KEY_PATH") {
|
||||||
|
debug!("BAL_SERVER_PUB_KEY_PATH: {}",value);
|
||||||
|
cfg_lock.pub_key_path = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if let Ok(value) = env::var("BAL_SERVER_INFO"){
|
if let Ok(value) = env::var("BAL_SERVER_INFO"){
|
||||||
debug!("BAL_SERVER_INFO: {}",value);
|
debug!("BAL_SERVER_INFO: {}",value);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user