lotus/node/impl/full/mpool.go

56 lines
1.5 KiB
Go
Raw Normal View History

2019-08-20 16:48:33 +00:00
package full
import (
"context"
2019-10-02 18:00:08 +00:00
2019-08-20 16:48:33 +00:00
"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
b, err := a.WalletBalance(ctx, msg.From)
if err != nil {
return nil, xerrors.Errorf("mpool push: getting origin balance: %w", err)
}
if b.LessThan(msg.Value) {
return nil, xerrors.Errorf("mpool push: not enough funds: %s < %s", b, msg.Value)
}
2019-09-16 14:17:08 +00:00
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)
}