@@ -22,11 +22,9 @@ import (
2222 "time"
2323
2424 ouroboros "github.com/blinklabs-io/gouroboros"
25- "github.com/blinklabs-io/gouroboros/cbor"
2625 "github.com/blinklabs-io/gouroboros/cmd/common"
26+ "github.com/blinklabs-io/gouroboros/ledger"
2727 "github.com/blinklabs-io/gouroboros/protocol/txsubmission"
28-
29- "golang.org/x/crypto/blake2b"
3028)
3129
3230type txSubmissionFlags struct {
@@ -117,19 +115,17 @@ func main() {
117115 os .Exit (1 )
118116 }
119117
120- // Generate TX hash
121- // Unwrap raw transaction bytes into a CBOR array
122- var txUnwrap []cbor.RawMessage
123- if _ , err := cbor .Decode (txBytes , & txUnwrap ); err != nil {
124- fmt .Printf ("ERROR: failed to unwrap transaction CBOR: %s" , err )
118+ // convert to tx
119+ txType , err := ledger .DetermineTransactionType (txBytes )
120+ if err != nil {
121+ fmt .Printf ("ERROR: could not parse transaction to determine type: %s" , err )
122+ os .Exit (1 )
123+ }
124+ tx , err := ledger .NewTransactionFromCbor (txType , txBytes )
125+ if err != nil {
126+ fmt .Printf ("failed to parse transaction CBOR: %s" , err )
125127 os .Exit (1 )
126128 }
127- // index 0 is the transaction body
128- // Store index 0 (transaction body) as byte array
129- txBody := txUnwrap [0 ]
130-
131- // Convert the body into a blake2b256 hash string
132- txHash = blake2b .Sum256 (txBody )
133129
134130 // Create our "done" channel
135131 doneChan = make (chan any )
@@ -140,7 +136,7 @@ func main() {
140136 // Wait until we're done
141137 <- doneChan
142138
143- fmt .Printf ("Successfully sent transaction %x\n " , txHash )
139+ fmt .Printf ("Successfully sent transaction %x\n " , tx . Hash () )
144140
145141 if err := o .Close (); err != nil {
146142 fmt .Printf ("ERROR: failed to close connection: %s\n " , err )
0 commit comments