Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion protocol/localstatequery/localstatequery.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ type CallbackContext struct {

// Callback function types
type AcquireFunc func(CallbackContext, AcquireTarget, bool) error
type QueryFunc func(CallbackContext, any) (any, error)
type QueryFunc func(CallbackContext, QueryWrapper) (any, error)
type ReleaseFunc func(CallbackContext) error

// New returns a new LocalStateQuery object
Expand Down
6 changes: 4 additions & 2 deletions protocol/localstatequery/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,15 +154,17 @@ func NewMsgFailure(failure uint8) *MsgFailure {

type MsgQuery struct {
protocol.MessageBase
Query interface{}
Query QueryWrapper
}

func NewMsgQuery(query interface{}) *MsgQuery {
m := &MsgQuery{
MessageBase: protocol.MessageBase{
MessageType: MessageTypeQuery,
},
Query: query,
Query: QueryWrapper{
Query: query,
},
}
return m
}
Expand Down
20 changes: 12 additions & 8 deletions protocol/localstatequery/messages_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ package localstatequery

import (
"encoding/hex"
"reflect"
"testing"

"github.com/blinklabs-io/gouroboros/cbor"
"github.com/blinklabs-io/gouroboros/protocol"
"github.com/blinklabs-io/gouroboros/protocol/common"
"reflect"
"testing"
)

type testDefinition struct {
Expand Down Expand Up @@ -49,12 +50,12 @@ var tests = []testDefinition{
CborHex: "8203820082028101",
Message: NewMsgQuery(
// Current era hard-fork query
[]interface{}{
uint64(0),
[]interface{}{
uint64(2),
[]interface{}{
uint64(1),
&BlockQuery{
Query: &HardForkQuery{
Query: &HardForkCurrentEraQuery{
simpleQueryBase{
Type: QueryTypeHardForkCurrentEra,
},
},
},
},
Expand Down Expand Up @@ -105,6 +106,9 @@ func TestDecode(t *testing.T) {
}
// Set the raw CBOR so the comparison should succeed
test.Message.SetCbor(cborData)
if m, ok := msg.(*MsgQuery); ok {
m.Query.SetCbor(nil)
}
if !reflect.DeepEqual(msg, test.Message) {
t.Fatalf(
"CBOR did not decode to expected message object\n got: %#v\n wanted: %#v",
Expand Down
Loading
Loading