Struct NodeId

Source
pub struct NodeId(/* private fields */);
Expand description

Byte representation of a node identifier.

This type is used when referring to nodes without doing cryptographic operations. It can be used in search algorithms, LN explorers, manager UIs etc. By avoiding cryptography it is significantly more performant but may make debugging harder. It is therefore recommended to perform checking at system boundaries where performance is not very important - e.g. user inputs.

Despite this not being a guaranteed point on the curve it still performs cheap basic sanity check: whether the key begins with 0x02 or 0x03.

§Example

let marvin_str = "029ef8ee0ba895e2807ac1df1987a7888116c468e70f42e7b089e06811b0e45482";
let marvin = marvin_str.parse::<ln_types::NodeId>().unwrap();
assert_eq!(marvin.to_string(), marvin_str);

Implementations§

Source§

impl NodeId

Source

pub fn from_raw_bytes(bytes: [u8; 33]) -> Result<Self, InvalidNodeId>

Creates NodeId from raw byte representation.

Source

pub fn to_vec(self) -> Vec<u8>

Available on crate feature alloc only.

Puts the byte representation into Vec<u8>.

This is meant for convenience around APIs that require Vec<u8>. Since it allocates it’s best to avoid it if possible.

Source

pub fn to_array(self) -> [u8; 33]

Convenience conversion to byte array.

This can be used instead of From to avoid inference issues.

Trait Implementations§

Source§

impl AsRef<[u8]> for NodeId

Source§

fn as_ref(&self) -> &[u8]

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl AsRef<[u8; 33]> for NodeId

Source§

fn as_ref(&self) -> &[u8; 33]

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl Borrow<[u8]> for NodeId

Source§

fn borrow(&self) -> &[u8]

Immutably borrows from an owned value. Read more
Source§

impl Borrow<[u8; 33]> for NodeId

Source§

fn borrow(&self) -> &[u8; 33]

Immutably borrows from an owned value. Read more
Source§

impl Clone for NodeId

Source§

fn clone(&self) -> NodeId

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for NodeId

Same as Display

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for NodeId

Available on crate feature serde only.

NodeId is deserialized as hex from human-readable formats and as bytes from non-human-readable.

Source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for NodeId

Shows NodeId as hex

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a> From<&'a NodePubkey> for NodeId

Available on crate feature secp256k1 only.
Source§

