diff --git a/go.mod b/go.mod index 455e54d..484dd40 100644 --- a/go.mod +++ b/go.mod @@ -3,11 +3,10 @@ module github.com/blinklabs-io/txtop go 1.20 require ( - github.com/blinklabs-io/gouroboros v0.54.0 + github.com/blinklabs-io/gouroboros v0.55.0 github.com/gdamore/tcell/v2 v2.6.0 github.com/kelseyhightower/envconfig v1.4.0 github.com/rivo/tview v0.0.0-20230928053139-9bc1d28d88a9 - golang.org/x/crypto v0.14.0 ) require ( @@ -18,6 +17,7 @@ require ( github.com/mattn/go-runewidth v0.0.14 // indirect github.com/rivo/uniseg v0.4.3 // indirect github.com/x448/float16 v0.8.4 // indirect + golang.org/x/crypto v0.14.0 // indirect golang.org/x/sys v0.13.0 // indirect golang.org/x/term v0.13.0 // indirect golang.org/x/text v0.13.0 // indirect diff --git a/go.sum b/go.sum index 0d69293..b74af58 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,5 @@ -github.com/blinklabs-io/gouroboros v0.54.0 h1:ZRp+L7Xb2wRn3N02a7EQ8jpBfqL6FKjnpauJdCiHEqE= -github.com/blinklabs-io/gouroboros v0.54.0/go.mod h1:ID2Lq1XtYrBvmk/y+yQiX45sZiV8n+urOmT0s46d2+U= +github.com/blinklabs-io/gouroboros v0.55.0 h1:Sdjy8WwaeiVdnBys+xxYkUEWgNMN0QztlgOkFVzdNQU= +github.com/blinklabs-io/gouroboros v0.55.0/go.mod h1:D5YJka8EyVmiXNMbRvjH23H9lNMLA4+qSlNNC/j7R0k= github.com/fxamacker/cbor/v2 v2.5.0 h1:oHsG0V/Q6E/wqTS2O1Cozzsy69nqCiguo5Q1a1ADivE= github.com/fxamacker/cbor/v2 v2.5.0/go.mod h1:TA1xS00nchWmaBnEIxPSE5oHLuJBAVvqrtAnWBwBCVo= github.com/gdamore/encoding v1.0.0 h1:+7OoQ1Bc6eTm5niUzBa0Ctsh6JbMW6Ra+YNuAtDBdko= diff --git a/main.go b/main.go index f103be7..d57a2fc 100644 --- a/main.go +++ b/main.go @@ -15,18 +15,16 @@ package main import ( - "encoding/hex" "fmt" "os" "strings" "time" ouroboros "github.com/blinklabs-io/gouroboros" - "github.com/blinklabs-io/gouroboros/cbor" + "github.com/blinklabs-io/gouroboros/ledger" "github.com/gdamore/tcell/v2" "github.com/kelseyhightower/envconfig" "github.com/rivo/tview" - "golang.org/x/crypto/blake2b" ) var globalConfig = &Config{ @@ -187,26 +185,26 @@ func GetTransactions(oConn *ouroboros.Connection) string { sb.WriteString(" [white]Transactions:\n") sb.WriteString(fmt.Sprintf(" [white]%-20s %s\n", "Size", "TxHash")) for { - tx, err := oConn.LocalTxMonitor().Client.NextTx() + txRawBytes, err := oConn.LocalTxMonitor().Client.NextTx() if err != nil { sb.WriteString(fmt.Sprintf(" [red]ERROR: NextTx: %s\n", err)) return fmt.Sprint(sb.String()) } - if tx == nil { + if txRawBytes == nil { break } - size := len(tx) - var txUnwrap []cbor.RawMessage - _, err = cbor.Decode(tx, &txUnwrap) + size := len(txRawBytes) + txType, err := ledger.DetermineTransactionType(txRawBytes) if err != nil { - sb.WriteString(fmt.Sprintf(" [red]ERROR: txUnwrap: %s", err)) + sb.WriteString(fmt.Sprintf(" [red]ERROR: TxType: %s\n", err)) return fmt.Sprint(sb.String()) } - txBody := txUnwrap[0] - txIdHash := blake2b.Sum256(txBody) - txIdHex := hex.EncodeToString(txIdHash[:]) - - sb.WriteString(fmt.Sprintf(" [white]%-20d [blue]%s[white]\n", size, txIdHex)) + tx, err := ledger.NewTransactionFromCbor(txType, txRawBytes) + if err != nil { + sb.WriteString(fmt.Sprintf(" [red]ERROR: Tx: %s\n", err)) + return fmt.Sprint(sb.String()) + } + sb.WriteString(fmt.Sprintf(" [white]%-20d [blue]%s[white]\n", size, tx.Hash())) } return fmt.Sprint(sb.String()) }