Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
n8maninger committed Nov 6, 2024
1 parent 11627ef commit a151885
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 50 deletions.
36 changes: 18 additions & 18 deletions sia/src/encoding/v1_encoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,26 +52,26 @@ impl<T: V1SiaEncodable> V1SiaEncodable for [T] {
}

impl<T: V1SiaEncodable> V1SiaEncodable for Option<T> {
fn encode_v1<W: Write>(&self, w: &mut W) -> Result<()> {
match self {
Some(v) => {
true.encode_v1(w)?;
v.encode_v1(w)
}
None => false.encode_v1(w),
}
}
fn encode_v1<W: Write>(&self, w: &mut W) -> Result<()> {
match self {
Some(v) => {
true.encode_v1(w)?;
v.encode_v1(w)
}
None => false.encode_v1(w),
}
}
}

impl <T: V1SiaDecodable> V1SiaDecodable for Option<T> {
fn decode_v1<R: Read>(r: &mut R) -> Result<Self> {
let has_value = bool::decode_v1(r)?;
if has_value {
Ok(Some(T::decode_v1(r)?))
} else {
Ok(None)
}
}
impl<T: V1SiaDecodable> V1SiaDecodable for Option<T> {
fn decode_v1<R: Read>(r: &mut R) -> Result<Self> {
let has_value = bool::decode_v1(r)?;
if has_value {
Ok(Some(T::decode_v1(r)?))
} else {
Ok(None)
}
}
}

macro_rules! impl_sia_numeric {
Expand Down
36 changes: 18 additions & 18 deletions sia/src/encoding/v2_encoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,26 +68,26 @@ impl<T: SiaEncodable> SiaEncodable for [T] {
}

impl<T: SiaEncodable> SiaEncodable for Option<T> {
fn encode<W: Write>(&self, w: &mut W) -> Result<()> {
match self {
Some(v) => {
true.encode(w)?;
v.encode(w)
}
None => false.encode(w),
}
}
fn encode<W: Write>(&self, w: &mut W) -> Result<()> {
match self {
Some(v) => {
true.encode(w)?;
v.encode(w)
}
None => false.encode(w),
}
}
}

impl <T: SiaDecodable> SiaDecodable for Option<T> {
fn decode<R: Read>(r: &mut R) -> Result<Self> {
let has_value = bool::decode(r)?;
if has_value {
Ok(Some(T::decode(r)?))
} else {
Ok(None)
}
}
impl<T: SiaDecodable> SiaDecodable for Option<T> {
fn decode<R: Read>(r: &mut R) -> Result<Self> {
let has_value = bool::decode(r)?;
if has_value {
Ok(Some(T::decode(r)?))
} else {
Ok(None)
}
}
}

macro_rules! impl_sia_numeric {
Expand Down
17 changes: 8 additions & 9 deletions sia/src/signing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ use crate::encoding::{SiaDecodable, SiaDecode, SiaEncodable, SiaEncode};
use crate::{ChainIndex, Hash256, HexParseError};
use base64::prelude::*;
use ed25519_dalek::{Signature as ED25519Signature, Signer, SigningKey, Verifier, VerifyingKey};
use serde::{de::Error, Deserialize, Serialize};
use serde::de::Error;
use serde::{Deserialize, Serialize};

/// An ed25519 public key that can be used to verify a signature
#[derive(Debug, PartialEq, Clone, Copy, SiaEncode, SiaDecode)]
Expand Down Expand Up @@ -232,15 +233,13 @@ impl SigningState {
mod tests {
use std::vec;

use crate::{
transactions::{
CoveredFields, FileContract, FileContractID, FileContractRevision, SiacoinInput,
SiacoinOutput, SiafundInput, SiafundOutput, StorageProof, Transaction,
TransactionSignature,
},
unlock_conditions::UnlockConditions,
Address, Currency, Leaf,
use crate::transactions::{
CoveredFields, FileContract, FileContractID, FileContractRevision, SiacoinInput,
SiacoinOutput, SiafundInput, SiafundOutput, StorageProof, Transaction,
TransactionSignature,
};
use crate::unlock_conditions::UnlockConditions;
use crate::{Address, Currency, Leaf};

use super::*;

Expand Down
6 changes: 3 additions & 3 deletions sia/src/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ use crate::encoding::{
use crate::signing::{PrivateKey, SigningState};
use crate::specifier::{specifier, Specifier};
use crate::unlock_conditions::UnlockConditions;
use crate::Hash256;
use crate::{encoding, Address, Currency, Leaf};
use crate::{encoding, Address, Currency, Hash256, Leaf};
use blake2b_simd::Params;
use serde::{Deserialize, Serialize};

Expand Down Expand Up @@ -363,7 +362,8 @@ impl Transaction {

// Create a helper module for base64 serialization
mod base64 {
use base64::{engine::general_purpose::STANDARD, Engine};
use base64::engine::general_purpose::STANDARD;
use base64::Engine;
use serde::{Deserialize, Deserializer, Serializer};

pub fn serialize<S: Serializer>(v: &[u8], s: S) -> Result<S::Ok, S::Error> {
Expand Down
3 changes: 1 addition & 2 deletions sia/src/unlock_conditions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ use crate::encoding::{
use crate::merkle::{Accumulator, LEAF_HASH_PREFIX};
use crate::signing::PublicKey;
use crate::specifier::{specifier, Specifier};
use crate::Address;
use crate::HexParseError;
use crate::{Address, HexParseError};
use blake2b_simd::Params;
use core::fmt;
use serde::de::Error;
Expand Down

0 comments on commit a151885

Please sign in to comment.