diff --git a/compiler/compiler/func.go b/compiler/compiler/func.go index b0bdf94..240a2cd 100644 --- a/compiler/compiler/func.go +++ b/compiler/compiler/func.go @@ -121,14 +121,30 @@ func (c *Compiler) compileDefineFuncNode(v *parser.DefineFuncNode) value.Value { argTypes := make([]parser.TypeNode, len(v.Arguments)) argTypesName := "" + // Struct and Interface are mangled in another manner to support receiver-method. + getTypeManglingName := func(p string, name string) string { + if ty, hit := c.currentPackage.GetPkgType(name, true); hit { + return ty.Name() + } else if pkg, ok := c.packages[p]; ok { + if ty, hit := pkg.GetPkgType(name, true); hit { + return ty.Name() + } + } + return "" + } for k, v := range v.Arguments { argTypes[k] = v.Type - if ty, hit := c.currentPackage.GetPkgType(v.Type.Type(), true); hit { - argTypesName += ty.Name() - } else if pkg, ok := c.packages[v.Type.GetPackage()]; ok { - if ty, hit := pkg.GetPkgType(v.Type.Type(), true); hit { - argTypesName += ty.Name() + typeMangling := getTypeManglingName(v.Type.GetPackage(), v.Type.Type()) + if sliceTy, ok := v.Type.(*parser.SliceTypeNode); ok && typeMangling == "" { + itemTy := sliceTy.ItemType + itemTyMangling := getTypeManglingName(itemTy.GetPackage(), itemTy.Type()) + if itemTyMangling != "" { + typeMangling = "slice" + itemTyMangling } + } + // todo: support more compound types + if typeMangling != "" { + argTypesName += typeMangling } else { argTypesName += v.Type.Mangling() } diff --git a/pkg/tx/tx.cell b/pkg/tx/tx.cell index 05d1da9..b8d9dee 100644 --- a/pkg/tx/tx.cell +++ b/pkg/tx/tx.cell @@ -69,6 +69,6 @@ func getWitness() string { func getBlake2b(data string) string { return get_blake2b(data) } -func executeFunc(hash string, hashType uint8, funcName string, isOwnerMode bool, extensionIndex int64, args string) int64 { +func executeFunc(hash string, hashType uint8, funcName string, isOwnerMode bool, extensionIndex uint64, args string) int64 { return execute_func(hash, hashType, funcName, isOwnerMode, extensionIndex, args) } diff --git a/tests/examples/xudt.cell b/tests/examples/xudt.cell index 855121f..47de2a2 100644 --- a/tests/examples/xudt.cell +++ b/tests/examples/xudt.cell @@ -199,7 +199,7 @@ func main() { } blake160Hash := args[tx.BLAKE2B_BLOCK_SIZE+FLAGS_SIZE:] witness := tx.getWitness() - witnessBlake2bHash := tx.getBlake2b() + witnessBlake2bHash := tx.getBlake2b(witness) if witnessBlake2bHash[0:tx.BLAKE160_SIZE] == blake160Hash { return ERROR_HASH_MISMATCHED } @@ -222,7 +222,7 @@ func main() { // decode ownerScript raw bytes to Script var ownerScript CellScript - err := tx.executeFunc(ownerScriptHash, ownerScript.hashType, "validate", owner_mode, 0, ownerScript.args) + err := tx.executeFunc(ownerScriptHash, ownerScript.hashType, "validate", owner_mode, 0u64, ownerScript.args) if err == SUCCESS { owner_mode = true } @@ -254,7 +254,7 @@ func main() { extensionScripts := loadExtensionScripts() // execute all scripts for i, script := range(extensionScripts) { - tx.executeFunc(script.codeHash, script.hashType, "validate", owner_mode, i, script.args) + tx.executeFunc(script.codeHash, script.hashType, "validate", owner_mode, uint64(i), script.args) } return SUCCESS }