Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(transaction encoding): transparent fields #3498

Merged
merged 1 commit into from
Feb 11, 2022
Merged
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
29 changes: 27 additions & 2 deletions zebra-chain/src/transaction/serialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,10 @@ impl ZcashSerialize for Transaction {
outputs,
lock_time,
} => {
// Denoted as `tx_in_count` and `tx_in` in the spec.
inputs.zcash_serialize(&mut writer)?;

// Denoted as `tx_out_count` and `tx_out` in the spec.
outputs.zcash_serialize(&mut writer)?;

// Denoted as `lock_time` in the spec.
Expand All @@ -443,7 +446,10 @@ impl ZcashSerialize for Transaction {
lock_time,
joinsplit_data,
} => {
// Denoted as `tx_in_count` and `tx_in` in the spec.
inputs.zcash_serialize(&mut writer)?;

// Denoted as `tx_out_count` and `tx_out` in the spec.
outputs.zcash_serialize(&mut writer)?;

// Denoted as `lock_time` in the spec.
Expand All @@ -465,7 +471,10 @@ impl ZcashSerialize for Transaction {
// Denoted as `nVersionGroupId` in the spec.
writer.write_u32::<LittleEndian>(OVERWINTER_VERSION_GROUP_ID)?;

// Denoted as `tx_in_count` and `tx_in` in the spec.
inputs.zcash_serialize(&mut writer)?;

// Denoted as `tx_out_count` and `tx_out` in the spec.
outputs.zcash_serialize(&mut writer)?;

// Denoted as `lock_time` in the spec.
Expand All @@ -492,7 +501,10 @@ impl ZcashSerialize for Transaction {
// Denoted as `nVersionGroupId` in the spec.
writer.write_u32::<LittleEndian>(SAPLING_VERSION_GROUP_ID)?;

// Denoted as `tx_in_count` and `tx_in` in the spec.
inputs.zcash_serialize(&mut writer)?;

// Denoted as `tx_out_count` and `tx_out` in the spec.
outputs.zcash_serialize(&mut writer)?;

// Denoted as `lock_time` in the spec.
Expand Down Expand Up @@ -573,8 +585,10 @@ impl ZcashSerialize for Transaction {
// Denoted as `nExpiryHeight` in the spec.
writer.write_u32::<LittleEndian>(expiry_height.0)?;

// transparent
// Denoted as `tx_in_count` and `tx_in` in the spec.
inputs.zcash_serialize(&mut writer)?;

// Denoted as `tx_out_count` and `tx_out` in the spec.
outputs.zcash_serialize(&mut writer)?;

// sapling
Expand Down Expand Up @@ -647,7 +661,9 @@ impl ZcashDeserialize for Transaction {
// https://zips.z.cash/protocol/protocol.pdf#txnconsensus
match (version, overwintered) {
(1, false) => Ok(Transaction::V1 {
// Denoted as `tx_in_count` and `tx_in` in the spec.
inputs: Vec::zcash_deserialize(&mut limited_reader)?,
// Denoted as `tx_out_count` and `tx_out` in the spec.
outputs: Vec::zcash_deserialize(&mut limited_reader)?,
// Denoted as `lock_time` in the spec.
lock_time: LockTime::zcash_deserialize(&mut limited_reader)?,
Expand All @@ -656,7 +672,9 @@ impl ZcashDeserialize for Transaction {
// Version 2 transactions use Sprout-on-BCTV14.
type OptV2Jsd = Option<JoinSplitData<Bctv14Proof>>;
Ok(Transaction::V2 {
// Denoted as `tx_in_count` and `tx_in` in the spec.
inputs: Vec::zcash_deserialize(&mut limited_reader)?,
// Denoted as `tx_out_count` and `tx_out` in the spec.
outputs: Vec::zcash_deserialize(&mut limited_reader)?,
// Denoted as `lock_time` in the spec.
lock_time: LockTime::zcash_deserialize(&mut limited_reader)?,
Expand All @@ -674,7 +692,9 @@ impl ZcashDeserialize for Transaction {
// Version 3 transactions use Sprout-on-BCTV14.
type OptV3Jsd = Option<JoinSplitData<Bctv14Proof>>;
Ok(Transaction::V3 {
// Denoted as `tx_in_count` and `tx_in` in the spec.
inputs: Vec::zcash_deserialize(&mut limited_reader)?,
// Denoted as `tx_out_count` and `tx_out` in the spec.
outputs: Vec::zcash_deserialize(&mut limited_reader)?,
// Denoted as `lock_time` in the spec.
lock_time: LockTime::zcash_deserialize(&mut limited_reader)?,
Expand Down Expand Up @@ -705,7 +725,10 @@ impl ZcashDeserialize for Transaction {
// instead we have to pull the component parts out manually and
// then assemble them.

// Denoted as `tx_in_count` and `tx_in` in the spec.
let inputs = Vec::zcash_deserialize(&mut limited_reader)?;

// Denoted as `tx_out_count` and `tx_out` in the spec.
let outputs = Vec::zcash_deserialize(&mut limited_reader)?;

// Denoted as `lock_time` in the spec.
Expand Down Expand Up @@ -788,8 +811,10 @@ impl ZcashDeserialize for Transaction {
// Denoted as `nExpiryHeight` in the spec.
let expiry_height = block::Height(limited_reader.read_u32::<LittleEndian>()?);

// transparent
// Denoted as `tx_in_count` and `tx_in` in the spec.
let inputs = Vec::zcash_deserialize(&mut limited_reader)?;

// Denoted as `tx_out_count` and `tx_out` in the spec.
let outputs = Vec::zcash_deserialize(&mut limited_reader)?;

// sapling
Expand Down