Initial cloud-services repo - gateway service + pkg modules

This commit is contained in:
Chris Rai
2026-01-30 23:14:52 -05:00
commit fbb820d7b3
1037 changed files with 171318 additions and 0 deletions

56
pkg/common/binary_hex.go Normal file
View File

@@ -0,0 +1,56 @@
package common
import (
"encoding/hex"
"fmt"
"strings"
)
func NewBinaryHex(data []byte) BinaryHex {
var result BinaryHex = data
return result
}
type BinaryHex []byte
func (bh BinaryHex) Bytes() []byte {
return []byte(bh)
}
func (bh *BinaryHex) SetBytes(value []byte) {
v := BinaryHex(value)
*bh = v
}
func (bh BinaryHex) String() string {
return hex.EncodeToString(bh)
}
// TODO Hack to render []byte as int array for the JSON RPC. Otherwise Go renders in base64
func (bh BinaryHex) UintArray() []uint {
bytes := bh.Bytes()
result := make([]uint, len(bytes))
for i, d := range bytes {
result[i] = uint(d)
}
return result
}
func (bh *BinaryHex) SetHex(data string) error {
x, err := hex.DecodeString(strings.Trim(string(data), `"`))
if err != nil {
return err
}
*bh = x
return nil
}
func (bh BinaryHex) MarshalJSON() ([]byte, error) {
return []byte(fmt.Sprintf(`"%s"`, bh.String())), nil
}
func (bh *BinaryHex) UnmarshalJSON(data []byte) error {
return bh.SetHex(string(data))
}