-
Notifications
You must be signed in to change notification settings - Fork 180
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6422 from onflow/bastian/evm-storage-account-crea…
…tion-migration [Cadence 1.0 migration] Add EVM storage account creation migration
- Loading branch information
Showing
2 changed files
with
77 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package migrations | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/rs/zerolog" | ||
|
||
"github.com/onflow/flow-go/cmd/util/ledger/util/registers" | ||
"github.com/onflow/flow-go/model/flow" | ||
) | ||
|
||
func NewAccountCreationMigration( | ||
address flow.Address, | ||
logger zerolog.Logger, | ||
) RegistersMigration { | ||
|
||
return func(registersByAccount *registers.ByAccount) error { | ||
|
||
migrationRuntime := NewBasicMigrationRuntime(registersByAccount) | ||
|
||
// Check if the account already exists | ||
exists, err := migrationRuntime.Accounts.Exists(address) | ||
if err != nil { | ||
return fmt.Errorf( | ||
"failed to check if account %s exists: %w", | ||
address, | ||
err, | ||
) | ||
} | ||
|
||
// If the account already exists, do nothing | ||
if exists { | ||
logger.Info().Msgf("account %s already exists", address) | ||
return nil | ||
} | ||
|
||
// Create the account | ||
err = migrationRuntime.Accounts.Create(nil, address) | ||
if err != nil { | ||
return fmt.Errorf( | ||
"failed to create account %s: %w", | ||
address, | ||
err, | ||
) | ||
} | ||
|
||
logger.Info().Msgf("created account %s", address) | ||
|
||
// Commit the changes to the migrated registers | ||
err = migrationRuntime.Commit( | ||
map[flow.Address]struct{}{ | ||
address: {}, | ||
}, | ||
logger, | ||
) | ||
if err != nil { | ||
return fmt.Errorf("failed to commit account creation: %w", err) | ||
} | ||
|
||
return nil | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters