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

Introduce FeeMetadata #2085

Draft
wants to merge 1 commit into
base: testnet3
Choose a base branch
from
Draft
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
43 changes: 43 additions & 0 deletions ledger/block/src/transaction/fee/metadata.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright (C) 2019-2023 Aleo Systems Inc.
// This file is part of the snarkVM library.

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at:
// http://www.apache.org/licenses/LICENSE-2.0

// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

use super::*;

use std::marker::PhantomData;

#[derive(Copy, Clone, Debug)]
pub struct FeeMetadata<N: Network> {
/// The number of blocks after the current block that the fee is valid for.
expires_in: Option<u16>,
/// PhantomData.
_phantom: PhantomData<N>,
}

impl<N: Network> FeeMetadata<N> {
/// Specifies the number of blocks until expiration.
const EXPIRES_IN: u16 = 21600 / N::BLOCK_TIME;

// 21000 blocks / 10 seconds per block = ~6 hours

/// Initializes a new `FeeMetadata` instance with the given expiration.
pub fn new(expires_in: Option<u16>) -> Result<Self> {
if let Some(num_blocks) = &expires_in {
if *num_blocks > Self::EXPIRES_IN {
bail!("Fee expiration is too far in the future")
}
}

Ok(Self { expires_in, _phantom: PhantomData })
}
}
2 changes: 2 additions & 0 deletions ledger/block/src/transaction/fee/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

pub mod metadata;

mod bytes;
mod serialize;
mod string;
Expand Down