Marco Comotti
Marco Comotti

Reputation: 21

Substrate Blockchain - Change block structure

I'm trying to modify the block structure for a blockchain based on Substrate that I'm trying to develop. In particular I would like to add a vector in the header and another one inside the body of the block. Does someone know how it is possible to do that?

I'm a newbie in Substrate :'(

Thanks in advance to everyone who will contribute!

Upvotes: 2

Views: 430

Answers (2)

bkchr
bkchr

Reputation: 641

The block and header type in Substrate are generic.

The header needs to implement https://docs.rs/sp-runtime/latest/sp_runtime/traits/trait.Header.html and the block needs to implement https://docs.rs/sp-runtime/latest/sp_runtime/traits/trait.Block.html.

Substrate itself provides two types for that already https://docs.rs/sp-runtime/latest/sp_runtime/generic/struct.Block.html and https://docs.rs/sp-runtime/latest/sp_runtime/generic/struct.Header.html.

When you setup your blockchain, which you mainly do through the runtime you can choose these types.

Upvotes: 4

Squirrel
Squirrel

Reputation: 1276

If you're after including some data for each block then it's called an Inherent extrinsic ( https://docs.substrate.io/v3/concepts/extrinsics/#inherents ) and would not have a fee associated with it.

Header is a type defined in your runtime so you can change it to include any additional data that you'd like. Search for this definition:

pub type Header = generic::Header<BlockNumber, BlakeTwo256>;

See it in context here: https://github.com/substrate-developer-hub/substrate-node-template/blob/ad7ce8e3dabb2d1f8f4b4094db5b0e754760e9be/runtime/src/lib.rs#L75

Upvotes: 1

Related Questions