mirror of
https://github.com/serai-dex/serai.git
synced 2025-12-08 12:19:24 +00:00
Bitcoin Output/Transaction definitions
This commit is contained in:
@@ -46,7 +46,24 @@ pub trait Id:
|
||||
+ BorshDeserialize
|
||||
{
|
||||
}
|
||||
impl<const N: usize> Id for [u8; N] where [u8; N]: Default {}
|
||||
impl<
|
||||
I: Send
|
||||
+ Sync
|
||||
+ Clone
|
||||
+ Default
|
||||
+ PartialEq
|
||||
+ Eq
|
||||
+ Hash
|
||||
+ AsRef<[u8]>
|
||||
+ AsMut<[u8]>
|
||||
+ Debug
|
||||
+ Encode
|
||||
+ Decode
|
||||
+ BorshSerialize
|
||||
+ BorshDeserialize,
|
||||
> Id for I
|
||||
{
|
||||
}
|
||||
|
||||
/// A wrapper for a group element which implements the scale/borsh traits.
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
|
||||
|
||||
@@ -19,10 +19,19 @@ pub trait Address:
|
||||
+ BorshSerialize
|
||||
+ BorshDeserialize
|
||||
{
|
||||
/// Write this address.
|
||||
fn write(&self, writer: &mut impl io::Write) -> io::Result<()>;
|
||||
/// Read an address.
|
||||
fn read(reader: &mut impl io::Read) -> io::Result<Self>;
|
||||
}
|
||||
// This casts a wide net, yet it only implements `Address` for things `Into<ExternalAddress>` so
|
||||
// it should only implement this for addresses
|
||||
impl<
|
||||
A: Send
|
||||
+ Sync
|
||||
+ Clone
|
||||
+ Into<ExternalAddress>
|
||||
+ TryFrom<ExternalAddress>
|
||||
+ BorshSerialize
|
||||
+ BorshDeserialize,
|
||||
> Address for A
|
||||
{
|
||||
}
|
||||
|
||||
/// The type of the output.
|
||||
|
||||
@@ -48,7 +48,7 @@ impl<A: Address> Payment<A> {
|
||||
|
||||
/// Read a Payment.
|
||||
pub fn read(reader: &mut impl io::Read) -> io::Result<Self> {
|
||||
let address = A::read(reader)?;
|
||||
let address = A::deserialize_reader(reader)?;
|
||||
let reader = &mut IoReader(reader);
|
||||
let balance = Balance::decode(reader).map_err(io::Error::other)?;
|
||||
let data = Option::<Vec<u8>>::decode(reader).map_err(io::Error::other)?;
|
||||
@@ -56,7 +56,7 @@ impl<A: Address> Payment<A> {
|
||||
}
|
||||
/// Write the Payment.
|
||||
pub fn write(&self, writer: &mut impl io::Write) -> io::Result<()> {
|
||||
self.address.write(writer).unwrap();
|
||||
self.address.serialize(writer)?;
|
||||
self.balance.encode_to(writer);
|
||||
self.data.encode_to(writer);
|
||||
Ok(())
|
||||
|
||||
Reference in New Issue
Block a user