streamingfast / substreams-rs

9 stars 3 forks source link

Implement `has` on `StoreGetXXX` #13

Closed maoueh closed 5 months ago

maoueh commented 1 year ago

Today we have StoreGet with the following definition:

pub trait StoreGet<T> {
    fn new(idx: u32) -> Self;
    fn get_at<K: AsRef<str>>(&self, ord: u64, key: K) -> Option<T>;
    fn get_last<K: AsRef<str>>(&self, key: K) -> Option<T>;
    fn get_first<K: AsRef<str>>(&self, key: K) -> Option<T>;
}

And then some specialized implementation of this trait like StoreGetProto that will automatically process the output and decode it to the specified proto message.

However, in some cases, we only care if a specific key is present like when implementing "dynamic data source" pattern on Ethereum. In those cases, we often don't need the actual data and we only want to determine if we should process the output of not.

This task is about adding fn has<K: AsRef<str>>(&self, ord: u64, key: K) -> bool support in StoreGet and for all concrete implementations. The method should only check if the key exists and avoid all decoding related to it.

colindickson commented 1 year ago

@maoueh i propose to change the method name to has_at since it has essentially the same signature as get_at

colindickson commented 1 year ago

will be implementing has_at, has_first and has_last to mirror the get_ methods

colindickson commented 1 year ago

done on unstable