-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
426 additions
and
114 deletions.
There are no files selected for viewing
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,86 @@ | ||
//! Methods for building transactions. | ||
use crate::{ | ||
amount::{Amount, NonNegative}, | ||
block::Height, | ||
parameters::{Network, NetworkUpgrade}, | ||
transaction::{LockTime, Transaction}, | ||
transparent, | ||
}; | ||
|
||
impl Transaction { | ||
/// Returns a new version 5 coinbase transaction for `network` and `height`, | ||
/// which contains the specified `outputs`. | ||
pub fn new_v5_coinbase( | ||
network: Network, | ||
height: Height, | ||
outputs: impl IntoIterator<Item = (Amount<NonNegative>, transparent::Script)>, | ||
) -> Transaction { | ||
// # Consensus | ||
// | ||
// These consensus rules apply to v5 coinbase transactions after NU5 activation: | ||
// | ||
// > A coinbase transaction for a block at block height greater than 0 MUST have | ||
// > a script that, as its first item, encodes the block height height as follows. ... | ||
// > let heightBytes be the signed little-endian representation of height, | ||
// > using the minimum nonzero number of bytes such that the most significant byte | ||
// > is < 0x80. The length of heightBytes MUST be in the range {1 .. 5}. | ||
// > Then the encoding is the length of heightBytes encoded as one byte, | ||
// > followed by heightBytes itself. This matches the encoding used by Bitcoin | ||
// > in the implementation of [BIP-34] | ||
// > (but the description here is to be considered normative). | ||
// | ||
// > A coinbase transaction script MUST have length in {2 .. 100} bytes. | ||
// | ||
// Zebra does not add any extra coinbase data. | ||
// | ||
// Since we're not using a lock time, any sequence number is valid here. | ||
// See `Transaction::lock_time()` for the relevant consensus rules. | ||
// | ||
// <https://zips.z.cash/protocol/protocol.pdf#txnconsensus> | ||
let inputs = vec![transparent::Input::new_coinbase(height, None, None)]; | ||
|
||
// > The block subsidy is composed of a miner subsidy and a series of funding streams. | ||
// | ||
// <https://zips.z.cash/protocol/protocol.pdf#subsidyconcepts> | ||
// | ||
// > The total value in zatoshi of transparent outputs from a coinbase transaction, | ||
// > minus vbalanceSapling, minus vbalanceOrchard, MUST NOT be greater than | ||
// > the value in zatoshi of block subsidy plus the transaction fees | ||
// > paid by transactions in this block. | ||
// | ||
// <https://zips.z.cash/protocol/protocol.pdf#txnconsensus> | ||
let outputs = outputs | ||
.into_iter() | ||
.map(|(amount, lock_script)| transparent::Output::new_coinbase(amount, lock_script)) | ||
.collect(); | ||
|
||
Transaction::V5 { | ||
// > The transaction version number MUST be 4 or 5. ... | ||
// > If the transaction version number is 5 then the version group ID MUST be 0x26A7270A. | ||
// > If effectiveVersion ≥ 5, the nConsensusBranchId field MUST match the consensus | ||
// > branch ID used for SIGHASH transaction hashes, as specified in [ZIP-244]. | ||
network_upgrade: NetworkUpgrade::current(network, height), | ||
|
||
// There is no documented consensus rule for the lock time field in coinbase transactions, | ||
// so we just leave it unlocked. | ||
lock_time: LockTime::unlocked(), | ||
|
||
// > The nExpiryHeight field of a coinbase transaction MUST be equal to its block height. | ||
expiry_height: height, | ||
|
||
inputs, | ||
outputs, | ||
|
||
// Zebra does not support shielded coinbase yet. | ||
// | ||
// > In a version 5 coinbase transaction, the enableSpendsOrchard flag MUST be 0. | ||
// > In a version 5 transaction, the reserved bits 2 .. 7 of the flagsOrchard field | ||
// > MUST be zero. | ||
// | ||
// See the Zcash spec for additional shielded coinbase consensus rules. | ||
sapling_shielded_data: None, | ||
orchard_shielded_data: None, | ||
} | ||
} | ||
} |
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.