Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions zcash_primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,16 @@ log = "0.4"
pairing = { version = "0.15.0", path = "../pairing" }
rand = "0.7"
rand_core = "0.5.1"
ripemd160 = { version = "0.8", optional = true }
secp256k1 = { version = "=0.15.0", optional = true }

@str4d str4d Aug 18, 2019

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dependency is pinned until rust-bitcoin/rust-secp256k1#150 is resolved, because we don't want to pull rand 0.6 into our dependency tree (and we aren't using the rand feature of secp256k1).

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have they fixed this yet? (Issue isn't closed but they seem to have merged some things.)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They merged a fix, and then immediately reverted it because they had more point releases to make, and the fix for this requires a minor version bump.

sha2 = "0.8"

[dev-dependencies]
hex-literal = "0.2"
rand_xorshift = "0.2"

[features]
transparent-inputs = ["ripemd160", "secp256k1"]

[badges]
maintenance = { status = "actively-developed" }
33 changes: 30 additions & 3 deletions zcash_primitives/src/legacy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ enum OpCode {
}

/// A serialized script, used inside transparent inputs and outputs of a transaction.
#[derive(Debug, Default)]
#[derive(Clone, Debug, Default)]
pub struct Script(pub Vec<u8>);

impl Script {
Expand All @@ -38,6 +38,31 @@ impl Script {
pub fn write<W: Write>(&self, mut writer: W) -> io::Result<()> {
Vector::write(&mut writer, &self.0, |w, e| w.write_u8(*e))
}

/// Returns the address that this Script contains, if any.
pub fn address(&self) -> Option<TransparentAddress> {
if self.0.len() == 25
&& self.0[0] == OpCode::Dup as u8
&& self.0[1] == OpCode::Hash160 as u8
&& self.0[2] == 0x14
&& self.0[23] == OpCode::EqualVerify as u8
&& self.0[24] == OpCode::CheckSig as u8
{
let mut hash = [0; 20];
hash.copy_from_slice(&self.0[3..23]);
Some(TransparentAddress::PublicKey(hash))
} else if self.0.len() == 23
&& self.0[0] == OpCode::Hash160 as u8
&& self.0[1] == 0x14
&& self.0[22] == OpCode::Equal as u8
{
let mut hash = [0; 20];
hash.copy_from_slice(&self.0[2..22]);
Some(TransparentAddress::Script(hash))
} else {
None
}
}
}

impl Shl<OpCode> for Script {
Expand Down Expand Up @@ -151,7 +176,8 @@ mod tests {
0x76, 0xa9, 0x14, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x88, 0xac,
]
)
);
assert_eq!(addr.script().address(), Some(addr));
}

#[test]
Expand All @@ -163,6 +189,7 @@ mod tests {
0xa9, 0x14, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x87,
]
)
);
assert_eq!(addr.script().address(), Some(addr));
}
}
2 changes: 1 addition & 1 deletion zcash_primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub mod primitives;
pub mod prover;
pub mod redjubjub;
pub mod sapling;
mod serialize;
pub mod serialize;
pub mod transaction;
mod util;
pub mod zip32;
Expand Down
Loading