lotus/api/struct.go

237 lines
9.8 KiB
Go
Raw Normal View History

package api
import (
"context"
2019-07-25 00:55:19 +00:00
"github.com/libp2p/go-libp2p-core/network"
2019-07-09 15:19:27 +00:00
"github.com/filecoin-project/go-lotus/chain"
2019-07-11 02:36:43 +00:00
"github.com/filecoin-project/go-lotus/chain/address"
"github.com/filecoin-project/go-lotus/chain/store"
2019-07-21 06:09:30 +00:00
"github.com/filecoin-project/go-lotus/chain/types"
sectorbuilder "github.com/filecoin-project/go-sectorbuilder"
2019-07-09 22:58:51 +00:00
2019-07-12 09:59:18 +00:00
"github.com/ipfs/go-cid"
"github.com/libp2p/go-libp2p-core/peer"
)
2019-07-23 20:05:44 +00:00
// All permissions are listed in permissioned.go
var _ = AllPermissions
2019-07-24 00:09:34 +00:00
type CommonStruct struct {
2019-07-24 01:10:26 +00:00
Internal struct {
2019-07-23 20:05:44 +00:00
AuthVerify func(ctx context.Context, token string) ([]string, error) `perm:"read"`
2019-07-23 18:53:13 +00:00
AuthNew func(ctx context.Context, perms []string) ([]byte, error) `perm:"admin"`
2019-07-23 17:27:45 +00:00
2019-07-25 00:55:19 +00:00
NetConnectedness func(context.Context, peer.ID) (network.Connectedness, error) `perm:"read"`
NetPeers func(context.Context) ([]peer.AddrInfo, error) `perm:"read"`
NetConnect func(context.Context, peer.AddrInfo) error `perm:"write"`
NetAddrsListen func(context.Context) (peer.AddrInfo, error) `perm:"read"`
NetDisconnect func(context.Context, peer.ID) error `perm:"write"`
2019-07-24 00:09:34 +00:00
2019-07-23 20:05:44 +00:00
ID func(context.Context) (peer.ID, error) `perm:"read"`
Version func(context.Context) (Version, error) `perm:"read"`
2019-07-24 00:09:34 +00:00
}
}
// FullNodeStruct implements API passing calls to user-provided function values.
type FullNodeStruct struct {
CommonStruct
2019-07-08 19:07:16 +00:00
2019-07-24 00:09:34 +00:00
Internal struct {
2019-07-31 16:54:28 +00:00
ChainNotify func(context.Context) (<-chan *store.HeadChange, error) `perm:"read"`
ChainSubmitBlock func(ctx context.Context, blk *chain.BlockMsg) error `perm:"write"`
ChainHead func(context.Context) (*types.TipSet, error) `perm:"read"`
ChainGetRandomness func(context.Context, *types.TipSet) ([]byte, error) `perm:"read"`
ChainWaitMsg func(context.Context, cid.Cid) (*MsgWait, error) `perm:"read"`
ChainGetBlock func(context.Context, cid.Cid) (*types.BlockHeader, error) `perm:"read"`
2019-08-02 03:51:34 +00:00
ChainGetBlockMessages func(context.Context, cid.Cid) (*BlockMessages, error) `perm:"read"`
ChainGetBlockReceipts func(context.Context, cid.Cid) ([]*types.MessageReceipt, error) `perm:"read"`
2019-07-31 16:54:28 +00:00
ChainCall func(context.Context, *types.Message, *types.TipSet) (*types.MessageReceipt, error) `perm:"read"`
2019-07-09 15:19:27 +00:00
2019-07-26 04:54:22 +00:00
MpoolPending func(context.Context, *types.TipSet) ([]*types.SignedMessage, error) `perm:"read"`
MpoolPush func(context.Context, *types.SignedMessage) error `perm:"write"`
2019-07-11 02:36:43 +00:00
2019-07-23 20:05:44 +00:00
MinerStart func(context.Context, address.Address) error `perm:"admin"`
2019-07-26 04:54:22 +00:00
MinerCreateBlock func(context.Context, address.Address, *types.TipSet, []types.Ticket, types.ElectionProof, []*types.SignedMessage) (*chain.BlockMsg, error) `perm:"write"`
2019-07-09 22:58:51 +00:00
2019-07-23 20:05:44 +00:00
WalletNew func(context.Context, string) (address.Address, error) `perm:"write"`
2019-07-23 20:15:29 +00:00
WalletList func(context.Context) ([]address.Address, error) `perm:"write"`
2019-07-23 20:05:44 +00:00
WalletBalance func(context.Context, address.Address) (types.BigInt, error) `perm:"read"`
WalletSign func(context.Context, address.Address, []byte) (*types.Signature, error) `perm:"sign"`
2019-07-23 20:15:29 +00:00
WalletDefaultAddress func(context.Context) (address.Address, error) `perm:"write"`
2019-07-23 20:05:44 +00:00
MpoolGetNonce func(context.Context, address.Address) (uint64, error) `perm:"read"`
2019-07-13 00:41:32 +00:00
2019-07-18 16:51:21 +00:00
ClientImport func(ctx context.Context, path string) (cid.Cid, error) `perm:"write"`
2019-07-23 20:05:44 +00:00
ClientListImports func(ctx context.Context) ([]Import, error) `perm:"read"`
StateMinerSectors func(context.Context, address.Address) ([]*SectorInfo, error) `perm:"read"`
StateMinerProvingSet func(context.Context, address.Address) ([]*SectorInfo, error) `perm:"read"`
}
}
2019-07-24 00:09:34 +00:00
type StorageMinerStruct struct {
CommonStruct
2019-07-23 17:27:45 +00:00
2019-07-24 01:10:26 +00:00
Internal struct {
StoreGarbageData func(context.Context) (uint64, error) `perm:"write"`
SectorsStatus func(context.Context, uint64) (sectorbuilder.SectorSealingStatus, error) `perm:"read"`
SectorsStagedList func(context.Context) ([]sectorbuilder.StagedSectorMetadata, error) `perm:"read"`
SectorsStagedSeal func(context.Context) error `perm:"write"`
2019-07-24 00:09:34 +00:00
}
2019-07-23 17:27:45 +00:00
}
2019-07-24 00:58:31 +00:00
func (c *CommonStruct) AuthVerify(ctx context.Context, token string) ([]string, error) {
return c.Internal.AuthVerify(ctx, token)
}
func (c *CommonStruct) AuthNew(ctx context.Context, perms []string) ([]byte, error) {
return c.Internal.AuthNew(ctx, perms)
}
2019-07-25 00:55:19 +00:00
func (c *CommonStruct) NetConnectedness(ctx context.Context, pid peer.ID) (network.Connectedness, error) {
return c.Internal.NetConnectedness(ctx, pid)
}
2019-07-24 00:58:31 +00:00
func (c *CommonStruct) NetPeers(ctx context.Context) ([]peer.AddrInfo, error) {
return c.Internal.NetPeers(ctx)
}
func (c *CommonStruct) NetConnect(ctx context.Context, p peer.AddrInfo) error {
return c.Internal.NetConnect(ctx, p)
}
func (c *CommonStruct) NetAddrsListen(ctx context.Context) (peer.AddrInfo, error) {
return c.Internal.NetAddrsListen(ctx)
2019-07-25 00:55:19 +00:00
}
func (c *CommonStruct) NetDisconnect(ctx context.Context, p peer.ID) error {
return c.Internal.NetDisconnect(ctx, p)
2019-07-24 00:58:31 +00:00
}
// ID implements API.ID
func (c *CommonStruct) ID(ctx context.Context) (peer.ID, error) {
return c.Internal.ID(ctx)
}
// Version implements API.Version
func (c *CommonStruct) Version(ctx context.Context) (Version, error) {
return c.Internal.Version(ctx)
}
2019-07-24 00:09:34 +00:00
func (c *FullNodeStruct) ClientListImports(ctx context.Context) ([]Import, error) {
2019-07-12 10:44:01 +00:00
return c.Internal.ClientListImports(ctx)
}
2019-07-24 00:09:34 +00:00
func (c *FullNodeStruct) ClientImport(ctx context.Context, path string) (cid.Cid, error) {
2019-07-12 09:59:18 +00:00
return c.Internal.ClientImport(ctx, path)
}
2019-07-26 04:54:22 +00:00
func (c *FullNodeStruct) MpoolPending(ctx context.Context, ts *types.TipSet) ([]*types.SignedMessage, error) {
2019-07-11 02:36:43 +00:00
return c.Internal.MpoolPending(ctx, ts)
}
func (c *FullNodeStruct) MpoolPush(ctx context.Context, smsg *types.SignedMessage) error {
2019-07-17 06:15:07 +00:00
return c.Internal.MpoolPush(ctx, smsg)
}
2019-07-24 00:09:34 +00:00
func (c *FullNodeStruct) MinerStart(ctx context.Context, addr address.Address) error {
2019-07-11 02:36:43 +00:00
return c.Internal.MinerStart(ctx, addr)
}
2019-07-26 04:54:22 +00:00
func (c *FullNodeStruct) MinerCreateBlock(ctx context.Context, addr address.Address, base *types.TipSet, tickets []types.Ticket, eproof types.ElectionProof, msgs []*types.SignedMessage) (*chain.BlockMsg, error) {
2019-07-11 02:36:43 +00:00
return c.Internal.MinerCreateBlock(ctx, addr, base, tickets, eproof, msgs)
2019-07-09 22:58:51 +00:00
}
2019-07-24 00:09:34 +00:00
func (c *FullNodeStruct) ChainSubmitBlock(ctx context.Context, blk *chain.BlockMsg) error {
2019-07-09 15:19:27 +00:00
return c.Internal.ChainSubmitBlock(ctx, blk)
}
2019-07-26 04:54:22 +00:00
func (c *FullNodeStruct) ChainHead(ctx context.Context) (*types.TipSet, error) {
2019-07-09 15:19:27 +00:00
return c.Internal.ChainHead(ctx)
}
2019-07-26 04:54:22 +00:00
func (c *FullNodeStruct) ChainGetRandomness(ctx context.Context, pts *types.TipSet) ([]byte, error) {
2019-07-11 02:36:43 +00:00
return c.Internal.ChainGetRandomness(ctx, pts)
}
2019-07-24 00:09:34 +00:00
func (c *FullNodeStruct) ChainWaitMsg(ctx context.Context, msgc cid.Cid) (*MsgWait, error) {
return c.Internal.ChainWaitMsg(ctx, msgc)
}
2019-07-31 16:54:28 +00:00
func (c *FullNodeStruct) ChainCall(ctx context.Context, msg *types.Message, ts *types.TipSet) (*types.MessageReceipt, error) {
return c.Internal.ChainCall(ctx, msg, ts)
}
2019-07-24 00:09:34 +00:00
func (c *FullNodeStruct) WalletNew(ctx context.Context, typ string) (address.Address, error) {
2019-07-13 00:41:32 +00:00
return c.Internal.WalletNew(ctx, typ)
}
2019-07-24 00:09:34 +00:00
func (c *FullNodeStruct) WalletList(ctx context.Context) ([]address.Address, error) {
2019-07-13 00:41:32 +00:00
return c.Internal.WalletList(ctx)
}
2019-07-24 00:09:34 +00:00
func (c *FullNodeStruct) WalletBalance(ctx context.Context, a address.Address) (types.BigInt, error) {
2019-07-18 20:26:04 +00:00
return c.Internal.WalletBalance(ctx, a)
}
func (c *FullNodeStruct) WalletSign(ctx context.Context, k address.Address, msg []byte) (*types.Signature, error) {
return c.Internal.WalletSign(ctx, k, msg)
}
2019-07-24 00:09:34 +00:00
func (c *FullNodeStruct) WalletDefaultAddress(ctx context.Context) (address.Address, error) {
return c.Internal.WalletDefaultAddress(ctx)
}
2019-07-24 00:09:34 +00:00
func (c *FullNodeStruct) MpoolGetNonce(ctx context.Context, addr address.Address) (uint64, error) {
2019-07-17 06:05:11 +00:00
return c.Internal.MpoolGetNonce(ctx, addr)
}
func (c *FullNodeStruct) ChainGetBlock(ctx context.Context, b cid.Cid) (*types.BlockHeader, error) {
2019-07-23 00:54:27 +00:00
return c.Internal.ChainGetBlock(ctx, b)
}
2019-08-02 03:51:34 +00:00
func (c *FullNodeStruct) ChainGetBlockMessages(ctx context.Context, b cid.Cid) (*BlockMessages, error) {
2019-07-23 00:54:27 +00:00
return c.Internal.ChainGetBlockMessages(ctx, b)
}
func (c *FullNodeStruct) ChainGetBlockReceipts(ctx context.Context, b cid.Cid) ([]*types.MessageReceipt, error) {
return c.Internal.ChainGetBlockReceipts(ctx, b)
}
func (c *FullNodeStruct) ChainNotify(ctx context.Context) (<-chan *store.HeadChange, error) {
return c.Internal.ChainNotify(ctx)
}
func (c *FullNodeStruct) StateMinerSectors(ctx context.Context, addr address.Address) ([]*SectorInfo, error) {
return c.Internal.StateMinerSectors(ctx, addr)
}
func (c *FullNodeStruct) StateMinerProvingSet(ctx context.Context, addr address.Address) ([]*SectorInfo, error) {
return c.Internal.StateMinerProvingSet(ctx, addr)
}
2019-07-27 01:54:03 +00:00
func (c *StorageMinerStruct) StoreGarbageData(ctx context.Context) (uint64, error) {
return c.Internal.StoreGarbageData(ctx)
}
// Get the status of a given sector by ID
func (c *StorageMinerStruct) SectorsStatus(ctx context.Context, sid uint64) (sectorbuilder.SectorSealingStatus, error) {
return c.Internal.SectorsStatus(ctx, sid)
}
// List all staged sectors
func (c *StorageMinerStruct) SectorsStagedList(ctx context.Context) ([]sectorbuilder.StagedSectorMetadata, error) {
return c.Internal.SectorsStagedList(ctx)
}
// Seal all staged sectors
func (c *StorageMinerStruct) SectorsStagedSeal(ctx context.Context) error {
return c.Internal.SectorsStagedSeal(ctx)
}
2019-07-24 00:09:34 +00:00
var _ Common = &CommonStruct{}
var _ FullNode = &FullNodeStruct{}
var _ StorageMiner = &StorageMinerStruct{}