-
Notifications
You must be signed in to change notification settings - Fork 251
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
zcash_transparent: Refactor code so it compiles in its new crate
- Loading branch information
Showing
28 changed files
with
303 additions
and
273 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
use alloc::string::ToString; | ||
use core::fmt; | ||
use core2::io::{self, Read, Write}; | ||
|
||
#[cfg(feature = "std")] | ||
use memuse::DynamicUsage; | ||
|
||
/// The identifier for a Zcash transaction. | ||
/// | ||
/// - For v1-4 transactions, this is a double-SHA-256 hash of the encoded transaction. | ||
/// This means that it is malleable, and only a reliable identifier for transactions | ||
/// that have been mined. | ||
/// - For v5 transactions onwards, this identifier is derived only from "effecting" data, | ||
/// and is non-malleable in all contexts. | ||
#[derive(Clone, Copy, PartialOrd, Ord, PartialEq, Eq, Hash)] | ||
pub struct TxId([u8; 32]); | ||
|
||
#[cfg(feature = "std")] | ||
memuse::impl_no_dynamic_usage!(TxId); | ||
|
||
impl fmt::Debug for TxId { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
// The (byte-flipped) hex string is more useful than the raw bytes, because we can | ||
// look that up in RPC methods and block explorers. | ||
let txid_str = self.to_string(); | ||
f.debug_tuple("TxId").field(&txid_str).finish() | ||
} | ||
} | ||
|
||
impl fmt::Display for TxId { | ||
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
let mut data = self.0; | ||
data.reverse(); | ||
formatter.write_str(&hex::encode(data)) | ||
} | ||
} | ||
|
||
impl AsRef<[u8; 32]> for TxId { | ||
fn as_ref(&self) -> &[u8; 32] { | ||
&self.0 | ||
} | ||
} | ||
|
||
impl From<TxId> for [u8; 32] { | ||
fn from(value: TxId) -> Self { | ||
value.0 | ||
} | ||
} | ||
|
||
impl TxId { | ||
pub const fn from_bytes(bytes: [u8; 32]) -> Self { | ||
TxId(bytes) | ||
} | ||
|
||
pub fn read<R: Read>(mut reader: R) -> io::Result<Self> { | ||
let mut hash = [0u8; 32]; | ||
reader.read_exact(&mut hash)?; | ||
Ok(TxId::from_bytes(hash)) | ||
} | ||
|
||
pub fn write<W: Write>(&self, mut writer: W) -> io::Result<()> { | ||
writer.write_all(&self.0)?; | ||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.