implement a few of the TODOs
This commit is contained in:
parent
9a7823ab84
commit
05b8158285
@ -26,6 +26,11 @@ type Import struct {
|
||||
Size uint64
|
||||
}
|
||||
|
||||
type MsgWait struct {
|
||||
InBlock cid.Cid
|
||||
Receipt types.MessageReceipt
|
||||
}
|
||||
|
||||
// API is a low-level interface to the Filecoin network
|
||||
type API interface {
|
||||
// chain
|
||||
@ -33,7 +38,7 @@ type API interface {
|
||||
ChainHead(context.Context) (*chain.TipSet, error) // TODO: check serialization
|
||||
ChainSubmitBlock(ctx context.Context, blk *chain.BlockMsg) error // TODO: check serialization
|
||||
ChainGetRandomness(context.Context, *chain.TipSet) ([]byte, error)
|
||||
ChainWaitMsg(context.Context, cid.Cid) (cid.Cid, *types.MessageReceipt, error)
|
||||
ChainWaitMsg(context.Context, cid.Cid) (*MsgWait, error)
|
||||
|
||||
// messages
|
||||
|
||||
@ -80,7 +85,7 @@ type API interface {
|
||||
WalletDefaultAddress(context.Context) (address.Address, error)
|
||||
|
||||
// Really not sure where this belongs. It could go on the wallet, or the message pool, or the chain...
|
||||
WalletGetNonce(context.Context, address.Address) (uint64, error)
|
||||
MpoolGetNonce(context.Context, address.Address) (uint64, error)
|
||||
|
||||
// // import
|
||||
// // export
|
||||
|
@ -5,7 +5,6 @@ import (
|
||||
|
||||
"github.com/filecoin-project/go-lotus/chain"
|
||||
"github.com/filecoin-project/go-lotus/chain/address"
|
||||
"github.com/filecoin-project/go-lotus/chain/types"
|
||||
|
||||
"github.com/ipfs/go-cid"
|
||||
"github.com/libp2p/go-libp2p-core/peer"
|
||||
@ -20,7 +19,7 @@ type Struct struct {
|
||||
ChainSubmitBlock func(ctx context.Context, blk *chain.BlockMsg) error
|
||||
ChainHead func(context.Context) (*chain.TipSet, error)
|
||||
ChainGetRandomness func(context.Context, *chain.TipSet) ([]byte, error)
|
||||
ChainWaitMsg func(context.Context, cid.Cid) (cid.Cid, *types.MessageReceipt, error)
|
||||
ChainWaitMsg func(context.Context, cid.Cid) (*MsgWait, error)
|
||||
|
||||
MpoolPending func(context.Context, *chain.TipSet) ([]*chain.SignedMessage, error)
|
||||
MpoolPush func(context.Context, *chain.SignedMessage) error
|
||||
@ -33,7 +32,7 @@ type Struct struct {
|
||||
WalletBalance func(context.Context, address.Address) (types.BigInt, error)
|
||||
WalletSign func(context.Context, address.Address, []byte) (*chain.Signature, error)
|
||||
WalletDefaultAddress func(context.Context) (address.Address, error)
|
||||
WalletGetNonce func(context.Context, address.Address) (uint64, error)
|
||||
MpoolGetNonce func(context.Context, address.Address) (uint64, error)
|
||||
|
||||
ClientImport func(ctx context.Context, path string) (cid.Cid, error)
|
||||
ClientListImports func(ctx context.Context) ([]Import, error)
|
||||
@ -92,7 +91,7 @@ func (c *Struct) ChainGetRandomness(ctx context.Context, pts *chain.TipSet) ([]b
|
||||
return c.Internal.ChainGetRandomness(ctx, pts)
|
||||
}
|
||||
|
||||
func (c *Struct) ChainWaitMsg(ctx context.Context, msgc cid.Cid) (cid.Cid, *types.MessageReceipt, error) {
|
||||
func (c *Struct) ChainWaitMsg(ctx context.Context, msgc cid.Cid) (*MsgWait, error) {
|
||||
return c.Internal.ChainWaitMsg(ctx, msgc)
|
||||
}
|
||||
|
||||
@ -126,8 +125,8 @@ func (c *Struct) WalletDefaultAddress(ctx context.Context) (address.Address, err
|
||||
return c.Internal.WalletDefaultAddress(ctx)
|
||||
}
|
||||
|
||||
func (c *Struct) WalletGetNonce(ctx context.Context, addr address.Address) (uint64, error) {
|
||||
return c.Internal.WalletGetNonce(ctx, addr)
|
||||
func (c *Struct) MpoolGetNonce(ctx context.Context, addr address.Address) (uint64, error) {
|
||||
return c.Internal.MpoolGetNonce(ctx, addr)
|
||||
}
|
||||
|
||||
var _ API = &Struct{}
|
||||
|
@ -4,6 +4,7 @@ import (
|
||||
"sync"
|
||||
|
||||
"github.com/filecoin-project/go-lotus/chain/address"
|
||||
hamt "github.com/ipfs/go-hamt-ipld"
|
||||
)
|
||||
|
||||
type MessagePool struct {
|
||||
@ -74,6 +75,36 @@ func (mp *MessagePool) Add(m *SignedMessage) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (mp *MessagePool) GetNonce(addr address.Address) (uint64, error) {
|
||||
mp.lk.Lock()
|
||||
defer mp.lk.Unlock()
|
||||
|
||||
mset, ok := mp.pending[addr]
|
||||
if ok {
|
||||
return mset.startNonce + uint64(len(mset.msgs)), nil
|
||||
}
|
||||
|
||||
head := mp.cs.GetHeaviestTipSet()
|
||||
|
||||
state, err := mp.cs.TipSetState(head.Cids())
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
cst := hamt.CSTFromBstore(mp.cs.bs)
|
||||
st, err := LoadStateTree(cst, state)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
act, err := st.GetActor(addr)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return act.Nonce, nil
|
||||
}
|
||||
|
||||
func (mp *MessagePool) Remove(m *SignedMessage) {
|
||||
mp.lk.Lock()
|
||||
defer mp.lk.Unlock()
|
||||
|
@ -67,7 +67,7 @@ var createMinerCmd = &cli.Command{
|
||||
return err
|
||||
}
|
||||
|
||||
nonce, err := api.WalletGetNonce(ctx, addr)
|
||||
nonce, err := api.MpoolGetNonce(ctx, addr)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -101,17 +101,17 @@ var createMinerCmd = &cli.Command{
|
||||
return err
|
||||
}
|
||||
|
||||
inblk, rect, err := api.ChainWaitMsg(ctx, smsg.Cid())
|
||||
mwait, err := api.ChainWaitMsg(ctx, smsg.Cid())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
maddr, err := address.NewFromBytes(rect.Return)
|
||||
maddr, err := address.NewFromBytes(mwait.Receipt.Return)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Printf("miner created in block %s\n", inblk)
|
||||
fmt.Printf("miner created in block %s\n", mwait.InBlock)
|
||||
fmt.Println("new miner address: %s\n", maddr)
|
||||
|
||||
return nil
|
||||
|
@ -2,6 +2,7 @@ package jsonrpc
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"reflect"
|
||||
)
|
||||
|
||||
@ -42,7 +43,8 @@ func processFuncOut(funcType reflect.Type) (valOut int, errOut int, n int) {
|
||||
panic("expected error as second return value")
|
||||
}
|
||||
default:
|
||||
panic("too many error values")
|
||||
errstr := fmt.Sprintf("too many return values: %s", funcType)
|
||||
panic(errstr)
|
||||
}
|
||||
|
||||
return
|
||||
|
@ -51,7 +51,8 @@ func (a *API) ChainGetRandomness(ctx context.Context, pts *chain.TipSet) ([]byte
|
||||
return []byte("foo bar random"), nil
|
||||
}
|
||||
|
||||
func (a *API) ChainWaitMsg(ctx context.Context, msg cid.Cid) (*api.WaitMsg, error) {
|
||||
func (a *API) ChainWaitMsg(ctx context.Context, msg cid.Cid) (*api.MsgWait, error) {
|
||||
panic("TODO")
|
||||
}
|
||||
|
||||
func (a *API) ID(context.Context) (peer.ID, error) {
|
||||
|
Loading…
Reference in New Issue
Block a user