bump binary to fix instruction decoding
This commit is contained in:
parent
68f8c70fc2
commit
2f2a32f497
2
go.mod
2
go.mod
|
@ -4,7 +4,7 @@ go 1.14
|
|||
|
||||
require (
|
||||
github.com/GeertJohan/go.rice v1.0.0
|
||||
github.com/dfuse-io/binary v0.0.0-20201117130902-7df96997b0a8
|
||||
github.com/dfuse-io/binary v0.0.0-20201117201711-8656308cf309
|
||||
github.com/dfuse-io/logging v0.0.0-20201110202154-26697de88c79
|
||||
github.com/google/go-cmp v0.4.1 // indirect
|
||||
github.com/gorilla/rpc v1.2.0
|
||||
|
|
2
go.sum
2
go.sum
|
@ -50,6 +50,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
|
|||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/dfuse-io/binary v0.0.0-20201117130902-7df96997b0a8 h1:/bHa8o+/kXoQU4VBLPm+Pe8aR+UPotIqzh3UVNi11cA=
|
||||
github.com/dfuse-io/binary v0.0.0-20201117130902-7df96997b0a8/go.mod h1:GDFX6qH3BQZPWTeYaA4ZW98T94zs2skRoG3oMz/0jw0=
|
||||
github.com/dfuse-io/binary v0.0.0-20201117201711-8656308cf309 h1:GO2JfJeCROHoV48h+1ioDCTW2sqeu7exi3cZrzIak+g=
|
||||
github.com/dfuse-io/binary v0.0.0-20201117201711-8656308cf309/go.mod h1:GDFX6qH3BQZPWTeYaA4ZW98T94zs2skRoG3oMz/0jw0=
|
||||
github.com/dfuse-io/logging v0.0.0-20201110202154-26697de88c79 h1:+HRtcJejUYA/2rnyTMbOaZ4g7f4aVuFduTV/03dbpLY=
|
||||
github.com/dfuse-io/logging v0.0.0-20201110202154-26697de88c79/go.mod h1:V+ED4kT/t/lKtH99JQmKIb0v9WL3VaYkJ36CfHlVECI=
|
||||
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
|
||||
|
|
|
@ -21,9 +21,9 @@ func registryDecodeInstruction(accounts []solana.PublicKey, rawInstruction *sola
|
|||
return inst, nil
|
||||
}
|
||||
|
||||
func DecodeInstruction(accounts []solana.PublicKey, rawInstruction *solana.CompiledInstruction) (*Instruction, error) {
|
||||
func DecodeInstruction(accounts []solana.PublicKey, compiledInstruction *solana.CompiledInstruction) (*Instruction, error) {
|
||||
var inst *Instruction
|
||||
if err := bin.NewDecoder(rawInstruction.Data).Decode(&inst); err != nil {
|
||||
if err := bin.NewDecoder(compiledInstruction.Data).Decode(&inst); err != nil {
|
||||
return nil, fmt.Errorf("unable to decode instruction for serum program: %w", err)
|
||||
}
|
||||
|
||||
|
@ -165,7 +165,7 @@ type MatchOrderAccounts struct {
|
|||
type InstructionMatchOrder struct {
|
||||
Limit uint16
|
||||
|
||||
Accounts *MatchOrderAccounts `bin="-"`
|
||||
Accounts *MatchOrderAccounts `bin:"-"`
|
||||
}
|
||||
|
||||
func (i *InstructionMatchOrder) setAccounts(accounts []solana.PublicKey) error {
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
package serum
|
||||
|
||||
import (
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
bin "github.com/dfuse-io/binary"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestDecodeInstruction(t *testing.T) {
|
||||
x := `00020000000500`
|
||||
data, err := hex.DecodeString(x)
|
||||
require.NoError(t, err)
|
||||
var instruction *Instruction
|
||||
err = bin.NewDecoder(data).Decode(&instruction)
|
||||
require.NoError(t, err)
|
||||
fmt.Println(instruction)
|
||||
}
|
|
@ -239,14 +239,14 @@ func (q *EventQueue) Decode(data []byte) error {
|
|||
return fmt.Errorf("event queue: decode header: %w", err)
|
||||
}
|
||||
|
||||
remainingData := decoder.Remaining()
|
||||
if remainingData%EventDataLength != 0 {
|
||||
return fmt.Errorf("event queue: wrong event data length %d", remainingData)
|
||||
}
|
||||
//remainingData := decoder.Remaining()
|
||||
//if remainingData%EventDataLength != 0 {
|
||||
// return fmt.Errorf("event queue: wrong event data length %d", remainingData)
|
||||
//}
|
||||
//
|
||||
//eventCount := remainingData / EventDataLength
|
||||
|
||||
eventCount := remainingData / EventDataLength
|
||||
|
||||
for i := 0; i < eventCount; i++ {
|
||||
for decoder.Remaining() >= 88 {
|
||||
var e *Event
|
||||
err = decoder.Decode(&e)
|
||||
if err != nil {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package serum
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/base64"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
|
@ -8,6 +9,8 @@ import (
|
|||
"io/ioutil"
|
||||
"testing"
|
||||
|
||||
"github.com/dfuse-io/solana-go/rpc"
|
||||
|
||||
bin "github.com/dfuse-io/binary"
|
||||
"github.com/dfuse-io/solana-go"
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
@ -29,19 +32,27 @@ func TestDecoder_Market(t *testing.T) {
|
|||
}
|
||||
func TestDecoder_Event(t *testing.T) {
|
||||
|
||||
b64 := `c2VydW0RAAAAAAAAAKMoAAAAAAAAAAAAAAAAAAAD+gUAAAAAAAYJAAAAAAAAP9MRAAAAAACwUAY6AAAAAAAAAAAAAAAA/Af4//////8aBQAAAAAAAJGeNN64UdRK+szEsGLeTBiPnrTkfJaOEzsacSpRiAYs6zimHOimKK8CAQAAAAAAAEC6CycAAAAAAAAAAAAAAAAAAAAAAAAAAP/3BwAAAAAAIAUAAAAAAACRnjTeuFHUSvrMxLBi3kwYj5605HyWjhM7GnEqUYgGLH2wFQ01ceby`
|
||||
//b64 := `c2VydW0RAAAAAAAAAKMoAAAAAAAAAAAAAAAAAAAD+gUAAAAAAAYJAAAAAAAAP9MRAAAAAACwUAY6AAAAAAAAAAAAAAAA/Af4//////8aBQAAAAAAAJGeNN64UdRK+szEsGLeTBiPnrTkfJaOEzsacSpRiAYs6zimHOimKK8CAQAAAAAAAEC6CycAAAAAAAAAAAAAAAAAAAAAAAAAAP/3BwAAAAAAIAUAAAAAAACRnjTeuFHUSvrMxLBi3kwYj5605HyWjhM7GnEqUYgGLH2wFQ01ceby`
|
||||
|
||||
q := &EventQueue{}
|
||||
err := q.DecodeFromBase64(b64)
|
||||
client := rpc.NewClient("http://api.mainnet-beta.solana.com:80/rpc")
|
||||
info, err := client.GetAccountInfo(context.Background(), solana.MustPublicKeyFromBase58("13iGJcA4w5hcJZDjJbJQor1zUiDLE4jv2rMW9HkD5Eo1"))
|
||||
require.NoError(t, err)
|
||||
|
||||
q := &EventQueue{}
|
||||
err = q.Decode(info.Value.Data)
|
||||
require.NoError(t, err)
|
||||
|
||||
fmt.Println("data length:", len(info.Value.Data))
|
||||
fmt.Println("serum?:", string(q.Header.Serum[:]))
|
||||
for _, e := range q.Events {
|
||||
fmt.Println("Type:", e.Flag)
|
||||
fmt.Println("Side:", e.Side())
|
||||
fmt.Println("Filled:", e.Filled())
|
||||
fmt.Println("event owner:", e.Owner)
|
||||
}
|
||||
fmt.Println("count:", q.Header.Count)
|
||||
fmt.Println("seq", q.Header.SeqNum)
|
||||
fmt.Println("events", len(q.Events))
|
||||
//for _, e := range q.Events {
|
||||
// fmt.Println("Type:", e.Flag)
|
||||
// fmt.Println("Side:", e.Side())
|
||||
// fmt.Println("Filled:", e.Filled())
|
||||
// fmt.Println("event owner:", e.Owner)
|
||||
//}
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue