2018-02-09 16:08:50 +00:00
|
|
|
package smartcontract
|
|
|
|
|
|
|
|
import (
|
2018-02-15 15:35:49 +00:00
|
|
|
"errors"
|
2018-02-09 16:08:50 +00:00
|
|
|
|
2018-02-15 15:35:49 +00:00
|
|
|
"github.com/CityOfZion/neo-go/pkg/vm/compiler"
|
2018-02-09 16:08:50 +00:00
|
|
|
"github.com/urfave/cli"
|
|
|
|
)
|
|
|
|
|
|
|
|
// NewCommand returns a new contract command.
|
|
|
|
func NewCommand() cli.Command {
|
|
|
|
return cli.Command{
|
|
|
|
Name: "contract",
|
|
|
|
Usage: "compile - debug - deploy smart contracts",
|
|
|
|
Subcommands: []cli.Command{
|
|
|
|
{
|
|
|
|
Name: "compile",
|
|
|
|
Usage: "compile a smart contract to a .avm file",
|
|
|
|
Action: contractCompile,
|
2018-02-15 15:35:49 +00:00
|
|
|
Flags: []cli.Flag{
|
|
|
|
cli.StringFlag{
|
|
|
|
Name: "out, o",
|
|
|
|
Usage: "Output of the compiled contract",
|
|
|
|
},
|
|
|
|
},
|
2018-02-09 16:08:50 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "opdump",
|
|
|
|
Usage: "dump the opcode of a .go file",
|
|
|
|
Action: contractDumpOpcode,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func contractCompile(ctx *cli.Context) error {
|
2018-02-15 15:35:49 +00:00
|
|
|
if len(ctx.Args()) == 0 {
|
|
|
|
return errors.New("not enough arguments")
|
|
|
|
}
|
|
|
|
|
2018-02-19 09:24:28 +00:00
|
|
|
o := &compiler.Options{
|
|
|
|
Outfile: ctx.String("out"),
|
|
|
|
Debug: true,
|
2018-02-15 15:35:49 +00:00
|
|
|
}
|
|
|
|
|
2018-02-19 09:24:28 +00:00
|
|
|
src := ctx.Args()[0]
|
|
|
|
return compiler.CompileAndSave(src, o)
|
2018-02-09 16:08:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func contractDumpOpcode(ctx *cli.Context) error {
|
2018-02-19 09:24:28 +00:00
|
|
|
if len(ctx.Args()) == 0 {
|
|
|
|
return errors.New("not enough arguments")
|
2018-02-09 16:08:50 +00:00
|
|
|
}
|
2018-02-19 09:24:28 +00:00
|
|
|
src := ctx.Args()[0]
|
|
|
|
return compiler.DumpOpcode(src)
|
2018-02-09 16:08:50 +00:00
|
|
|
}
|