diff --git a/rpc/rpcserver/server.go b/rpc/rpcserver/server.go index a2250a6..fa3bf58 100644 --- a/rpc/rpcserver/server.go +++ b/rpc/rpcserver/server.go @@ -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) } diff --git a/wallet/wallet.go b/wallet/wallet.go index 476eea8..167d402 100644 --- a/wallet/wallet.go +++ b/wallet/wallet.go @@ -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