-
Notifications
You must be signed in to change notification settings - Fork 124
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
Make api and primitives generic over Runtime #340
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
7dae69d
to
ba25bfc
Compare
add traits add balanes impl add Runtime trait make api generic over Runtime remove interfaces fix clippy fix staking feature fix doc make RuntimeVersion generic over Runtime revert last commit fix examples
ba25bfc
to
4679f17
Compare
@@ -180,7 +180,7 @@ impl EventDetails { | |||
|
|||
// topics come after the event data in EventRecord. They aren't used for | |||
// anything at the moment, so just decode and throw them away. | |||
let _topics = Vec::<Hash>::decode(input)?; | |||
let _topics = Vec::<H256>::decode(input)?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hardcoded H256 for now.. as they're not used and are unlikely to be different from H256 at the moment.
@@ -22,20 +22,3 @@ pub use extrinsics::*; | |||
|
|||
pub mod extrinsic_params; | |||
pub mod extrinsics; | |||
|
|||
/// The block number type used in this runtime. | |||
pub type BlockNumber = u64; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not needed anymore, because all these params should now be generic inside the api-client.
self.signer = Some(signer); | ||
} | ||
|
||
/// Get the public part of the api signer account. | ||
pub fn signer_account(&self) -> Option<AccountId> { | ||
pub fn signer_account(&self) -> Option<AccountId32> { | ||
let pair = self.signer.as_ref()?; | ||
let multi_signer = MultiSigner::from(pair.public()); | ||
Some(multi_signer.into_account()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MultiSigner only implements into_account
for AccountId32. Not sure why, but I guess there's a reason.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, because moonbeam does in fact implement an account id with 20 bytes, but still use the multisigner if I am not mistaken.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice to see everything getting so generic. However, I am unsure if depending on the runtime directly is a potential blocker for some use cases, especially the no-std world because it compiles to wasm in no-std. So maybe we need to have a layer in between like:
pub trait RuntimeConfig {
type Balance;
// etc.
// We could even define the tips here
}
// We could add feature gated configs like:
impl RuntimeConfig for KitchenSinkRuntime {
type Balance = KitchenSinkRuntime::Balance
// etc
}
I am not sure if this creates problems on other ends though.
The pallets-itself also assume wasm in no-std, so in my opinion, you can't get around the runtime config trait that I am suggesting. So if you want to merge this PR now, I suggest fixing the trait immediately afterwards, so we don't have a breaking interface in subsequent releases. |
…/scs/substrate-api-client into bh/make-api-generic-over-runtime
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice looks good now. I like the approach! :)
Only a few minor remarks are left.
//! Re-defintion of substrate primitives. | ||
//! Needed because substrate pallets compile to wasm in no_std. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can note that all these primitives are from the pallet-balances, aren't they?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They are not. Should I paste a link from where they are taken?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, this would be fabulous! 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done :)
self.signer = Some(signer); | ||
} | ||
|
||
/// Get the public part of the api signer account. | ||
pub fn signer_account(&self) -> Option<AccountId> { | ||
pub fn signer_account(&self) -> Option<AccountId32> { | ||
let pair = self.signer.as_ref()?; | ||
let multi_signer = MultiSigner::from(pair.public()); | ||
Some(multi_signer.into_account()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, because moonbeam does in fact implement an account id with 20 bytes, but still use the multisigner if I am not mistaken.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, looks good to me!
P
(probably for Pair) toSigner
no_std
due to default wasm compilation.