Skip to content

Commit

Permalink
Parse unknown transactions based on address
Browse files Browse the repository at this point in the history
  • Loading branch information
sarataha committed Jan 31, 2025
1 parent 9aeaad0 commit 19036e3
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
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 "InvokeEVM"
} else if strings.HasPrefix(to.String(), "f0") ||
strings.HasPrefix(to.String(), "f1") ||
strings.HasPrefix(to.String(), "f2") ||
strings.HasPrefix(to.String(), "f3") {
return "Send"
}
}
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: "InvokeEVM",
},
{
name: "Unknown txType with f0 address",
txType: parser.MethodUnknown,
to: "f01656666",
expected: "Send",
},
{
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

0 comments on commit 19036e3

Please sign in to comment.