Skip to content

Commit 7be3038

Browse files
committed
feat: defer parsing localtxsubmission reject reason
Fixes #85
1 parent a1cea01 commit 7be3038

File tree

3 files changed

+11
-8
lines changed

3 files changed

+11
-8
lines changed

cmd/go-ouroboros-network/localtxsubmission.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import (
55
"encoding/json"
66
"flag"
77
"fmt"
8-
ouroboros "github.com/cloudstruct/go-ouroboros-network"
98
"github.com/cloudstruct/go-cardano-ledger"
9+
ouroboros "github.com/cloudstruct/go-ouroboros-network"
1010
"github.com/cloudstruct/go-ouroboros-network/protocol/localtxsubmission"
1111
"io/ioutil"
1212
"os"
@@ -105,8 +105,8 @@ func localTxSubmissionAcceptTxHandler() error {
105105
return nil
106106
}
107107

108-
func localTxSubmissionRejectTxHandler(reason interface{}) error {
109-
fmt.Printf("The transaction was rejected: %#v\n", reason)
108+
func localTxSubmissionRejectTxHandler(reasonCbor []byte) error {
109+
fmt.Printf("The transaction was rejected (reason in hex-encoded CBOR): %#v\n", reasonCbor)
110110
os.Exit(1)
111111
return nil
112112
}

protocol/localtxsubmission/localtxsubmission.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ type CallbackConfig struct {
5959
// Callback function types
6060
type SubmitTxFunc func(interface{}) error
6161
type AcceptTxFunc func() error
62-
type RejectTxFunc func(interface{}) error
62+
type RejectTxFunc func([]byte) error
6363
type DoneFunc func() error
6464

6565
func New(options protocol.ProtocolOptions) *LocalTxSubmission {
@@ -135,7 +135,7 @@ func (l *LocalTxSubmission) handleRejectTx(msgGeneric protocol.Message) error {
135135
}
136136
msg := msgGeneric.(*MsgRejectTx)
137137
// Call the user callback function
138-
return l.callbackConfig.RejectTxFunc(msg.Reason)
138+
return l.callbackConfig.RejectTxFunc([]byte(msg.Reason))
139139
}
140140

141141
func (l *LocalTxSubmission) handleDone() error {

protocol/localtxsubmission/messages.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,18 @@ func NewMsgAcceptTx() *MsgAcceptTx {
8080

8181
type MsgRejectTx struct {
8282
protocol.MessageBase
83-
Reason interface{}
83+
// TODO: find a better way to handle this
84+
// We use RawMessage here because the failure reason can often contain
85+
// structures that we can't currently parse, such as maps with []uint8 keys
86+
Reason cbor.RawMessage
8487
}
8588

86-
func NewMsgRejectTx(reason interface{}) *MsgRejectTx {
89+
func NewMsgRejectTx(reasonCbor []byte) *MsgRejectTx {
8790
m := &MsgRejectTx{
8891
MessageBase: protocol.MessageBase{
8992
MessageType: MESSAGE_TYPE_REJECT_TX,
9093
},
91-
Reason: reason,
94+
Reason: cbor.RawMessage(reasonCbor),
9295
}
9396
return m
9497
}

0 commit comments

Comments
 (0)