Skip to content

Commit

Permalink
ffi: implement access
Browse files Browse the repository at this point in the history
Signed-off-by: Vincenzo Palazzo <[email protected]>
  • Loading branch information
vincenzopalazzo committed Nov 13, 2024
1 parent d2dcf7f commit 42d23c6
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion ffi/ffi-fundamentals/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ crate-type = ["cdylib"]

[dependencies]
fundamentals ={ path = "../../fundamentals", features = ["pyo3"] }
pyo3 = "0.22"
pyo3 = { version = "0.22", features = ["extension-module"] }
2 changes: 1 addition & 1 deletion fundamentals/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ license = "MIT"

[dependencies]
fundamentals-derive = { version = "0.0.1-alpha.2" }
pyo3 = { version = "0.22", optional = true }
pyo3 = { version = "0.22", optional = true, features = [ "extension-module" ] }

[dev-dependencies]
hex = "0.4.3"
Expand Down
6 changes: 5 additions & 1 deletion fundamentals/src/bitflag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@
//! Author: Vincenzo Palazzo <[email protected]>.
use std::vec::Vec;

#[cfg(feature = "pyo3")]
use pyo3::pyclass;

use crate::core::{FromWire, ToWire};

// FIXME: rename to bitvector :)
#[derive(Clone, Debug)]
#[cfg_attr(feature = "pyo3", pyclass)]
#[derive(Clone, Debug, Default)]
pub struct BitFlag {
pub len: u16,
inner: Vec<u8>,
Expand Down
26 changes: 20 additions & 6 deletions fundamentals/src/bolt/bolt1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ use std::io::{Read, Write};

use fundamentals_derive::{DecodeWire, EncodeWire};
#[cfg(feature = "pyo3")]
use pyo3::pyclass;
use pyo3::prelude::*;

use crate::core::{FromWire, ToWire};
use crate::prelude::*;

#[cfg_attr(feature = "pyo3", pyclass)]
#[cfg_attr(feature = "pyo3", pyclass(set_all))]
#[derive(DecodeWire, EncodeWire, Debug, Clone)]
pub struct Error {
#[msg_type = 17]
Expand All @@ -17,7 +17,7 @@ pub struct Error {
pub data: BitFlag,
}

#[cfg_attr(feature = "pyo3", pyclass)]
#[cfg_attr(feature = "pyo3", pyclass(set_all))]
#[derive(DecodeWire, EncodeWire, Debug, Clone)]
pub struct Init {
#[msg_type = 16]
Expand All @@ -27,7 +27,21 @@ pub struct Init {
pub init_tlvs: Stream,
}

#[cfg_attr(feature = "pyo3", pyclass)]
/// Python impl method to expose python API
#[cfg_attr(feature = "pyo3", pymethods)]
impl Init {
#[new]
fn new() -> PyResult<Self> {
Ok(Self {
ty: 16,
globalfeatures: BitFlag::default(),
features: BitFlag::default(),
init_tlvs: Stream::default(),
})
}
}

#[cfg_attr(feature = "pyo3", pyclass(set_all))]
#[derive(DecodeWire, EncodeWire, Debug, Clone)]
pub struct Ping {
#[msg_type = 18]
Expand All @@ -36,15 +50,15 @@ pub struct Ping {
pub ignored: BitFlag,
}

#[cfg_attr(feature = "pyo3", pyclass)]
#[cfg_attr(feature = "pyo3", pyclass(set_all))]
#[derive(DecodeWire, EncodeWire, Debug, Clone)]
pub struct Pong {
#[msg_type = 19]
pub ty: u16,
pub ignored: BitFlag,
}

#[cfg_attr(feature = "pyo3", pyclass)]
#[cfg_attr(feature = "pyo3", pyclass(set_all))]
#[derive(DecodeWire, EncodeWire, Debug, Clone)]
pub struct Warning {
#[msg_type = 1]
Expand Down
7 changes: 6 additions & 1 deletion fundamentals/src/tlv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,17 @@
//! makes parsing faster and the data smaller than in comparable text based protocols.
//!
//! Author: Vincenzo Palazzo <[email protected]>
#[cfg(feature = "pyo3")]
use pyo3::pyclass;

use crate::core::{FromWire, ToWire};
use crate::types::BigSize;

/// Stream - A `tlv_stream` is a series of (possibly zero) `tlv_record`s, represented as the
/// concatenation of the encoded `tlv_record`s. When used to extend existing
/// messages, a `tlv_stream` is typically placed after all currently defined fields.
#[derive(Clone)]
#[cfg_attr(feature = "pyo3", pyclass)]
#[derive(Clone, Default)]
pub struct Stream {
pub records: Vec<Record>,
}
Expand Down Expand Up @@ -78,6 +82,7 @@ impl FromWire for Stream {
/// * [`bigsize`: `type`]
/// * [`bigsize`: `length`]
/// * [`length`: `value`]
#[cfg_attr(feature = "pyo3", pyclass)]
#[derive(Clone)]
pub struct Record {
/// The `type` is encoded using the BigSize format. It functions as a
Expand Down

0 comments on commit 42d23c6

Please sign in to comment.