Skip to content
This repository was archived by the owner on Feb 8, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 37 additions & 57 deletions internal/verifierapi/fees.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,6 @@ import (
"github.com/google/uuid"
)

// func (v VerifierApi) CreatePluginPolicy() (ptypes.PluginPolicy, error) {
// url := "/policy"
// method := http.MethodPost
// }
// func (v VerifierApi) UpdatePluginPolicyById() {
// url := "/policy"
// method := http.MethodPut
// }
// func (v VerifierApi) GetAllPluginPolicies() {
// url := "/policies"
// method := http.MethodGet
// }
// func (v VerifierApi) GetPluginPolicyById() {
// url := "/policy/:policyId"
// method := http.MethodGet
// }
// func (v VerifierApi) DeletePluginPolicyById() {
// url := "/policy/:policyId"
// method := http.MethodDelete
// }
// func (v VerifierApi) GetPluginPolicyTransactionHistory() {
// url := "/policies/:policyId/history"
// method := http.MethodGet
// }

// dto types
type FeeDto struct {
ID uuid.UUID `json:"id" validate:"required"`
Amount int `json:"amount" validate:"required"`
Expand All @@ -46,91 +20,97 @@ type FeeDto struct {
}

type FeeHistoryDto struct {
// PolicyId uuid.UUID `json:"policy_id" validate:"required"`
Fees []FeeDto `json:"fees" validate:"required"`
TotalFeesIncurred int `json:"total_fees_incurred" validate:"required"` // Total fees incurred in the smallest unit, e.g., "1000000" for 0.01 VULTI
FeesPendingCollection int `json:"fees_pending_collection" validate:"required"` // Total fees pending collection in the smallest unit, e.g., "1000000" for 0.01 VULTI
PolicyId uuid.UUID `json:"policy_id" validate:"required"`
Fees []FeeDto `json:"fees" validate:"required"`
TotalFeesIncurred int `json:"total_fees_incurred" validate:"required"` // Total fees incurred in the smallest unit, e.g., "1000000" for 0.01 VULTI
FeesPendingCollection int `json:"fees_pending_collection" validate:"required"` // Total fees pending collection in the smallest unit, e.g., "1000000" for 0.01 VULTI
}

// TODO add auth
func (v VerifierApi) GetPluginPolicyFees(policyId uuid.UUID) (FeeHistoryDto, error) {
func (v VerifierApi) GetPluginPolicyFees(policyId uuid.UUID) (*FeeHistoryDto, error) {
url := fmt.Sprintf("/fees/policy/%s", policyId.String())
v.logger.Debug("Getting plugin policy fees for policy: ", policyId.String())
v.logger.Debug("URL: ", url)
response, err := v.get(url)
if err != nil {
return FeeHistoryDto{}, fmt.Errorf("failed to get plugin policy fees: %w", err)
return nil, fmt.Errorf("failed to get plugin policy fees: %w", err)
}
defer func() {
if err := response.Body.Close(); err != nil {
v.logger.WithError(err).Error("Failed to close response body")
}
}()
if response.StatusCode == http.StatusNotFound {
return FeeHistoryDto{}, fmt.Errorf("policy not found")
return nil, fmt.Errorf("policy not found")
}

if response.StatusCode != http.StatusOK {
return FeeHistoryDto{}, fmt.Errorf("failed to get plugin policy fees, status code: %d", response.StatusCode)
return nil, fmt.Errorf("failed to get plugin policy fees, status code: %d", response.StatusCode)
}

var feeHistory APIResponse[FeeHistoryDto]
if err := json.NewDecoder(response.Body).Decode(&feeHistory); err != nil {
return FeeHistoryDto{}, fmt.Errorf("failed to decode plugin policy fees response: %w", err)
return nil, fmt.Errorf("failed to decode plugin policy fees response: %w", err)
}

if feeHistory.Error.Message != "" {
return FeeHistoryDto{}, fmt.Errorf("failed to get plugin policy fees, error: %s, details: %s", feeHistory.Error.Message, feeHistory.Error.DetailedResponse)
return nil, fmt.Errorf("failed to get plugin policy fees, error: %s, details: %s", feeHistory.Error.Message, feeHistory.Error.DetailedResponse)
}

return feeHistory.Data, nil
return &feeHistory.Data, nil
Comment thread
johnnyluo marked this conversation as resolved.
}

// TODO add auth
func (v VerifierApi) GetPublicKeysFees(ecdsaPublicKey string) (FeeHistoryDto, error) {
func (v VerifierApi) GetPublicKeysFees(ecdsaPublicKey string) (*FeeHistoryDto, error) {
url := fmt.Sprintf("/fees/publickey/%s", ecdsaPublicKey)
response, err := v.get(url)
if err != nil {
return FeeHistoryDto{}, fmt.Errorf("failed to get public key fees: %w", err)
return nil, fmt.Errorf("failed to get public key fees: %w", err)
}

//TODO - this probably shouldn't be a 404, just an empty wrapped response with 0
defer func() {
if err := response.Body.Close(); err != nil {
v.logger.WithError(err).Error("Failed to close response body")
}
}()
if response.StatusCode == http.StatusNotFound {
return FeeHistoryDto{}, fmt.Errorf("public key not found")
return nil, fmt.Errorf("public key not found")
}

if response.StatusCode != http.StatusOK {
return FeeHistoryDto{}, fmt.Errorf("failed to get public key fees, status code: %d", response.StatusCode)
return nil, fmt.Errorf("failed to get public key fees, status code: %d", response.StatusCode)
}

var feeHistory APIResponse[FeeHistoryDto]
if err := json.NewDecoder(response.Body).Decode(&feeHistory); err != nil {
return FeeHistoryDto{}, fmt.Errorf("failed to decode public key fees response: %w", err)
return nil, fmt.Errorf("failed to decode public key fees response: %w", err)
}

if feeHistory.Error.Message != "" {
return FeeHistoryDto{}, fmt.Errorf("failed to get public key fees, error: %s, details: %s", feeHistory.Error.Message, feeHistory.Error.DetailedResponse)
return nil, fmt.Errorf("failed to get public key fees, error: %s, details: %s", feeHistory.Error.Message, feeHistory.Error.DetailedResponse)
}

return feeHistory.Data, nil
return &feeHistory.Data, nil
}

func (v VerifierApi) GetAllPublicKeysFees() (map[string]FeeHistoryDto, error) {
url := "/fees/all"
v.logger.Debug("Getting all public key fees")
v.logger.Debug("URL: ", url)
response, err := v.get(url)
if err != nil {
return map[string]FeeHistoryDto{}, fmt.Errorf("failed to get all public key fees: %w", err)
return nil, fmt.Errorf("failed to get all public key fees: %w", err)
}

defer func() {
if err := response.Body.Close(); err != nil {
v.logger.WithError(err).Error("Failed to close response body")
}
}()
if response.StatusCode != http.StatusOK {
return map[string]FeeHistoryDto{}, fmt.Errorf("failed to get all public key fees, status code: %d", response.StatusCode)
return nil, fmt.Errorf("failed to get all public key fees, status code: %d", response.StatusCode)
}

var apiResponse APIResponse[map[string]FeeHistoryDto]
if err := json.NewDecoder(response.Body).Decode(&apiResponse); err != nil {
return map[string]FeeHistoryDto{}, fmt.Errorf("failed to decode all public key fees response: %w", err)
return nil, fmt.Errorf("failed to decode all public key fees response: %w", err)
}
defer response.Body.Close()

if apiResponse.Error.Message != "" {
return map[string]FeeHistoryDto{}, fmt.Errorf("failed to get all public key fees, error: %s, details: %s", apiResponse.Error.Message, apiResponse.Error.DetailedResponse)
return nil, fmt.Errorf("failed to get all public key fees, error: %s, details: %s", apiResponse.Error.Message, apiResponse.Error.DetailedResponse)
}

return apiResponse.Data, nil
Expand Down
7 changes: 2 additions & 5 deletions internal/verifierapi/verifierapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ import (
"github.com/sirupsen/logrus"
)

/*
Verifier API Response types
*/
// APIResponse is a generic response type for the Verifier API.
type APIResponse[T any] struct {
Data T `json:"data,omitempty"`
Error ErrorResponse `json:"error"`
Expand All @@ -22,8 +20,7 @@ type ErrorResponse struct {
DetailedResponse string `json:"details,omitempty"`
}

//Verifier API type

// VerifierApi is a client for interacting with the Verifier API.
type VerifierApi struct {
URL string
logger *logrus.Logger
Expand Down