fn from(value: &'a NodePubkey) -> Self

Converts to this type from the input type.
Source§

impl From<NodeId> for [u8; 33]

Source§

fn from(value: NodeId) -> Self

Converts to this type from the input type.
Source§

impl From<NodePubkey> for NodeId

Available on crate feature secp256k1 only.
Source§

fn from(value: NodePubkey) -> Self

Converts to this type from the input type.
Source§

impl<'a> FromSql<'a> for NodeId

Available on crate feature postgres-types only.

Supports BYTEA, TEXT, and VARCHAR.

Decoded as bytes if BYTEA is used, as hex string otherwise.

Source§

fn from_sql( ty: &Type, raw: &'a [u8], ) -> Result<Self, Box<dyn Error + Send + Sync + 'static>>

Creates a new value of this type from a buffer of data of the specified Postgres Type in its binary format. Read more
Source§

fn accepts(ty: &Type) -> bool

Determines if a value of this type can be created from the specified Postgres Type.
Source§

fn from_sql_null(ty: &Type) -> Result<Self, Box<dyn Error + Send + Sync>>

Creates a new value of this type from a NULL SQL value. Read more
Source§

fn from_sql_nullable( ty: &Type, raw: Option<&'a [u8]>, ) -> Result<Self, Box<dyn Error + Send + Sync>>

A convenience function that delegates to from_sql and from_sql_null depending on the value of raw.
Source§

impl FromStr for NodeId

Expects hex representation

Source§

type Err = ParseError

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
Source§

impl Hash for NodeId

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl LowerHex for NodeId

Same as Display

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Ord for NodeId

Source§

fn cmp(&self, other: &NodeId) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl ParseArgFromStr for NodeId

Available on crate feature parse_arg only.
Source§

fn describe_type<W: Write>(writer: W) -> Result

Writes human-readable description of the type to the writer. Read more
Source§

impl PartialEq for NodeId

Source§

fn eq(&self, other: &NodeId) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for NodeId

Source§

fn partial_cmp(&self, other: &NodeId) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Serialize for NodeId

Available on crate feature serde only.

NodeId is serialized as hex to human-readable formats and as bytes to non-human-readable.

Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl ToSql for NodeId

Available on crate feature postgres-types only.

Supports BYTEA, TEXT, and VARCHAR.

Stored as bytes if BYTEA is used, as hex string otherwise.

Source§

fn to_sql( &self, ty: &Type, out: &mut BytesMut, ) -> Result<IsNull, Box<dyn Error + Send + Sync + 'static>>

Converts the value of self into the binary format of the specified Postgres Type, appending it to out. Read more
Source§

fn accepts(ty: &Type) -> bool

Determines if a value of this type can be converted to the specified Postgres Type.
Source§

fn to_sql_checked( &self, ty: &Type, out: &mut BytesMut, ) -> Result<IsNull, Box<dyn Error + Sync + Send>>

An adaptor method used internally by Rust-Postgres. Read more
Source§

fn encode_format(&self, _ty: &Type) -> Format

Specify the encode format
Source§

impl<'a> TryFrom<&'a [u8]> for NodeId

Source§

type Error = DecodeError

The type returned in the event of a conversion error.
Source§

fn try_from(slice: &'a [u8]) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<'a> TryFrom<&'a str> for NodeId

Expects hex representation

Source§

type Error = ParseError

The type returned in the event of a conversion error.
Source§

fn try_from(s: &'a str) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Box<[u8]>> for NodeId

Available on crate feature alloc only.
Source§

type Error = DecodeError

The type returned in the event of a conversion error.
Source§

fn try_from(slice: Box<[u8]>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Box<str>> for NodeId

Available on crate feature alloc only.

Expects hex representation

Source§

type Error = ParseError

The type returned in the event of a conversion error.
Source§

fn try_from(s: Box<str>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<NodeId> for NodePubkey

Available on crate feature secp256k1 only.
Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(value: NodeId) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<String> for NodeId

Available on crate feature alloc only.

Expects hex representation

Source§

type Error = ParseError

The type returned in the event of a conversion error.
Source§

fn try_from(s: String) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Vec<u8>> for NodeId

Available on crate feature alloc only.
Source§

type Error = DecodeError

The type returned in the event of a conversion error.
Source§

fn try_from(vec: Vec<u8>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl UpperHex for NodeId

As Display but with upper-case letters

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Value for NodeId

Available on crate feature slog only.

Currently uses Display but may use emit_bytes if/when it’s implemented.

Source§

fn serialize( &self, _rec: &Record<'_>, key: Key, serializer: &mut dyn Serializer, ) -> Result

Serialize self into Serializer Read more
Source§

impl Copy for NodeId

Source§

impl Eq for NodeId

Source§

impl StructuralPartialEq for NodeId

Auto Trait Implementations§

§

impl Freeze for NodeId

§

impl RefUnwindSafe for NodeId

§

impl Send for NodeId

§

impl Sync for NodeId

§

impl Unpin for NodeId

§

impl UnwindSafe for NodeId

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> BorrowToSql for T
where T: ToSql,

Source§

fn borrow_to_sql(&self) -> &dyn ToSql

Returns a reference to self as a ToSql trait object.
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ParseArg for T
where T: ParseArgFromStr, <T as FromStr>::Err: Display,

Source§

type Error = ParseArgError<<T as FromStr>::Err>

Type returned in the Err variant of Result when parsing fails.
Source§

fn parse_arg(arg: &OsStr) -> Result<T, <T as ParseArg>::Error>

Parses the argument.
Source§

fn describe_type<W>(writer: W) -> Result<(), Error>
where W: Write,

Writes human-readable description of the type to the writer. Read more
Source§

fn parse_owned_arg(arg: OsString) -> Result<Self, Self::Error>

Parses the argument consuming it. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> FromSqlOwned for T
where T: for<'a> FromSql<'a>,