From 8b1ad3b4700582561aa23af1b63dc060e122de3e Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Mon, 6 Dec 2021 16:35:29 -0800 Subject: [PATCH] Merge pull request #775 from ennmichael/unconfirmed-txn-notification-label Fixed a bug where unconfirmed txn notifications were missing a label --- waddrmgr/manager_test.go | 129 +-------------------------------------- wallet/wallet.go | 19 +++--- 2 files changed, 10 insertions(+), 138 deletions(-) diff --git a/waddrmgr/manager_test.go b/waddrmgr/manager_test.go index c731483a0f..0fbbaed10d 100644 --- a/waddrmgr/manager_test.go +++ b/waddrmgr/manager_test.go @@ -990,8 +990,8 @@ func testImportScript(tc *testContext) bool { "3b033a2fd64fe14a9b955e5355f0c6ac", ), expected: expectedAddr{ - address: "ltc1pc57jdm7kcnufnc339fvy2caflj6lkfeqasdfghftl7dd77dfpresrcsury", - addressHash: hexToBytes("c53d26efd6c4f899e2312a584563a9fcb5fb2720ec1a945d2bff9adf79a908f3"), + address: "ltc1pu92qt24cl4spyp4rsj9sa3y4ma6a3fszgewcmway9f6f80vgnduqhmaa4e", + addressHash: hexToBytes("e15405aab8fd601206a3848b0ec495df75d8a602465d8dbba42a7493bd889b78"), internal: false, imported: true, compressed: true, @@ -3304,128 +3304,3 @@ func TestManagedAddressValidation(t *testing.T) { } } - -// TestTaprootPubKeyDerivation tests that p2tr addresses can be derived from the -// scoped manager when using the BIP0086 key scope. -func TestTaprootPubKeyDerivation(t *testing.T) { - t.Parallel() - - teardown, db := emptyDB(t) - defer teardown() - - // From: https://github.com/bitcoin/bips/blob/master/bip-0086.mediawiki - rootKey, _ := hdkeychain.NewKeyFromString( - "xprv9s21ZrQH143K3GJpoapnV8SFfukcVBSfeCficPSGfubmSFDxo1kuHnLi" + - "sriDvSnRRuL2Qrg5ggqHKNVpxR86QEC8w35uxmGoggxtQTPvfUu", - ) - - // We'll start the test by creating a new root manager that will be - // used for the duration of the test. - var mgr *Manager - err := walletdb.Update(db, func(tx walletdb.ReadWriteTx) error { - ns, err := tx.CreateTopLevelBucket(waddrmgrNamespaceKey) - if err != nil { - return err - } - err = Create( - ns, rootKey, pubPassphrase, privPassphrase, - &chaincfg.MainNetParams, fastScrypt, time.Time{}, - ) - if err != nil { - return err - } - mgr, err = Open(ns, pubPassphrase, &chaincfg.MainNetParams) - if err != nil { - return err - } - - return mgr.Unlock(ns, privPassphrase) - }) - require.NoError(t, err, "create/open: unexpected error: %v", err) - - defer mgr.Close() - - // Now that we have the manager created, we'll fetch one of the default - // scopes for usage within this test. - scopedMgr, err := mgr.FetchScopedKeyManager(KeyScopeBIP0086) - require.NoError( - t, err, "unable to fetch scope %v: %v", KeyScopeBIP0086, err, - ) - - externalPath := DerivationPath{ - InternalAccount: 0, - Account: hdkeychain.HardenedKeyStart, - Branch: 0, - Index: 0, - } - internalPath := DerivationPath{ - InternalAccount: 0, - Account: hdkeychain.HardenedKeyStart, - Branch: 1, - Index: 0, - } - - assertAddressDerivation( - t, db, func(ns walletdb.ReadWriteBucket) (ManagedAddress, error) { - return scopedMgr.DeriveFromKeyPath(ns, externalPath) - }, - "bc1p5cyxnuxmeuwuvkwfem96lqzszd02n6xdcjrs20cac6yqjjwudpxqkedrcr", - ) - assertAddressDerivation( - t, db, func(ns walletdb.ReadWriteBucket) (ManagedAddress, error) { - addrs, err := scopedMgr.NextExternalAddresses(ns, 0, 1) - if err != nil { - return nil, err - } - return addrs[0], nil - }, - "bc1p5cyxnuxmeuwuvkwfem96lqzszd02n6xdcjrs20cac6yqjjwudpxqkedrcr", - ) - assertAddressDerivation( - t, db, func(ns walletdb.ReadWriteBucket) (ManagedAddress, error) { - return scopedMgr.LastExternalAddress(ns, 0) - }, - "bc1p5cyxnuxmeuwuvkwfem96lqzszd02n6xdcjrs20cac6yqjjwudpxqkedrcr", - ) - assertAddressDerivation( - t, db, func(ns walletdb.ReadWriteBucket) (ManagedAddress, error) { - return scopedMgr.DeriveFromKeyPath(ns, internalPath) - }, - "bc1p3qkhfews2uk44qtvauqyr2ttdsw7svhkl9nkm9s9c3x4ax5h60wqwruhk7", - ) - assertAddressDerivation( - t, db, func(ns walletdb.ReadWriteBucket) (ManagedAddress, error) { - addrs, err := scopedMgr.NextInternalAddresses(ns, 0, 1) - if err != nil { - return nil, err - } - return addrs[0], nil - }, - "bc1p3qkhfews2uk44qtvauqyr2ttdsw7svhkl9nkm9s9c3x4ax5h60wqwruhk7", - ) - assertAddressDerivation( - t, db, func(ns walletdb.ReadWriteBucket) (ManagedAddress, error) { - return scopedMgr.LastInternalAddress(ns, 0) - }, - "bc1p3qkhfews2uk44qtvauqyr2ttdsw7svhkl9nkm9s9c3x4ax5h60wqwruhk7", - ) -} - -// assertAddressDerivation makes sure the address derived in the given callback -// is the one that is expected. -func assertAddressDerivation(t *testing.T, db walletdb.DB, - fn func(walletdb.ReadWriteBucket) (ManagedAddress, error), - expectedAddr string) { - - var address ManagedAddress - err := walletdb.Update(db, func(tx walletdb.ReadWriteTx) error { - ns := tx.ReadWriteBucket(waddrmgrNamespaceKey) - - var err error - address, err = fn(ns) - return err - }) - require.NoError(t, err, "unable to derive addr: %v", err) - - require.Equal(t, expectedAddr, address.Address().String()) -} diff --git a/wallet/wallet.go b/wallet/wallet.go index a387899b87..4201e4df6a 100644 --- a/wallet/wallet.go +++ b/wallet/wallet.go @@ -3725,19 +3725,16 @@ func (w *Wallet) reliablyPublishTransaction(tx *wire.MsgTx, } } - 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 len(label) != 0 { + txmgrNs := dbTx.ReadWriteBucket(wtxmgrNamespaceKey) + if err = w.TxStore.PutTxLabel(txmgrNs, tx.TxHash(), label); err != nil { + return err + } + } + + return w.addRelevantTx(dbTx, txRec, nil) }) if err != nil { return nil, err