forked from TrueCloudLab/neoneo-go
cli: rework smart contract configs
Use plain yaml structure.
This commit is contained in:
parent
7d89ccdb6f
commit
3adc9150d3
1 changed files with 28 additions and 31 deletions
|
@ -14,6 +14,7 @@ import (
|
||||||
"github.com/CityOfZion/neo-go/pkg/rpc"
|
"github.com/CityOfZion/neo-go/pkg/rpc"
|
||||||
"github.com/CityOfZion/neo-go/pkg/vm"
|
"github.com/CityOfZion/neo-go/pkg/vm"
|
||||||
"github.com/CityOfZion/neo-go/pkg/vm/compiler"
|
"github.com/CityOfZion/neo-go/pkg/vm/compiler"
|
||||||
|
"github.com/go-yaml/yaml"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/urfave/cli"
|
"github.com/urfave/cli"
|
||||||
)
|
)
|
||||||
|
@ -135,7 +136,17 @@ func initSmartContract(ctx *cli.Context) error {
|
||||||
// TODO: Fix the missing neo-go.yml file with the `init` command when the package manager is in place.
|
// TODO: Fix the missing neo-go.yml file with the `init` command when the package manager is in place.
|
||||||
if !ctx.Bool("skip-details") {
|
if !ctx.Bool("skip-details") {
|
||||||
details := parseContractDetails()
|
details := parseContractDetails()
|
||||||
if err := ioutil.WriteFile(filepath.Join(basePath, "neo-go.yml"), details.toStormFile(), 0644); err != nil {
|
details.ReturnType = rpc.ByteArray
|
||||||
|
details.Parameters = make([]rpc.StackParamType, 2)
|
||||||
|
details.Parameters[0] = rpc.String
|
||||||
|
details.Parameters[1] = rpc.Array
|
||||||
|
|
||||||
|
project := &ProjectConfig{Contract: details}
|
||||||
|
b, err := yaml.Marshal(project)
|
||||||
|
if err != nil {
|
||||||
|
return cli.NewExitError(err, 1)
|
||||||
|
}
|
||||||
|
if err := ioutil.WriteFile(filepath.Join(basePath, "neo-go.yml"), b, 0644); err != nil {
|
||||||
return cli.NewExitError(err, 1)
|
return cli.NewExitError(err, 1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -204,38 +215,24 @@ func testInvoke(ctx *cli.Context) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// ContractDetails contains contract metadata.
|
// ProjectConfig contains project metadata.
|
||||||
type ContractDetails struct {
|
type ProjectConfig struct {
|
||||||
Author string
|
Version uint
|
||||||
Email string
|
Contract ContractDetails `yaml:"project"`
|
||||||
Version string
|
|
||||||
ProjectName string
|
|
||||||
Description string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d ContractDetails) toStormFile() []byte {
|
// ContractDetails contains contract metadata.
|
||||||
buf := new(bytes.Buffer)
|
type ContractDetails struct {
|
||||||
|
Author string
|
||||||
buf.WriteString("# NEO-GO specific configuration. Do not modify this unless you know what you are doing!\n")
|
Email string
|
||||||
buf.WriteString("neo-go:\n")
|
Version string
|
||||||
buf.WriteString(" version: 1.0\n")
|
ProjectName string `yaml:"name"`
|
||||||
|
Description string
|
||||||
buf.WriteString("\n")
|
HasStorage bool
|
||||||
|
HasDynamicInvocation bool
|
||||||
buf.WriteString("# Project section contains information about your smart contract\n")
|
IsPayable bool
|
||||||
buf.WriteString("project:\n")
|
ReturnType rpc.StackParamType
|
||||||
buf.WriteString(" author: " + d.Author)
|
Parameters []rpc.StackParamType
|
||||||
buf.WriteString(" email: " + d.Email)
|
|
||||||
buf.WriteString(" version: " + d.Version)
|
|
||||||
buf.WriteString(" name: " + d.ProjectName)
|
|
||||||
buf.WriteString(" description: " + d.Description)
|
|
||||||
|
|
||||||
buf.WriteString("\n")
|
|
||||||
|
|
||||||
buf.WriteString("# Module section contains a list of imported modules\n")
|
|
||||||
buf.WriteString("# This will be automatically managed by the neo-go package manager\n")
|
|
||||||
buf.WriteString("modules: \n")
|
|
||||||
return buf.Bytes()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseContractDetails() ContractDetails {
|
func parseContractDetails() ContractDetails {
|
||||||
|
|
Loading…
Reference in a new issue