-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathp2p_payment_destination.go
48 lines (40 loc) · 1.12 KB
/
p2p_payment_destination.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package server
import (
"github.com/bitcoin-sv/go-paymail/errors"
"github.com/gin-gonic/gin"
"net/http"
"github.com/bitcoin-sv/go-paymail"
)
/*
Incoming Data Object Example:
{
"satoshis": 1000100,
}
*/
type p2pDestinationRequestBody struct {
Satoshis uint64 `json:"satoshis,omitempty"`
}
// p2pDestination will return an output script(s) for a destination (used with SendP2PTransaction)
//
// Specs: https://docs.moneybutton.com/docs/paymail-07-p2p-payment-destination.html
func (c *Configuration) p2pDestination(context *gin.Context) {
var b p2pDestinationRequestBody
err := context.Bind(&b)
if err != nil {
errors.ErrorResponse(context, errors.ErrCannotBindRequest)
return
}
alias, domain, md, ok := c.GetPaymailAndCreateMetadata(context, b.Satoshis)
if !ok {
// ErrorResponse already set up in GetPaymailAndCreateMetadata
return
}
var response *paymail.PaymentDestinationPayload
if response, err = c.actions.CreateP2PDestinationResponse(
context.Request.Context(), alias, domain, b.Satoshis, md,
); err != nil {
errors.ErrorResponse(context, err)
return
}
context.JSON(http.StatusOK, response)
}