Skip to content

Commit 52b4697

Browse files
authored
feat: support for decoding localstatequery queries (#813)
1 parent 70be436 commit 52b4697

File tree

4 files changed

+338
-11
lines changed

4 files changed

+338
-11
lines changed

protocol/localstatequery/localstatequery.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ type CallbackContext struct {
155155

156156
// Callback function types
157157
type AcquireFunc func(CallbackContext, AcquireTarget, bool) error
158-
type QueryFunc func(CallbackContext, any) (any, error)
158+
type QueryFunc func(CallbackContext, QueryWrapper) (any, error)
159159
type ReleaseFunc func(CallbackContext) error
160160

161161
// New returns a new LocalStateQuery object

protocol/localstatequery/messages.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,15 +154,17 @@ func NewMsgFailure(failure uint8) *MsgFailure {
154154

155155
type MsgQuery struct {
156156
protocol.MessageBase
157-
Query interface{}
157+
Query QueryWrapper
158158
}
159159

160160
func NewMsgQuery(query interface{}) *MsgQuery {
161161
m := &MsgQuery{
162162
MessageBase: protocol.MessageBase{
163163
MessageType: MessageTypeQuery,
164164
},
165-
Query: query,
165+
Query: QueryWrapper{
166+
Query: query,
167+
},
166168
}
167169
return m
168170
}

protocol/localstatequery/messages_test.go

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,12 @@ package localstatequery
1616

1717
import (
1818
"encoding/hex"
19+
"reflect"
20+
"testing"
21+
1922
"github.com/blinklabs-io/gouroboros/cbor"
2023
"github.com/blinklabs-io/gouroboros/protocol"
2124
"github.com/blinklabs-io/gouroboros/protocol/common"
22-
"reflect"
23-
"testing"
2425
)
2526

2627
type testDefinition struct {
@@ -49,12 +50,12 @@ var tests = []testDefinition{
4950
CborHex: "8203820082028101",
5051
Message: NewMsgQuery(
5152
// Current era hard-fork query
52-
[]interface{}{
53-
uint64(0),
54-
[]interface{}{
55-
uint64(2),
56-
[]interface{}{
57-
uint64(1),
53+
&BlockQuery{
54+
Query: &HardForkQuery{
55+
Query: &HardForkCurrentEraQuery{
56+
simpleQueryBase{
57+
Type: QueryTypeHardForkCurrentEra,
58+
},
5859
},
5960
},
6061
},
@@ -105,6 +106,9 @@ func TestDecode(t *testing.T) {
105106
}
106107
// Set the raw CBOR so the comparison should succeed
107108
test.Message.SetCbor(cborData)
109+
if m, ok := msg.(*MsgQuery); ok {
110+
m.Query.SetCbor(nil)
111+
}
108112
if !reflect.DeepEqual(msg, test.Message) {
109113
t.Fatalf(
110114
"CBOR did not decode to expected message object\n got: %#v\n wanted: %#v",

0 commit comments

Comments
 (0)