Skip to content

Commit

Permalink
Merge pull request #8 from prettyCoders/filecoin-client-fs
Browse files Browse the repository at this point in the history
修复 ChainGetParentMessage 数据解析为空数据Bug
  • Loading branch information
myxtype committed Apr 12, 2021
2 parents b3b2547 + 31993b7 commit e469582
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 3 deletions.
6 changes: 3 additions & 3 deletions chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func (c *Client) ChainGetBlockMessages(ctx context.Context, id cid.Cid) (*types.
}

// ChainHead returns the current head of the chain.
func (c *Client) ChainHead(ctx context.Context, ) (*types.TipSet, error) {
func (c *Client) ChainHead(ctx context.Context) (*types.TipSet, error) {
var ts *types.TipSet
return ts, c.Request(ctx, c.FilecoinMethod("ChainHead"), &ts)
}
Expand Down Expand Up @@ -56,8 +56,8 @@ func (c *Client) ChainGetNode(ctx context.Context, p string) (*types.IpldObject,
}

// ChainGetParentMessages returns messages stored in parent tipset of the specified block.
func (c *Client) ChainGetParentMessages(ctx context.Context, id cid.Cid) ([]types.Message, error) {
var msgs []types.Message
func (c *Client) ChainGetParentMessages(ctx context.Context, id cid.Cid) ([]types.ParentMessage, error) {
var msgs []types.ParentMessage
return msgs, c.Request(ctx, c.FilecoinMethod("ChainGetParentMessages"), &msgs, id)
}

Expand Down
28 changes: 28 additions & 0 deletions chain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package filecoin

import (
"context"
"github.com/filecoin-project/go-address"
"github.com/ipfs/go-cid"
"testing"
)
Expand Down Expand Up @@ -64,3 +65,30 @@ func TestClient_ChainGetTipSetByHeight(t *testing.T) {
}
}
}

// 遍历区块的 parentMessages
func TestClient_ChainGetParentMessages(t *testing.T) {
var blockHeight int64 = 646458
c := testClient()
tipSet, err := c.ChainGetTipSetByHeight(context.Background(), blockHeight, nil)
if err != nil {
t.Error(err)
}
//同一个 tipSet 下的 block 的 parentMessages 相同
pms, err := c.ChainGetParentMessages(context.Background(), tipSet.Cids[0])
if err != nil {
t.Error(err)
}
t.Log(len(pms))
for _, pm := range pms {
address.CurrentNetwork = address.Mainnet
cid := pm.Cid.Cid
from := pm.Message.From.String()
to := pm.Message.To.String()
value := pm.Message.Value
t.Log(cid)
t.Log(from)
t.Log(to)
t.Log(value)
}
}
9 changes: 9 additions & 0 deletions types/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@ type Message struct {
Params []byte `json:"Params"`
}

type ParentMessage struct {
Cid Cid `json:"Cid"`
Message Message `json:"Message"`
}

type Cid struct {
Cid string `json:"/"`
}

func (m *Message) Caller() address.Address {
return m.From
}
Expand Down

0 comments on commit e469582

Please sign in to comment.