consensus/monero/client/rpc/daemon/binary_endpoints.go
DataHoarder 142a21861e
All checks were successful
continuous-integration/drone/push Build is passing
Replace json hex strings with types.Hash and types.Bytes on monero rpc
2024-04-07 20:19:12 +02:00

65 lines
1.3 KiB
Go

package daemon
import (
"bytes"
"context"
"errors"
"git.gammaspectra.live/P2Pool/consensus/v3/monero/client/levin"
"git.gammaspectra.live/P2Pool/consensus/v3/types"
"io"
)
const (
endpointGetOIndexes = "/get_o_indexes.bin"
)
func (c *Client) GetOIndexes(
ctx context.Context, txid types.Hash,
) (indexes []uint64, finalError error) {
storage := levin.PortableStorage{Entries: levin.Entries{
levin.Entry{
Name: "txid",
Serializable: levin.BoostString(txid[:]),
},
}}
data := storage.Bytes()
resp, err := c.RawBinaryRequest(ctx, endpointGetOIndexes, bytes.NewReader(data))
if err != nil {
return nil, err
}
defer resp.Close()
if buf, err := io.ReadAll(resp); err != nil {
return nil, err
} else {
defer func() {
if r := recover(); r != nil {
indexes = nil
finalError = errors.New("error decoding")
}
}()
responseStorage, err := levin.NewPortableStorageFromBytes(buf)
if err != nil {
return nil, err
}
for _, e := range responseStorage.Entries {
if e.Name == "o_indexes" {
if entries, ok := e.Value.(levin.Entries); ok {
indexes = make([]uint64, 0, len(entries))
for _, e2 := range entries {
if v, ok := e2.Value.(uint64); ok {
indexes = append(indexes, v)
}
}
return indexes, nil
}
}
}
}
return nil, errors.New("could not get outputs")
}