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 primitive types #959

Closed
shaunxw opened this issue Jun 19, 2023 · 2 comments
Closed

Introduce primitive types #959

shaunxw opened this issue Jun 19, 2023 · 2 comments
Assignees
Labels
runtime This PR/Issue is related to the topic “runtime”. Stale

Comments

@shaunxw
Copy link
Member

shaunxw commented Jun 19, 2023

Introduce primitives types in a dedicated primitives crate, something like Polkadot core primitives, including Balance, BlockNumber, AccountId, etc.

They would help to get rid of repeating primitive types definition across local/Shibuya/Shiden/Astar runtimes and collator:

Astar/runtime/astar/src/lib.rs

Lines 1064 to 1067 in 5187393

/// Balance of an account.
pub type Balance = u128;
/// Alias to 512-bit hash when used in the context of a transaction signature on the chain.
pub type Signature = sp_runtime::MultiSignature;

/// Balance of an account.
pub type Balance = u128;
/// Alias to 512-bit hash when used in the context of a transaction signature on the chain.
pub type Signature = sp_runtime::MultiSignature;

They can also be imported into astar pallets, making defining complex types easier by removing verbose trait bounds. For instance,

pub struct RewardInfo<Balance: HasCompact + MaxEncodedLen> {
/// Total amount of rewards for stakers in an era
#[codec(compact)]
pub stakers: Balance,
/// Total amount of rewards for dapps in an era
#[codec(compact)]
pub dapps: Balance,
}
could be re-written as:

use primitives::Balance;

pub struct RewardInfo {
    /// Total amount of rewards for stakers in an era 
    #[codec(compact)] 
    pub stakers: Balance, 
    /// Total amount of rewards for dapps in an era 
    #[codec(compact)] 
    pub dapps: Balance, 
 } 
@shaunxw shaunxw added the runtime This PR/Issue is related to the topic “runtime”. label Jun 19, 2023
@gitofdeepanshu gitofdeepanshu mentioned this issue Jun 20, 2023
5 tasks
@github-actions
Copy link

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 7 days.

@github-actions github-actions bot added the Stale label Jul 21, 2023
@shaunxw
Copy link
Member Author

shaunxw commented Jul 21, 2023

Finished with #961

@shaunxw shaunxw closed this as completed Jul 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
runtime This PR/Issue is related to the topic “runtime”. Stale
Projects
None yet
Development

No branches or pull requests

2 participants