Skip to content

Instantly share code, notes, and snippets.

@milancermak
Created April 25, 2022 18:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save milancermak/0ac1f4bcd756c363d51554cd947fb9ab to your computer and use it in GitHub Desktop.
Save milancermak/0ac1f4bcd756c363d51554cd947fb9ab to your computer and use it in GitHub Desktop.
cairo wishlist

Custom decorators

Similar to Solidity's modifiers, the only_admin decorator would call the only_admin function before calling mint.

func only_admin():
    let (caller) = get_caller_address()
    let (admin) = admin.read()
    with_attr error_message("Auth: not admin"):
        assert caller = admin
    end
end

@only_admin
func mint():
  # func body...
end

Another use to synthesize getters

@getter
@storage_var
func foo() -> (value : felt):
end

Using the above @getter decorator would automatically create a simple get_foo function:

func get_foo() -> (value : felt):
    let (value) = foo.read()
    return (value)
end

I'd apprecitate just to have a way how to auto-declare a public getter for a storage_var, I have a lot of boring code just like the above.

If you can also give us a way how to run it before or after a decorated function, that would be great.

Random things

  • hide implicit args, no more typing of the holy trinity {syscall_ptr : felt*, pedersen_ptr : HashBuiltin*, range_check_ptr}
  • solve revoked references - newcomers to the lang get, without exception, bitten by this. I learnt to live with it but it would be much appreciated if it would get solved by the compiler
  • dynamic arrays (and improve working with arrays in general) - don't be like vyper :)
  • bit packing and unpacking in stdlib - everyone is building their own

structs

  • a way how to concisely update a large struct, see here
  • new for (composite) structs - a way to create an empty struct so I don't have to do this

Use function results in place

Instead of

let (caller) = get_caller_address()
owner.write(caller)

I want to be able to write

owner.write(get_caller_address())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment