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) profileInfo, err = store.ReadEntry(ctx, sessionId, common.DATA_FIRST_NAME)
if err != nil { if err != nil {
if db.IsNotFound(err) { if db.IsNotFound(err) {
res.Content = "Not provided" res.Content = "-"
break break
} }
return res, err 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) profileInfo, err = store.ReadEntry(ctx, sessionId, common.DATA_FAMILY_NAME)
if err != nil { if err != nil {
if db.IsNotFound(err) { if db.IsNotFound(err) {
res.Content = "Not provided" res.Content = "-"
break break
} }
return res, err 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) profileInfo, err = store.ReadEntry(ctx, sessionId, common.DATA_GENDER)
if err != nil { if err != nil {
if db.IsNotFound(err) { if db.IsNotFound(err) {
res.Content = "Not provided" res.Content = "-"
break break
} }
return res, err 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) profileInfo, err = store.ReadEntry(ctx, sessionId, common.DATA_YOB)
if err != nil { if err != nil {
if db.IsNotFound(err) { if db.IsNotFound(err) {
res.Content = "Not provided" res.Content = "-"
break break
} }
return res, err 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) profileInfo, err = store.ReadEntry(ctx, sessionId, common.DATA_LOCATION)
if err != nil { if err != nil {
if db.IsNotFound(err) { if db.IsNotFound(err) {
res.Content = "Not provided" res.Content = "-"
break break
} }
return res, err 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) profileInfo, err = store.ReadEntry(ctx, sessionId, common.DATA_OFFERINGS)
if err != nil { if err != nil {
if db.IsNotFound(err) { if db.IsNotFound(err) {
res.Content = "Not provided" res.Content = "-"
break break
} }
return res, err return res, err

View File

@ -1,26 +1,20 @@
package remote package remote
import ( import (
"bytes"
"context" "context"
"encoding/json" "encoding/json"
"errors" "errors"
"io" "io"
"log"
"net/http" "net/http"
"net/url" "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/config"
"git.grassecon.net/urdt/ussd/models" "git.grassecon.net/urdt/ussd/models"
"github.com/grassrootseconomics/eth-custodial/pkg/api"
dataserviceapi "github.com/grassrootseconomics/ussd-data-service/pkg/api"
) )
var ( 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 { type AccountServiceInterface interface {
@ -85,6 +79,7 @@ func (as *AccountService) CheckBalance(ctx context.Context, publicKey string) (*
return &balanceResult, err return &balanceResult, err
} }
// CreateAccount creates a new account in the custodial system. // CreateAccount creates a new account in the custodial system.
// Returns: // Returns:
// - *models.AccountResponse: A pointer to an AccountResponse struct containing the details of the created account. // - *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 return r, nil
} }
// FetchTransactions retrieves the last 10 transactions for a given public key from the data indexer API endpoint // FetchTransactions retrieves the last 10 transactions for a given public key from the data indexer API endpoint
// Parameters: // Parameters:
// - publicKey: The public key associated with the account. // - publicKey: The public key associated with the account.
@ -155,6 +151,7 @@ func (as *AccountService) FetchTransactions(ctx context.Context, publicKey strin
return r, nil return r, nil
} }
// VoucherData retrieves voucher metadata from the data indexer API endpoint. // VoucherData retrieves voucher metadata from the data indexer API endpoint.
// Parameters: // Parameters:
// - address: The voucher address. // - address: The voucher address.
@ -187,7 +184,6 @@ func doRequest(ctx context.Context, req *http.Request, rcpt any) (*api.OKRespons
} }
defer resp.Body.Close() 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) body, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
return nil, err 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) { func doCustodialRequest(ctx context.Context, req *http.Request, rcpt any) (*api.OKResponse, error) {
req.Header.Set("X-GE-KEY", config.CustodialAPIKey) req.Header.Set("X-GE-KEY", config.CustodialAPIKey)
logRequestDetails(req, config.CustodialAPIKey)
return doRequest(ctx, req, rcpt) return doRequest(ctx, req, rcpt)
} }
func doDataRequest(ctx context.Context, req *http.Request, rcpt any) (*api.OKResponse, error) { func doDataRequest(ctx context.Context, req *http.Request, rcpt any) (*api.OKResponse, error) {
req.Header.Set("X-GE-KEY", config.DataAPIKey) req.Header.Set("X-GE-KEY", config.DataAPIKey)
logRequestDetails(req, config.CustodialAPIKey)
return doRequest(ctx, req, rcpt) 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))
}