Bitcoin Output/Transaction definitions

This commit is contained in:
Luke Parker
2024-09-10 03:48:06 -04:00
parent 0ccf71df1e
commit 247cc8f0cc
17 changed files with 504 additions and 299 deletions

View File

@@ -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)]

View File

@@ -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.

View File

@@ -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(())