-
Notifications
You must be signed in to change notification settings - Fork 189
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
[core]: add computed read for components #714
Comments
Hi sir! Is someone working on this? I would like to give it a try. |
Hey! You're welcome to give it a shot! |
Hey @dubzn have you made progress on this? |
Implementation:Declaration
#[derive(Model, Copy, Drop, Serde)]
struct Army {
#[key]
player: ContractAddress,
archers: u16,
cavalry: u16,
infantry: u16,
// Computed fields should appear at the end
#[computed]
population: u16,
}
IntrospectionIntrospect provides serialised fn serialize_computed_defaults( ref values ) {
layout.append( Default::<u16>::default() );
} ReconstructionAfter fetch we append the default values before deserialising (similar to how we do for keys). SchemaIntrospection::<Army>::serialize_computed_defaults( ref __Army_values__ );
...
let mut army = serde::Serde::<Army>::deserialize( ref __Army_values_span__ ); Finally, we add the computed values, army.population = army.compute_population(); All done! |
@shramee a computed value doesn't need to exist on the struct. it should be defined based on the For a computed value, we want to be able to understand it's dependencies during compilation, so we can identity the underlying values that should trigger recompilation. For example:
|
So we have,
|
@ponderingdemocritus @tarrencev @kariy, |
New usage:
Examples: #[external(v0)]
#[computed]
fn tile_terrain(self: @ContractState, vec: Vec2) -> felt252 {
'land'
}
#[external(v0)]
#[computed(Position)]
fn quadrant(self: @ContractState, pos: Position) -> Quadrant {
// 10 is zero
if pos.vec.x < 10 {
if pos.vec.y < 10 {
Quadrant::NN
} else {
Quadrant::NP
}
} else {
if pos.vec.y < 10 {
Quadrant::PN
} else {
Quadrant::PP
}
}
} |
Will consider it as closed by #1152. Do no hesitate to re-open is required. |
This has been discussed before but adding it for posterity and in case a new contributor wants to tackle it.
Is your feature request related to a problem? Please describe.
Games require computed values for context, currently, it is not possible to query for computed values within components.
Describe the solution you'd like
The ability to add an attribute to a component implementation that allows clients to view the computed value.
Indexing writer contract view functions
from: @shramee
A contract function that doesn't update storage used to be called a view function on StarkNet. I'm not sure if that's still the case but below, by
view
I mean contract view function.Experience for the developers remains the same, but indexers can provide config to index certain views
Torii to support indexing for any view function on any of the writer contracts.
Model
argumentModel
, Torii can provide it all from it's database.The text was updated successfully, but these errors were encountered: