Use more informative type names in Extension trait.

This commit is contained in:
Kris Nuttycombe 2020-09-23 13:35:14 -06:00
parent 36c28341b3
commit 6a536aa88a
3 changed files with 13 additions and 13 deletions

View File

@ -1,7 +1,7 @@
//! Consensus logic for Transparent Zcash Extensions.
use std::convert::TryFrom;
use zcash_primitives::consensus::NetworkUpgrade;
use zcash_primitives::consensus::{BlockHeight, NetworkUpgrade};
use zcash_primitives::extensions::transparent::{Error, Extension, Precondition, Witness};
use zcash_primitives::transaction::{components::TzeOut, Transaction};
@ -41,12 +41,12 @@ impl From<ExtensionId> for u32 {
/// an assigned extension type ID. This type may be modified in the future if
/// additional context information is required by newly integrated TZEs.
pub struct Context<'a> {
pub height: i32,
pub height: BlockHeight,
pub tx: &'a Transaction,
}
impl<'a> Context<'a> {
pub fn new(height: i32, tx: &'a Transaction) -> Self {
pub fn new(height: BlockHeight, tx: &'a Transaction) -> Self {
Context { height, tx }
}
}

View File

@ -249,8 +249,8 @@ pub trait Context {
pub struct Program;
impl<C: Context> Extension<C> for Program {
type P = Precondition;
type W = Witness;
type Precondition = Precondition;
type Witness = Witness;
type Error = Error;
/// Runs the program against the given precondition, witness, and context.

View File

@ -116,12 +116,12 @@ pub trait Extension<C> {
/// Extension-specific precondition type. The extension will need to implement
/// [`FromPayload<Error = Self::Error>`] for this type in order for their
/// extension to be eligible for integration into consensus rules.
type P;
type Precondition;
/// Extension-specific witness type. The extension will need to implement
/// [`FromPayload<Error = Self::Error>`] for this type in order for their
/// extension to be eligible for integration into consensus rules.
type W;
type Witness;
/// Extension-specific error type. This should encompass both parsing and verification errors.
type Error;
@ -131,8 +131,8 @@ pub trait Extension<C> {
/// precondition, and an error in any other case.
fn verify_inner(
&self,
precondition: &Self::P,
witness: &Self::W,
precondition: &Self::Precondition,
witness: &Self::Witness,
context: &C,
) -> Result<(), Self::Error>;
@ -146,12 +146,12 @@ pub trait Extension<C> {
context: &C,
) -> Result<(), Self::Error>
where
Self::P: FromPayload<Error = Self::Error>,
Self::W: FromPayload<Error = Self::Error>,
Self::Precondition: FromPayload<Error = Self::Error>,
Self::Witness: FromPayload<Error = Self::Error>,
{
self.verify_inner(
&Self::P::from_payload(precondition.mode, &precondition.payload)?,
&Self::W::from_payload(witness.mode, &witness.payload)?,
&Self::Precondition::from_payload(precondition.mode, &precondition.payload)?,
&Self::Witness::from_payload(witness.mode, &witness.payload)?,
&context,
)
}