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/rosetta/services/network_service.go

101 lines
2.3 KiB

Node API Refactor - pt3 (Stage 3.1 of Node API Overhaul) (#3297) * [rosetta] Add server with example block & network services * Update go.mod for rosetta SDK Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [internal/configs] Add RosettaServer to node config Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [cmd] Add rosetta port flag Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [node] Add rosetta server start & rename api.go Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Change server start to use nodeconfig of rosetta Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [cmd] Cleanup debugging prints Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Fix stdout print & document placeholders Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Fix lint & make StartSevers more consistent Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [cmd] Disable rosetta by default Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [test] Make explorer deploy rosetta server Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Use direct http server for start * Make go.mod changes minimal Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Fix fmt Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Fix fmt of go.mod Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Use port 9700 instead of 10000 Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [cmd] Bump config version Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [cmd] Add v1.0.0 config backwards compatibility test * Included update message if old config is loaded Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [test] Do not broadcast invalid tx on localnet Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [cmd] Correct for invalid port when loading old config Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [cmd] Make rosetta variable names consistent Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
4 years ago
package services
import (
"context"
"github.com/coinbase/rosetta-sdk-go/server"
"github.com/coinbase/rosetta-sdk-go/types"
"github.com/harmony-one/harmony/hmy"
)
// NetworkAPIService implements the server.NetworkAPIServicer interface.
type NetworkAPIService struct {
hmy *hmy.Harmony
network *types.NetworkIdentifier
}
// NewNetworkAPIService creates a new instance of a NetworkAPIService.
func NewNetworkAPIService(
network *types.NetworkIdentifier, hmy *hmy.Harmony,
) server.NetworkAPIServicer {
return &NetworkAPIService{
hmy: hmy,
network: network,
}
}
// NetworkList implements the /network/list endpoint (placeholder)
// FIXME: remove placeholder & implement block endpoint
func (s *NetworkAPIService) NetworkList(
ctx context.Context,
request *types.MetadataRequest,
) (*types.NetworkListResponse, *types.Error) {
return &types.NetworkListResponse{
NetworkIdentifiers: []*types.NetworkIdentifier{
s.network,
},
}, nil
}
// NetworkStatus implements the /network/status endpoint (placeholder)
// FIXME: remove placeholder & implement block endpoint
func (s *NetworkAPIService) NetworkStatus(
ctx context.Context,
request *types.NetworkRequest,
) (*types.NetworkStatusResponse, *types.Error) {
return &types.NetworkStatusResponse{
CurrentBlockIdentifier: &types.BlockIdentifier{
Index: 1000,
Hash: "block 1000",
},
CurrentBlockTimestamp: int64(1586483189000),
GenesisBlockIdentifier: &types.BlockIdentifier{
Index: 0,
Hash: "block 0",
},
Peers: []*types.Peer{
{
PeerID: "peer 1",
},
},
}, nil
}
// NetworkOptions implements the /network/options endpoint (placeholder)
// FIXME: remove placeholder & implement block endpoint
func (s *NetworkAPIService) NetworkOptions(
ctx context.Context,
request *types.NetworkRequest,
) (*types.NetworkOptionsResponse, *types.Error) {
return &types.NetworkOptionsResponse{
Version: &types.Version{
RosettaVersion: "1.4.0",
NodeVersion: "0.0.1",
},
Allow: &types.Allow{
OperationStatuses: []*types.OperationStatus{
{
Status: "Success",
Successful: true,
},
{
Status: "Reverted",
Successful: false,
},
},
OperationTypes: []string{
"Transfer",
"Reward",
},
Errors: []*types.Error{
{
Code: 1,
Message: "not implemented",
Retriable: false,
},
},
},
}, nil
}