Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add name for MethodMeta #5387

Merged
merged 1 commit into from
Oct 17, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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