Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var Cmd = &cobra.Command{ Use: "deploy", Short: "Deploy Cadence contracts", Run: func(cmd *cobra.Command, args []string) { project := cli.LoadProject(c.ConfigPath) host := project.Host(conf.Network) grpcClient, err := client.New(host, grpc.WithInsecure()) if err != nil { cli.Exit(1, err.Error()) return } if project.ContractConflictExists(conf.Network) { fmt.Println("\n❌ Currently it is not possible to deploy same contract with multiple accounts, please check Deployments in config and make sure contract is only present in one account") cli.Exit(1, "") return } sender := txsender.NewSender(grpcClient) processor := contracts.NewPreprocessor( contracts.FilesystemLoader{}, project.GetAliases(conf.Network), ) for _, contract := range project.GetContractsByNetwork(conf.Network) { err = processor.AddContractSource( contract.Name, contract.Source, contract.Target, ) if err != nil { cli.Exit(1, err.Error()) return } } err = processor.ResolveImports() if err != nil { cli.Exit(1, err.Error()) return } contracts, err := processor.ContractDeploymentOrder() if err != nil { cli.Exit(1, err.Error()) return } fmt.Printf( "Deploying %v contracts for accounts: %s\n", len(contracts), strings.Join(project.GetAllAccountNames(), ","), ) var errs []error for _, contract := range contracts { targetAccount := project.GetAccountByAddress(contract.Target().String()) ctx := context.Background() targetAccountInfo, err := grpcClient.GetAccountAtLatestBlock(ctx, targetAccount.Address()) if err != nil { cli.Exitf(1, "Failed to fetch information for account %s", targetAccount.Address()) return } var tx *flow.Transaction _, exists := targetAccountInfo.Contracts[contract.Name()] if exists { if !conf.Update { continue } tx = prepareUpdateContractTransaction(targetAccount.Address(), contract) } else { tx = prepareAddContractTransaction(targetAccount.Address(), contract) } getResult := sender.Send(ctx, tx, targetAccount) spinner := cli.NewSpinner( fmt.Sprintf("%s ", cli.Bold(contract.Name())), " deploying...", ) spinner.Start() result := <-getResult if result.Error() == nil { spinner.Stop(fmt.Sprintf("%s -> 0x%s", cli.Green(contract.Name()), contract.Target())) } else { spinner.Stop(fmt.Sprintf("%s error", cli.Red(contract.Name()))) errs = append(errs, result.Error()) } } if len(errs) == 0 { fmt.Println("\n✅ All contracts deployed successfully") } else { fmt.Println("\n❌ Failed to deploy all contracts") } }, }
Functions ¶
This section is empty.
Types ¶
Click to show internal directories.
Click to hide internal directories.