Implemented GetOutputIndexes for transactions
This commit is contained in:
parent
cb0632e09c
commit
100020b782
2
go.mod
2
go.mod
|
@ -4,7 +4,7 @@ go 1.19
|
|||
|
||||
require (
|
||||
filippo.io/edwards25519 v1.0.1-0.20220803165937-8c58ed0e3550
|
||||
git.gammaspectra.live/P2Pool/go-monero v0.0.0-20230305004001-d8d87587c8a8
|
||||
git.gammaspectra.live/P2Pool/go-monero v0.0.0-20230320202621-f9cc428f9e16
|
||||
git.gammaspectra.live/P2Pool/go-randomx v0.0.0-20221025112134-5190471ef823
|
||||
git.gammaspectra.live/P2Pool/moneroutil v0.0.0-20221007140323-a2daa2d5fc48
|
||||
git.gammaspectra.live/P2Pool/randomx-go-bindings v0.0.0-20221027134633-11f5607e6752
|
||||
|
|
4
go.sum
4
go.sum
|
@ -1,7 +1,7 @@
|
|||
filippo.io/edwards25519 v1.0.1-0.20220803165937-8c58ed0e3550 h1:Mqu6Q2e//30TWeP5bM9Th5KEzWdFAFd80Y2ZXN9fmeE=
|
||||
filippo.io/edwards25519 v1.0.1-0.20220803165937-8c58ed0e3550/go.mod h1:N1IkdkCkiLB6tki+MYJoSx2JTY9NUlxZE7eHn5EwJns=
|
||||
git.gammaspectra.live/P2Pool/go-monero v0.0.0-20230305004001-d8d87587c8a8 h1:FFhYIN01+QhQ53VH1RA08nH318kFYEkBmEdz0iMm0kA=
|
||||
git.gammaspectra.live/P2Pool/go-monero v0.0.0-20230305004001-d8d87587c8a8/go.mod h1:E6nns07xjNbnF+3LKZAjQ9zwpJGLivti8WCKfm+/OII=
|
||||
git.gammaspectra.live/P2Pool/go-monero v0.0.0-20230320202621-f9cc428f9e16 h1:e7n5xJd0otigqyVVfU5nHeWvBSHqQLic7YPinbna2sg=
|
||||
git.gammaspectra.live/P2Pool/go-monero v0.0.0-20230320202621-f9cc428f9e16/go.mod h1:E6nns07xjNbnF+3LKZAjQ9zwpJGLivti8WCKfm+/OII=
|
||||
git.gammaspectra.live/P2Pool/go-randomx v0.0.0-20221025112134-5190471ef823 h1:HxIuImZsB15Ix59K5VznoHzZ1ut5hW0AAqiDJpOd2+g=
|
||||
git.gammaspectra.live/P2Pool/go-randomx v0.0.0-20221025112134-5190471ef823/go.mod h1:3kT0v4AMwT/OdorfH2gRWPwoOrUX/LV03HEeBsaXG1c=
|
||||
git.gammaspectra.live/P2Pool/moneroutil v0.0.0-20221007140323-a2daa2d5fc48 h1:ExrYG0RSrx/I4McPWgUF4B8R2OkblMrMki2ia8vG6Bw=
|
||||
|
|
|
@ -7,12 +7,16 @@ import (
|
|||
"encoding/hex"
|
||||
"errors"
|
||||
"fmt"
|
||||
"git.gammaspectra.live/P2Pool/go-monero/pkg/levin"
|
||||
"git.gammaspectra.live/P2Pool/go-monero/pkg/rpc"
|
||||
"git.gammaspectra.live/P2Pool/go-monero/pkg/rpc/daemon"
|
||||
"git.gammaspectra.live/P2Pool/p2pool-observer/monero/transaction"
|
||||
"git.gammaspectra.live/P2Pool/p2pool-observer/types"
|
||||
"github.com/floatdrop/lru"
|
||||
"io"
|
||||
"log"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
@ -55,8 +59,9 @@ func GetDefaultClient() *Client {
|
|||
|
||||
// Client
|
||||
type Client struct {
|
||||
c *rpc.Client
|
||||
d *daemon.Client
|
||||
c *rpc.Client
|
||||
d *daemon.Client
|
||||
address string
|
||||
|
||||
coinbaseTransactionCache *lru.LRU[types.Hash, *transaction.CoinbaseTransaction]
|
||||
|
||||
|
@ -69,6 +74,7 @@ func NewClient(address string) (*Client, error) {
|
|||
return nil, err
|
||||
}
|
||||
return &Client{
|
||||
address: address,
|
||||
c: c,
|
||||
d: daemon.NewClient(c),
|
||||
coinbaseTransactionCache: lru.New[types.Hash, *transaction.CoinbaseTransaction](1024),
|
||||
|
@ -215,6 +221,70 @@ type Output struct {
|
|||
Unlocked bool
|
||||
}
|
||||
|
||||
// GetOutputIndexes Get global output indexes
|
||||
func (c *Client) GetOutputIndexes(id types.Hash) (indexes []uint64, finalError error) {
|
||||
<-c.throttler
|
||||
|
||||
uri, _ := url.Parse(c.address)
|
||||
uri.Path = "/get_o_indexes.bin"
|
||||
|
||||
storage := levin.PortableStorage{Entries: levin.Entries{
|
||||
levin.Entry{
|
||||
Name: "txid",
|
||||
Serializable: levin.BoostString(id[:]),
|
||||
},
|
||||
}}
|
||||
|
||||
data := storage.Bytes()
|
||||
|
||||
body := io.NopCloser(bytes.NewReader(data))
|
||||
response, err := http.DefaultClient.Do(&http.Request{
|
||||
Method: "POST",
|
||||
URL: uri,
|
||||
Header: http.Header{
|
||||
"content-type": []string{"application/octet-stream"},
|
||||
},
|
||||
Body: body,
|
||||
ContentLength: int64(len(data)),
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer response.Body.Close()
|
||||
if response.StatusCode < 200 || response.StatusCode > 299 {
|
||||
return nil, fmt.Errorf("non-2xx status code: %d", response.StatusCode)
|
||||
}
|
||||
|
||||
if buf, err := io.ReadAll(response.Body); 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")
|
||||
}
|
||||
|
||||
func (c *Client) GetOuts(inputs ...uint64) ([]Output, error) {
|
||||
<-c.throttler
|
||||
|
||||
|
|
|
@ -6,11 +6,20 @@ import (
|
|||
"testing"
|
||||
)
|
||||
|
||||
func init() {
|
||||
func init() {
|
||||
SetDefaultClientSettings(os.Getenv("MONEROD_RPC_URL"))
|
||||
}
|
||||
|
||||
var txHash, _ = types.HashFromString("d9922a1d03160a16e4704b44dc0ed0e5dffc46db94ca86d6f10545132a0926a0")
|
||||
var txHashCoinbase, _ = types.HashFromString("dc18b8ad30e15b21c733032288ac0afa08ae51c972b4ee6546ad74aa77c39ebb")
|
||||
|
||||
func TestOutputIndexes(t *testing.T) {
|
||||
if result, err := GetDefaultClient().GetOutputIndexes(txHashCoinbase); err != nil {
|
||||
t.Fatal(err)
|
||||
} else {
|
||||
t.Log(result)
|
||||
}
|
||||
}
|
||||
|
||||
func TestInputs(t *testing.T) {
|
||||
if result, err := GetDefaultClient().GetTransactionInputs(txHash); err != nil {
|
||||
|
@ -18,7 +27,7 @@ func TestInputs(t *testing.T) {
|
|||
} else {
|
||||
t.Log(result)
|
||||
|
||||
inputs := make([]uint64, 0, len(result) * 16 * 128)
|
||||
inputs := make([]uint64, 0, len(result)*16*128)
|
||||
for _, i := range result[0].Inputs {
|
||||
inputs = append(inputs, i.KeyOffsets...)
|
||||
}
|
||||
|
@ -29,4 +38,4 @@ func TestInputs(t *testing.T) {
|
|||
t.Log(result2)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue