Compare commits
No commits in common. "9c972ffa6bb0faf851c4c6e607178e905e3937a9" and "46b2b354fdcfcef0dc16b140e2ffee297c800dcd" have entirely different histories.
9c972ffa6b
...
46b2b354fd
1
.gitignore
vendored
1
.gitignore
vendored
@ -6,4 +6,3 @@ go.work*
|
|||||||
cmd/.state/
|
cmd/.state/
|
||||||
id_*
|
id_*
|
||||||
*.gdbm
|
*.gdbm
|
||||||
*.log
|
|
||||||
|
@ -1,13 +1,9 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
|
||||||
"log"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
@ -31,27 +27,10 @@ import (
|
|||||||
var (
|
var (
|
||||||
logg = logging.NewVanilla()
|
logg = logging.NewVanilla()
|
||||||
scriptDir = path.Join("services", "registration")
|
scriptDir = path.Join("services", "registration")
|
||||||
WarningLogger *log.Logger
|
|
||||||
InfoLogger *log.Logger
|
|
||||||
ErrorLogger *log.Logger
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
initializers.LoadEnvVariables()
|
initializers.LoadEnvVariables()
|
||||||
|
|
||||||
logFile := "urdt-ussd-africastalking.log"
|
|
||||||
|
|
||||||
file, err := os.OpenFile(logFile, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0666)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
InfoLogger = log.New(file, "INFO: ", log.Ldate|log.Ltime|log.Lshortfile)
|
|
||||||
ErrorLogger = log.New(file, "ERROR: ", log.Ldate|log.Ltime|log.Lshortfile)
|
|
||||||
|
|
||||||
// Inject into remote package
|
|
||||||
remote.InfoLogger = InfoLogger
|
|
||||||
remote.ErrorLogger = ErrorLogger
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type atRequestParser struct{}
|
type atRequestParser struct{}
|
||||||
@ -59,30 +38,9 @@ type atRequestParser struct{}
|
|||||||
func (arp *atRequestParser) GetSessionId(rq any) (string, error) {
|
func (arp *atRequestParser) GetSessionId(rq any) (string, error) {
|
||||||
rqv, ok := rq.(*http.Request)
|
rqv, ok := rq.(*http.Request)
|
||||||
if !ok {
|
if !ok {
|
||||||
ErrorLogger.Println("got an invalid request:", rq)
|
|
||||||
return "", handlers.ErrInvalidRequest
|
return "", handlers.ErrInvalidRequest
|
||||||
}
|
}
|
||||||
|
|
||||||
// Capture body (if any) for logging
|
|
||||||
body, err := io.ReadAll(rqv.Body)
|
|
||||||
if err != nil {
|
|
||||||
ErrorLogger.Println("failed to read request body:", err)
|
|
||||||
return "", fmt.Errorf("failed to read request body: %v", err)
|
|
||||||
}
|
|
||||||
// Reset the body for further reading
|
|
||||||
rqv.Body = io.NopCloser(bytes.NewReader(body))
|
|
||||||
|
|
||||||
// Log the body as JSON
|
|
||||||
bodyLog := map[string]string{"body": string(body)}
|
|
||||||
logBytes, err := json.Marshal(bodyLog)
|
|
||||||
if err != nil {
|
|
||||||
ErrorLogger.Println("failed to marshal request body:", err)
|
|
||||||
} else {
|
|
||||||
InfoLogger.Println("Received request:", string(logBytes))
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := rqv.ParseForm(); err != nil {
|
if err := rqv.ParseForm(); err != nil {
|
||||||
ErrorLogger.Println("failed to parse form data: %v", err)
|
|
||||||
return "", fmt.Errorf("failed to parse form data: %v", err)
|
return "", fmt.Errorf("failed to parse form data: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,7 +4,6 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"path"
|
"path"
|
||||||
@ -24,28 +23,12 @@ import (
|
|||||||
var (
|
var (
|
||||||
logg = logging.NewVanilla()
|
logg = logging.NewVanilla()
|
||||||
scriptDir = path.Join("services", "registration")
|
scriptDir = path.Join("services", "registration")
|
||||||
WarningLogger *log.Logger
|
|
||||||
InfoLogger *log.Logger
|
|
||||||
ErrorLogger *log.Logger
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
initializers.LoadEnvVariables()
|
initializers.LoadEnvVariables()
|
||||||
|
|
||||||
logFile := "urdt-ussd-async.log"
|
|
||||||
|
|
||||||
file, err := os.OpenFile(logFile, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0666)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
InfoLogger = log.New(file, "INFO: ", log.Ldate|log.Ltime|log.Lshortfile)
|
|
||||||
ErrorLogger = log.New(file, "ERROR: ", log.Ldate|log.Ltime|log.Lshortfile)
|
|
||||||
|
|
||||||
// Inject into remote package
|
|
||||||
remote.InfoLogger = InfoLogger
|
|
||||||
remote.ErrorLogger = ErrorLogger
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type asyncRequestParser struct {
|
type asyncRequestParser struct {
|
||||||
sessionId string
|
sessionId string
|
||||||
input []byte
|
input []byte
|
||||||
|
@ -4,7 +4,6 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
@ -27,27 +26,10 @@ import (
|
|||||||
var (
|
var (
|
||||||
logg = logging.NewVanilla()
|
logg = logging.NewVanilla()
|
||||||
scriptDir = path.Join("services", "registration")
|
scriptDir = path.Join("services", "registration")
|
||||||
WarningLogger *log.Logger
|
|
||||||
InfoLogger *log.Logger
|
|
||||||
ErrorLogger *log.Logger
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
initializers.LoadEnvVariables()
|
initializers.LoadEnvVariables()
|
||||||
|
|
||||||
logFile := "urdt-ussd-http.log"
|
|
||||||
|
|
||||||
file, err := os.OpenFile(logFile, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0666)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
InfoLogger = log.New(file, "INFO: ", log.Ldate|log.Ltime|log.Lshortfile)
|
|
||||||
ErrorLogger = log.New(file, "ERROR: ", log.Ldate|log.Ltime|log.Lshortfile)
|
|
||||||
|
|
||||||
// Inject into remote package
|
|
||||||
remote.InfoLogger = InfoLogger
|
|
||||||
remote.ErrorLogger = ErrorLogger
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
18
cmd/main.go
18
cmd/main.go
@ -4,7 +4,6 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
|
|
||||||
@ -21,27 +20,10 @@ import (
|
|||||||
var (
|
var (
|
||||||
logg = logging.NewVanilla()
|
logg = logging.NewVanilla()
|
||||||
scriptDir = path.Join("services", "registration")
|
scriptDir = path.Join("services", "registration")
|
||||||
WarningLogger *log.Logger
|
|
||||||
InfoLogger *log.Logger
|
|
||||||
ErrorLogger *log.Logger
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
initializers.LoadEnvVariables()
|
initializers.LoadEnvVariables()
|
||||||
|
|
||||||
logFile := "urdt-ussd-cli.log"
|
|
||||||
|
|
||||||
file, err := os.OpenFile(logFile, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0666)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
InfoLogger = log.New(file, "INFO: ", log.Ldate|log.Ltime|log.Lshortfile)
|
|
||||||
ErrorLogger = log.New(file, "ERROR: ", log.Ldate|log.Ltime|log.Lshortfile)
|
|
||||||
|
|
||||||
// Inject into remote package
|
|
||||||
remote.InfoLogger = InfoLogger
|
|
||||||
remote.ErrorLogger = ErrorLogger
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
@ -5,19 +5,16 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
|
||||||
|
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 (
|
||||||
InfoLogger *log.Logger
|
|
||||||
ErrorLogger *log.Logger
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type AccountServiceInterface interface {
|
type AccountServiceInterface interface {
|
||||||
@ -82,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.
|
||||||
@ -128,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.
|
||||||
@ -152,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.
|
||||||
@ -176,8 +176,6 @@ func doRequest(ctx context.Context, req *http.Request, rcpt any) (*api.OKRespons
|
|||||||
var okResponse api.OKResponse
|
var okResponse api.OKResponse
|
||||||
var errResponse api.ErrResponse
|
var errResponse api.ErrResponse
|
||||||
|
|
||||||
InfoLogger.Printf("Outgoing request:", req.URL, req.Body)
|
|
||||||
|
|
||||||
req.Header.Set("Content-Type", "application/json")
|
req.Header.Set("Content-Type", "application/json")
|
||||||
resp, err := http.DefaultClient.Do(req)
|
resp, err := http.DefaultClient.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user