diff --git a/src/cmd/cgogen.go b/src/cmd/cgogen.go old mode 100644 new mode 100755 index c67a90d..c91d4a9 --- a/src/cmd/cgogen.go +++ b/src/cmd/cgogen.go @@ -609,7 +609,7 @@ func processFunc(fast *ast.File, fdecl *ast.FuncDecl, outFile *jen.File, dependa } if len(typeName) > 0 && rune(typeName[0]) == '[' { typeName = "*C.GoSlice_" - } else if dealOutStringAsGostring && typeName == "string" { + } else if typeName == "string" { typeName = "*C.GoString_" } else if IsBasicGoType(typeName) { typeName = "*" + typeName @@ -828,8 +828,12 @@ func getCodeToConvertInParameter(_typeExpr *ast.Expr, packName string, name stri if !isPointer { leftPart = leftPart.Op("*") } - leftPart = leftPart.Parens(jen.Op("*").Id(packName).Id(".").Id(typeName)). - Parens(jen.Qual("unsafe", "Pointer").Parens(jen.Id(argName(name)))) + if typeName == "FeeCalculator" { + leftPart = jen.Id(name).Op(":=").Add(getCallbackCode(name)) + } else { + leftPart = leftPart.Parens(jen.Op("*").Id(packName).Id(".").Id(typeName)). + Parens(jen.Qual("unsafe", "Pointer").Parens(jen.Id(argName(name)))) + } return jenCodeToArray(leftPart) } } @@ -954,6 +958,7 @@ func isInplaceConvertType(typeName string) bool { } /* Process a type expression. Returns the code in C for the type and ok if successful */ +// typedata func processTypeExpression(fast *ast.File, type_expr ast.Expr, packageName string, name string, definedTypes *[]string, @@ -1368,6 +1373,23 @@ var basicTypesMap = map[string]string{ var packageSeparator = "__" +func getCallbackCode(varName string) *jen.Statement { + + varFunction := jen.Func().Params( + jen.Id("pTx").Id("*coin.Transaction"), + ).Parens(jen.Uint64().Op(",").Error()).Block( + jen.Var().Id("fee").Id("C.GoUint64_"), + jen.Id("handle").Op(":=").Id("registerTransactionHandle").Call(jen.Id("pTx")), + jen.Id("result").Op(":=").Id("C.callFeeCalculator").Call(jen.Id("_"+varName), jen.Id("handle"), jen.Id("&fee")), + jen.Id("closeHandle").Call(jen.Id("Handle").Call(jen.Id("handle"))), + jen.If(jen.Id("result").Op("==").Id("SKY_OK")).Block( + jen.Return(jen.Id("uint64").Call(jen.Id("fee")), jen.Nil())), + jen.Return(jen.Lit(0), jen.Qual("errors", "New").Call(jen.Lit("Error calculating fee"))), + ) + + return varFunction +} + func getPathPackage(path string) (packagePath_ string, mainPackagePath_ string) { index := strings.LastIndex(path, "/") diff --git a/vendor/vendor.json b/vendor/vendor.json deleted file mode 100644 index aef8800..0000000 --- a/vendor/vendor.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "comment": "", - "ignore": "test", - "package": [ - { - "checksumSHA1": "GtqEEHjKsMGUSCqjPyKLi+DfcEs=", - "path": "github.com/dave/jennifer/jen", - "revision": "724ff9887965e893831e9493011297e6bc01ecb4", - "revisionTime": "2019-11-26T19:34:09Z" - } - ], - "rootPath": "github.com/fibercrypto/cgogen" -}