mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-11-29 23:33:37 +00:00
compiler: specify safe methods in config
This commit is contained in:
parent
d7194e4da5
commit
2341ae0c53
5 changed files with 16 additions and 1 deletions
|
@ -363,6 +363,7 @@ func initSmartContract(ctx *cli.Context) error {
|
||||||
m := ProjectConfig{
|
m := ProjectConfig{
|
||||||
Name: contractName,
|
Name: contractName,
|
||||||
SupportedStandards: []string{},
|
SupportedStandards: []string{},
|
||||||
|
SafeMethods: []string{},
|
||||||
Events: []manifest.Event{
|
Events: []manifest.Event{
|
||||||
{
|
{
|
||||||
Name: "Hello world!",
|
Name: "Hello world!",
|
||||||
|
@ -423,6 +424,7 @@ func contractCompile(ctx *cli.Context) error {
|
||||||
o.Name = conf.Name
|
o.Name = conf.Name
|
||||||
o.ContractEvents = conf.Events
|
o.ContractEvents = conf.Events
|
||||||
o.ContractSupportedStandards = conf.SupportedStandards
|
o.ContractSupportedStandards = conf.SupportedStandards
|
||||||
|
o.SafeMethods = conf.SafeMethods
|
||||||
}
|
}
|
||||||
|
|
||||||
result, err := compiler.CompileAndSave(src, o)
|
result, err := compiler.CompileAndSave(src, o)
|
||||||
|
@ -646,6 +648,7 @@ func testInvokeScript(ctx *cli.Context) error {
|
||||||
// ProjectConfig contains project metadata.
|
// ProjectConfig contains project metadata.
|
||||||
type ProjectConfig struct {
|
type ProjectConfig struct {
|
||||||
Name string
|
Name string
|
||||||
|
SafeMethods []string
|
||||||
SupportedStandards []string
|
SupportedStandards []string
|
||||||
Events []manifest.Event
|
Events []manifest.Event
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,6 +59,7 @@ func RuntimeNotify(args []interface{}) {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t,
|
require.Equal(t,
|
||||||
`name: testContract
|
`name: testContract
|
||||||
|
safemethods: []
|
||||||
supportedstandards: []
|
supportedstandards: []
|
||||||
events:
|
events:
|
||||||
- name: Hello world!
|
- name: Hello world!
|
||||||
|
|
|
@ -51,6 +51,9 @@ type Options struct {
|
||||||
|
|
||||||
// The list of standards supported by the contract.
|
// The list of standards supported by the contract.
|
||||||
ContractSupportedStandards []string
|
ContractSupportedStandards []string
|
||||||
|
|
||||||
|
// SafeMethods contains list of methods which will be marked as safe in manifest.
|
||||||
|
SafeMethods []string
|
||||||
}
|
}
|
||||||
|
|
||||||
type buildInfo struct {
|
type buildInfo struct {
|
||||||
|
|
|
@ -433,6 +433,12 @@ func (di *DebugInfo) ConvertToManifest(o *Options) (*manifest.Manifest, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
for i := range o.SafeMethods {
|
||||||
|
if mMethod.Name == o.SafeMethods[i] {
|
||||||
|
mMethod.Safe = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
methods = append(methods, mMethod)
|
methods = append(methods, mMethod)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -150,7 +150,7 @@ func _deploy(isUpdate bool) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
t.Run("convert to Manifest", func(t *testing.T) {
|
t.Run("convert to Manifest", func(t *testing.T) {
|
||||||
actual, err := d.ConvertToManifest(&Options{Name: "MyCTR"})
|
actual, err := d.ConvertToManifest(&Options{Name: "MyCTR", SafeMethods: []string{"methodInt", "methodString"}})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
// note: offsets are hard to predict, so we just take them from the output
|
// note: offsets are hard to predict, so we just take them from the output
|
||||||
expected := &manifest.Manifest{
|
expected := &manifest.Manifest{
|
||||||
|
@ -183,12 +183,14 @@ func _deploy(isUpdate bool) {}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
ReturnType: smartcontract.IntegerType,
|
ReturnType: smartcontract.IntegerType,
|
||||||
|
Safe: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "methodString",
|
Name: "methodString",
|
||||||
Offset: 101,
|
Offset: 101,
|
||||||
Parameters: []manifest.Parameter{},
|
Parameters: []manifest.Parameter{},
|
||||||
ReturnType: smartcontract.StringType,
|
ReturnType: smartcontract.StringType,
|
||||||
|
Safe: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "methodByteArray",
|
Name: "methodByteArray",
|
||||||
|
|
Loading…
Reference in a new issue