The core protocol of WoopChain
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.
woop/rpc/private_debug.go

75 lines
1.9 KiB

Node API Refactor - pt2 (Stage 2.2 of Node API Overhaul) (#3259) * [rpc] Refactor - expose RPC functions in rpc package Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Refactor - Undo v1 & v2 code duplication pt1 * Move apiv1 into rpc package as baseline * Create version enum * Refactor API creation to use version enum Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Refactor - Rejoin GetBlockByNumber & GetBlockByHash * Both RPC versions are supported in 1 function * Created types directory for v1 & v2 response types * Added framework to make rpc layer more clear and legible Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Refactor - Undo v1 & v2 code duplication pt2 * Rejoin blockchain.go functions * Create legacy service * Improve inline documentation Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Refactor - Undo v1 & v2 code duplication pt3 * Use StructuredResponse when returning an exposed type from RPC * Remove addrlock.go * Add RPCBlock creation with exposed struct for easy utility from consumers * Update blockchain.go to reflect changes of RPCBlock Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Refactor - Undo v1 & v2 code duplication pt3 * Create types for RPCs that are returned. * Reorganize types to appropriate v1 & v2 package. Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Refactor - Undo v1 & v2 code duplication pt4 * Add context to all RPCs * Add response switches based on different versions of the API * Add debug logs for RPC that don't return errors Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Refactor - Undo v1 & v2 code duplication pt5 * Add versions switches to all transaction related RPCs * Integrate response with newly defined structures * Add debug messages for RPCs that don't return errors * Add inline documentation for all transaction related RPCs Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Refactor - Undo v1 & v2 code duplication pt6 * Remove apiv2 * Move StructuredResponse & TxHistoryArgs to main rpc types.go Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Refactor - Undo v1 & v2 code duplication pt7 * Create contract, pool, staking & transaction services * Move apis into correct services * Remove util.go (functions are now baked into RPCs in pool.go) * Remove transaction.go (functions/methods are distributed among created services) * Update changes for StructuredResponse Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Refactor - Add rpc server start/stop to pkg Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [node] Refactor - use new RPC start / stop for servers Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [hmy] Refactor - rename network.go to net.go to match rpc * Change names for consistency with rpc pkg Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * fix go lint & go imports Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Refactor - Fix GetTransactionReceipt for staking txs Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Refactor - Rename v1 & v2 struct to not have leading 'RPC' * Update comments Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Refactor - make defaultBlocksPeriod be the num blocks per epoch Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
4 years ago
package rpc
import (
"context"
"github.com/harmony-one/harmony/eth/rpc"
Node API Refactor - pt2 (Stage 2.2 of Node API Overhaul) (#3259) * [rpc] Refactor - expose RPC functions in rpc package Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Refactor - Undo v1 & v2 code duplication pt1 * Move apiv1 into rpc package as baseline * Create version enum * Refactor API creation to use version enum Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Refactor - Rejoin GetBlockByNumber & GetBlockByHash * Both RPC versions are supported in 1 function * Created types directory for v1 & v2 response types * Added framework to make rpc layer more clear and legible Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Refactor - Undo v1 & v2 code duplication pt2 * Rejoin blockchain.go functions * Create legacy service * Improve inline documentation Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Refactor - Undo v1 & v2 code duplication pt3 * Use StructuredResponse when returning an exposed type from RPC * Remove addrlock.go * Add RPCBlock creation with exposed struct for easy utility from consumers * Update blockchain.go to reflect changes of RPCBlock Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Refactor - Undo v1 & v2 code duplication pt3 * Create types for RPCs that are returned. * Reorganize types to appropriate v1 & v2 package. Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Refactor - Undo v1 & v2 code duplication pt4 * Add context to all RPCs * Add response switches based on different versions of the API * Add debug logs for RPC that don't return errors Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Refactor - Undo v1 & v2 code duplication pt5 * Add versions switches to all transaction related RPCs * Integrate response with newly defined structures * Add debug messages for RPCs that don't return errors * Add inline documentation for all transaction related RPCs Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Refactor - Undo v1 & v2 code duplication pt6 * Remove apiv2 * Move StructuredResponse & TxHistoryArgs to main rpc types.go Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Refactor - Undo v1 & v2 code duplication pt7 * Create contract, pool, staking & transaction services * Move apis into correct services * Remove util.go (functions are now baked into RPCs in pool.go) * Remove transaction.go (functions/methods are distributed among created services) * Update changes for StructuredResponse Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Refactor - Add rpc server start/stop to pkg Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [node] Refactor - use new RPC start / stop for servers Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [hmy] Refactor - rename network.go to net.go to match rpc * Change names for consistency with rpc pkg Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * fix go lint & go imports Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Refactor - Fix GetTransactionReceipt for staking txs Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Refactor - Rename v1 & v2 struct to not have leading 'RPC' * Update comments Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Refactor - make defaultBlocksPeriod be the num blocks per epoch Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
4 years ago
"github.com/harmony-one/harmony/hmy"
)
// PrivateDebugService Internal JSON RPC for debugging purpose
type PrivateDebugService struct {
hmy *hmy.Harmony
version Version
}
// NewPrivateDebugAPI creates a new API for the RPC interface
// TODO(dm): expose public via config
func NewPrivateDebugAPI(hmy *hmy.Harmony, version Version) rpc.API {
return rpc.API{
Namespace: version.Namespace(),
Version: APIVersion,
Service: &PrivateDebugService{hmy, version},
Public: false,
}
}
// ConsensusViewChangingID return the current view changing ID to RPC
func (s *PrivateDebugService) ConsensusViewChangingID(
ctx context.Context,
) uint64 {
return s.hmy.NodeAPI.GetConsensusViewChangingID()
}
// ConsensusCurViewID return the current view ID to RPC
func (s *PrivateDebugService) ConsensusCurViewID(
ctx context.Context,
) uint64 {
return s.hmy.NodeAPI.GetConsensusCurViewID()
}
// GetConsensusMode return the current consensus mode
func (s *PrivateDebugService) GetConsensusMode(
ctx context.Context,
) string {
return s.hmy.NodeAPI.GetConsensusMode()
}
// GetConsensusPhase return the current consensus mode
func (s *PrivateDebugService) GetConsensusPhase(
ctx context.Context,
) string {
return s.hmy.NodeAPI.GetConsensusPhase()
}
// GetConfig get harmony config
func (s *PrivateDebugService) GetConfig(
ctx context.Context,
) (StructuredResponse, error) {
return NewStructuredResponse(s.hmy.NodeAPI.GetConfig())
}
// GetLastSigningPower get last signed power
func (s *PrivateDebugService) GetLastSigningPower(
ctx context.Context,
) (float64, error) {
return s.hmy.NodeAPI.GetLastSigningPower()
}
// GetLastSigningPower2 get last signed power
func (s *PrivateDebugService) GetLastSigningPower2(
ctx context.Context,
) (float64, error) {
return s.hmy.NodeAPI.GetLastSigningPower2()
}