Skip to content

Commit

Permalink
Merge pull request #97 from cloudstruct/feature/localtxsubmission-fai…
Browse files Browse the repository at this point in the history
…l-reason

feat: defer parsing localtxsubmission reject reason
  • Loading branch information
agaffney authored Sep 6, 2022
2 parents a1cea01 + 7be3038 commit 537bbcc
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
6 changes: 3 additions & 3 deletions cmd/go-ouroboros-network/localtxsubmission.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
4 changes: 2 additions & 2 deletions protocol/localtxsubmission/localtxsubmission.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
9 changes: 6 additions & 3 deletions protocol/localtxsubmission/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 537bbcc

Please sign in to comment.