Skip to content

Commit

Permalink
Merge pull request #4 from carlaKC/common-structs
Browse files Browse the repository at this point in the history
sim-lib: Add event queue common structs
  • Loading branch information
sr-gi authored Aug 14, 2023
2 parents 5e3cec1 + efd1263 commit 1ec8fcd
Show file tree
Hide file tree
Showing 3 changed files with 140 additions and 10 deletions.
106 changes: 106 additions & 0 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions sim-lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ edition = "2021"
[dependencies]
serde = { version="1.0.183", features=["derive"] }
serde_json = "1.0.104"
bitcoin = { version = "0.30.1" }
lightning = { version = "0.0.116" }
42 changes: 32 additions & 10 deletions sim-lib/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
use serde::{Deserialize, Serialize};
use bitcoin::secp256k1::PublicKey;
use lightning::ln::PaymentHash;

// Phase 0: User input - see config.json

// Phase 1: Parsed User Input

#[derive(Serialize, Deserialize, Debug)]
pub struct NodeConnection {
Expand All @@ -13,17 +19,33 @@ pub struct Config {
nodes: Vec<NodeConnection>,
}

pub fn add(left: usize, right: usize) -> usize {
left + right
// Phase 2: Event Queue

#[allow(dead_code)]
enum PaymentError {}

/// LightningNode represents the functionality that is required to execute events on a lightning node.
trait LightningNode {
fn send_payment(&self, dest: PublicKey, amt_msat: u64) -> Result<PaymentHash, ()>;
fn track_payment(&self, hash: PaymentHash) -> Result<(), PaymentError>;
}

#[allow(dead_code)]
enum NodeAction {
// Dispatch a payment of the specified amount to the public key provided.
SendPayment(PublicKey, u64),
}

#[cfg(test)]
mod tests {
use super::*;
#[allow(dead_code)]
struct Event {
// The public key of the node executing this event.
source: PublicKey,

#[test]
fn it_works() {
let result = add(2, 2);
assert_eq!(result, 4);
}
// Offset is the time offset from the beginning of execution that this event should be executed.
offset: u64,

// An action to be executed on the source node.
action: NodeAction,
}

// Phase 3: CSV output - TODO

0 comments on commit 1ec8fcd

Please sign in to comment.