diff --git a/chain.go b/chain.go index 0fba79d..dc6469f 100644 --- a/chain.go +++ b/chain.go @@ -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) } @@ -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) } diff --git a/chain_test.go b/chain_test.go index 8cc7529..596bdd5 100644 --- a/chain_test.go +++ b/chain_test.go @@ -2,6 +2,7 @@ package filecoin import ( "context" + "github.com/filecoin-project/go-address" "github.com/ipfs/go-cid" "testing" ) @@ -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) + } +} diff --git a/types/message.go b/types/message.go index 40a2bb6..efebfae 100644 --- a/types/message.go +++ b/types/message.go @@ -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 }