-
Notifications
You must be signed in to change notification settings - Fork 16
Add runtime API for authorizations #491
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
Changes from all commits
5cad9b3
ea387bf
a2bc0cc
8ee491b
5191043
0bbcb4f
a96d53f
8b63f52
e3291bf
105d32e
d11c8bc
bef9784
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| [package] | ||
| name = "pallet-bulletin-transaction-storage-runtime-api" | ||
| version = "0.1.0" | ||
| authors.workspace = true | ||
| edition.workspace = true | ||
| license = "Apache-2.0" | ||
| homepage.workspace = true | ||
| repository.workspace = true | ||
| description = "Runtime API for the Bulletin Chain transaction-storage pallet" | ||
|
|
||
| [package.metadata.docs.rs] | ||
| targets = ["x86_64-unknown-linux-gnu"] | ||
|
|
||
| [dependencies] | ||
| bulletin-transaction-storage-primitives = { workspace = true } | ||
| codec = { workspace = true } | ||
| scale-info = { features = ["derive"], workspace = true } | ||
| sp-api = { workspace = true } | ||
|
|
||
| [features] | ||
| default = ["std"] | ||
| std = [ | ||
| "bulletin-transaction-storage-primitives/std", | ||
| "codec/std", | ||
| "scale-info/std", | ||
| "sp-api/std", | ||
| ] | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| //! Runtime API for the Bulletin Chain transaction-storage pallet. | ||
| //! | ||
| //! Exposes one summary call and two boolean predicates that mirror the | ||
| //! validation logic of `store` and `renew`. Clients can use these to preview | ||
| //! whether a call will be accepted before signing it. | ||
|
|
||
| #![cfg_attr(not(feature = "std"), no_std)] | ||
|
|
||
| use bulletin_transaction_storage_primitives::TransactionRef; | ||
| use codec::{Codec, Decode, Encode}; | ||
| use scale_info::TypeInfo; | ||
|
|
||
| /// Active-authorization summary for an account. Returned by | ||
| /// [`BulletinTransactionStorageApi::account_authorization`] when the account | ||
| /// has an unexpired authorization entry. | ||
| #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Encode, Decode, TypeInfo)] | ||
| pub struct AccountAuthorization<BlockNumber> { | ||
| /// Block at which this account's authorization expires. | ||
| pub expires_at: BlockNumber, | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not sure if client will be able to interpret this - relay block, Bulletin para block?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you want to use time? Relay chain block would be better for me, I'm vouching for that
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Well, I don't know now, we don't use relay chain blocks, and everything is in Bulletin parachain blocks. I am not sure about the time. For now, with actual impl, I would just consider this Bulletin para block number and client could interpret this to the real clock time?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With authorization slots, this will be relay blocks |
||
| /// Total byte cap granted by the authorizer. | ||
| pub bytes_allowance: u64, | ||
| /// Bytes already consumed by `store` calls. | ||
| pub bytes_used: u64, | ||
| /// Bytes already consumed by `renew` calls (counts against the same | ||
| /// `bytes_allowance` cap). | ||
| pub bytes_permanent_used: u64, | ||
| } | ||
|
|
||
| sp_api::decl_runtime_apis! { | ||
| /// Runtime API for the Bulletin Chain transaction-storage pallet. | ||
| pub trait BulletinTransactionStorageApi<AccountId, BlockNumber> | ||
| where | ||
| AccountId: Codec, | ||
| BlockNumber: Codec, | ||
| { | ||
| /// Authorization summary for `account`, or `None` if the account has | ||
| /// no unexpired authorization. | ||
| fn account_authorization(account: AccountId) -> Option<AccountAuthorization<BlockNumber>>; | ||
|
|
||
| /// Returns `true` iff a `store(data)` call where `data.len() == data_len` | ||
| /// would currently pass transaction validation for `account`. | ||
| fn can_store(account: AccountId, data_len: u32) -> bool; | ||
|
|
||
| /// Returns `true` iff a `renew(entry)` call would currently pass transaction | ||
| /// validation for `account`. | ||
| fn can_renew(account: AccountId, entry: TransactionRef<BlockNumber>) -> bool; | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.