Add Magic::from_params
Currently `Magic` has per network consts but no way to dynamically get the magic bytes for a network. Note also that we are currently trying to reduce the usage of `Network` in the public API. Add a public constructor to the `Magic` type that accepts a `Params` parameter to determine the network to use.
This commit is contained in:
parent
499f36f972
commit
3ec5eff56e
|
@ -28,6 +28,7 @@ use internals::{debug_from_display, write_err};
|
|||
use io::{BufRead, Write};
|
||||
|
||||
use crate::consensus::encode::{self, Decodable, Encodable};
|
||||
use crate::consensus::Params;
|
||||
use crate::prelude::*;
|
||||
use crate::Network;
|
||||
|
||||
|
@ -226,6 +227,11 @@ impl Magic {
|
|||
|
||||
/// Get network magic bytes.
|
||||
pub fn to_bytes(self) -> [u8; 4] { self.0 }
|
||||
|
||||
/// Returns the magic bytes for the network defined by `params`.
|
||||
pub fn from_params(params: impl AsRef<Params>) -> Self {
|
||||
params.as_ref().network.into()
|
||||
}
|
||||
}
|
||||
|
||||
impl FromStr for Magic {
|
||||
|
|
Loading…
Reference in New Issue