You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
bit4sat/ln/invoice.go

75 lines
1.4 KiB
Go

package ln
import (
"fmt"
"strconv"
"time"
)
type Currency int
const (
CurMSat Currency = iota
CurSat
CurBTC
CurUSD
CurEur
)
const (
InfoEndpoint = "info"
InvoiceEndpoint = "invoice"
PollInvoiceEndpoint = "invoice"
)
var (
CurrencyString = map[Currency]string{
CurUSD: "USD",
CurSat: "SAT",
CurBTC: "BTC",
CurMSat: "MSAT",
CurEur: "EUR",
}
CurrencyID = map[string]Currency{
"USD": CurUSD,
"SAT": CurSat,
"MSAT": CurMSat,
"BTC": CurBTC,
"EUR": CurEur,
}
)
type timestamp time.Time
func (t *timestamp) UnmarshalJSON(in []byte) error {
val, err := strconv.Atoi(string(in))
if err != nil {
return fmt.Errorf("cannot unmarshal timestamp int")
}
parsedTime := time.Unix(int64(val), 0)
*t = timestamp(parsedTime)
return nil
}
func (t timestamp) String() string {
return time.Time(t).Format(time.RFC3339)
}
type Invoice struct {
Id string `json:"id"`
UploadId string `json:"upload_id"`
Description string `json:"description"`
Msatoshi string `json:"msatoshi"`
Payreq string `json:"payreq"`
RHash string `json:"rhash"`
Status string `json:"status"`
QuotedCurrency string `json:"quoted_currency"`
QuotedAmount string `json:"quoted_amount"`
PaidAt timestamp `json:"paid_at"`
CreatedAt timestamp `json:"created_at"`
ExpiresAt timestamp `json:"expires_at"`
}