diff --git a/walletdb/bdb/db.go b/walletdb/bdb/db.go index 956a190..bf34e7a 100644 --- a/walletdb/bdb/db.go +++ b/walletdb/bdb/db.go @@ -99,6 +99,14 @@ func (tx *transaction) Rollback() error { return convertErr(tx.boltTx.Rollback()) } +// OnCommit takes a function closure that will be executed when the transaction +// successfully gets committed. +// +// This function is part of the walletdb.ReadWriteTx interface implementation. +func (tx *transaction) OnCommit(f func()) { + tx.boltTx.OnCommit(f) +} + // bucket is an internal type used to represent a collection of key/value pairs // and implements the walletdb Bucket interfaces. type bucket bbolt.Bucket @@ -214,6 +222,15 @@ func (b *bucket) ReadWriteCursor() walletdb.ReadWriteCursor { return (*cursor)((*bbolt.Bucket)(b).Cursor()) } +// Tx returns the bucket's transaction. +// +// This function is part of the walletdb.ReadWriteBucket interface implementation. +func (b *bucket) Tx() walletdb.ReadWriteTx { + return &transaction{ + (*bbolt.Bucket)(b).Tx(), + } +} + // cursor represents a cursor over key/value pairs and nested buckets of a // bucket. // diff --git a/walletdb/interface.go b/walletdb/interface.go index 754e08b..f89fa91 100644 --- a/walletdb/interface.go +++ b/walletdb/interface.go @@ -42,6 +42,10 @@ type ReadWriteTx interface { // Commit commits all changes that have been on the transaction's root // buckets and all of their sub-buckets to persistent storage. Commit() error + + // OnCommit takes a function closure that will be executed when the + // transaction successfully gets committed. + OnCommit(func()) } // ReadBucket represents a bucket (a hierarchical structure within the database) @@ -119,6 +123,9 @@ type ReadWriteBucket interface { // Cursor returns a new cursor, allowing for iteration over the bucket's // key/value pairs and nested buckets in forward or backward order. ReadWriteCursor() ReadWriteCursor + + // Tx returns the bucket's transaction. + Tx() ReadWriteTx } // ReadCursor represents a bucket cursor that can be positioned at the start or