@@ -92,6 +92,10 @@ type AddrBook interface {
9292 // asset groups related to them.
9393 GroupStore
9494
95+ // FetchScriptKeyStore houses the methods related to fetching all
96+ // information about a script key.
97+ FetchScriptKeyStore
98+
9599 // FetchAddrs returns all the addresses based on the constraints of the
96100 // passed AddrQuery.
97101 FetchAddrs (ctx context.Context , arg AddrQuery ) ([]Addresses , error )
@@ -153,11 +157,6 @@ type AddrBook interface {
153157 FetchGenesisByAssetID (ctx context.Context ,
154158 assetID []byte ) (sqlc.GenesisInfoView , error )
155159
156- // FetchScriptKeyByTweakedKey attempts to fetch the script key and
157- // corresponding internal key from the database.
158- FetchScriptKeyByTweakedKey (ctx context.Context ,
159- tweakedScriptKey []byte ) (ScriptKey , error )
160-
161160 // FetchInternalKeyLocator fetches the key locator for an internal key.
162161 FetchInternalKeyLocator (ctx context.Context , rawKey []byte ) (KeyLocator ,
163162 error )
@@ -1158,43 +1157,21 @@ func (t *TapAddressBook) FetchScriptKey(ctx context.Context,
11581157 tweakedScriptKey * btcec.PublicKey ) (* asset.TweakedScriptKey , error ) {
11591158
11601159 var (
1161- readOpts = NewAddrBookReadTx ()
11621160 scriptKey * asset.TweakedScriptKey
1161+ err error
11631162 )
1164- err := t .db .ExecTx (ctx , & readOpts , func (db AddrBook ) error {
1165- dbKey , err := db .FetchScriptKeyByTweakedKey (
1166- ctx , tweakedScriptKey .SerializeCompressed (),
1167- )
1168- if err != nil {
1169- return err
1170- }
11711163
1172- rawKey , err := btcec .ParsePubKey (dbKey .RawKey )
1173- if err != nil {
1174- return fmt .Errorf ("unable to parse raw key: %w" , err )
1175- }
1176-
1177- scriptKey = & asset.TweakedScriptKey {
1178- Tweak : dbKey .Tweak ,
1179- RawKey : keychain.KeyDescriptor {
1180- PubKey : rawKey ,
1181- KeyLocator : keychain.KeyLocator {
1182- Family : keychain .KeyFamily (
1183- dbKey .KeyFamily ,
1184- ),
1185- Index : uint32 (dbKey .KeyIndex ),
1186- },
1187- },
1188- DeclaredKnown : dbKey .DeclaredKnown .Valid ,
1189- }
1190-
1191- return nil
1164+ readOpts := NewAddrBookReadTx ()
1165+ dbErr := t .db .ExecTx (ctx , & readOpts , func (db AddrBook ) error {
1166+ scriptKey , err = fetchScriptKey (ctx , db , tweakedScriptKey )
1167+ return err
11921168 })
1169+
11931170 switch {
1194- case errors .Is (err , sql .ErrNoRows ):
1171+ case errors .Is (dbErr , sql .ErrNoRows ):
11951172 return nil , address .ErrScriptKeyNotFound
11961173
1197- case err != nil :
1174+ case dbErr != nil :
11981175 return nil , err
11991176 }
12001177
0 commit comments