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: u32Nemesis と Importance のブロックだけにある
Implementations§
Source§impl Block
impl Block
Sourcepub fn from_bytes(bytes: &[u8]) -> Result<Self, BlockDecodeError>
pub fn from_bytes(bytes: &[u8]) -> Result<Self, BlockDecodeError>
バイト列から読む。トランザクションは中身を読まずに、1件ずつの範囲だけを確かめる。
Sourcepub fn verify_signature(&self) -> bool
pub fn verify_signature(&self) -> bool
ハーベストしたアカウントの署名を確かめる。
Sourcepub fn hash(&self) -> Hash256
pub fn hash(&self) -> Hash256
ブロックのハッシュ。catapult の model::CalculateHash(const Block&) と同じく、
署名、署名者の公開鍵、署名の対象を続けた SHA3-256。トランザクションと違い generation hash seed は入らない。
次のブロックの PreviousBlockHash がこれになる。
Sourcepub fn generation_hash(&self) -> GenerationHash
pub fn generation_hash(&self) -> GenerationHash
VRF の証明の gamma から、このブロックの generation hash を求める。証明は確かめない。
Sourcepub fn verify_generation_hash_proof(
&self,
vrf_public_key: &PublicKey,
alpha: &[u8; 32],
) -> Option<GenerationHash>
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、
鍵は署名者の公開鍵になる。
Sourcepub fn transactions(&self) -> impl Iterator<Item = &[u8]>
pub fn transactions(&self) -> impl Iterator<Item = &[u8]>
中のトランザクションのバイト列。パディングは含まない。
Sourcepub fn calculate_transactions_hash(
&self,
generation_hash_seed: &GenerationHashSeed,
) -> Result<Hash256, DecodeError>
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 を確かめないので、この違いはそのまま残っている。
Sourcepub fn transaction_merkle_path(
&self,
generation_hash_seed: &GenerationHashSeed,
index: usize,
) -> Result<Option<Vec<MerklePathNode>>, DecodeError>
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。
Sourcepub fn merkle_leaves(
&self,
generation_hash_seed: &GenerationHashSeed,
) -> Result<Vec<Hash256>, DecodeError>
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 の値と合わない。
Sourcepub fn verify_transactions_hash(
&self,
generation_hash_seed: &GenerationHashSeed,
) -> Result<bool, DecodeError>
pub fn verify_transactions_hash( &self, generation_hash_seed: &GenerationHashSeed, ) -> Result<bool, DecodeError>
ヘッダーの TransactionsHash が、中のトランザクションと合うか。 ブロックの署名は TransactionsHash に掛かるので、署名と合わせて確かめれば、中のトランザクションもブロックの署名者が認めたものになる。
Sourcepub fn verify_receipts_hash(&self, statement: &BlockStatement) -> bool
pub fn verify_receipts_hash(&self, statement: &BlockStatement) -> bool
ヘッダーの ReceiptsHash が、ステートメントから求めた Merkle の根と合うか。 ステートメントはブロックに入っておらず、ブロックを実行して求めるもの。受け取ったり読み込んだりしたステートメントが、 ヘッダーと合っているかを確かめる。