-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
654e65b
commit 81b1900
Showing
3 changed files
with
88 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
"""Abi query for inflation data spec""" | ||
import logging | ||
from dataclasses import dataclass | ||
from typing import Optional | ||
|
||
from telliot_feeds.dtypes.float_type import UnsignedFloatType | ||
from telliot_feeds.dtypes.value_type import ValueType | ||
from telliot_feeds.queries.abi_query import AbiQuery | ||
|
||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
@dataclass | ||
class InflationData(AbiQuery): | ||
""" | ||
More info: https://github.com/tellor-io/dataSpecs/blob/main/types/InflationData.md | ||
Attributes: | ||
- location: The area of the world where the data was collected (e.g. USA) | ||
- agency: The acronym for or full name of the agency that collected the data (e.g. BLS) | ||
- category: The category should describe which basket of goods is used to calculate inflation of (e.g. housing) | ||
- description: The description should include additional information needed to differentiate the | ||
data.(e.g. index) | ||
""" | ||
|
||
location: Optional[str] = None | ||
agency: Optional[str] = None | ||
category: Optional[str] = None | ||
description: Optional[str] = None | ||
|
||
#: ABI used for encoding/decoding parameters | ||
abi = [ | ||
{"name": "location", "type": "string"}, | ||
{"name": "agency", "type": "string"}, | ||
{"name": "category", "type": "string"}, | ||
{"name": "description", "type": "string"}, | ||
] | ||
|
||
@property | ||
def value_type(self) -> ValueType: | ||
"""Data type returned for a InflationData query. | ||
- `ufixed256x18`: 256-bit unsigned integer with 18 decimals of precision | ||
- `packed`: false | ||
""" | ||
return UnsignedFloatType(abi_type="ufixed256x18", packed=False) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from telliot_feeds.queries.inflation_data import InflationData | ||
|
||
|
||
def test_inflation_data_query(): | ||
"""Test InflationData query encoding""" | ||
q = InflationData( | ||
location="USA", | ||
agency="BLS", | ||
category="", | ||
description="CPI", | ||
) | ||
|
||
assert q.query_data.hex() == "00000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000d496e666c6174696f6e44617461000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000160000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000120000000000000000000000000000000000000000000000000000000000000000355534100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003424c530000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000034350490000000000000000000000000000000000000000000000000000000000" # noqa: E501 | ||
assert q.query_id.hex() == "389577823bc36cc44f87d115fcf1d681b9a12be480d449e85013a8cd788fc58a" |