diff --git a/README.md b/README.md index 792cdf5..52984d7 100644 --- a/README.md +++ b/README.md @@ -64,7 +64,7 @@ nightly In this new esp-rs repo, find the path to your `riscv32-esp-elf-gcc` binary within the `.embuild` dir: -`export CC=/Users/evanfeenstra/code/sphinx-key/sphinx-key/signer/.embuild/espressif/tools/riscv32-esp-elf/esp-2021r2-patch3-8.4.0/riscv32-esp-elf/bin/riscv32-esp-elf-gcc` +`export CC=/Users/evanfeenstra/code/sphinx-key/sphinx-key/sphinx-key/.embuild/espressif/tools/riscv32-esp-elf/esp-2021r2-patch3-8.4.0/riscv32-esp-elf/bin/riscv32-esp-elf-gcc` ### get std features of vls: diff --git a/signer/src/lib.rs b/signer/src/lib.rs index 769e4a0..9792ee5 100644 --- a/signer/src/lib.rs +++ b/signer/src/lib.rs @@ -6,6 +6,7 @@ use vls_protocol::serde_bolt::WireString; use vls_protocol_signer::lightning_signer; use vls_protocol_signer::vls_protocol; +pub use vls_protocol::model::PubKey; pub use vls_protocol_signer::handler::{Handler, RootHandler}; pub struct InitResponse { @@ -40,8 +41,34 @@ pub fn init(bytes: Vec) -> anyhow::Result { }) } -pub fn handle(_root_handler: &RootHandler, _bytes: Vec) -> anyhow::Result> { - Ok(Vec::new()) +pub fn handle( + root_handler: &RootHandler, + bytes: Vec, + dummy_peer: PubKey, +) -> anyhow::Result> { + let mut md = MsgDriver::new(bytes); + let (sequence, dbid) = read_serial_request_header(&mut md).expect("read request header"); + let mut message = msgs::read(&mut md).expect("message read failed"); + + // Override the peerid when it is passed in certain messages + match message { + Message::NewChannel(ref mut m) => m.node_id = dummy_peer.clone(), + Message::ClientHsmFd(ref mut m) => m.peer_id = dummy_peer.clone(), + Message::GetChannelBasepoints(ref mut m) => m.node_id = dummy_peer.clone(), + Message::SignCommitmentTx(ref mut m) => m.peer_id = dummy_peer.clone(), + _ => {} + }; + + let reply = if dbid > 0 { + let handler = root_handler.for_new_client(0, dummy_peer.clone(), dbid); + handler.handle(message).expect("handle") + } else { + root_handler.handle(message).expect("handle") + }; + let mut out_md = MsgDriver::new_empty(); + write_serial_response_header(&mut out_md, sequence).expect("write reply header"); + msgs::write_vec(&mut out_md, reply.as_vec()).expect("write reply"); + Ok(out_md.bytes()) } pub fn parse_ping_and_form_response(msg_bytes: Vec) -> Vec { @@ -59,12 +86,6 @@ pub fn parse_ping_and_form_response(msg_bytes: Vec) -> Vec { md.bytes() } -// pub fn say_hi() { -// let persister: Arc = Arc::new(DummyPersister); - -// println!("Hello, world!"); -// } - fn from_wire_string(s: &WireString) -> String { String::from_utf8(s.0.to_vec()).expect("malformed string") }