Cairo type hints
Add type hints to your Cairo-lang files and feed the generated json files to Stark-Dot-Net code generators.
Install
pip install cairo-type-hints
Example usage:
python compile-cairo-type-hints \
-i ./src/my-awesome-contract.cairo \
-o ./artifacts/hints/test-hints.json
Adding hints to structs
A type hint is a comment with a colon, a space and then a type. Valid types are int, string, and address. For example, #: int.
Type hints are added inline per member of the struct. For example:
struct UserMeta:
member index : felt #: int
member hash : felt
member position : Position
end
Members without a type hint will default to string for felt and the struct type for structs.
The above Cairo-lang example outputs:
[
{
"name":"UserMeta",
"members":[
{
"type":"int",
"name":"index"
},
{
"type":"string",
"name":"hash"
},
{
"type":"Position",
"name":"position"
}
],
"type":"struct"
}
]
Adding hints to functions
Function hint comments mimic Cairo-lang function type declarations and are placed as the first statement in a function body. For example:
#: (index : int, position : Position) -> (user : User)
@view
func get_user_by_index {
syscall_ptr : felt*, pedersen_ptr : HashBuiltin*,
range_check_ptr
} (index : felt, position : Position) -> (user : User):
#: (index : int, position : Position) -> (user : User)
let (hash) = users_index_to_hash.read(index)
let (user) = get_user_by_hash(hash)
return (user = user)
end
The above Cairo-lang example outputs:
[
{
"name":"get_user_by_index",
"inputs":[
{
"type":"int",
"name":"index"
},
{
"type":"Position",
"name":"position"
}
],
"outputs":[
{
"type":"User",
"name":"user"
}
],
"type":"function"
}
]
Development
Install and switch to python 3.9.x
$ pyenv install 3.9.9
$ pyenv local 3.9.9
Create a virtual environment and activate it
$ python -m venv env
$ source venv/bin/activate
Do some awesome work!
Build and publish the package
$ python setup.py bdist_wheel sdist
$ twine upload dist/*
Metadata
Release files for cairo-type-hints 0.1.7
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| cairo-type-hints-0.1.7.tar.gz | 6.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| cairo_type_hints-0.1.7-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 15.9 kB
Release files / cairo-type-hints-0.1.7.tar.gz
| Download URL | cairo-type-hints-0.1.7.tar.gz |
|---|---|
| Size | 6.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9cb37c75ede4e37c517fe34c3c9a811cb7c278564ed7eebdad9a4e7bc92e4e15
|
|
BLAKE2b-256 checksum How to use checksums |
584edde08462eec23225ed86736cac9c583bc4c38a99a3d01a111da598e5a6d4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.0 CPython/3.9.9
|
Release files / cairo_type_hints-0.1.7-py3-none-any.whl
| Download URL | cairo_type_hints-0.1.7-py3-none-any.whl |
|---|---|
| Size | 9.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8145f647cb6ec0b500d383440e05edd39161dd3477d9d3d131626dd504f0e8b2
|
|
BLAKE2b-256 checksum How to use checksums |
7eee872f31505189eee5c7539d9293ffca3f01ce74ce4b00f2bcf9d7fd8a237e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.0 CPython/3.9.9
|