Move point struct to shared primitives
This commit is contained in:
parent
0f4f98dd3d
commit
c2ffc7aa3b
14 changed files with 53 additions and 104 deletions
|
|
@ -1,7 +1,8 @@
|
|||
use net2::TcpStreamExt;
|
||||
use pallas_machines::primitives::Point;
|
||||
use std::net::TcpStream;
|
||||
|
||||
use pallas_blockfetch::{BlockFetchClient, Point};
|
||||
use pallas_blockfetch::BlockFetchClient;
|
||||
use pallas_handshake::n2n::{Client, VersionTable};
|
||||
use pallas_handshake::MAINNET_MAGIC;
|
||||
use pallas_machines::run_agent;
|
||||
|
|
|
|||
|
|
@ -1,30 +1,5 @@
|
|||
use log::info;
|
||||
use pallas_machines::{Agent, CodecError, DecodePayload, EncodePayload, MachineOutput, PayloadDecoder, PayloadEncoder, Transition};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Point(pub u64, pub Vec<u8>);
|
||||
|
||||
impl EncodePayload for Point {
|
||||
fn encode_payload(
|
||||
&self,
|
||||
e: &mut PayloadEncoder,
|
||||
) -> Result<(), Box<dyn std::error::Error>> {
|
||||
e.array(2)?.u64(self.0)?.bytes(&self.1)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl DecodePayload for Point {
|
||||
fn decode_payload(
|
||||
d: &mut PayloadDecoder,
|
||||
) -> Result<Self, Box<dyn std::error::Error>> {
|
||||
d.array()?;
|
||||
let slot = d.u64()?;
|
||||
let hash = d.bytes()?;
|
||||
|
||||
Ok(Point(slot, Vec::from(hash)))
|
||||
}
|
||||
}
|
||||
use pallas_machines::{Agent, CodecError, DecodePayload, EncodePayload, MachineOutput, PayloadDecoder, PayloadEncoder, Transition, primitives::Point};
|
||||
|
||||
#[derive(Debug, PartialEq, Clone)]
|
||||
pub enum State {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
use pallas_chainsync::{ClientConsumer, NoopStorage, Point};
|
||||
use pallas_chainsync::{ClientConsumer, NoopStorage};
|
||||
use pallas_handshake::n2c::{Client, VersionTable};
|
||||
use pallas_handshake::MAINNET_MAGIC;
|
||||
use pallas_machines::primitives::Point;
|
||||
use pallas_machines::run_agent;
|
||||
use pallas_multiplexer::Multiplexer;
|
||||
use std::os::unix::net::UnixStream;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
use net2::TcpStreamExt;
|
||||
use pallas_machines::primitives::Point;
|
||||
use std::net::TcpStream;
|
||||
|
||||
use pallas_chainsync::{ClientConsumer, NoopStorage, Point};
|
||||
use pallas_chainsync::{ClientConsumer, NoopStorage};
|
||||
use pallas_handshake::n2n::{Client, VersionTable};
|
||||
use pallas_handshake::MAINNET_MAGIC;
|
||||
use pallas_machines::run_agent;
|
||||
|
|
|
|||
|
|
@ -3,39 +3,7 @@ use std::fmt::Debug;
|
|||
use log::{debug, log_enabled, trace};
|
||||
|
||||
use minicbor::data::Tag;
|
||||
use pallas_machines::{
|
||||
Agent, CodecError, DecodePayload, EncodePayload, MachineError, MachineOutput, PayloadDecoder,
|
||||
PayloadEncoder, Transition,
|
||||
};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Point(pub u64, pub Vec<u8>);
|
||||
|
||||
impl Debug for Point {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
f.debug_tuple("Point")
|
||||
.field(&self.0)
|
||||
.field(&hex::encode(&self.1))
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
|
||||
impl EncodePayload for Point {
|
||||
fn encode_payload(&self, e: &mut PayloadEncoder) -> Result<(), Box<dyn std::error::Error>> {
|
||||
e.array(2)?.u64(self.0)?.bytes(&self.1)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl DecodePayload for Point {
|
||||
fn decode_payload(d: &mut PayloadDecoder) -> Result<Self, Box<dyn std::error::Error>> {
|
||||
d.array()?;
|
||||
let slot = d.u64()?;
|
||||
let hash = d.bytes()?;
|
||||
|
||||
Ok(Point(slot, Vec::from(hash)))
|
||||
}
|
||||
}
|
||||
use pallas_machines::{Agent, CodecError, DecodePayload, EncodePayload, MachineError, MachineOutput, PayloadDecoder, PayloadEncoder, Transition, primitives::Point};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct WrappedHeader(u64, Vec<u8>);
|
||||
|
|
|
|||
|
|
@ -133,9 +133,9 @@ pub enum Output {
|
|||
|
||||
#[derive(Debug)]
|
||||
pub struct Client {
|
||||
state: State,
|
||||
output: Output,
|
||||
version_table: VersionTable,
|
||||
pub state: State,
|
||||
pub output: Output,
|
||||
pub version_table: VersionTable,
|
||||
}
|
||||
|
||||
impl Client {
|
||||
|
|
|
|||
|
|
@ -1,12 +1,10 @@
|
|||
use minicbor::data::Cbor;
|
||||
use pallas_localstate::{OneShotClient, Point, Query};
|
||||
use pallas_localstate::{OneShotClient, Query};
|
||||
use pallas_handshake::n2c::{Client, VersionTable};
|
||||
use pallas_handshake::{MAINNET_MAGIC};
|
||||
use pallas_machines::{DecodePayload, EncodePayload, run_agent};
|
||||
use pallas_multiplexer::Multiplexer;
|
||||
use std::net::TcpStream;
|
||||
use std::os::unix::net::UnixStream;
|
||||
use net2::*;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
struct BlockQuery {}
|
||||
|
|
|
|||
|
|
@ -1,23 +1,6 @@
|
|||
use super::*;
|
||||
use pallas_machines::*;
|
||||
|
||||
impl EncodePayload for Point {
|
||||
fn encode_payload(&self, e: &mut PayloadEncoder) -> Result<(), Box<dyn std::error::Error>> {
|
||||
e.array(2)?.u64(self.0)?.bytes(&self.1)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl DecodePayload for Point {
|
||||
fn decode_payload(d: &mut PayloadDecoder) -> Result<Self, Box<dyn std::error::Error>> {
|
||||
d.array()?;
|
||||
let slot = d.u64()?;
|
||||
let hash = d.bytes()?;
|
||||
|
||||
Ok(Point(slot, Vec::from(hash)))
|
||||
}
|
||||
}
|
||||
|
||||
impl EncodePayload for AcquireFailure {
|
||||
fn encode_payload(&self, e: &mut PayloadEncoder) -> Result<(), Box<dyn std::error::Error>> {
|
||||
let code = match self {
|
||||
|
|
|
|||
|
|
@ -4,21 +4,7 @@ use std::fmt::Debug;
|
|||
|
||||
use log::debug;
|
||||
|
||||
use pallas_machines::{
|
||||
Agent, DecodePayload, EncodePayload, MachineError, MachineOutput, Transition,
|
||||
};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Point(pub u64, pub Vec<u8>);
|
||||
|
||||
impl Debug for Point {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
f.debug_tuple("Point")
|
||||
.field(&self.0)
|
||||
.field(&hex::encode(&self.1))
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
use pallas_machines::{Agent, DecodePayload, EncodePayload, MachineError, MachineOutput, Transition, primitives::Point};
|
||||
|
||||
#[derive(Debug, PartialEq, Clone)]
|
||||
pub enum State {
|
||||
|
|
|
|||
|
|
@ -14,3 +14,4 @@ authors = [
|
|||
pallas-multiplexer = { path = "../pallas-multiplexer/" }
|
||||
minicbor = { version="0.11.4", features=["half"] }
|
||||
log = "0.4.14"
|
||||
hex = "0.4.3"
|
||||
19
pallas-machines/src/codec.rs
Normal file
19
pallas-machines/src/codec.rs
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
use super::primitives::*;
|
||||
use super::payloads::*;
|
||||
|
||||
impl EncodePayload for Point {
|
||||
fn encode_payload(&self, e: &mut PayloadEncoder) -> Result<(), Box<dyn std::error::Error>> {
|
||||
e.array(2)?.u64(self.0)?.bytes(&self.1)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl DecodePayload for Point {
|
||||
fn decode_payload(d: &mut PayloadDecoder) -> Result<Self, Box<dyn std::error::Error>> {
|
||||
d.array()?;
|
||||
let slot = d.u64()?;
|
||||
let hash = d.bytes()?;
|
||||
|
||||
Ok(Point(slot, Vec::from(hash)))
|
||||
}
|
||||
}
|
||||
|
|
@ -1,12 +1,14 @@
|
|||
mod payload;
|
||||
mod payloads;
|
||||
pub mod primitives;
|
||||
mod codec;
|
||||
|
||||
use log::{debug, trace, warn};
|
||||
use log::{debug, trace};
|
||||
use pallas_multiplexer::{Channel, Payload};
|
||||
use std::borrow::Borrow;
|
||||
use std::fmt::{Debug, Display};
|
||||
use std::sync::mpsc::{Receiver, Sender};
|
||||
use std::sync::mpsc::{Sender};
|
||||
|
||||
pub use payload::*;
|
||||
pub use payloads::*;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum MachineError<State, Msg>
|
||||
|
|
|
|||
14
pallas-machines/src/primitives.rs
Normal file
14
pallas-machines/src/primitives.rs
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
use std::fmt::Debug;
|
||||
|
||||
/// A point within a chain
|
||||
#[derive(Clone)]
|
||||
pub struct Point(pub u64, pub Vec<u8>);
|
||||
|
||||
impl Debug for Point {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
f.debug_tuple("Point")
|
||||
.field(&self.0)
|
||||
.field(&hex::encode(&self.1))
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue