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

parse unknown action_type based on address #281

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
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
18 changes: 18 additions & 0 deletions actors/multisig.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import (
"bytes"
"encoding/json"
"fmt"
"strings"

"github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/go-state-types/builtin"
"github.com/filecoin-project/go-state-types/builtin/v11/miner"
Expand All @@ -24,6 +26,8 @@ Still needs to parse:
Receive
*/
func (p *ActorParser) ParseMultisig(txType string, msg *parser.LotusMessage, msgRct *parser.LotusMessageReceipt, height int64, key filTypes.TipSetKey) (map[string]interface{}, error) {
txType = determineTxType(txType, msg.To)

switch txType {
case parser.MethodConstructor: // TODO: not tested
return p.msigConstructor(msg.Params)
Expand Down Expand Up @@ -51,6 +55,20 @@ func (p *ActorParser) ParseMultisig(txType string, msg *parser.LotusMessage, msg
return map[string]interface{}{}, parser.ErrUnknownMethod
}

func determineTxType(txType string, to address.Address) string {
if txType == parser.MethodUnknown {
if strings.HasPrefix(to.String(), "f4") {
return parser.MethodInvokeEVM
} else if strings.HasPrefix(to.String(), "f0") ||
strings.HasPrefix(to.String(), "f1") ||
strings.HasPrefix(to.String(), "f2") ||
strings.HasPrefix(to.String(), "f3") {
return parser.MethodSend
}
}
return txType
}

func (p *ActorParser) msigConstructor(raw []byte) (map[string]interface{}, error) {
metadata := make(map[string]interface{})
reader := bytes.NewReader(raw)
Expand Down
46 changes: 46 additions & 0 deletions actors/multisig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"strings"
"testing"

"github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-state-types/builtin/v11/miner"
"github.com/filecoin-project/go-state-types/builtin/v11/verifreg"
multisig2 "github.com/filecoin-project/go-state-types/builtin/v14/multisig"
Expand Down Expand Up @@ -255,6 +256,51 @@ func TestParseMultisigMetadata(t *testing.T) {
}
}

func TestDetermineTxType(t *testing.T) {
tests := []struct {
name string
txType string
to string
expected string
}{
{
name: "Unknown txType with f4 address",
txType: parser.MethodUnknown,
to: createFakeF4Address(t),
expected: parser.MethodInvokeEVM,
},
{
name: "Unknown txType with f0 address",
txType: parser.MethodUnknown,
to: "f01656666",
expected: parser.MethodSend,
},
{
name: "Known txType",
txType: parser.MethodSend,
to: "f01656666",
expected: parser.MethodSend,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
toAddress, err := address.NewFromString(tt.to)
fmt.Printf("toAddress: %s\n", toAddress)
require.NoError(t, err)
actual := determineTxType(tt.txType, toAddress)
fmt.Printf("actual: %s\n", actual)
assert.Equal(t, tt.expected, actual)
})
}
}
func createFakeF4Address(t *testing.T) string {
namespace := uint64(1234)
subaddress := []byte("fake_subaddress")
addr, err := address.NewDelegatedAddress(namespace, subaddress)
require.NoError(t, err)
return addr.String()
}

func unmarshalExpected(txType, jsonStr string) (interface{}, error) {
var v interface{}
switch txType {
Expand Down
1 change: 1 addition & 0 deletions parser/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ const (
MethodBurnFromExported = "BurnFromExported" // MethodsDatacap
MethodAllowanceExported = "AllowanceExported" // MethodsDatacap
MethodGranularityExported = "GranularityExported" // MethodsDatacap
MethodInvokeEVM = "InvokeEVM" // MethodsEVM

MethodUnknown = "Unknown" // Common
)
Expand Down