Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use gouroboros tx hash #9

Merged
merged 1 commit into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -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=
Expand Down
26 changes: 12 additions & 14 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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())
}
Expand Down
Loading