2019-11-19 21:27:25 +00:00
|
|
|
package events
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2019-11-20 16:36:37 +00:00
|
|
|
"golang.org/x/xerrors"
|
|
|
|
|
2019-11-24 16:35:50 +00:00
|
|
|
"github.com/filecoin-project/lotus/chain/store"
|
2019-11-19 21:27:25 +00:00
|
|
|
"github.com/filecoin-project/lotus/chain/types"
|
|
|
|
)
|
|
|
|
|
2019-11-24 16:35:50 +00:00
|
|
|
func (e *calledEvents) CheckMsg(ctx context.Context, smsg store.ChainMsg, hnd CalledHandler) CheckFunc {
|
|
|
|
msg := smsg.VMMessage()
|
|
|
|
|
2019-11-19 21:27:25 +00:00
|
|
|
return func(ts *types.TipSet) (done bool, more bool, err error) {
|
|
|
|
fa, err := e.cs.StateGetActor(ctx, msg.From, ts)
|
|
|
|
if err != nil {
|
|
|
|
return false, true, err
|
|
|
|
}
|
|
|
|
|
2019-11-24 16:35:50 +00:00
|
|
|
if msg.Nonce > fa.Nonce {
|
|
|
|
return false, true, nil
|
|
|
|
}
|
2019-11-19 21:27:25 +00:00
|
|
|
|
2019-11-24 16:35:50 +00:00
|
|
|
rec, err := e.cs.StateGetReceipt(ctx, smsg.VMMessage().Cid(), ts)
|
2019-11-19 21:27:25 +00:00
|
|
|
if err != nil {
|
2019-11-24 16:35:50 +00:00
|
|
|
return false, true, xerrors.Errorf("getting receipt in CheckMsg: %w", err)
|
2019-11-19 21:27:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
more, err = hnd(msg, rec, ts, ts.Height())
|
|
|
|
|
2019-11-24 16:35:50 +00:00
|
|
|
return true, more, err
|
2019-11-19 21:27:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-20 19:44:38 +00:00
|
|
|
func (e *calledEvents) MatchMsg(inmsg *types.Message) MatchFunc {
|
2019-11-19 21:27:25 +00:00
|
|
|
return func(msg *types.Message) (bool, error) {
|
2019-11-20 16:36:37 +00:00
|
|
|
if msg.From == inmsg.From && msg.Nonce == inmsg.Nonce && !inmsg.Equals(msg) {
|
|
|
|
return false, xerrors.Errorf("matching msg %s from %s, nonce %d: got duplicate origin/nonce msg %s", inmsg.Cid(), inmsg.From, inmsg.Nonce, msg.Nonce)
|
|
|
|
}
|
|
|
|
|
2019-11-19 21:27:25 +00:00
|
|
|
return inmsg.Equals(msg), nil
|
|
|
|
}
|
|
|
|
}
|