Skip to content

Commit

Permalink
Refactor/dpp rename (#33)
Browse files Browse the repository at this point in the history
* chore: renaming to dpp

* chore: updating go-dpp dep. fix lint

Co-authored-by: Mark Robson <[email protected]>
  • Loading branch information
roppa and Mark Robson authored Mar 4, 2022
1 parent ffb6d39 commit 866077d
Show file tree
Hide file tree
Showing 53 changed files with 477 additions and 780 deletions.
3 changes: 1 addition & 2 deletions ARCHITECTURE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Architecture

P4 uses a standard 3 layer architecture with clear separation between these layers of the application:
DPP uses a standard 3 layer architecture with clear separation between these layers of the application:

![3 Tier Layout](https://aspblogs.blob.core.windows.net/media/fredriknormen/WindowsLiveWriter/UsingWebServicesina3tierarchitecture_134F6/3tier_thumb.jpg "3 tier layout")

Expand Down
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# p4

[![Release](https://img.shields.io/github/release-pre/libsv/go-p4.svg?logo=github&style=flat&v=1)](https://github.com/libsv/go-p4/releases)
[![Build Status](https://img.shields.io/github/workflow/status/libsv/go-p4/run-go-tests?logo=github&v=3)](https://github.com/libsv/go-p4/actions)
[![Report](https://goreportcard.com/badge/github.com/libsv/go-p4?style=flat&v=1)](https://goreportcard.com/report/github.com/libsv/go-p4)
[![Release](https://img.shields.io/github/release-pre/libsv/go-p4.svg?logo=github&style=flat&v=1)](https://github.com/libsv/go-dpp/releases)
[![Build Status](https://img.shields.io/github/workflow/status/libsv/go-p4/run-go-tests?logo=github&v=3)](https://github.com/libsv/go-dpp/actions)
[![Report](https://goreportcard.com/badge/github.com/libsv/go-dpp?style=flat&v=1)](https://goreportcard.com/report/github.com/libsv/go-dpp)
[![Go](https://img.shields.io/github/go-mod/go-version/libsv/go-p4?v=1)](https://golang.org/)
[![Sponsor](https://img.shields.io/badge/sponsor-libsv-181717.svg?logo=github&style=flat&v=3)](https://github.com/sponsors/libsv)
[![Donate](https://img.shields.io/badge/donate-bitcoin-ff9900.svg?logo=bitcoin&style=flat&v=3)](https://gobitcoinsv.com/#sponsor)
Expand All @@ -23,7 +23,7 @@ Values can also be passed at build time to provide information such as build inf
### Server

| Key | Description | Default |
|------------------------|--------------------------------------------------------------------|----------------|
| ---------------------- | ------------------------------------------------------------------ | -------------- |
| SERVER_PORT | Port which this server should use | :8445 |
| SERVER_HOST | Host name under which this server is found | p4 |
| SERVER_SWAGGER_ENABLED | If set to true we will expose an endpoint hosting the Swagger docs | true |
Expand All @@ -32,7 +32,7 @@ Values can also be passed at build time to provide information such as build inf
### Environment / Deployment Info

| Key | Description | Default |
|---------------------|----------------------------------------------------------------------------|------------------|
| ------------------- | -------------------------------------------------------------------------- | ---------------- |
| ENV_ENVIRONMENT | What enviornment we are running in, for example 'production' | dev |
| ENV_REGION | Region we are running in, for example 'eu-west-1' | local |
| ENV_COMMIT | Commit hash for the current build | test |
Expand All @@ -43,13 +43,13 @@ Values can also be passed at build time to provide information such as build inf
### Logging

| Key | Description | Default |
|-----------|-----------------------------------------------------------------------|---------|
| --------- | --------------------------------------------------------------------- | ------- |
| LOG_LEVEL | Level of logging we want within the server (debug, error, warn, info) | info |

### PayD Wallet

| Key | Description | Default |
|-------------|----------------------------------------------------------|---------|
| ----------- | -------------------------------------------------------- | ------- |
| PAYD_HOST | Host for the wallet we are connecting to | payd |
| PAYD_PORT | Port the PayD wallet is listening on | :8443 |
| PAYD_SECURE | If true the P4 server will validate the wallet TLS certs | false |
Expand Down Expand Up @@ -87,10 +87,10 @@ services:
GOFLAGS: "-mod=vendor"
DB_DSN: "file:data/wallet.db?cache=shared&_foreign_keys=true;"
DB_SCHEMA_PATH: "data/sqlite/migrations"
command: watcher -run github.com/libsv/go-p4/cmd/rest-server/ -watch github.com/libsv/go-p4
working_dir: /go/src/github.com/libsv/go-p4
command: watcher -run github.com/libsv/go-dpp/cmd/rest-server/ -watch github.com/libsv/go-dpp
working_dir: /go/src/github.com/libsv/go-dpp
volumes:
- ~/git/libsv/go-p4:/go/src/github.com/libsv/go-p4
- ~/git/libsv/go-p4:/go/src/github.com/libsv/go-dpp
```
## CI / CD
Expand Down
58 changes: 29 additions & 29 deletions cmd/internal/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,34 +9,34 @@ import (
"github.com/gorilla/websocket"
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
p4svr "github.com/libsv/p4-server"
"github.com/libsv/p4-server/data"
"github.com/libsv/p4-server/data/payd"
"github.com/libsv/p4-server/data/sockets"
"github.com/libsv/p4-server/docs"
"github.com/libsv/p4-server/log"
p4Handlers "github.com/libsv/p4-server/transports/http"
p4Middleware "github.com/libsv/p4-server/transports/http/middleware"
p4soc "github.com/libsv/p4-server/transports/sockets"
dppProxy "github.com/libsv/dpp-proxy"
"github.com/libsv/dpp-proxy/data"
"github.com/libsv/dpp-proxy/data/payd"
"github.com/libsv/dpp-proxy/data/sockets"
"github.com/libsv/dpp-proxy/docs"
"github.com/libsv/dpp-proxy/log"
dppHandlers "github.com/libsv/dpp-proxy/transports/http"
dppMiddleware "github.com/libsv/dpp-proxy/transports/http/middleware"
dppSoc "github.com/libsv/dpp-proxy/transports/sockets"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
"github.com/spf13/viper"
echoSwagger "github.com/swaggo/echo-swagger"
smw "github.com/theflyingcodr/sockets/middleware"
"github.com/theflyingcodr/sockets/server"

"github.com/libsv/go-p4"
"github.com/libsv/p4-server/config"
"github.com/libsv/p4-server/data/noop"
socData "github.com/libsv/p4-server/data/sockets"
"github.com/libsv/p4-server/service"
"github.com/libsv/dpp-proxy/config"
"github.com/libsv/dpp-proxy/data/noop"
socData "github.com/libsv/dpp-proxy/data/sockets"
"github.com/libsv/dpp-proxy/service"
"github.com/libsv/go-dpp"
)

// Deps holds all the dependencies.
type Deps struct {
PaymentService p4.PaymentService
PaymentRequestService p4.PaymentRequestService
ProofsService p4.ProofsService
PaymentService dpp.PaymentService
PaymentRequestService dpp.PaymentRequestService
ProofsService dpp.ProofsService
}

// SetupDeps will setup all required dependent services.
Expand Down Expand Up @@ -82,7 +82,7 @@ func SetupEcho(l log.Logger) *echo.Echo {
AllowOrigins: []string{"*"},
AllowHeaders: []string{echo.HeaderOrigin, echo.HeaderContentType, echo.HeaderAccept},
}))
e.HTTPErrorHandler = p4Middleware.ErrorHandler(l)
e.HTTPErrorHandler = dppMiddleware.ErrorHandler(l)
return e
}

Expand All @@ -96,9 +96,9 @@ func SetupSwagger(cfg config.Server, e *echo.Echo) {
func SetupHTTPEndpoints(deps *Deps, e *echo.Echo) {
g := e.Group("/")
// handlers
p4Handlers.NewPaymentHandler(deps.PaymentService).RegisterRoutes(g)
p4Handlers.NewPaymentRequestHandler(deps.PaymentRequestService).RegisterRoutes(g)
p4Handlers.NewProofs(deps.ProofsService).RegisterRoutes(g)
dppHandlers.NewPaymentHandler(deps.PaymentService).RegisterRoutes(g)
dppHandlers.NewPaymentRequestHandler(deps.PaymentRequestService).RegisterRoutes(g)
dppHandlers.NewProofs(deps.ProofsService).RegisterRoutes(g)
}

// SetupSockets will setup handlers and socket server.
Expand All @@ -112,9 +112,9 @@ func SetupSockets(cfg config.Socket, e *echo.Echo) *server.SocketServer {
// add middleware, with panic going first
s.WithMiddleware(smw.PanicHandler, smw.Timeout(smw.NewTimeoutConfig()), smw.Metrics())

p4soc.NewPaymentRequest().Register(s)
p4soc.NewPayment().Register(s)
p4Handlers.NewProofs(service.NewProof(sockets.NewPayd(s))).RegisterRoutes(g)
dppSoc.NewPaymentRequest().Register(s)
dppSoc.NewPayment().Register(s)
dppHandlers.NewProofs(service.NewProof(sockets.NewPayd(s))).RegisterRoutes(g)

// this is our websocket endpoint, clients will hit this with the channelID they wish to connect to
e.GET("/ws/:channelID", wsHandler(s))
Expand All @@ -136,10 +136,10 @@ func SetupHybrid(cfg config.Config, l log.Logger, e *echo.Echo) *server.SocketSe
paymentReqSvc := service.NewPaymentRequestProxy(paymentStore, cfg.Transports, cfg.Server)
proofsSvc := service.NewProof(paymentStore)

p4Handlers.NewPaymentHandler(paymentSvc).RegisterRoutes(g)
p4Handlers.NewPaymentRequestHandler(paymentReqSvc).RegisterRoutes(g)
p4Handlers.NewProofs(proofsSvc).RegisterRoutes(g)
p4soc.NewHealthHandler().Register(s)
dppHandlers.NewPaymentHandler(paymentSvc).RegisterRoutes(g)
dppHandlers.NewPaymentRequestHandler(paymentReqSvc).RegisterRoutes(g)
dppHandlers.NewProofs(proofsSvc).RegisterRoutes(g)
dppSoc.NewHealthHandler().Register(s)

e.GET("/ws/:channelID", wsHandler(s))
return s
Expand All @@ -162,7 +162,7 @@ func wsHandler(svr *server.SocketServer) echo.HandlerFunc {

if c.QueryParam("internal") != "true" {
if !svr.HasChannel(chID) {
return c.JSON(http.StatusNotFound, p4svr.ClientError{
return c.JSON(http.StatusNotFound, dppProxy.ClientError{
ID: "",
Code: "404",
Message: fmt.Sprintf("Connection for invoice '%s' not found", chID),
Expand Down
6 changes: 3 additions & 3 deletions cmd/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import (
"os/signal"
"time"

"github.com/libsv/p4-server/cmd/internal"
"github.com/libsv/p4-server/config"
"github.com/libsv/p4-server/log"
"github.com/libsv/dpp-proxy/cmd/internal"
"github.com/libsv/dpp-proxy/config"
"github.com/libsv/dpp-proxy/log"
)

const appname = "payment-protocol-rest-server"
Expand Down
2 changes: 1 addition & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ type Socket struct {
ChannelTimeout time.Duration
}

// Transports enables or disables p4 transports.
// Transports enables or disables dpp transports.
type Transports struct {
Mode string
}
Expand Down
4 changes: 2 additions & 2 deletions config/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import (
// These can be overwritten when running the service.
func SetupDefaults() {
// Web server defaults
viper.SetDefault(EnvServerHost, "p4")
viper.SetDefault(EnvServerHost, "dpp")
viper.SetDefault(EnvServerPort, ":8445")
viper.SetDefault(EnvServerFQDN, "p4:8445")
viper.SetDefault(EnvServerFQDN, "dpp:8445")
viper.SetDefault(EnvServerSwaggerEnabled, true)
viper.SetDefault(EnvServerSwaggerHost, "localhost:8445")

Expand Down
2 changes: 1 addition & 1 deletion data/http_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"io/ioutil"
"net/http"

server "github.com/libsv/p4-server"
server "github.com/libsv/dpp-proxy"
"github.com/pkg/errors"
validator "github.com/theflyingcodr/govalidator"
"github.com/theflyingcodr/lathos/errs"
Expand Down
18 changes: 9 additions & 9 deletions data/noop/noop.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import (
"context"
"time"

"github.com/libsv/dpp-proxy/log"
"github.com/libsv/go-bt/v2"
"github.com/libsv/go-bt/v2/bscript"
"github.com/libsv/p4-server/log"

"github.com/libsv/go-p4"
"github.com/libsv/go-dpp"
)

type noop struct {
Expand All @@ -26,13 +26,13 @@ func NewNoOp(l log.Logger) *noop {
// PaymentCreate will post a request to payd to validate and add the txos to the wallet.
//
// If invalid a non 204 status code is returned.
func (n *noop) PaymentCreate(ctx context.Context, args p4.PaymentCreateArgs, req p4.Payment) (*p4.PaymentACK, error) {
func (n *noop) PaymentCreate(ctx context.Context, args dpp.PaymentCreateArgs, req dpp.Payment) (*dpp.PaymentACK, error) {
n.l.Info("hit noop.PaymentCreate")
return &p4.PaymentACK{}, nil
return &dpp.PaymentACK{}, nil
}

func (n noop) PaymentRequest(ctx context.Context, args p4.PaymentRequestArgs) (*p4.PaymentRequest, error) {
return &p4.PaymentRequest{
func (n noop) PaymentRequest(ctx context.Context, args dpp.PaymentRequestArgs) (*dpp.PaymentRequest, error) {
return &dpp.PaymentRequest{
Network: "noop",
CreationTimestamp: time.Now(),
ExpirationTimestamp: time.Now().Add(time.Hour),
Expand All @@ -44,15 +44,15 @@ func (n noop) PaymentRequest(ctx context.Context, args p4.PaymentRequestArgs) (*
Memo: "noop",
PaymentURL: "noop",
SPVRequired: true,
MerchantData: &p4.Merchant{
MerchantData: &dpp.Merchant{
AvatarURL: "noop",
Name: "noop",
Email: "noop",
Address: "noop",
ExtendedData: nil,
},
Destinations: p4.PaymentDestinations{
Outputs: []p4.Output{{
Destinations: dpp.PaymentDestinations{
Outputs: []dpp.Output{{
Amount: 0,
LockingScript: &bscript.Script{},
Description: "noop",
Expand Down
8 changes: 4 additions & 4 deletions data/payd/models/payd.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import (
"github.com/libsv/go-bc/spv"
"github.com/libsv/go-bt/v2"

"github.com/libsv/go-p4"
"github.com/libsv/go-dpp"
)

// PayDPaymentRequest is used to send a payment to PayD for valdiation and storage.
type PayDPaymentRequest struct {
SPVEnvelope *spv.Envelope `json:"spvEnvelope"`
RawTX *string `json:"rawTx"`
ProofCallbacks map[string]p4.ProofCallback `json:"proofCallbacks"`
SPVEnvelope *spv.Envelope `json:"spvEnvelope"`
RawTX *string `json:"rawTx"`
ProofCallbacks map[string]dpp.ProofCallback `json:"proofCallbacks"`
}

// Destination is a payment output with locking script.
Expand Down
18 changes: 9 additions & 9 deletions data/payd/payd.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import (
"github.com/libsv/go-bk/envelope"
"github.com/pkg/errors"

"github.com/libsv/go-p4"
"github.com/libsv/p4-server/config"
"github.com/libsv/p4-server/data"
"github.com/libsv/p4-server/data/payd/models"
"github.com/libsv/dpp-proxy/config"
"github.com/libsv/dpp-proxy/data"
"github.com/libsv/dpp-proxy/data/payd/models"
"github.com/libsv/go-dpp"
)

// Known endpoints for the payd wallet implementing the payment protocol interface.
Expand All @@ -37,8 +37,8 @@ func NewPayD(cfg *config.PayD, client data.HTTPClient) *payd {
}

// PaymentRequest will fetch a payment request message from payd for a given payment.
func (p *payd) PaymentRequest(ctx context.Context, args p4.PaymentRequestArgs) (*p4.PaymentRequest, error) {
var resp p4.PaymentRequest
func (p *payd) PaymentRequest(ctx context.Context, args dpp.PaymentRequestArgs) (*dpp.PaymentRequest, error) {
var resp dpp.PaymentRequest
if err := p.client.Do(ctx, http.MethodGet, fmt.Sprintf(urlPayments, p.baseURL(), args.PaymentID), http.StatusOK, nil, &resp); err != nil {
return nil, err
}
Expand All @@ -49,21 +49,21 @@ func (p *payd) PaymentRequest(ctx context.Context, args p4.PaymentRequestArgs) (
// PaymentCreate will post a request to payd to validate and add the txos to the wallet.
//
// If invalid a non 204 status code is returned.
func (p *payd) PaymentCreate(ctx context.Context, args p4.PaymentCreateArgs, req p4.Payment) (*p4.PaymentACK, error) {
func (p *payd) PaymentCreate(ctx context.Context, args dpp.PaymentCreateArgs, req dpp.Payment) (*dpp.PaymentACK, error) {
paymentReq := models.PayDPaymentRequest{
RawTX: req.RawTX,
SPVEnvelope: req.SPVEnvelope,
ProofCallbacks: req.ProofCallbacks,
}
var ack p4.PaymentACK
var ack dpp.PaymentACK
if err := p.client.Do(ctx, http.MethodPost, fmt.Sprintf(urlPayments, p.baseURL(), args.PaymentID), http.StatusNoContent, paymentReq, &ack); err != nil {
return nil, err
}
return &ack, nil
}

// ProofCreate will pass on the proof to a payd instance for storage.
func (p *payd) ProofCreate(ctx context.Context, args p4.ProofCreateArgs, req envelope.JSONEnvelope) error {
func (p *payd) ProofCreate(ctx context.Context, args dpp.ProofCreateArgs, req envelope.JSONEnvelope) error {
return errors.WithStack(p.client.Do(ctx, http.MethodPost, fmt.Sprintf(urlProofs, p.baseURL(), args.TxID), http.StatusCreated, req, nil))
}

Expand Down
Loading

0 comments on commit 866077d

Please sign in to comment.