diff --git a/ln/api.go b/ln/api.go index a7d0a10..1ab9cea 100644 --- a/ln/api.go +++ b/ln/api.go @@ -66,14 +66,14 @@ func PollPaidInvoice(invoiceId string, invoicePaidChan chan<- *Invoice, errorCha for { msg := <-watchPaidChannel - //log.Printf("received message on %s", msg.Channel) + log.Printf("received message on %s", msg.Channel) split := strings.Split(msg.Channel, ":") if len(split) != 2 { errorChan <- fmt.Errorf("error in pubsub channel parsing %s", msg.Channel) } targetInvoiceId := strings.Split(msg.Channel, ":")[1] - //log.Printf("target invoice is %s", targetInvoiceId) + log.Printf("target invoice is %s", targetInvoiceId) if targetInvoiceId == invoiceId { invoice := Invoice{} diff --git a/ln/invoice.go b/ln/invoice.go index 9cf9322..2043aad 100644 --- a/ln/invoice.go +++ b/ln/invoice.go @@ -3,9 +3,9 @@ package ln import ( "encoding/hex" "encoding/json" - "fmt" "log" "strconv" + "strings" "time" "github.com/lightningnetwork/lnd/lnrpc" @@ -65,14 +65,31 @@ func (t *timestamp) UnmarshalJSON(in []byte) error { return nil } - val, err := strconv.Atoi(string(in)) + // Try to first parse in RFC3339 + var val time.Time + var err error + + // put the input in string mode + strIn := string(in) + + // clean + strIn = strings.Replace(strIn, "\"", "", -1) + + if val, err = time.Parse(time.RFC3339, strIn); err != nil { + + val, err := strconv.Atoi(strIn) + if err != nil { + log.Printf("error unmarshal time %s", in) + return err + } + + parsedTime := time.Unix(int64(val), 0) + *t = timestamp(parsedTime) + return nil - if err != nil { - return fmt.Errorf("cannot unmarshal timestamp int") } - parsedTime := time.Unix(int64(val), 0) - *t = timestamp(parsedTime) + *t = timestamp(val) return nil } diff --git a/storage/upload_ctrl.go b/storage/upload_ctrl.go index 7791ec7..4cbd3bb 100644 --- a/storage/upload_ctrl.go +++ b/storage/upload_ctrl.go @@ -170,12 +170,18 @@ func (ctrl UploadCtrl) CheckStatus(c *gin.Context) { } // Get invoice id for upload - invoiceId, err := GetUploadIdInvoice(uploadId) + invoiceId, err := GetUploadIdInvoiceId(uploadId) if err != nil { utils.JSONErrPriv(c, http.StatusInternalServerError, err) return } + // No invoice found + if invoiceId == "" { + utils.JSONErr(c, http.StatusNotFound, "no invoice found") + return + } + // Get invoice invoice, err := ln.CheckInvoice(invoiceId) if err != nil { @@ -225,6 +231,11 @@ func (ctrl UploadCtrl) PollStatus(c *gin.Context) { return } + if invoice == nil { + utils.JSONErr(c, http.StatusInternalServerError, "no invoice found") + return + } + if uploadStatus.WaitPay() { invoiceChan := make(chan *ln.Invoice) @@ -238,6 +249,7 @@ func (ctrl UploadCtrl) PollStatus(c *gin.Context) { log.Println("blocking") select { case invoice := <-invoiceChan: + log.Printf("poll: received invoice notif %s", invoice.RHash) // if expired return with expired response if invoice.Expired { @@ -257,6 +269,8 @@ func (ctrl UploadCtrl) PollStatus(c *gin.Context) { //////////////// ///// Invoice was paid //////////////// + // + log.Println("POLL: invoice was paid") uploadStatus |= UpPaid err := SetUploadStatus(uploadId, uploadStatus) diff --git a/storage/upload_model.go b/storage/upload_model.go index aba78dc..f05ded5 100644 --- a/storage/upload_model.go +++ b/storage/upload_model.go @@ -207,7 +207,7 @@ type Upload struct { //} func GetUploadInvoice(uploadId string) (*ln.Invoice, error) { - invoice := ln.Invoice{} + var invoice ln.Invoice uploadInvoiceKey := fmt.Sprintf("upload_%s_invoice", uploadId) @@ -219,7 +219,8 @@ func GetUploadInvoice(uploadId string) (*ln.Invoice, error) { return &invoice, nil } -func GetUploadIdInvoice(uploadId string) (string, error) { +func GetUploadIdInvoiceId(uploadId string) (string, error) { + invoice, err := GetUploadInvoice(uploadId) return invoice.RHash, err diff --git a/watchers/invoices.go b/watchers/invoices.go index 35f1447..a8479c8 100644 --- a/watchers/invoices.go +++ b/watchers/invoices.go @@ -28,7 +28,7 @@ func getLastSettledInvoiceIndex() uint64 { err := db.DB.Redis.Do(radix.FlatCmd(&cursor, "GET", LastSettledInvoiceIndexKey)) if err != nil { - log.Fatal(err) + return uint64(0) } return cursor @@ -37,7 +37,7 @@ func getLastSettledInvoiceIndex() uint64 { func setLastSettledInvoiceIndex(index uint64) { err := db.DB.Redis.Do(radix.FlatCmd(nil, "SET", LastSettledInvoiceIndexKey, index)) if err != nil { - log.Fatal(err) + panic(err) } } @@ -162,4 +162,8 @@ func handleSettledInvoice(invoice *lnrpc.Invoice) { err = db.DB.Redis.Do(radix.FlatCmd(nil, "PUBLISH", key, newInvoiceJson)) + if err != nil { + panic(err) + } + } diff --git a/web/index.html b/web/index.html index f728f4c..d2016f0 100644 --- a/web/index.html +++ b/web/index.html @@ -5,7 +5,7 @@ - +
diff --git a/web/package.json b/web/package.json index 16bf0b8..ebd7062 100644 --- a/web/package.json +++ b/web/package.json @@ -22,7 +22,8 @@ "tachyons": "4.10.0", "vue": "^2.6.8", "vue-hot-reload-api": "^2.3.3", - "vue-router": "^3.0.2" + "vue-router": "^3.0.2", + "vuex": "^3.1.0" }, "alias": { "vue": "./node_modules/vue/dist/vue.common.js" diff --git a/web/src/App.vue b/web/src/App.vue index 4482b56..5632f42 100644 --- a/web/src/App.vue +++ b/web/src/App.vue @@ -1,15 +1,41 @@ diff --git a/web/src/Home.vue b/web/src/Home.vue index 1dd948d..f2a0827 100644 --- a/web/src/Home.vue +++ b/web/src/Home.vue @@ -1,6 +1,16 @@