bump binary to fix instruction decoding

This commit is contained in:
billettc 2020-11-17 15:18:39 -05:00
parent 68f8c70fc2
commit 2f2a32f497
6 changed files with 53 additions and 20 deletions

2
go.mod
View File

@ -4,7 +4,7 @@ go 1.14
require ( require (
github.com/GeertJohan/go.rice v1.0.0 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/dfuse-io/logging v0.0.0-20201110202154-26697de88c79
github.com/google/go-cmp v0.4.1 // indirect github.com/google/go-cmp v0.4.1 // indirect
github.com/gorilla/rpc v1.2.0 github.com/gorilla/rpc v1.2.0

2
go.sum
View File

@ -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/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 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-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 h1:+HRtcJejUYA/2rnyTMbOaZ4g7f4aVuFduTV/03dbpLY=
github.com/dfuse-io/logging v0.0.0-20201110202154-26697de88c79/go.mod h1:V+ED4kT/t/lKtH99JQmKIb0v9WL3VaYkJ36CfHlVECI= 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= github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=

View File

@ -21,9 +21,9 @@ func registryDecodeInstruction(accounts []solana.PublicKey, rawInstruction *sola
return inst, nil 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 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) return nil, fmt.Errorf("unable to decode instruction for serum program: %w", err)
} }
@ -165,7 +165,7 @@ type MatchOrderAccounts struct {
type InstructionMatchOrder struct { type InstructionMatchOrder struct {
Limit uint16 Limit uint16
Accounts *MatchOrderAccounts `bin="-"` Accounts *MatchOrderAccounts `bin:"-"`
} }
func (i *InstructionMatchOrder) setAccounts(accounts []solana.PublicKey) error { func (i *InstructionMatchOrder) setAccounts(accounts []solana.PublicKey) error {

20
serum/instruction_test.go Normal file
View File

@ -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)
}

View File

@ -239,14 +239,14 @@ func (q *EventQueue) Decode(data []byte) error {
return fmt.Errorf("event queue: decode header: %w", err) return fmt.Errorf("event queue: decode header: %w", err)
} }
remainingData := decoder.Remaining() //remainingData := decoder.Remaining()
if remainingData%EventDataLength != 0 { //if remainingData%EventDataLength != 0 {
return fmt.Errorf("event queue: wrong event data length %d", remainingData) // return fmt.Errorf("event queue: wrong event data length %d", remainingData)
} //}
//
//eventCount := remainingData / EventDataLength
eventCount := remainingData / EventDataLength for decoder.Remaining() >= 88 {
for i := 0; i < eventCount; i++ {
var e *Event var e *Event
err = decoder.Decode(&e) err = decoder.Decode(&e)
if err != nil { if err != nil {

View File

@ -1,6 +1,7 @@
package serum package serum
import ( import (
"context"
"encoding/base64" "encoding/base64"
"encoding/hex" "encoding/hex"
"encoding/json" "encoding/json"
@ -8,6 +9,8 @@ import (
"io/ioutil" "io/ioutil"
"testing" "testing"
"github.com/dfuse-io/solana-go/rpc"
bin "github.com/dfuse-io/binary" bin "github.com/dfuse-io/binary"
"github.com/dfuse-io/solana-go" "github.com/dfuse-io/solana-go"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
@ -29,19 +32,27 @@ func TestDecoder_Market(t *testing.T) {
} }
func TestDecoder_Event(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{} client := rpc.NewClient("http://api.mainnet-beta.solana.com:80/rpc")
err := q.DecodeFromBase64(b64) info, err := client.GetAccountInfo(context.Background(), solana.MustPublicKeyFromBase58("13iGJcA4w5hcJZDjJbJQor1zUiDLE4jv2rMW9HkD5Eo1"))
require.NoError(t, err) 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[:])) fmt.Println("serum?:", string(q.Header.Serum[:]))
for _, e := range q.Events { fmt.Println("count:", q.Header.Count)
fmt.Println("Type:", e.Flag) fmt.Println("seq", q.Header.SeqNum)
fmt.Println("Side:", e.Side()) fmt.Println("events", len(q.Events))
fmt.Println("Filled:", e.Filled()) //for _, e := range q.Events {
fmt.Println("event owner:", e.Owner) // fmt.Println("Type:", e.Flag)
} // fmt.Println("Side:", e.Side())
// fmt.Println("Filled:", e.Filled())
// fmt.Println("event owner:", e.Owner)
//}
} }