Return user invoices

and maybe correctly encode the Buffers?
This commit is contained in:
Michael Bumann
2022-01-21 11:49:08 +01:00
parent 55fbaeea92
commit 228edcbe39
3 changed files with 76 additions and 4 deletions

32
lib/javascriptbuffer.go Normal file
View 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
}