-
Notifications
You must be signed in to change notification settings - Fork 262
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
The ConstantsClient
API needs better documentation
#811
Comments
Offhand, it does seem like you are overcomplicating things a bit; perhaps this example will help?: https://github.com/paritytech/subxt/blob/master/examples/examples/fetch_constants.rs Assuming you have used the // Create a client to use:
let api = OnlineClient::<PolkadotConfig>::new().await?;
// Build a constant address to query:
let address = polkadot::constants().system().block_hash_count();
// Look it up:
let block_hash_count = api.constants().at(&address)?; One of the reasons for this API accepting concrete types is that you can also pass a dynamic "address" instead if you don't want to use the // Create a client to use:
let api = OnlineClient::<PolkadotConfig>::new().await?;
// Build a dynamic constant address instead of a static one to query:
let address = subxt::dynamic::constant("System", "BlockHashCount");
// Look it up (opting to decode the constant to a dynamic `Value` type; you can also manually work
// with the bytes instead of using `to_value()`:
let block_hash_count = api.constants().at(&address)?.to_value()?; I think offhand that the APIs are not too difficult to use, but the documentation is clearly lacking. We should:
I'm open to other suggestions also though! |
Thanks for those examples, yes something like the second is what I was after. If I can get to a PR I will :) Related, I guess there is some reason for only having |
Yup pretty much; It could (and did once) have variants for u8/u16 etc and there are arguments in favour of that too, but the size of the enum has to fit You have the option to implement your own types that can be decoded to instead though if you prefer to roll your own custom type! |
ConstantsClient
API is too difficult to useConstantsClient
API needs better documentation
Maybe I'm using it wrong, in which case this issue could be to provide some documentation on how to actually get constants, but here's what I have.
I would expect that I could just pass in a pallet, const name and a value (NOT this
DecodedValue
value type, but au64
for example, and the client just returns me the value, decoded into the type I provide it, or something along these lines. Isn't clear at all how to use it, and I only got this far by reading the code, would be ideal if a user didn't, and could just use the API from the documentation provided.One thing that I was confused about is why even have an object be passable into
.at()
, why not just pass in the generic, and doAddress::pallet_name()
? Seems that would be simpler.The text was updated successfully, but these errors were encountered: