diff --git a/chains/txmgr/types/tx.go b/chains/txmgr/types/tx.go index e87ae6b..98e39e8 100644 --- a/chains/txmgr/types/tx.go +++ b/chains/txmgr/types/tx.go @@ -188,8 +188,8 @@ type TxAttempt[ IsPurgeAttempt bool } -func (a *TxAttempt[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, SEQ, FEE]) String() string { - return fmt.Sprintf("TxAttempt(ID:%d,TxID:%d,Fee:%s,TxType:%d", a.ID, a.TxID, a.TxFee, a.TxType) +func (a TxAttempt[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, SEQ, FEE]) String() string { + return fmt.Sprintf("TxAttempt(ID:%d,TxID:%d,Fee:%s,TxType:%d,CreatedAt:%s)", a.ID, a.TxID, a.TxFee, a.TxType, a.CreatedAt.Format(time.RFC3339)) } type Tx[ diff --git a/chains/txmgr/types/tx_test.go b/chains/txmgr/types/tx_test.go index b945017..9201f51 100644 --- a/chains/txmgr/types/tx_test.go +++ b/chains/txmgr/types/tx_test.go @@ -2,6 +2,7 @@ package types import ( "fmt" + "math/big" "testing" "github.com/stretchr/testify/assert" @@ -48,3 +49,21 @@ func TestTxAttemptState(t *testing.T) { } }) } + +func TestTxLogging(t *testing.T) { + tx := Tx[*big.Int, *big.Int, *big.Int, *big.Int, *big.Int, *big.Int]{ + ID: 1, + TxAttempts: []TxAttempt[*big.Int, *big.Int, *big.Int, *big.Int, *big.Int, *big.Int]{ + { + ID: 2, + }, + }, + } + + attempt := &tx.TxAttempts[0] + // set recursive reference + attempt.Tx = tx + // ensure that in both cases we prevent fmt from stacking in a loop attempt->tx->attempt by defining String method on attempt. + println(fmt.Sprintf("%+v", *attempt)) + println(fmt.Sprintf("%+v", attempt)) +}