Skip to content

Commit

Permalink
Merge pull request #6326 from onflow/auto-update-onflow-cadence-v1.0.…
Browse files Browse the repository at this point in the history
…0-preview.46

Update to Cadence v1.0.0-preview.47
  • Loading branch information
turbolent authored Aug 13, 2024
2 parents d63da0e + a06ed0b commit 3a2217d
Show file tree
Hide file tree
Showing 9 changed files with 220 additions and 85 deletions.
42 changes: 27 additions & 15 deletions cmd/util/ledger/migrations/cadence.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,8 @@ type IssueStorageCapConMigration struct {
accountsCapabilities *capcons.AccountsCapabilities
interpreterMigrationRuntimeConfig InterpreterMigrationRuntimeConfig
programs map[runtime.Location]*interpreter.Program
mapping *capcons.PathTypeCapabilityMapping
typedCapabilityMapping *capcons.PathTypeCapabilityMapping
untypedCapabilityMapping *capcons.PathCapabilityMapping
reporter reporters.ReportWriter
logVerboseDiff bool
verboseErrorOutput bool
Expand All @@ -243,19 +244,21 @@ func NewIssueStorageCapConMigration(
chainID flow.ChainID,
storageDomainCapabilities *capcons.AccountsCapabilities,
programs map[runtime.Location]*interpreter.Program,
storageCapabilityMapping *capcons.PathTypeCapabilityMapping,
typedStorageCapabilityMapping *capcons.PathTypeCapabilityMapping,
untypedStorageCapabilityMapping *capcons.PathCapabilityMapping,
opts Options,
) *IssueStorageCapConMigration {
return &IssueStorageCapConMigration{
name: "cadence_storage_cap_con_issue_migration",
reporter: rwf.ReportWriter(issueStorageCapConMigrationReporterName),
chainID: chainID,
accountsCapabilities: storageDomainCapabilities,
programs: programs,
mapping: storageCapabilityMapping,
logVerboseDiff: opts.LogVerboseDiff,
verboseErrorOutput: opts.VerboseErrorOutput,
errorMessageHandler: errorMessageHandler,
name: "cadence_storage_cap_con_issue_migration",
reporter: rwf.ReportWriter(issueStorageCapConMigrationReporterName),
chainID: chainID,
accountsCapabilities: storageDomainCapabilities,
programs: programs,
typedCapabilityMapping: typedStorageCapabilityMapping,
untypedCapabilityMapping: untypedStorageCapabilityMapping,
logVerboseDiff: opts.LogVerboseDiff,
verboseErrorOutput: opts.VerboseErrorOutput,
errorMessageHandler: errorMessageHandler,
}
}

Expand Down Expand Up @@ -332,11 +335,17 @@ func (m *IssueStorageCapConMigration) MigrateAccount(

capcons.IssueAccountCapabilities(
inter,
migrationRuntime.Storage,
reporter,
address,
accountCapabilities,
handler,
m.mapping,
m.typedCapabilityMapping,
m.untypedCapabilityMapping,
func(valueType interpreter.StaticType) interpreter.Authorization {
// TODO:
return interpreter.UnauthorizedAccess
},
)

err = migrationRuntime.Storage.NondeterministicCommit(inter, false)
Expand Down Expand Up @@ -387,7 +396,8 @@ func NewCadence1ValueMigrations(
privatePublicCapabilityMapping := &capcons.PathCapabilityMapping{}
// Populated by IssueStorageCapConMigration
// used by CadenceCapabilityValueMigration
storageCapabilityMapping := &capcons.PathTypeCapabilityMapping{}
typedStorageCapabilityMapping := &capcons.PathTypeCapabilityMapping{}
untypedStorageCapabilityMapping := &capcons.PathCapabilityMapping{}

// Populated by StorageCapMigration,
// used by IssueStorageCapConMigration
Expand Down Expand Up @@ -448,7 +458,8 @@ func NewCadence1ValueMigrations(
opts.ChainID,
storageDomainCapabilities,
programs,
storageCapabilityMapping,
typedStorageCapabilityMapping,
untypedStorageCapabilityMapping,
opts,
)
return migration.name, migration
Expand All @@ -470,7 +481,8 @@ func NewCadence1ValueMigrations(
errorMessageHandler,
programs,
privatePublicCapabilityMapping,
storageCapabilityMapping,
typedStorageCapabilityMapping,
untypedStorageCapabilityMapping,
opts,
)
return migration.name, migration
Expand Down
53 changes: 49 additions & 4 deletions cmd/util/ledger/migrations/cadence_values_migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,8 @@ func NewCadence1CapabilityValueMigration(
errorMessageHandler *errorMessageHandler,
programs map[runtime.Location]*interpreter.Program,
privatePublicCapabilityMapping *capcons.PathCapabilityMapping,
storageCapabilityMapping *capcons.PathTypeCapabilityMapping,
typedStorageCapabilityMapping *capcons.PathTypeCapabilityMapping,
untypedStorageCapabilityMapping *capcons.PathCapabilityMapping,
opts Options,
) *CadenceBaseMigration {
var diffReporter reporters.ReportWriter
Expand All @@ -403,9 +404,10 @@ func NewCadence1CapabilityValueMigration(
) []migrations.ValueMigration {
return []migrations.ValueMigration{
&capcons.CapabilityValueMigration{
PrivatePublicCapabilityMapping: privatePublicCapabilityMapping,
StorageCapabilityMapping: storageCapabilityMapping,
Reporter: reporter,
PrivatePublicCapabilityMapping: privatePublicCapabilityMapping,
TypedStorageCapabilityMapping: typedStorageCapabilityMapping,
UntypedStorageCapabilityMapping: untypedStorageCapabilityMapping,
Reporter: reporter,
},
}
},
Expand Down Expand Up @@ -542,6 +544,18 @@ func (t *cadenceValueMigrationReporter) MissingBorrowType(
})
}

func (t *cadenceValueMigrationReporter) InferredMissingBorrowType(
accountAddress common.Address,
addressPath interpreter.AddressPath,
borrowType *interpreter.ReferenceStaticType,
) {
t.reportWriter.Write(storageCapConsInferredBorrowTypeEntry{
AccountAddress: accountAddress,
AddressPath: addressPath,
BorrowType: borrowType,
})
}

func (t *cadenceValueMigrationReporter) IssuedStorageCapabilityController(
accountAddress common.Address,
addressPath interpreter.AddressPath,
Expand Down Expand Up @@ -891,3 +905,34 @@ func (e storageCapConsMissingBorrowTypeEntry) MarshalJSON() ([]byte, error) {
Path: e.AddressPath.Path.String(),
})
}

// StorageCapConMissingBorrowType

type storageCapConsInferredBorrowTypeEntry struct {
AccountAddress common.Address
AddressPath interpreter.AddressPath
BorrowType *interpreter.ReferenceStaticType
}

var _ valueMigrationReportEntry = storageCapConsInferredBorrowTypeEntry{}
var _ json.Marshaler = storageCapConsInferredBorrowTypeEntry{}

func (e storageCapConsInferredBorrowTypeEntry) accountAddress() common.Address {
return e.AccountAddress
}

func (e storageCapConsInferredBorrowTypeEntry) MarshalJSON() ([]byte, error) {
return json.Marshal(struct {
Kind string `json:"kind"`
AccountAddress string `json:"account_address"`
Address string `json:"address"`
Path string `json:"path"`
BorrowType string `json:"borrow_type"`
}{
Kind: "storage-capcon-inferred-borrow-type",
AccountAddress: e.AccountAddress.HexWithPrefix(),
Address: e.AddressPath.Address.HexWithPrefix(),
Path: e.AddressPath.Path.String(),
BorrowType: string(e.BorrowType.ID()),
})
}
Loading

0 comments on commit 3a2217d

Please sign in to comment.