Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor existing native composite values to use 'CompositeValue' #668

Closed
wants to merge 12 commits into from
Closed
Prev Previous commit
Next Next commit
Refactor AuthAccountType to use CompositeType
  • Loading branch information
SupunS committed Mar 8, 2021
commit d51a4dd6d06280c3072fec996a92fa295a07b77f
34 changes: 19 additions & 15 deletions runtime/interpreter/value.go
Original file line number Diff line number Diff line change
Expand Up @@ -5690,6 +5690,10 @@ func (v *CompositeValue) KeyString() string {
}

func (v *CompositeValue) TypeID() common.TypeID {
if v.Location == nil {
return common.TypeID(v.QualifiedIdentifier)
}

return v.Location.TypeID(v.QualifiedIdentifier)
}

Expand Down Expand Up @@ -6704,49 +6708,49 @@ func NewAuthAccountValue(
) *CompositeValue {

fields := NewStringValueOrderedMap()
fields.Set("address", address)
fields.Set("addPublicKey", addPublicKeyFunction)
fields.Set("removePublicKey", removePublicKeyFunction)
fields.Set("getCapability", accountGetCapabilityFunction(address, true))
fields.Set("contracts", contracts)
fields.Set("keys", keys)
fields.Set(sema.AuthAccountAddressField, address)
fields.Set(sema.AuthAccountAddPublicKeyField, addPublicKeyFunction)
fields.Set(sema.AuthAccountRemovePublicKeyField, removePublicKeyFunction)
fields.Set(sema.AuthAccountGetCapabilityField, accountGetCapabilityFunction(address, true))
fields.Set(sema.AuthAccountContractsField, contracts)
fields.Set(sema.AuthAccountKeysField, keys)

// Computed fields
computedFields := NewStringComputedFieldOrderedMap()

computedFields.Set("storageUsed", func(inter *Interpreter) Value {
computedFields.Set(sema.AuthAccountStorageUsedField, func(inter *Interpreter) Value {
return storageUsedGet(inter)
})

computedFields.Set("storageCapacity", func(*Interpreter) Value {
computedFields.Set(sema.AuthAccountStorageCapacityField, func(*Interpreter) Value {
return storageCapacityGet()
})

computedFields.Set("load", func(inter *Interpreter) Value {
computedFields.Set(sema.AuthAccountLoadField, func(inter *Interpreter) Value {
return inter.authAccountLoadFunction(address)
})

computedFields.Set("copy", func(inter *Interpreter) Value {
computedFields.Set(sema.AuthAccountCopyField, func(inter *Interpreter) Value {
return inter.authAccountCopyFunction(address)
})

computedFields.Set("save", func(inter *Interpreter) Value {
computedFields.Set(sema.AuthAccountSaveField, func(inter *Interpreter) Value {
return inter.authAccountSaveFunction(address)
})

computedFields.Set("borrow", func(inter *Interpreter) Value {
computedFields.Set(sema.AuthAccountBorrowField, func(inter *Interpreter) Value {
return inter.authAccountBorrowFunction(address)
})

computedFields.Set("link", func(inter *Interpreter) Value {
computedFields.Set(sema.AuthAccountLinkField, func(inter *Interpreter) Value {
return inter.authAccountLinkFunction(address)
})

computedFields.Set("unlink", func(inter *Interpreter) Value {
computedFields.Set(sema.AuthAccountUnlinkField, func(inter *Interpreter) Value {
return inter.authAccountUnlinkFunction(address)
})

computedFields.Set("getLinkTarget", func(inter *Interpreter) Value {
computedFields.Set(sema.AuthAccountGetLinkTargetField, func(inter *Interpreter) Value {
return inter.accountGetLinkTargetFunction(address)
})

Expand Down
4 changes: 3 additions & 1 deletion runtime/sema/authaccount_contracts.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ import (
"github.com/onflow/cadence/runtime/common"
)

const AuthAccountContractsTypeName = "Contracts"

// AuthAccountContractsType represents the type `AuthAccount.Contracts`
//
var AuthAccountContractsType = &SimpleType{
Name: "Contracts",
Name: AuthAccountContractsTypeName,
QualifiedName: "AuthAccount.Contracts",
TypeID: "AuthAccount.Contracts",
IsInvalid: false,
Expand Down
Loading