mirror of
https://github.com/LBRYFoundation/lbcwallet.git
synced 2025-08-23 17:47:29 +00:00
wallet: use walletdb.Update in FundPsbt
To make sure we don't create any manual DB transactions, we refactor FundPsbt to use walletdb.Update instead.
This commit is contained in:
parent
60a04006d6
commit
33a0a065f9
1 changed files with 20 additions and 25 deletions
|
@ -186,33 +186,28 @@ func (w *Wallet) FundPsbt(packet *psbt.Packet, keyScope *waddrmgr.KeyScope,
|
||||||
inputSource := constantInputSource(credits)
|
inputSource := constantInputSource(credits)
|
||||||
|
|
||||||
// We also need a change source which needs to be able to insert
|
// We also need a change source which needs to be able to insert
|
||||||
// a new change addresse into the database.
|
// a new change address into the database.
|
||||||
dbtx, err := w.db.BeginReadWriteTx()
|
err = walletdb.Update(w.db, func(dbtx walletdb.ReadWriteTx) error {
|
||||||
if err != nil {
|
_, changeSource, err := w.addrMgrWithChangeSource(
|
||||||
return 0, err
|
dbtx, keyScope, account,
|
||||||
}
|
)
|
||||||
_, changeSource, err := w.addrMgrWithChangeSource(
|
if err != nil {
|
||||||
dbtx, keyScope, account,
|
return err
|
||||||
)
|
}
|
||||||
if err != nil {
|
|
||||||
return 0, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// Ask the txauthor to create a transaction with our selected
|
// Ask the txauthor to create a transaction with our
|
||||||
// coins. This will perform fee estimation and add a change
|
// selected coins. This will perform fee estimation and
|
||||||
// output if necessary.
|
// add a change output if necessary.
|
||||||
tx, err = txauthor.NewUnsignedTransaction(
|
tx, err = txauthor.NewUnsignedTransaction(
|
||||||
txOut, feeSatPerKB, inputSource, changeSource,
|
txOut, feeSatPerKB, inputSource, changeSource,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
_ = dbtx.Rollback()
|
return fmt.Errorf("fee estimation not "+
|
||||||
return 0, fmt.Errorf("fee estimation not successful: "+
|
"successful: %v", err)
|
||||||
"%v", err)
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// The transaction could be created, let's commit the DB TX to
|
return nil
|
||||||
// store the change address (if one was created).
|
})
|
||||||
err = dbtx.Commit()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, fmt.Errorf("could not add change address to "+
|
return 0, fmt.Errorf("could not add change address to "+
|
||||||
"database: %v", err)
|
"database: %v", err)
|
||||||
|
|
Loading…
Add table
Reference in a new issue