onflow / cadence

Cadence, the resource-oriented smart contract programming language 🏃‍♂️
https://developers.flow.com/cadence
Apache License 2.0
532 stars 139 forks source link

Allow adding fields to contracts #1540

Open turbolent opened 2 years ago

turbolent commented 2 years ago

Issue To Be Solved

Declaring new composite fields is currently unsupported for all kinds of composites (resources, structs, contracts).

Currently, contracts are implemented as composite values, just like resources and structs, i.e. each contract variable is a field in the composite value.

When declaring a new field for a composite, we need to migrate all already existing composite values and add the new field, which might be prohibitively expensive for some composite declarations, like resources and structs of popular contracts (e.g. there are millions of TopShot Moment resources stored).

However, given that contract values are singletons, we could actually allow adding fields to contracts, as only one single value is stored and needs to be migrated.

Suggested Solution

j1010001 commented 1 year ago

Might get more generally solved by FLIP https://github.com/onflow/flow/pull/1097