wallet: add label to PublishTransaction

All label parameter to PublishTransaction. Pass in an empty string
in rpc call as a placeholder for follow up PR which will add a label
parameter to the PublishTransaction request.
This commit is contained in:
carla 2020-04-30 09:08:11 +02:00
parent 50869085eb
commit d2f9185f6a
No known key found for this signature in database
GPG key ID: 4CA7FE54A6213C91
2 changed files with 20 additions and 6 deletions

View file

@ -519,7 +519,7 @@ func (s *walletServer) PublishTransaction(ctx context.Context, req *pb.PublishTr
"Bytes do not represent a valid raw transaction: %v", err)
}
err = s.wallet.PublishTransaction(&msgTx)
err = s.wallet.PublishTransaction(&msgTx, "")
if err != nil {
return nil, translateError(err)
}

View file

@ -3118,7 +3118,7 @@ func (w *Wallet) SendOutputs(outputs []*wire.TxOut, account uint32,
return nil, err
}
txHash, err := w.reliablyPublishTransaction(createdTx.Tx)
txHash, err := w.reliablyPublishTransaction(createdTx.Tx, "")
if err != nil {
return nil, err
}
@ -3311,8 +3311,8 @@ func (e *ErrReplacement) Unwrap() error {
//
// This function is unstable and will be removed once syncing code is moved out
// of the wallet.
func (w *Wallet) PublishTransaction(tx *wire.MsgTx) error {
_, err := w.reliablyPublishTransaction(tx)
func (w *Wallet) PublishTransaction(tx *wire.MsgTx, label string) error {
_, err := w.reliablyPublishTransaction(tx, label)
return err
}
@ -3321,7 +3321,9 @@ func (w *Wallet) PublishTransaction(tx *wire.MsgTx) error {
// relevant database state, and finally possible removing the transaction from
// the database (along with cleaning up all inputs used, and outputs created) if
// the transaction is rejected by the backend.
func (w *Wallet) reliablyPublishTransaction(tx *wire.MsgTx) (*chainhash.Hash, error) {
func (w *Wallet) reliablyPublishTransaction(tx *wire.MsgTx,
label string) (*chainhash.Hash, error) {
chainClient, err := w.requireChainClient()
if err != nil {
return nil, err
@ -3336,7 +3338,19 @@ func (w *Wallet) reliablyPublishTransaction(tx *wire.MsgTx) (*chainhash.Hash, er
return nil, err
}
err = walletdb.Update(w.db, func(dbTx walletdb.ReadWriteTx) error {
return w.addRelevantTx(dbTx, txRec, nil)
if err := w.addRelevantTx(dbTx, txRec, nil); err != nil {
return err
}
// If the tx label is empty, we can return early.
if len(label) == 0 {
return nil
}
// If there is a label we should write, get the namespace key
// and record it in the tx store.
txmgrNs := dbTx.ReadWriteBucket(wtxmgrNamespaceKey)
return w.TxStore.PutTxLabel(txmgrNs, tx.TxHash(), label)
})
if err != nil {
return nil, err