diff --git a/core/state/statedb.libevm.go b/core/state/statedb.libevm.go index 7db3d676e9..df758f01d6 100644 --- a/core/state/statedb.libevm.go +++ b/core/state/statedb.libevm.go @@ -24,6 +24,11 @@ import ( "github.com/ava-labs/libevm/libevm/stateconf" ) +// TxHash returns the current transaction hash set by [StateDB.SetTxContext]. +func (s *StateDB) TxHash() common.Hash { + return s.thash +} + // SnapshotTree mirrors the functionality of a [snapshot.Tree], allowing for // drop-in replacements. This is intended as a temporary feature as a workaround // until a standard Tree can be used. diff --git a/core/state/statedb.libevm_test.go b/core/state/statedb.libevm_test.go index 255f880e07..6b8285ee4f 100644 --- a/core/state/statedb.libevm_test.go +++ b/core/state/statedb.libevm_test.go @@ -36,6 +36,18 @@ import ( "github.com/ava-labs/libevm/triedb/hashdb" ) +func TestTxHash(t *testing.T) { + db := NewDatabase(rawdb.NewMemoryDatabase()) + state, err := New(types.EmptyRootHash, db, nil) + require.NoError(t, err) + + assert.Zero(t, state.TxHash(), "Tx hash should initially be uninitialized") + + hash := common.Hash{1} + state.SetTxContext(hash, 3) + assert.Equal(t, hash, state.TxHash(), "Tx hash should have been updated") +} + func TestStateDBCommitPropagatesOptions(t *testing.T) { memdb := rawdb.NewMemoryDatabase() trieRec := &triedbRecorder{Database: hashdb.New(memdb, nil, &trie.MerkleResolver{})}