Skip to content

Add support for Timestamp type for Timeseries entities #433

@vladikopl01

Description

@vladikopl01

There was an update to the-graph subgraph specVersion of 1.3.0, which added the Timeseries entity type.

The docs for the timeseries entity type require developers to set the timestamp property of the entity to Timestamp! type. Unfortunately, after looking in the source code of the LimeChain implementation that was used in matchstick, there is no Timestamp type support.

Here is LimeChain version: https://github.com/LimeChain/graph-node/blob/master/runtime/wasm/src/asc_abi/class.rs#L558-L574

impl StoreValueKind {
    pub(crate) fn get_kind(value: &store::Value) -> StoreValueKind {
        use self::store::Value;

        match value {
            Value::String(_) => StoreValueKind::String,
            Value::Int(_) => StoreValueKind::Int,
            Value::Int8(_) => StoreValueKind::Int8,
            Value::BigDecimal(_) => StoreValueKind::BigDecimal,
            Value::Bool(_) => StoreValueKind::Bool,
            Value::List(_) => StoreValueKind::Array,
            Value::Null => StoreValueKind::Null,
            Value::Bytes(_) => StoreValueKind::Bytes,
            Value::BigInt(_) => StoreValueKind::BigInt,
        }
    }
}

Here is the-graph version: https://github.com/graphprotocol/graph-node/blob/master/runtime/wasm/src/asc_abi/class.rs#L580-L597

impl StoreValueKind {
    pub(crate) fn get_kind(value: &store::Value) -> StoreValueKind {
        use self::store::Value;

        match value {
            Value::String(_) => StoreValueKind::String,
            Value::Int(_) => StoreValueKind::Int,
            Value::Int8(_) => StoreValueKind::Int8,
            Value::Timestamp(_) => StoreValueKind::Timestamp,
            Value::BigDecimal(_) => StoreValueKind::BigDecimal,
            Value::Bool(_) => StoreValueKind::Bool,
            Value::List(_) => StoreValueKind::Array,
            Value::Null => StoreValueKind::Null,
            Value::Bytes(_) => StoreValueKind::Bytes,
            Value::BigInt(_) => StoreValueKind::BigInt,
        }
    }
}

After trying to set the entity's timestamp as Timestamp! type and save the entity, the matchstick runtime gives such error:

let vaultSnapshot = new VaultSnapshot(0);
vaultSnapshot.timestamp = params.timestamp.toI64();
vaultSnapshot.save(); // <-- here
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Other(value 9 is out of range for StoreValueKind)', src/context/mod.rs:183:65
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
 ›   Error: Matchstick exited with an error

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions