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.8 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"
8 months ago
"github.com/woop-chain/woop/eth/rpc"
"github.com/woop-chain/woop/wiki"
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
)
// PrivateDebugService Internal JSON RPC for debugging purpose
type PrivateDebugService struct {
8 months ago
wiki *wiki.Woop
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
version Version
}
// NewPrivateDebugAPI creates a new API for the RPC interface
// TODO(dm): expose public via config
8 months ago
func NewPrivateDebugAPI(wiki *wiki.Woop, version Version) rpc.API {
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
return rpc.API{
Namespace: version.Namespace(),
Version: APIVersion,
8 months ago
Service: &PrivateDebugService{wiki, version},
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
Public: false,
}
}
// ConsensusViewChangingID return the current view changing ID to RPC
func (s *PrivateDebugService) ConsensusViewChangingID(
ctx context.Context,
) uint64 {
8 months ago
return s.wiki.NodeAPI.GetConsensusViewChangingID()
}
// ConsensusCurViewID return the current view ID to RPC
func (s *PrivateDebugService) ConsensusCurViewID(
ctx context.Context,
) uint64 {
8 months ago
return s.wiki.NodeAPI.GetConsensusCurViewID()
}
// GetConsensusMode return the current consensus mode
func (s *PrivateDebugService) GetConsensusMode(
ctx context.Context,
) string {
8 months ago
return s.wiki.NodeAPI.GetConsensusMode()
}
// GetConsensusPhase return the current consensus mode
func (s *PrivateDebugService) GetConsensusPhase(
ctx context.Context,
) string {
8 months ago
return s.wiki.NodeAPI.GetConsensusPhase()
}
8 months ago
// GetConfig get woop config
func (s *PrivateDebugService) GetConfig(
ctx context.Context,
) (StructuredResponse, error) {
8 months ago
return NewStructuredResponse(s.wiki.NodeAPI.GetConfig())
}
// GetLastSigningPower get last signed power
func (s *PrivateDebugService) GetLastSigningPower(
ctx context.Context,
) (float64, error) {
8 months ago
return s.wiki.NodeAPI.GetLastSigningPower()
}
// GetLastSigningPower2 get last signed power
func (s *PrivateDebugService) GetLastSigningPower2(
ctx context.Context,
) (float64, error) {
8 months ago
return s.wiki.NodeAPI.GetLastSigningPower2()
}