Skip to content

Commit

Permalink
fix: add name for MethodMeta (#5387)
Browse files Browse the repository at this point in the history
  • Loading branch information
simlecode authored Oct 17, 2022
1 parent 4045116 commit 1296457
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions venus-shared/utils/method_map.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -19,7 +21,8 @@ import (
)

type MethodMeta struct {
Num string
Num string
Name string

Params reflect.Type
Ret reflect.Type
Expand Down Expand Up @@ -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)),
}
Expand All @@ -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
Expand Down

0 comments on commit 1296457

Please sign in to comment.