2019-08-20 16:48:33 +00:00
|
|
|
package full
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"go.uber.org/fx"
|
2019-09-16 14:17:08 +00:00
|
|
|
"golang.org/x/xerrors"
|
2019-08-20 16:48:33 +00:00
|
|
|
|
|
|
|
"github.com/filecoin-project/go-lotus/chain"
|
|
|
|
"github.com/filecoin-project/go-lotus/chain/address"
|
|
|
|
"github.com/filecoin-project/go-lotus/chain/types"
|
|
|
|
)
|
|
|
|
|
|
|
|
type MpoolAPI struct {
|
|
|
|
fx.In
|
|
|
|
|
2019-09-16 14:17:08 +00:00
|
|
|
WalletAPI
|
|
|
|
|
2019-09-16 21:26:19 +00:00
|
|
|
Mpool *chain.MessagePool
|
2019-08-20 16:48:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (a *MpoolAPI) MpoolPending(ctx context.Context, ts *types.TipSet) ([]*types.SignedMessage, error) {
|
|
|
|
// TODO: need to make sure we don't return messages that were already included in the referenced chain
|
|
|
|
// also need to accept ts == nil just fine, assume nil == chain.Head()
|
|
|
|
return a.Mpool.Pending(), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *MpoolAPI) MpoolPush(ctx context.Context, smsg *types.SignedMessage) error {
|
2019-09-16 14:17:08 +00:00
|
|
|
return a.Mpool.Push(smsg)
|
|
|
|
}
|
|
|
|
|
2019-09-17 08:15:26 +00:00
|
|
|
func (a *MpoolAPI) MpoolPushMessage(ctx context.Context, msg *types.Message) (*types.SignedMessage, error) {
|
2019-09-16 14:17:08 +00:00
|
|
|
if msg.Nonce != 0 {
|
2019-09-17 08:15:26 +00:00
|
|
|
return nil, xerrors.Errorf("MpoolPushMessage expects message nonce to be 0, was %d", msg.Nonce)
|
2019-08-20 16:48:33 +00:00
|
|
|
}
|
|
|
|
|
2019-09-16 14:17:08 +00:00
|
|
|
return a.Mpool.PushWithNonce(msg.From, func(nonce uint64) (*types.SignedMessage, error) {
|
|
|
|
msg.Nonce = nonce
|
|
|
|
return a.WalletSignMessage(ctx, msg.From, msg)
|
|
|
|
})
|
2019-08-20 16:48:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (a *MpoolAPI) MpoolGetNonce(ctx context.Context, addr address.Address) (uint64, error) {
|
|
|
|
return a.Mpool.GetNonce(addr)
|
|
|
|
}
|