mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-03-30 15:08:33 +00:00
[NOD-1507] Implement model.DBTransaction (#997)
This commit is contained in:
parent
ca9161024f
commit
4ab2e0d498
@ -27,7 +27,11 @@ func (dbw *dbManager) Cursor(bucket model.DBBucket) (model.DBCursor, error) {
|
||||
}
|
||||
|
||||
func (dbw *dbManager) Begin() (model.DBTransaction, error) {
|
||||
panic("unimplemented")
|
||||
transaction, err := dbw.db.Begin()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return newDBTransaction(transaction), nil
|
||||
}
|
||||
|
||||
// New returns wraps the given database as an instance of model.DBManager
|
||||
|
34
domain/consensus/database/transaction.go
Normal file
34
domain/consensus/database/transaction.go
Normal file
@ -0,0 +1,34 @@
|
||||
package database
|
||||
|
||||
import (
|
||||
"github.com/kaspanet/kaspad/domain/consensus/model"
|
||||
"github.com/kaspanet/kaspad/infrastructure/db/database"
|
||||
)
|
||||
|
||||
type dbTransaction struct {
|
||||
transaction database.Transaction
|
||||
}
|
||||
|
||||
func (d dbTransaction) Put(key model.DBKey, value []byte) error {
|
||||
return d.transaction.Put(dbKeyToDatabaseKey(key), value)
|
||||
}
|
||||
|
||||
func (d dbTransaction) Delete(key model.DBKey) error {
|
||||
return d.transaction.Delete(dbKeyToDatabaseKey(key))
|
||||
}
|
||||
|
||||
func (d dbTransaction) Rollback() error {
|
||||
return d.transaction.Rollback()
|
||||
}
|
||||
|
||||
func (d dbTransaction) Commit() error {
|
||||
return d.Commit()
|
||||
}
|
||||
|
||||
func (d dbTransaction) RollbackUnlessClosed() error {
|
||||
return d.RollbackUnlessClosed()
|
||||
}
|
||||
|
||||
func newDBTransaction(transaction database.Transaction) model.DBTransaction {
|
||||
return &dbTransaction{transaction: transaction}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user