-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split ethereum and fabric deploy commands into separate sub commands
Signed-off-by: Nicko Guyer <nicko.guyer@kaleido.io>
- Loading branch information
Showing
8 changed files
with
122 additions
and
66 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
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,66 @@ | ||
/* | ||
Copyright © 2022 NAME HERE <EMAIL ADDRESS> | ||
*/ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/hyperledger/firefly-cli/internal/docker" | ||
"github.com/hyperledger/firefly-cli/internal/stacks" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// ethereumCmd represents the ethereum command | ||
var ethereumCmd = &cobra.Command{ | ||
Use: "ethereum <stack_name> <contract_json_file>", | ||
Short: "Deploy a compiled solidity contract", | ||
Long: `Deploy a solidity contract compiled with solc to the blockchain used by a FireFly stack | ||
To compile a .sol file to a .json file run: | ||
solc --combined-json abi,bin contract.sol > contract.json | ||
`, | ||
Args: cobra.ExactArgs(2), | ||
PreRunE: func(cmd *cobra.Command, args []string) error { | ||
return docker.CheckDockerConfig() | ||
}, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
stackName := args[0] | ||
filename := args[1] | ||
stackManager := stacks.NewStackManager(logger) | ||
if err := stackManager.LoadStack(stackName, verbose); err != nil { | ||
return err | ||
} | ||
contractNames, err := stackManager.GetContracts(filename, args[2:]) | ||
if err != nil { | ||
return err | ||
} | ||
if len(contractNames) < 1 { | ||
return fmt.Errorf("no contracts found in file: '%s'", filename) | ||
} | ||
selectedContractName := contractNames[0] | ||
if len(contractNames) > 1 { | ||
selectedContractName, err = selectMenu("select the contract to deploy", contractNames) | ||
fmt.Print("\n") | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
fmt.Printf("deploying %s... ", selectedContractName) | ||
contractAddress, err := stackManager.DeployContract(filename, selectedContractName, 0) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
fmt.Print("done\n\n") | ||
fmt.Printf("contract address: %s\n", contractAddress) | ||
fmt.Print("\n") | ||
return nil | ||
}, | ||
} | ||
|
||
func init() { | ||
deployCmd.AddCommand(ethereumCmd) | ||
} |
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,48 @@ | ||
/* | ||
Copyright © 2022 NAME HERE <EMAIL ADDRESS> | ||
*/ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/hyperledger/firefly-cli/internal/docker" | ||
"github.com/hyperledger/firefly-cli/internal/stacks" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// fabricCmd represents the fabric command | ||
var fabricCmd = &cobra.Command{ | ||
Use: "fabric <stack_name> <chaincode_package> <channel> <chaincodeName> <version>", | ||
Short: "Deploy fabric chaincode", | ||
Long: `Deploy a packaged chaincode to the Fabric network used by a FireFly stack`, | ||
Args: cobra.ExactArgs(5), | ||
PreRunE: func(cmd *cobra.Command, args []string) error { | ||
return docker.CheckDockerConfig() | ||
}, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
stackName := args[0] | ||
filename := args[1] | ||
channel := args[2] | ||
chaincode := args[3] | ||
version := args[4] | ||
stackManager := stacks.NewStackManager(logger) | ||
if err := stackManager.LoadStack(stackName, verbose); err != nil { | ||
return err | ||
} | ||
fmt.Printf("deploying %s... ", filename) | ||
contractAddress, err := stackManager.DeployContract(filename, filename, 0, channel, chaincode, version) | ||
if err != nil { | ||
return err | ||
} | ||
fmt.Print("done\n\n") | ||
fmt.Printf("deployed to: %s\n", contractAddress) | ||
fmt.Print("\n") | ||
return nil | ||
}, | ||
} | ||
|
||
func init() { | ||
deployCmd.AddCommand(fabricCmd) | ||
} |
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
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