mirror of
https://github.com/getAlby/lndhub.go.git
synced 2026-01-07 15:05:37 +01:00
Return user invoices
and maybe correctly encode the Buffers?
This commit is contained in:
32
lib/javascriptbuffer.go
Normal file
32
lib/javascriptbuffer.go
Normal file
@@ -0,0 +1,32 @@
|
||||
package lib
|
||||
|
||||
import (
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type JavaScriptBuffer struct {
|
||||
Data []uint8
|
||||
}
|
||||
|
||||
func (buf *JavaScriptBuffer) MarshalJSON() ([]byte, error) {
|
||||
var array string
|
||||
if buf.Data == nil {
|
||||
array = "null"
|
||||
} else {
|
||||
array = strings.Join(strings.Fields(fmt.Sprintf("%d", buf.Data)), ",")
|
||||
}
|
||||
jsonResult := fmt.Sprintf(`{"type": "Buffer", "data":%s}`, array)
|
||||
return []byte(jsonResult), nil
|
||||
}
|
||||
|
||||
func ToJavaScriptBuffer(hexString string) (*JavaScriptBuffer, error) {
|
||||
buf := JavaScriptBuffer{}
|
||||
hexArray, err := hex.DecodeString(hexString)
|
||||
if err != nil {
|
||||
return &buf, err
|
||||
}
|
||||
buf.Data = hexArray
|
||||
return &buf, nil
|
||||
}
|
||||
Reference in New Issue
Block a user