-
Notifications
You must be signed in to change notification settings - Fork 0
/
chain.go
66 lines (58 loc) · 2.62 KB
/
chain.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package main
import (
"context"
"fmt"
"time"
"github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-jsonrpc"
"github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/lotus/api"
"github.com/filecoin-project/lotus/api/client"
apitypes "github.com/filecoin-project/lotus/api/types"
"github.com/filecoin-project/lotus/blockstore"
"github.com/filecoin-project/lotus/build"
"github.com/filecoin-project/lotus/chain/actors/builtin/miner"
"github.com/filecoin-project/lotus/chain/types"
cliutil "github.com/filecoin-project/lotus/cli/util"
"github.com/filecoin-project/lotus/node/repo"
"github.com/ipfs/go-cid"
"github.com/urfave/cli/v2"
)
var (
genesisTime time.Time
)
type API interface {
blockstore.ChainIO
ChainGetGenesis(context.Context) (*types.TipSet, error) //perm:read
StateNetworkVersion(context.Context, types.TipSetKey) (apitypes.NetworkVersion, error)
ChainHead(context.Context) (*types.TipSet, error)
StateMinerActiveSectors(context.Context, address.Address, types.TipSetKey) ([]*miner.SectorOnChainInfo, error)
StateGetActor(context.Context, address.Address, types.TipSetKey) (*types.Actor, error)
StateMinerInfo(context.Context, address.Address, types.TipSetKey) (api.MinerInfo, error) //perm:read
MpoolPushMessage(context.Context, *types.Message, *api.MessageSendSpec) (*types.SignedMessage, error)
StateWaitMsg(ctx context.Context, cid cid.Cid, confidence uint64, limit abi.ChainEpoch, allowReplaced bool) (*api.MsgLookup, error)
ChainGetMessage(context.Context, cid.Cid) (*types.Message, error)
MpoolPending(context.Context, types.TipSetKey) ([]*types.SignedMessage, error)
MpoolGetConfig(context.Context) (*types.MpoolConfig, error)
GasEstimateMessageGas(context.Context, *types.Message, *api.MessageSendSpec, types.TipSetKey) (*types.Message, error)
WalletSignMessage(context.Context, address.Address, *types.Message) (*types.SignedMessage, error)
MpoolPush(context.Context, *types.SignedMessage) (cid.Cid, error)
}
func TimestampToEpoch(ts time.Time) abi.ChainEpoch {
sinceGenesis := ts.Sub(genesisTime)
expectedHeight := int64(sinceGenesis.Seconds()) / int64(build.BlockDelaySecs)
return abi.ChainEpoch(expectedHeight)
}
func SetupGenesisTime(ts time.Time) {
genesisTime = ts
}
func GetFullNodeAPI(ctx *cli.Context) (api.FullNode, jsonrpc.ClientCloser, error) {
addr, headers, err := cliutil.GetRawAPI(ctx, repo.FullNode, "v1")
if err != nil {
return nil, nil, err
}
if cliutil.IsVeryVerbose {
_, _ = fmt.Fprintln(ctx.App.Writer, "using full node API v1 endpoint:", addr)
}
return client.NewFullNodeRPCV1(ctx.Context, addr, headers, jsonrpc.WithTimeout(15*time.Minute))
}