Skip to content

Commit 41f006b

Browse files
authored
Merge pull request #141 from cloudstruct/feat/parse-tx-reject-reasons
feat: support for parsing TX reject reason CBOR
2 parents ea63d42 + d131d1c commit 41f006b

File tree

5 files changed

+18
-8
lines changed

5 files changed

+18
-8
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module github.com/cloudstruct/go-ouroboros-network
33
go 1.17
44

55
require (
6-
github.com/cloudstruct/go-cardano-ledger v0.1.0
6+
github.com/cloudstruct/go-cardano-ledger v0.4.0
77
github.com/fxamacker/cbor/v2 v2.4.0
88
)
99

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
github.com/cloudstruct/go-cardano-ledger v0.1.0 h1:HUyXl00je5aexGyrsZJ6D1gMUs0gIic8FVbQwlF6v3M=
2-
github.com/cloudstruct/go-cardano-ledger v0.1.0/go.mod h1:EBB9JG+3nBs3IV0p751yz1468XYkzJce1/A2X+xH8L8=
1+
github.com/cloudstruct/go-cardano-ledger v0.4.0 h1:4BZvwZSM82r/Bt+W4XHTstJEABg0jXcougcZgDmZBo0=
2+
github.com/cloudstruct/go-cardano-ledger v0.4.0/go.mod h1:EBB9JG+3nBs3IV0p751yz1468XYkzJce1/A2X+xH8L8=
33
github.com/fxamacker/cbor/v2 v2.4.0 h1:ri0ArlOR+5XunOP8CRUowT0pSJOwhW098ZCUyskZD88=
44
github.com/fxamacker/cbor/v2 v2.4.0/go.mod h1:TA1xS00nchWmaBnEIxPSE5oHLuJBAVvqrtAnWBwBCVo=
55
github.com/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM=

protocol/localtxsubmission/client.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package localtxsubmission
22

33
import (
44
"fmt"
5+
"github.com/cloudstruct/go-cardano-ledger"
56
"github.com/cloudstruct/go-ouroboros-network/protocol"
67
"sync"
78
)
@@ -75,7 +76,12 @@ func (c *Client) handleAcceptTx() error {
7576

7677
func (c *Client) handleRejectTx(msg protocol.Message) error {
7778
msgRejectTx := msg.(*MsgRejectTx)
78-
err := TransactionRejectedError{
79+
rejectErr, err := ledger.NewTxSubmitErrorFromCbor(msgRejectTx.Reason)
80+
if err != nil {
81+
return err
82+
}
83+
err = TransactionRejectedError{
84+
Reason: rejectErr,
7985
ReasonCbor: []byte(msgRejectTx.Reason),
8086
}
8187
c.submitResultChan <- err

protocol/localtxsubmission/error.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,13 @@ import (
66

77
type TransactionRejectedError struct {
88
ReasonCbor []byte
9+
Reason error
910
}
1011

1112
func (e TransactionRejectedError) Error() string {
12-
return fmt.Sprintf("transaction rejected: CBOR reason hex: %x", e.ReasonCbor)
13+
if e.Reason != nil {
14+
return e.Reason.Error()
15+
} else {
16+
return fmt.Sprintf("transaction rejected: CBOR reason hex: %x", e.ReasonCbor)
17+
}
1318
}

protocol/localtxsubmission/messages.go

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

8181
type MsgRejectTx struct {
8282
protocol.MessageBase
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
83+
// We use RawMessage here because the failure reason can be numerous different
84+
// structures, and we'll need to do further processing
8685
Reason cbor.RawMessage
8786
}
8887

0 commit comments

Comments
 (0)