native: add additional parameters to deploy
1. Management contract has 2 overloads of `deploy` method. 2. Normal contracts should have `_deploy` with 2 parameters.
This commit is contained in:
parent
849385a533
commit
c1cc7e6f9d
10 changed files with 149 additions and 32 deletions
|
@ -336,11 +336,11 @@ func (c *codegen) convertInitFuncs(f *ast.File, pkg *types.Package, seenBefore b
|
|||
|
||||
func isDeployFunc(decl *ast.FuncDecl) bool {
|
||||
if decl.Name.Name != "_deploy" || decl.Recv != nil ||
|
||||
decl.Type.Params.NumFields() != 1 ||
|
||||
decl.Type.Params.NumFields() != 2 ||
|
||||
decl.Type.Results.NumFields() != 0 {
|
||||
return false
|
||||
}
|
||||
typ, ok := decl.Type.Params.List[0].Type.(*ast.Ident)
|
||||
typ, ok := decl.Type.Params.List[1].Type.(*ast.Ident)
|
||||
return ok && typ.Name == "bool"
|
||||
}
|
||||
|
||||
|
@ -1869,7 +1869,7 @@ func (c *codegen) compile(info *buildInfo, pkg *loader.PackageInfo) error {
|
|||
|
||||
hasDeploy := deployLocals > -1
|
||||
if hasDeploy {
|
||||
emit.Instruction(c.prog.BinWriter, opcode.INITSLOT, []byte{byte(deployLocals), 1})
|
||||
emit.Instruction(c.prog.BinWriter, opcode.INITSLOT, []byte{byte(deployLocals), 2})
|
||||
c.convertDeployFuncs()
|
||||
c.deployEndOffset = c.prog.Len()
|
||||
emit.Opcodes(c.prog.BinWriter, opcode.RET)
|
||||
|
|
|
@ -150,11 +150,18 @@ func (c *codegen) emitDebugInfo(contract []byte) *DebugInfo {
|
|||
Start: uint16(c.initEndOffset + 1),
|
||||
End: uint16(c.deployEndOffset),
|
||||
},
|
||||
Parameters: []DebugParam{{
|
||||
Name: "isUpdate",
|
||||
Type: "Boolean",
|
||||
TypeSC: smartcontract.BoolType,
|
||||
}},
|
||||
Parameters: []DebugParam{
|
||||
{
|
||||
Name: "data",
|
||||
Type: "Any",
|
||||
TypeSC: smartcontract.AnyType,
|
||||
},
|
||||
{
|
||||
Name: "isUpdate",
|
||||
Type: "Boolean",
|
||||
TypeSC: smartcontract.BoolType,
|
||||
},
|
||||
},
|
||||
ReturnType: "Void",
|
||||
ReturnTypeSC: smartcontract.VoidType,
|
||||
SeqPoints: c.sequencePoints[manifest.MethodDeploy],
|
||||
|
|
|
@ -53,7 +53,7 @@ func MethodParams(addr interop.Hash160, h interop.Hash256,
|
|||
type MyStruct struct {}
|
||||
func (ms MyStruct) MethodOnStruct() { }
|
||||
func (ms *MyStruct) MethodOnPointerToStruct() { }
|
||||
func _deploy(isUpdate bool) {}
|
||||
func _deploy(data interface{}, isUpdate bool) {}
|
||||
`
|
||||
|
||||
info, err := getBuildInfo("foo.go", src)
|
||||
|
@ -100,11 +100,18 @@ func _deploy(isUpdate bool) {}
|
|||
|
||||
t.Run("param types", func(t *testing.T) {
|
||||
paramTypes := map[string][]DebugParam{
|
||||
"_deploy": {{
|
||||
Name: "isUpdate",
|
||||
Type: "Boolean",
|
||||
TypeSC: smartcontract.BoolType,
|
||||
}},
|
||||
"_deploy": {
|
||||
{
|
||||
Name: "data",
|
||||
Type: "Any",
|
||||
TypeSC: smartcontract.AnyType,
|
||||
},
|
||||
{
|
||||
Name: "isUpdate",
|
||||
Type: "Boolean",
|
||||
TypeSC: smartcontract.BoolType,
|
||||
},
|
||||
},
|
||||
"MethodInt": {{
|
||||
Name: "a",
|
||||
Type: "ByteString",
|
||||
|
@ -160,6 +167,7 @@ func _deploy(isUpdate bool) {}
|
|||
Name: "_deploy",
|
||||
Offset: 0,
|
||||
Parameters: []manifest.Parameter{
|
||||
manifest.NewParameter("data", smartcontract.AnyType),
|
||||
manifest.NewParameter("isUpdate", smartcontract.BoolType),
|
||||
},
|
||||
ReturnType: smartcontract.VoidType,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue