diff --git a/venus-shared/utils/method_map.go b/venus-shared/utils/method_map.go index a941575c8b..3365b3d13a 100644 --- a/venus-shared/utils/method_map.go +++ b/venus-shared/utils/method_map.go @@ -2,7 +2,9 @@ package utils import ( "reflect" + "runtime" "strconv" + "strings" "github.com/filecoin-project/go-state-types/abi" actorstypes "github.com/filecoin-project/go-state-types/actors" @@ -19,7 +21,8 @@ import ( ) type MethodMeta struct { - Num string + Num string + Name string Params reflect.Type Ret reflect.Type @@ -75,6 +78,7 @@ func loadMethodsMap() { // Explicitly add send, it's special. methods[builtin.MethodSend] = MethodMeta{ Num: "0", + Name: "Send", Params: reflect.TypeOf(new(abi.EmptyValue)), Ret: reflect.TypeOf(new(abi.EmptyValue)), } @@ -89,11 +93,33 @@ func loadMethodsMap() { ev := reflect.ValueOf(export) et := ev.Type() - methods[abi.MethodNum(number)] = MethodMeta{ + methodMeta := MethodMeta{ Num: strconv.Itoa(int(number)), Params: et.In(1), Ret: et.Out(0), } + + // if actor version grater than Version8, we could not get method name. + // venus-wallet need `fnName` + if awv.av < actorstypes.Version8 { + // Extract the method names using reflection. These + // method names always match the field names in the + // `builtin.Method*` structs (tested in the specs-actors + // tests). + fnName := runtime.FuncForPC(ev.Pointer()).Name() + fnName = strings.TrimSuffix(fnName[strings.LastIndexByte(fnName, '.')+1:], "-fm") + + switch abi.MethodNum(number) { + case builtin.MethodSend: + panic("method 0 is reserved for Send") + case builtin.MethodConstructor: + if fnName != "Constructor" { + panic("method 1 is reserved for Constructor") + } + } + methodMeta.Name = fnName + } + methods[abi.MethodNum(number)] = methodMeta } MethodsMap[actor.Code()] = methods