vyperlang / vyper

Pythonic Smart Contract Language for the EVM
https://vyperlang.org
Other
4.85k stars 791 forks source link

wip: implement methods for structs #4041

Open charles-cooper opened 4 months ago

charles-cooper commented 4 months ago

What I did

just messing around, opening the PR so others can follow progress

How I did it

How to verify it

Commit message

Commit message for the final, squashed PR. (Optional, but reviewers will appreciate it! Please see our commit message style guide for what we would ideally like to see in a commit message.)

Description for the changelog

Cute Animal Picture

![Put a link to a cute animal picture inside the parenthesis-->]()

fubuloubu commented 4 months ago

A few examples of the intended use might be nice to see for commenting on the implementation

charles-cooper commented 4 months ago

A few examples of the intended use might be nice to see for commenting on the implementation

check commit message - https://github.com/vyperlang/vyper/pull/4041/commits/d94f54819efa7e28b07f4ed4da73d38ff51d6a43

fubuloubu commented 4 months ago

A few examples of the intended use might be nice to see for commenting on the implementation

check commit message - d94f548

@external
def foo(f: Foo):
    s: Foo = f
    s.decrement_balance(1)

s is only in memory because decrement_balance is a mutable call? would it make sense to have a decorator or additional syntax that delineated view from mutable calls? (or maybe the opposite, @view can be applied to make it non-mutable, which means you can execute this function on f even though it's in calldata)

charles-cooper commented 4 months ago

A few examples of the intended use might be nice to see for commenting on the implementation

check commit message - d94f548

@external
def foo(f: Foo):
    s: Foo = f
    s.decrement_balance(1)

s is only in memory because decrement_balance is a mutable call? would it make sense to have a decorator or additional syntax that delineated view from mutable calls? (or maybe the opposite, @view can be applied to make it non-mutable, which means you can execute this function on f even though it's in calldata)

i thought about it, i think additional syntax is overkill. it depends more just on the location of the item, like if you can do s.balance -= 1 you can do s.decrement_balance(1)

fubuloubu commented 4 months ago

A few examples of the intended use might be nice to see for commenting on the implementation

check commit message - d94f548

@external
def foo(f: Foo):
    s: Foo = f
    s.decrement_balance(1)

s is only in memory because decrement_balance is a mutable call? would it make sense to have a decorator or additional syntax that delineated view from mutable calls? (or maybe the opposite, @view can be applied to make it non-mutable, which means you can execute this function on f even though it's in calldata)

i thought about it, i think additional syntax is overkill. it depends more just on the location of the item, like if you can do s.balance -= 1 you can do s.decrement_balance(1)

so you would be able to call a non-mutable method on f? that's perfect