Skip to main content

Block

Struct Block 

Source
pub struct Block {
Show 16 fields pub signature: Signature, pub signer_public_key: PublicKey, pub version: u8, pub network: NetworkIdentifier, pub block_type: BlockType, pub height: u64, pub timestamp: u64, pub difficulty: u64, pub generation_hash_proof: VrfProof, pub previous_block_hash: Hash256, pub transactions_hash: Hash256, pub receipts_hash: Hash256, pub state_hash: Hash256, pub beneficiary_address: Address, pub fee_multiplier: u32, pub importance_footer: Option<ImportanceFooter>, /* private fields */
}
Expand description

ブロック。

Fields§

§signature: Signature§signer_public_key: PublicKey

ハーベストしたアカウントの公開鍵。リモートハーベストならリモートアカウントのもの

§version: u8§network: NetworkIdentifier§block_type: BlockType§height: u64§timestamp: u64

ネメシスのブロックからのミリ秒

§difficulty: u64§generation_hash_proof: VrfProof§previous_block_hash: Hash256§transactions_hash: Hash256§receipts_hash: Hash256§state_hash: Hash256§beneficiary_address: Address§fee_multiplier: u32§importance_footer: Option<ImportanceFooter>

Nemesis と Importance のブロックだけにある

Implementations§

Source§

impl Block

Source

pub fn from_bytes(bytes: &[u8]) -> Result<Self, BlockDecodeError>

バイト列から読む。トランザクションは中身を読まずに、1件ずつの範囲だけを確かめる。

Source

pub fn verify_signature(&self) -> bool

ハーベストしたアカウントの署名を確かめる。

Source

pub fn hash(&self) -> Hash256

ブロックのハッシュ。catapult の model::CalculateHash(const Block&) と同じく、 署名、署名者の公開鍵、署名の対象を続けた SHA3-256。トランザクションと違い generation hash seed は入らない。 次のブロックの PreviousBlockHash がこれになる。

Source

pub fn generation_hash(&self) -> GenerationHash

VRF の証明の gamma から、このブロックの generation hash を求める。証明は確かめない。

Source

pub fn verify_generation_hash_proof( &self, vrf_public_key: &PublicKey, alpha: &[u8; 32], ) -> Option<GenerationHash>

VRF の証明を確かめて、通ればこのブロックの generation hash を返す。catapult の CheckGenerationHash の前半。

vrf_public_key は、ハーベストしたアカウントのメインアカウントにリンクされている VRF の鍵。 alpha は1つ前のブロックの generation hash で、Nemesis のブロックなら generation hash seed、 鍵は署名者の公開鍵になる。

Source

pub fn transactions(&self) -> impl Iterator<Item = &[u8]>

中のトランザクションのバイト列。パディングは含まない。

Source

pub fn calculate_transactions_hash( &self, generation_hash_seed: &GenerationHashSeed, ) -> Result<Hash256, DecodeError>

中のトランザクションから TransactionsHash を求める。catapult の CalculateBlockTransactionsHash。

それぞれの [Transaction::merkle_component_hash] を葉にした Merkle ツリーの根。 トランザクションのハッシュには generation hash seed が入るので、ブロックのネットワークのものを渡す。 葉を求めるにはトランザクションを丸ごと読むので、読めないものがあれば、そのエラーを返す。

Nemesis のブロックだけは求め方が違う。nemgen はトランザクションの種類ごとの決まりを使わずに (catapult の BlockExtensions を TransactionRegistry なしで作る)、署名の範囲を種類で切らずに ヘッダーの後半から最後までを丸ごとハッシュし、連署者も混ぜない。ノードは Nemesis をファイルから読み、 同期してきたブロックにしか TransactionsHash を確かめないので、この違いはそのまま残っている。

Source

pub fn transaction_merkle_path( &self, generation_hash_seed: &GenerationHashSeed, index: usize, ) -> Result<Option<Vec<MerklePathNode>>, DecodeError>

index 番目(0から)のトランザクションの葉から、TransactionsHash までの Merkle の経路。 経路と葉(Block::merkle_leaves。Nemesis 以外は [Transaction::merkle_component_hash])があれば、ブロック全体がなくても、 そのトランザクションがこのブロックに入っていることを merkle::verify_path で確かめられる。 index がトランザクションの数を超えていれば None。

Source

pub fn merkle_leaves( &self, generation_hash_seed: &GenerationHashSeed, ) -> Result<Vec<Hash256>, DecodeError>

TransactionsHash の葉を、ブロックの中の順に並べたもの。

ふつうは [Transaction::merkle_component_hash] で、REST の meta.merkleComponentHash と同じ。 Nemesis だけは求め方が違い(Block::calculate_transactions_hash)、アグリゲートの葉が REST の値と合わない。

Source

pub fn verify_transactions_hash( &self, generation_hash_seed: &GenerationHashSeed, ) -> Result<bool, DecodeError>

ヘッダーの TransactionsHash が、中のトランザクションと合うか。 ブロックの署名は TransactionsHash に掛かるので、署名と合わせて確かめれば、中のトランザクションもブロックの署名者が認めたものになる。

Source

pub fn verify_receipts_hash(&self, statement: &BlockStatement) -> bool

ヘッダーの ReceiptsHash が、ステートメントから求めた Merkle の根と合うか。 ステートメントはブロックに入っておらず、ブロックを実行して求めるもの。受け取ったり読み込んだりしたステートメントが、 ヘッダーと合っているかを確かめる。

Source

pub fn as_bytes(&self) -> &[u8] ⓘ

ブロック全体のバイト列。

Trait Implementations§

Source§

impl Clone for Block

Source§

fn clone(&self) -> Block

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Block

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for Block

Source§

impl From<&Block> for BlockStatistic

Source§

fn from(block: &Block) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for Block

Source§

fn eq(&self, other: &Block) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Block

Auto Trait Implementations§

§

impl Freeze for Block

§

impl RefUnwindSafe for Block

§

impl Send for Block

§

impl Sync for Block

§

impl Unpin for Block

§

impl UnsafeUnpin for Block

§

impl UnwindSafe for Block

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.