You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
79 lines
2.7 KiB
79 lines
2.7 KiB
5 years ago
|
package apiv2
|
||
6 years ago
|
|
||
|
import (
|
||
6 years ago
|
"context"
|
||
|
"math/big"
|
||
|
|
||
6 years ago
|
"github.com/harmony-one/harmony/api/proto"
|
||
5 years ago
|
"github.com/harmony-one/harmony/core/types"
|
||
5 years ago
|
nodeconfig "github.com/harmony-one/harmony/internal/configs/node"
|
||
5 years ago
|
staking "github.com/harmony-one/harmony/staking/types"
|
||
6 years ago
|
)
|
||
|
|
||
|
// PublicHarmonyAPI provides an API to access Harmony related information.
|
||
|
// It offers only methods that operate on public data that is freely available to anyone.
|
||
|
type PublicHarmonyAPI struct {
|
||
6 years ago
|
b Backend
|
||
6 years ago
|
}
|
||
|
|
||
|
// NewPublicHarmonyAPI ...
|
||
6 years ago
|
func NewPublicHarmonyAPI(b Backend) *PublicHarmonyAPI {
|
||
6 years ago
|
return &PublicHarmonyAPI{b}
|
||
6 years ago
|
}
|
||
|
|
||
|
// ProtocolVersion returns the current Harmony protocol version this node supports
|
||
5 years ago
|
func (s *PublicHarmonyAPI) ProtocolVersion() int {
|
||
|
return proto.ProtocolVersion
|
||
6 years ago
|
}
|
||
|
|
||
|
// Syncing returns false in case the node is currently not syncing with the network. It can be up to date or has not
|
||
|
// yet received the latest block headers from its pears. In case it is synchronizing:
|
||
|
// - startingBlock: block number this node started to synchronise from
|
||
|
// - currentBlock: block number this node is currently importing
|
||
|
// - highestBlock: block number of the highest block header this node has received from peers
|
||
|
// - pulledStates: number of state entries processed until now
|
||
|
// - knownStates: number of known state entries that still need to be pulled
|
||
|
func (s *PublicHarmonyAPI) Syncing() (interface{}, error) {
|
||
6 years ago
|
// TODO(ricl): find our Downloader module for syncing blocks
|
||
6 years ago
|
return false, nil
|
||
|
}
|
||
6 years ago
|
|
||
|
// GasPrice returns a suggestion for a gas price.
|
||
5 years ago
|
func (s *PublicHarmonyAPI) GasPrice(ctx context.Context) (*big.Int, error) {
|
||
6 years ago
|
// TODO(ricl): add SuggestPrice API
|
||
5 years ago
|
return big.NewInt(1), nil
|
||
6 years ago
|
}
|
||
5 years ago
|
|
||
5 years ago
|
// NodeMetadata captures select metadata of the RPC answering node
|
||
5 years ago
|
type NodeMetadata struct {
|
||
|
BLSPublicKey string `json:"blskey"`
|
||
|
Version string `json:"version"`
|
||
|
NetworkType string `json:"network"`
|
||
5 years ago
|
ChainID string `json:"chainid"`
|
||
5 years ago
|
IsLeader bool `json:"is-leader"`
|
||
5 years ago
|
ShardID uint32 `json:"shard-id"`
|
||
5 years ago
|
}
|
||
|
|
||
5 years ago
|
// GetNodeMetadata produces a NodeMetadata record, data is from the answering RPC node
|
||
5 years ago
|
func (s *PublicHarmonyAPI) GetNodeMetadata() NodeMetadata {
|
||
|
cfg := nodeconfig.GetDefaultConfig()
|
||
|
return NodeMetadata{
|
||
|
cfg.ConsensusPubKey.SerializeToHexStr(),
|
||
|
nodeconfig.GetVersion(),
|
||
|
string(cfg.GetNetworkType()),
|
||
5 years ago
|
s.b.ChainConfig().ChainID.String(),
|
||
5 years ago
|
s.b.IsLeader(),
|
||
5 years ago
|
s.b.GetShardID(),
|
||
5 years ago
|
}
|
||
|
}
|
||
5 years ago
|
|
||
|
// GetCurrentTransactionErrorSink ..
|
||
5 years ago
|
func (s *PublicHarmonyAPI) GetCurrentTransactionErrorSink() []types.RPCTransactionError {
|
||
|
return s.b.GetCurrentTransactionErrorSink()
|
||
|
}
|
||
|
|
||
|
// GetCurrentStakingErrorSink ..
|
||
|
func (s *PublicHarmonyAPI) GetCurrentStakingErrorSink() []staking.RPCTransactionError {
|
||
|
return s.b.GetCurrentStakingErrorSink()
|
||
5 years ago
|
}
|