Bitcoin keys now load into SideNode
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
use bitcoin::secp256k1::{rand, Keypair, Secp256k1, SecretKey};
|
use bitcoin::secp256k1::{rand, Keypair, PublicKey, Secp256k1, SecretKey};
|
||||||
use std::{
|
use std::{
|
||||||
fs::{self, File},
|
fs::{self, File},
|
||||||
io::Write,
|
io::Write,
|
||||||
@@ -6,14 +6,18 @@ use std::{
|
|||||||
str::FromStr,
|
str::FromStr,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub(crate) fn write(key_path: &PathBuf) -> Result<(), std::io::Error> {
|
pub fn make_keypair() -> bitcoin::secp256k1::Keypair {
|
||||||
let secp = Secp256k1::new();
|
let secp = Secp256k1::new();
|
||||||
let (secret_key, public_key) = secp.generate_keypair(&mut rand::thread_rng());
|
let (secret_key, _) = secp.generate_keypair(&mut rand::thread_rng());
|
||||||
|
Keypair::from_secret_key(&secp, &secret_key)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn write(key_path: &PathBuf) -> Result<(), std::io::Error> {
|
||||||
|
let key_pair = make_keypair();
|
||||||
let mut file = File::create(key_path)?;
|
let mut file = File::create(key_path)?;
|
||||||
|
|
||||||
let pub_str = public_key.to_string();
|
let pub_str = key_pair.public_key().to_string();
|
||||||
let priv_str = secret_key.display_secret().to_string();
|
let priv_str = key_pair.display_secret().to_string();
|
||||||
println!("private key: {priv_str}");
|
println!("private key: {priv_str}");
|
||||||
let out = format!("{pub_str}/{priv_str}");
|
let out = format!("{pub_str}/{priv_str}");
|
||||||
println!("out: {out}");
|
println!("out: {out}");
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ use tokio::{sync::mpsc, task};
|
|||||||
use websocket::WebSocketClient;
|
use websocket::WebSocketClient;
|
||||||
|
|
||||||
pub mod bft_crdt_keys;
|
pub mod bft_crdt_keys;
|
||||||
pub(crate) mod bitcoin_keys;
|
pub mod bitcoin_keys;
|
||||||
pub(crate) mod cli;
|
pub(crate) mod cli;
|
||||||
pub mod crdt;
|
pub mod crdt;
|
||||||
pub(crate) mod init;
|
pub(crate) mod init;
|
||||||
|
|||||||
@@ -2,7 +2,9 @@ use bft_json_crdt::{
|
|||||||
json_crdt::{BaseCrdt, SignedOp},
|
json_crdt::{BaseCrdt, SignedOp},
|
||||||
keypair::make_keypair,
|
keypair::make_keypair,
|
||||||
};
|
};
|
||||||
use side_node::{crdt::TransactionList, node::SideNode, utils, websocket::WebSocketClient};
|
use side_node::{
|
||||||
|
bitcoin_keys, crdt::TransactionList, node::SideNode, utils, websocket::WebSocketClient,
|
||||||
|
};
|
||||||
use tokio::sync::mpsc;
|
use tokio::sync::mpsc;
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
@@ -34,9 +36,9 @@ async fn test_distribute_via_websockets() {
|
|||||||
/// Wire everything up, ignoring things we are not using in the test
|
/// Wire everything up, ignoring things we are not using in the test
|
||||||
async fn setup(_: &str) -> SideNode {
|
async fn setup(_: &str) -> SideNode {
|
||||||
// First, load up the keys and create a bft-crdt
|
// First, load up the keys and create a bft-crdt
|
||||||
let keys = make_keypair();
|
let bft_crdt_keys = make_keypair();
|
||||||
let bitcoin_keys = bitcoin::secp256k1::Keypair::new();
|
let bitcoin_keys = bitcoin_keys::make_keypair();
|
||||||
let crdt = BaseCrdt::<TransactionList>::new(&keys);
|
let crdt = BaseCrdt::<TransactionList>::new(&bft_crdt_keys);
|
||||||
|
|
||||||
// Channels for internal communication, and a tokio task for stdin input
|
// Channels for internal communication, and a tokio task for stdin input
|
||||||
let (incoming_sender, incoming_receiver) = mpsc::channel::<SignedOp>(32);
|
let (incoming_sender, incoming_receiver) = mpsc::channel::<SignedOp>(32);
|
||||||
@@ -44,6 +46,13 @@ async fn setup(_: &str) -> SideNode {
|
|||||||
|
|
||||||
// Finally, create the node and return it
|
// Finally, create the node and return it
|
||||||
let handle = WebSocketClient::new(incoming_sender).await;
|
let handle = WebSocketClient::new(incoming_sender).await;
|
||||||
let node = SideNode::new(crdt, keys, incoming_receiver, stdin_receiver, handle);
|
let node = SideNode::new(
|
||||||
|
crdt,
|
||||||
|
bft_crdt_keys,
|
||||||
|
bitcoin_keys,
|
||||||
|
incoming_receiver,
|
||||||
|
stdin_receiver,
|
||||||
|
handle,
|
||||||
|
);
|
||||||
node
|
node
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user