github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/cmd/util/ledger/migrations/deploy_migration.go (about)

     1  package migrations
     2  
     3  import (
     4  	"github.com/onflow/cadence"
     5  	jsoncdc "github.com/onflow/cadence/encoding/json"
     6  	coreContracts "github.com/onflow/flow-core-contracts/lib/go/contracts"
     7  	"github.com/rs/zerolog"
     8  
     9  	evm "github.com/onflow/flow-go/fvm/evm/stdlib"
    10  	"github.com/onflow/flow-go/fvm/systemcontracts"
    11  	"github.com/onflow/flow-go/model/flow"
    12  )
    13  
    14  func NewDeploymentMigration(
    15  	chainID flow.ChainID,
    16  	contract Contract,
    17  	authorizer flow.Address,
    18  	expectedWriteAddresses map[flow.Address]struct{},
    19  	logger zerolog.Logger,
    20  ) RegistersMigration {
    21  
    22  	script := []byte(`
    23        transaction(name: String, code: String) {
    24            prepare(signer: auth(AddContract) &Account) {
    25                signer.contracts.add(name: name, code: code.utf8)
    26            }
    27        }
    28      `)
    29  
    30  	tx := flow.NewTransactionBody().
    31  		SetScript(script).
    32  		AddArgument(jsoncdc.MustEncode(cadence.String(contract.Name))).
    33  		AddArgument(jsoncdc.MustEncode(cadence.String(contract.Code))).
    34  		AddAuthorizer(authorizer)
    35  
    36  	return NewTransactionBasedMigration(
    37  		tx,
    38  		chainID,
    39  		logger,
    40  		expectedWriteAddresses,
    41  	)
    42  }
    43  
    44  func NewBurnerDeploymentMigration(
    45  	chainID flow.ChainID,
    46  	logger zerolog.Logger,
    47  ) RegistersMigration {
    48  	address := BurnerAddressForChain(chainID)
    49  	return NewDeploymentMigration(
    50  		chainID,
    51  		Contract{
    52  			Name: "Burner",
    53  			Code: coreContracts.Burner(),
    54  		},
    55  		address,
    56  		map[flow.Address]struct{}{
    57  			address: {},
    58  		},
    59  		logger,
    60  	)
    61  }
    62  
    63  func NewEVMDeploymentMigration(
    64  	chainID flow.ChainID,
    65  	logger zerolog.Logger,
    66  ) RegistersMigration {
    67  	systemContracts := systemcontracts.SystemContractsForChain(chainID)
    68  	address := systemContracts.EVMContract.Address
    69  	return NewDeploymentMigration(
    70  		chainID,
    71  		Contract{
    72  			Name: systemContracts.EVMContract.Name,
    73  			Code: evm.ContractCode(
    74  				systemContracts.NonFungibleToken.Address,
    75  				systemContracts.FungibleToken.Address,
    76  				systemContracts.FlowToken.Address,
    77  			),
    78  		},
    79  		address,
    80  		map[flow.Address]struct{}{
    81  			address: {},
    82  		},
    83  		logger,
    84  	)
    85  }