Use more informative type names in Extension trait.
This commit is contained in:
parent
36c28341b3
commit
6a536aa88a
|
@ -1,7 +1,7 @@
|
||||||
//! Consensus logic for Transparent Zcash Extensions.
|
//! Consensus logic for Transparent Zcash Extensions.
|
||||||
|
|
||||||
use std::convert::TryFrom;
|
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::extensions::transparent::{Error, Extension, Precondition, Witness};
|
||||||
use zcash_primitives::transaction::{components::TzeOut, Transaction};
|
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
|
/// an assigned extension type ID. This type may be modified in the future if
|
||||||
/// additional context information is required by newly integrated TZEs.
|
/// additional context information is required by newly integrated TZEs.
|
||||||
pub struct Context<'a> {
|
pub struct Context<'a> {
|
||||||
pub height: i32,
|
pub height: BlockHeight,
|
||||||
pub tx: &'a Transaction,
|
pub tx: &'a Transaction,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Context<'a> {
|
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 }
|
Context { height, tx }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -249,8 +249,8 @@ pub trait Context {
|
||||||
pub struct Program;
|
pub struct Program;
|
||||||
|
|
||||||
impl<C: Context> Extension<C> for Program {
|
impl<C: Context> Extension<C> for Program {
|
||||||
type P = Precondition;
|
type Precondition = Precondition;
|
||||||
type W = Witness;
|
type Witness = Witness;
|
||||||
type Error = Error;
|
type Error = Error;
|
||||||
|
|
||||||
/// Runs the program against the given precondition, witness, and context.
|
/// Runs the program against the given precondition, witness, and context.
|
||||||
|
|
|
@ -116,12 +116,12 @@ pub trait Extension<C> {
|
||||||
/// Extension-specific precondition type. The extension will need to implement
|
/// Extension-specific precondition type. The extension will need to implement
|
||||||
/// [`FromPayload<Error = Self::Error>`] for this type in order for their
|
/// [`FromPayload<Error = Self::Error>`] for this type in order for their
|
||||||
/// extension to be eligible for integration into consensus rules.
|
/// extension to be eligible for integration into consensus rules.
|
||||||
type P;
|
type Precondition;
|
||||||
|
|
||||||
/// Extension-specific witness type. The extension will need to implement
|
/// Extension-specific witness type. The extension will need to implement
|
||||||
/// [`FromPayload<Error = Self::Error>`] for this type in order for their
|
/// [`FromPayload<Error = Self::Error>`] for this type in order for their
|
||||||
/// extension to be eligible for integration into consensus rules.
|
/// 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.
|
/// Extension-specific error type. This should encompass both parsing and verification errors.
|
||||||
type Error;
|
type Error;
|
||||||
|
@ -131,8 +131,8 @@ pub trait Extension<C> {
|
||||||
/// precondition, and an error in any other case.
|
/// precondition, and an error in any other case.
|
||||||
fn verify_inner(
|
fn verify_inner(
|
||||||
&self,
|
&self,
|
||||||
precondition: &Self::P,
|
precondition: &Self::Precondition,
|
||||||
witness: &Self::W,
|
witness: &Self::Witness,
|
||||||
context: &C,
|
context: &C,
|
||||||
) -> Result<(), Self::Error>;
|
) -> Result<(), Self::Error>;
|
||||||
|
|
||||||
|
@ -146,12 +146,12 @@ pub trait Extension<C> {
|
||||||
context: &C,
|
context: &C,
|
||||||
) -> Result<(), Self::Error>
|
) -> Result<(), Self::Error>
|
||||||
where
|
where
|
||||||
Self::P: FromPayload<Error = Self::Error>,
|
Self::Precondition: FromPayload<Error = Self::Error>,
|
||||||
Self::W: FromPayload<Error = Self::Error>,
|
Self::Witness: FromPayload<Error = Self::Error>,
|
||||||
{
|
{
|
||||||
self.verify_inner(
|
self.verify_inner(
|
||||||
&Self::P::from_payload(precondition.mode, &precondition.payload)?,
|
&Self::Precondition::from_payload(precondition.mode, &precondition.payload)?,
|
||||||
&Self::W::from_payload(witness.mode, &witness.payload)?,
|
&Self::Witness::from_payload(witness.mode, &witness.payload)?,
|
||||||
&context,
|
&context,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue