@@ -2,7 +2,9 @@ package utils
22
33import (
44 "reflect"
5+ "runtime"
56 "strconv"
7+ "strings"
68
79 "github.com/filecoin-project/go-state-types/abi"
810 actorstypes "github.com/filecoin-project/go-state-types/actors"
@@ -19,7 +21,8 @@ import (
1921)
2022
2123type MethodMeta struct {
22- Num string
24+ Num string
25+ Name string
2326
2427 Params reflect.Type
2528 Ret reflect.Type
@@ -75,6 +78,7 @@ func loadMethodsMap() {
7578 // Explicitly add send, it's special.
7679 methods [builtin .MethodSend ] = MethodMeta {
7780 Num : "0" ,
81+ Name : "Send" ,
7882 Params : reflect .TypeOf (new (abi.EmptyValue )),
7983 Ret : reflect .TypeOf (new (abi.EmptyValue )),
8084 }
@@ -89,11 +93,33 @@ func loadMethodsMap() {
8993 ev := reflect .ValueOf (export )
9094 et := ev .Type ()
9195
92- methods [ abi . MethodNum ( number )] = MethodMeta {
96+ methodMeta : = MethodMeta {
9397 Num : strconv .Itoa (int (number )),
9498 Params : et .In (1 ),
9599 Ret : et .Out (0 ),
96100 }
101+
102+ // if actor version grater than Version8, we could not get method name.
103+ // venus-wallet need `fnName`
104+ if awv .av < actorstypes .Version8 {
105+ // Extract the method names using reflection. These
106+ // method names always match the field names in the
107+ // `builtin.Method*` structs (tested in the specs-actors
108+ // tests).
109+ fnName := runtime .FuncForPC (ev .Pointer ()).Name ()
110+ fnName = strings .TrimSuffix (fnName [strings .LastIndexByte (fnName , '.' )+ 1 :], "-fm" )
111+
112+ switch abi .MethodNum (number ) {
113+ case builtin .MethodSend :
114+ panic ("method 0 is reserved for Send" )
115+ case builtin .MethodConstructor :
116+ if fnName != "Constructor" {
117+ panic ("method 1 is reserved for Constructor" )
118+ }
119+ }
120+ methodMeta .Name = fnName
121+ }
122+ methods [abi .MethodNum (number )] = methodMeta
97123 }
98124
99125 MethodsMap [actor .Code ()] = methods
0 commit comments