Skip to content

Commit

Permalink
Merge pull request #25 from nodeset-org/ns-client
Browse files Browse the repository at this point in the history
Move the NodeSet client into HD Daemon
  • Loading branch information
jclapis authored Jul 8, 2024
2 parents 3f61be3 + 9e2a3da commit b34c0e6
Show file tree
Hide file tree
Showing 32 changed files with 1,500 additions and 88 deletions.
24 changes: 14 additions & 10 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,27 @@ import (

// Binder for the Hyperdrive daemon API server
type ApiClient struct {
context client.IRequesterContext
Service *ServiceRequester
Tx *TxRequester
Utils *UtilsRequester
Wallet *WalletRequester
context client.IRequesterContext
NodeSet *NodeSetRequester
NodeSet_StakeWise *NodeSetStakeWiseRequester
Service *ServiceRequester
Tx *TxRequester
Utils *UtilsRequester
Wallet *WalletRequester
}

// Creates a new API client instance
func NewApiClient(apiUrl *url.URL, logger *slog.Logger, tracer *httptrace.ClientTrace) *ApiClient {
context := client.NewNetworkRequesterContext(apiUrl, logger, tracer)

client := &ApiClient{
context: context,
Service: NewServiceRequester(context),
Tx: NewTxRequester(context),
Utils: NewUtilsRequester(context),
Wallet: NewWalletRequester(context),
context: context,
NodeSet: NewNodeSetRequester(context),
NodeSet_StakeWise: NewNodeSetStakeWiseRequester(context),
Service: NewServiceRequester(context),
Tx: NewTxRequester(context),
Utils: NewUtilsRequester(context),
Wallet: NewWalletRequester(context),
}
return client
}
Expand Down
65 changes: 65 additions & 0 deletions client/nodeset-stakewise.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package client

import (
"github.com/ethereum/go-ethereum/common"
"github.com/nodeset-org/hyperdrive-daemon/shared/types/api"
apiv1 "github.com/nodeset-org/nodeset-client-go/api-v1"
"github.com/rocket-pool/node-manager-core/api/client"
"github.com/rocket-pool/node-manager-core/api/types"
"github.com/rocket-pool/node-manager-core/beacon"
)

// Requester for StakeWise module calls to the nodeset.io service
type NodeSetStakeWiseRequester struct {
context client.IRequesterContext
}

func NewNodeSetStakeWiseRequester(context client.IRequesterContext) *NodeSetStakeWiseRequester {
return &NodeSetStakeWiseRequester{
context: context,
}
}

func (r *NodeSetStakeWiseRequester) GetName() string {
return "NodeSet-StakeWise"
}
func (r *NodeSetStakeWiseRequester) GetRoute() string {
return "nodeset/stakewise"
}
func (r *NodeSetStakeWiseRequester) GetContext() client.IRequesterContext {
return r.context
}

// Gets the list of validators that the node has registered with the provided vault
func (r *NodeSetStakeWiseRequester) GetRegisteredValidators(vault common.Address) (*types.ApiResponse[api.NodeSetStakeWise_GetRegisteredValidatorsData], error) {
args := map[string]string{
"vault": vault.Hex(),
}
return client.SendGetRequest[api.NodeSetStakeWise_GetRegisteredValidatorsData](r, "get-registered-validators", "GetRegisteredValidators", args)
}

// Gets the version of the latest deposit data set on the server for the provided vault
func (r *NodeSetStakeWiseRequester) GetDepositDataSetVersion(vault common.Address) (*types.ApiResponse[api.NodeSetStakeWise_GetDepositDataSetVersionData], error) {
args := map[string]string{
"vault": vault.Hex(),
}
return client.SendGetRequest[api.NodeSetStakeWise_GetDepositDataSetVersionData](r, "get-deposit-data-set/version", "GetDepositDataSetVersion", args)
}

// Gets the latest deposit data set on the server for the provided vault
func (r *NodeSetStakeWiseRequester) GetDepositDataSet(vault common.Address) (*types.ApiResponse[api.NodeSetStakeWise_GetDepositDataSetData], error) {
args := map[string]string{
"vault": vault.Hex(),
}
return client.SendGetRequest[api.NodeSetStakeWise_GetDepositDataSetData](r, "get-deposit-data-set", "GetDepositDataSet", args)
}

// Uploads new validator deposit data to the NodeSet service
func (r *NodeSetStakeWiseRequester) UploadDepositData(data []beacon.ExtendedDepositData) (*types.ApiResponse[api.NodeSetStakeWise_UploadDepositDataData], error) {
return client.SendPostRequest[api.NodeSetStakeWise_UploadDepositDataData](r, "upload-deposit-data", "UploadDepositData", data)
}

// Uploads signed exit messages to the NodeSet service
func (r *NodeSetStakeWiseRequester) UploadSignedExits(data []apiv1.ExitData) (*types.ApiResponse[api.NodeSetStakeWise_UploadSignedExitsData], error) {
return client.SendPostRequest[api.NodeSetStakeWise_UploadSignedExitsData](r, "upload-signed-exits", "UploadSignedExits", data)
}
41 changes: 41 additions & 0 deletions client/nodeset.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package client

import (
"github.com/nodeset-org/hyperdrive-daemon/shared/types/api"
"github.com/rocket-pool/node-manager-core/api/client"
"github.com/rocket-pool/node-manager-core/api/types"
)

// Requester for core calls to the nodeset.io service
type NodeSetRequester struct {
context client.IRequesterContext
}

func NewNodeSetRequester(context client.IRequesterContext) *NodeSetRequester {
return &NodeSetRequester{
context: context,
}
}

func (r *NodeSetRequester) GetName() string {
return "NodeSet"
}
func (r *NodeSetRequester) GetRoute() string {
return "nodeset"
}
func (r *NodeSetRequester) GetContext() client.IRequesterContext {
return r.context
}

// Gets the node's registration status with the NodeSet service
func (r *NodeSetRequester) GetRegistrationStatus() (*types.ApiResponse[api.NodeSetGetRegistrationStatusData], error) {
return client.SendGetRequest[api.NodeSetGetRegistrationStatusData](r, "get-registration-status", "GetRegistrationStatus", nil)
}

// Registers the node with the NodeSet service
func (r *NodeSetRequester) RegisterNode(email string) (*types.ApiResponse[api.NodeSetRegisterNodeData], error) {
args := map[string]string{
"email": email,
}
return client.SendGetRequest[api.NodeSetRegisterNodeData](r, "register-node", "RegisterNode", args)
}
Loading

0 comments on commit b34c0e6

Please sign in to comment.