-
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 #6251 from onflow/bastian/evm-setup-heartbeat
[Cadence 1.0 migration] Add migration to setup EVM heartbeat resource
- Loading branch information
Showing
8 changed files
with
154 additions
and
67 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,27 @@ | ||
package migrations | ||
|
||
import ( | ||
coreContracts "github.com/onflow/flow-core-contracts/lib/go/contracts" | ||
"github.com/rs/zerolog" | ||
|
||
"github.com/onflow/flow-go/model/flow" | ||
) | ||
|
||
func NewBurnerDeploymentMigration( | ||
chainID flow.ChainID, | ||
logger zerolog.Logger, | ||
) RegistersMigration { | ||
address := BurnerAddressForChain(chainID) | ||
return NewDeploymentMigration( | ||
chainID, | ||
Contract{ | ||
Name: "Burner", | ||
Code: coreContracts.Burner(), | ||
}, | ||
address, | ||
map[flow.Address]struct{}{ | ||
address: {}, | ||
}, | ||
logger, | ||
) | ||
} |
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
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
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,84 @@ | ||
package migrations | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/rs/zerolog" | ||
|
||
"github.com/onflow/flow-go/fvm/evm/stdlib" | ||
"github.com/onflow/flow-go/fvm/systemcontracts" | ||
"github.com/onflow/flow-go/model/flow" | ||
) | ||
|
||
func NewEVMDeploymentMigration( | ||
chainID flow.ChainID, | ||
logger zerolog.Logger, | ||
full bool, | ||
) RegistersMigration { | ||
|
||
systemContracts := systemcontracts.SystemContractsForChain(chainID) | ||
address := systemContracts.EVMContract.Address | ||
|
||
var code []byte | ||
if full { | ||
code = stdlib.ContractCode( | ||
systemContracts.NonFungibleToken.Address, | ||
systemContracts.FungibleToken.Address, | ||
systemContracts.FlowToken.Address, | ||
) | ||
} else { | ||
code = []byte(stdlib.ContractMinimalCode) | ||
} | ||
|
||
return NewDeploymentMigration( | ||
chainID, | ||
Contract{ | ||
Name: systemContracts.EVMContract.Name, | ||
Code: code, | ||
}, | ||
address, | ||
map[flow.Address]struct{}{ | ||
address: {}, | ||
}, | ||
logger, | ||
) | ||
} | ||
|
||
// NewEVMSetupMigration returns a migration that sets up the EVM contract account. | ||
// It performs the same operations as the EVM contract's initializer, calling the function EVM.setupHeartbeat, | ||
// which in turn creates an EVM.Heartbeat resource, and writes it to the account's storage. | ||
func NewEVMSetupMigration( | ||
chainID flow.ChainID, | ||
logger zerolog.Logger, | ||
) RegistersMigration { | ||
|
||
systemContracts := systemcontracts.SystemContractsForChain(chainID) | ||
evmContract := systemContracts.EVMContract | ||
|
||
tx := flow.NewTransactionBody(). | ||
SetScript([]byte(fmt.Sprintf( | ||
` | ||
import EVM from %s | ||
transaction { | ||
prepare() { | ||
EVM.setupHeartbeat() | ||
} | ||
} | ||
`, | ||
evmContract.Address.HexWithPrefix(), | ||
))) | ||
|
||
return NewTransactionBasedMigration( | ||
tx, | ||
chainID, | ||
logger, | ||
map[flow.Address]struct{}{ | ||
// The function call writes to the EVM contract account | ||
evmContract.Address: {}, | ||
// The function call writes to the global account, | ||
// as the function creates a resource, which gets initialized with a UUID | ||
flow.Address{}: {}, | ||
}, | ||
) | ||
} |
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
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
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
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