From 7be3038d2c91e76e7c3597fffe82208a5d62e6f3 Mon Sep 17 00:00:00 2001 From: Andrew Gaffney Date: Tue, 6 Sep 2022 15:18:51 -0500 Subject: [PATCH] feat: defer parsing localtxsubmission reject reason Fixes #85 --- cmd/go-ouroboros-network/localtxsubmission.go | 6 +++--- protocol/localtxsubmission/localtxsubmission.go | 4 ++-- protocol/localtxsubmission/messages.go | 9 ++++++--- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/cmd/go-ouroboros-network/localtxsubmission.go b/cmd/go-ouroboros-network/localtxsubmission.go index d8753cc4..f57bd840 100644 --- a/cmd/go-ouroboros-network/localtxsubmission.go +++ b/cmd/go-ouroboros-network/localtxsubmission.go @@ -5,8 +5,8 @@ import ( "encoding/json" "flag" "fmt" - ouroboros "github.com/cloudstruct/go-ouroboros-network" "github.com/cloudstruct/go-cardano-ledger" + ouroboros "github.com/cloudstruct/go-ouroboros-network" "github.com/cloudstruct/go-ouroboros-network/protocol/localtxsubmission" "io/ioutil" "os" @@ -105,8 +105,8 @@ func localTxSubmissionAcceptTxHandler() error { return nil } -func localTxSubmissionRejectTxHandler(reason interface{}) error { - fmt.Printf("The transaction was rejected: %#v\n", reason) +func localTxSubmissionRejectTxHandler(reasonCbor []byte) error { + fmt.Printf("The transaction was rejected (reason in hex-encoded CBOR): %#v\n", reasonCbor) os.Exit(1) return nil } diff --git a/protocol/localtxsubmission/localtxsubmission.go b/protocol/localtxsubmission/localtxsubmission.go index bfb7b716..0c4b7e29 100644 --- a/protocol/localtxsubmission/localtxsubmission.go +++ b/protocol/localtxsubmission/localtxsubmission.go @@ -59,7 +59,7 @@ type CallbackConfig struct { // Callback function types type SubmitTxFunc func(interface{}) error type AcceptTxFunc func() error -type RejectTxFunc func(interface{}) error +type RejectTxFunc func([]byte) error type DoneFunc func() error func New(options protocol.ProtocolOptions) *LocalTxSubmission { @@ -135,7 +135,7 @@ func (l *LocalTxSubmission) handleRejectTx(msgGeneric protocol.Message) error { } msg := msgGeneric.(*MsgRejectTx) // Call the user callback function - return l.callbackConfig.RejectTxFunc(msg.Reason) + return l.callbackConfig.RejectTxFunc([]byte(msg.Reason)) } func (l *LocalTxSubmission) handleDone() error { diff --git a/protocol/localtxsubmission/messages.go b/protocol/localtxsubmission/messages.go index 3360099f..893ee14e 100644 --- a/protocol/localtxsubmission/messages.go +++ b/protocol/localtxsubmission/messages.go @@ -80,15 +80,18 @@ func NewMsgAcceptTx() *MsgAcceptTx { type MsgRejectTx struct { protocol.MessageBase - Reason interface{} + // TODO: find a better way to handle this + // We use RawMessage here because the failure reason can often contain + // structures that we can't currently parse, such as maps with []uint8 keys + Reason cbor.RawMessage } -func NewMsgRejectTx(reason interface{}) *MsgRejectTx { +func NewMsgRejectTx(reasonCbor []byte) *MsgRejectTx { m := &MsgRejectTx{ MessageBase: protocol.MessageBase{ MessageType: MESSAGE_TYPE_REJECT_TX, }, - Reason: reason, + Reason: cbor.RawMessage(reasonCbor), } return m }