Compare commits

..

No commits in common. "68d162854614e9ae8b111f0a5d9bc440172b74f5" and "cc36ddcb6de9eeaec9ffb530e972658b533b5818" have entirely different histories.

3 changed files with 17 additions and 41 deletions

View File

@ -1177,7 +1177,7 @@ func (h *Handlers) GetCurrentProfileInfo(ctx context.Context, sym string, input
profileInfo, err = store.ReadEntry(ctx, sessionId, common.DATA_FIRST_NAME)
if err != nil {
if db.IsNotFound(err) {
res.Content = "Not provided"
res.Content = "-"
break
}
return res, err
@ -1187,7 +1187,7 @@ func (h *Handlers) GetCurrentProfileInfo(ctx context.Context, sym string, input
profileInfo, err = store.ReadEntry(ctx, sessionId, common.DATA_FAMILY_NAME)
if err != nil {
if db.IsNotFound(err) {
res.Content = "Not provided"
res.Content = "-"
break
}
return res, err
@ -1198,7 +1198,7 @@ func (h *Handlers) GetCurrentProfileInfo(ctx context.Context, sym string, input
profileInfo, err = store.ReadEntry(ctx, sessionId, common.DATA_GENDER)
if err != nil {
if db.IsNotFound(err) {
res.Content = "Not provided"
res.Content = "-"
break
}
return res, err
@ -1208,7 +1208,7 @@ func (h *Handlers) GetCurrentProfileInfo(ctx context.Context, sym string, input
profileInfo, err = store.ReadEntry(ctx, sessionId, common.DATA_YOB)
if err != nil {
if db.IsNotFound(err) {
res.Content = "Not provided"
res.Content = "-"
break
}
return res, err
@ -1219,7 +1219,7 @@ func (h *Handlers) GetCurrentProfileInfo(ctx context.Context, sym string, input
profileInfo, err = store.ReadEntry(ctx, sessionId, common.DATA_LOCATION)
if err != nil {
if db.IsNotFound(err) {
res.Content = "Not provided"
res.Content = "-"
break
}
return res, err
@ -1229,7 +1229,7 @@ func (h *Handlers) GetCurrentProfileInfo(ctx context.Context, sym string, input
profileInfo, err = store.ReadEntry(ctx, sessionId, common.DATA_OFFERINGS)
if err != nil {
if db.IsNotFound(err) {
res.Content = "Not provided"
res.Content = "-"
break
}
return res, err

View File

@ -1,26 +1,20 @@
package remote
import (
"bytes"
"context"
"encoding/json"
"errors"
"io"
"log"
"net/http"
"net/url"
"os"
dataserviceapi "github.com/grassrootseconomics/ussd-data-service/pkg/api"
"github.com/grassrootseconomics/eth-custodial/pkg/api"
"git.grassecon.net/urdt/ussd/config"
"git.grassecon.net/urdt/ussd/models"
"github.com/grassrootseconomics/eth-custodial/pkg/api"
dataserviceapi "github.com/grassrootseconomics/ussd-data-service/pkg/api"
)
var (
DebugLogger = log.New(os.Stdout, "DEBUG: ", log.Ldate|log.Ltime|log.Lshortfile)
InfoLogger = log.New(os.Stdout, "INFO: ", log.Ldate|log.Ltime)
ErrorLogger = log.New(os.Stderr, "ERROR: ", log.Ldate|log.Ltime|log.Lshortfile)
)
type AccountServiceInterface interface {
@ -85,6 +79,7 @@ func (as *AccountService) CheckBalance(ctx context.Context, publicKey string) (*
return &balanceResult, err
}
// CreateAccount creates a new account in the custodial system.
// Returns:
// - *models.AccountResponse: A pointer to an AccountResponse struct containing the details of the created account.
@ -131,6 +126,7 @@ func (as *AccountService) FetchVouchers(ctx context.Context, publicKey string) (
return r, nil
}
// FetchTransactions retrieves the last 10 transactions for a given public key from the data indexer API endpoint
// Parameters:
// - publicKey: The public key associated with the account.
@ -155,6 +151,7 @@ func (as *AccountService) FetchTransactions(ctx context.Context, publicKey strin
return r, nil
}
// VoucherData retrieves voucher metadata from the data indexer API endpoint.
// Parameters:
// - address: The voucher address.
@ -187,7 +184,6 @@ func doRequest(ctx context.Context, req *http.Request, rcpt any) (*api.OKRespons
}
defer resp.Body.Close()
InfoLogger.Printf("Received response for %s: Status Code: %d | Content-Type: %s", req.URL, resp.StatusCode, resp.Header.Get("Content-Type"))
body, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err
@ -218,30 +214,10 @@ func doRequest(ctx context.Context, req *http.Request, rcpt any) (*api.OKRespons
func doCustodialRequest(ctx context.Context, req *http.Request, rcpt any) (*api.OKResponse, error) {
req.Header.Set("X-GE-KEY", config.CustodialAPIKey)
logRequestDetails(req, config.CustodialAPIKey)
return doRequest(ctx, req, rcpt)
}
func doDataRequest(ctx context.Context, req *http.Request, rcpt any) (*api.OKResponse, error) {
req.Header.Set("X-GE-KEY", config.DataAPIKey)
logRequestDetails(req, config.CustodialAPIKey)
return doRequest(ctx, req, rcpt)
}
func logRequestDetails(req *http.Request, apiKey string) {
var bodyBytes []byte
contentType := req.Header.Get("Content-Type")
if req.Body != nil {
bodyBytes, err := io.ReadAll(req.Body)
if err != nil {
ErrorLogger.Printf("Error reading request body: %s", err)
return
}
req.Body = io.NopCloser(bytes.NewBuffer(bodyBytes))
} else {
bodyBytes = []byte("-")
}
InfoLogger.Printf("URL: %s | Content-Type: %s | Method: %s| Request Body: %s", req.URL, contentType, req.Method, string(bodyBytes))
}