Skip to content

Commit

Permalink
Remove implementation of SiaEncodable for Address and Algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisSchinnerl committed Apr 17, 2024
1 parent d157f1b commit aa25410
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 22 deletions.
15 changes: 1 addition & 14 deletions src/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,6 @@ impl fmt::Display for Address {
}
}

impl SiaEncodable for Address {
fn encode(&self, buf: &mut Vec<u8>) {
buf.extend_from_slice(&encoding::to_bytes(&self).unwrap());
}
}

#[derive(Debug, PartialEq, Clone, Copy)]
pub enum Algorithm {
ED25519,
Expand All @@ -150,20 +144,13 @@ impl Serialize for Algorithm {
where
S: serde::Serializer,
{

let spec: Specifier = match self {
Algorithm::ED25519 => Specifier::from("ed25519"),
};
spec.serialize(serializer)
}
}

impl SiaEncodable for Algorithm {
fn encode(&self, buf: &mut Vec<u8>) {
buf.extend_from_slice(&encoding::to_bytes(&self).unwrap());
}
}

/// A generic public key that can be used to spend a utxo or revise a file
/// contract
///
Expand Down Expand Up @@ -214,7 +201,7 @@ impl fmt::Display for UnlockKey {

impl SiaEncodable for UnlockKey {
fn encode(&self, buf: &mut Vec<u8>) {
self.algorithm.encode(buf);
encoding::to_writer(buf, &self.algorithm).unwrap();
buf.extend_from_slice(&32_u64.to_le_bytes());
buf.extend_from_slice(self.public_key.as_ref());
}
Expand Down
7 changes: 4 additions & 3 deletions src/specifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ const SPECIFIER_SIZE: usize = 16;
#[derive(Debug, PartialEq, Serialize)]
pub struct Specifier([u8; SPECIFIER_SIZE]);

// implement the `From` trait for the `Specifier` struct to allow for creating a
// Specifier from any type that can be converted to a slice of bytes such as
// 'String', '&str' or byte arrays.
impl<T: AsRef<[u8]>> From<T> for Specifier {
fn from(src: T) -> Self {
let src = src.as_ref();
assert!(src.len() <= SPECIFIER_SIZE, "specifier too long");
let mut spec = Specifier([0; SPECIFIER_SIZE]);
for (src, dst) in src.iter().zip(spec.0.iter_mut()) {
*dst = *src;
}
spec.0[..src.len()].copy_from_slice(src);
spec
}
}
Expand Down
11 changes: 6 additions & 5 deletions src/transactions.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use core::fmt;

use crate::encoding;
use crate::Currency;
use crate::Signature;
use crate::{Address, UnlockConditions};
Expand Down Expand Up @@ -75,7 +76,7 @@ pub struct SiacoinOutput {
impl SiaEncodable for SiacoinOutput {
fn encode(&self, buf: &mut Vec<u8>) {
self.value.encode(buf);
self.address.encode(buf);
encoding::to_writer(buf, &self.address).unwrap();
}
}

Expand Down Expand Up @@ -126,7 +127,7 @@ impl SiaEncodable for SiafundInput {
fn encode(&self, buf: &mut Vec<u8>) {
self.parent_id.encode(buf);
self.unlock_conditions.encode(buf);
self.claim_address.encode(buf);
encoding::to_writer(buf, &self.claim_address).unwrap();
}
}

Expand All @@ -140,7 +141,7 @@ pub struct SiafundOutput {
impl SiaEncodable for SiafundOutput {
fn encode(&self, buf: &mut Vec<u8>) {
self.value.encode(buf);
self.address.encode(buf);
encoding::to_writer(buf, &self.address).unwrap();
self.claim_start.encode(buf);
}
}
Expand Down Expand Up @@ -203,7 +204,7 @@ impl SiaEncodable for FileContract {
for output in &self.missed_proof_outputs {
output.encode(buf);
}
self.unlock_hash.encode(buf);
encoding::to_writer(buf, &self.unlock_hash).unwrap();
buf.extend_from_slice(&self.revision_number.to_le_bytes());
}
}
Expand Down Expand Up @@ -239,7 +240,7 @@ impl SiaEncodable for FileContractRevision {
for output in &self.missed_proof_outputs {
output.encode(buf);
}
self.unlock_hash.encode(buf);
encoding::to_writer(buf, &self.unlock_hash).unwrap();
}
}

Expand Down

0 comments on commit aa25410

Please sign in to comment.