Skip to content

Commit d79e141

Browse files
committed
tapdb: fix bug with null bool handling in db
In this commit, we fix some incorrect handling on null bool in SQL, that looks to be mostly benign. Before this commit, instead of doing `.Bool`, we did `.Valid`. The latter is only useful to check if something is zero, or NULL. In this case, we can just go with the bool value directly.
1 parent 6bcbbaa commit d79e141

File tree

4 files changed

+16
-10
lines changed

4 files changed

+16
-10
lines changed

tapdb/addrs.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,9 @@ func (t *TapAddressBook) QueryAddrs(ctx context.Context,
467467
return fmt.Errorf("unable to make addr: %w", err)
468468
}
469469

470-
declaredKnown := addr.ScriptKeyDeclaredKnown.Valid
470+
declaredKnown := extractBool(
471+
addr.ScriptKeyDeclaredKnown,
472+
)
471473
addrs = append(addrs, address.AddrWithKeyInfo{
472474
Tap: tapAddr,
473475
ScriptKeyTweak: asset.TweakedScriptKey{
@@ -620,9 +622,11 @@ func fetchAddr(ctx context.Context, db AddrBook, params *address.ChainParams,
620622
return &address.AddrWithKeyInfo{
621623
Tap: tapAddr,
622624
ScriptKeyTweak: asset.TweakedScriptKey{
623-
RawKey: scriptKeyDesc,
624-
Tweak: dbAddr.ScriptKeyTweak,
625-
DeclaredKnown: dbAddr.ScriptKeyDeclaredKnown.Valid,
625+
RawKey: scriptKeyDesc,
626+
Tweak: dbAddr.ScriptKeyTweak,
627+
DeclaredKnown: extractBool(
628+
dbAddr.ScriptKeyDeclaredKnown,
629+
),
626630
},
627631
InternalKeyDesc: internalKeyDesc,
628632
TaprootOutputKey: *taprootOutputKey,

tapdb/asset_minting.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -666,7 +666,9 @@ func fetchAssetSeedlings(ctx context.Context, q PendingAssetStore,
666666
PubKey: scriptKeyInternalPub,
667667
}
668668
scriptKeyTweak := dbSeedling.ScriptKeyTweak
669-
declaredKnown := dbSeedling.ScriptKeyDeclaredKnown.Valid
669+
declaredKnown := extractBool(
670+
dbSeedling.ScriptKeyDeclaredKnown,
671+
)
670672
seedling.ScriptKey = asset.ScriptKey{
671673
PubKey: tweakedScriptKey,
672674
TweakedScriptKey: &asset.TweakedScriptKey{
@@ -800,7 +802,7 @@ func fetchAssetSprouts(ctx context.Context, q PendingAssetStore,
800802
Family: keychain.KeyFamily(sprout.ScriptKeyFam),
801803
},
802804
}
803-
declaredKnown := sprout.ScriptKeyDeclaredKnown.Valid
805+
declaredKnown := extractBool(sprout.ScriptKeyDeclaredKnown)
804806
scriptKey := asset.ScriptKey{
805807
PubKey: tweakedScriptKey,
806808
TweakedScriptKey: &asset.TweakedScriptKey{

tapdb/assets_common.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ func fetchScriptKey(ctx context.Context, q FetchScriptKeyStore,
459459
Index: uint32(dbKey.KeyIndex),
460460
},
461461
},
462-
DeclaredKnown: dbKey.DeclaredKnown.Valid,
462+
DeclaredKnown: extractBool(dbKey.DeclaredKnown),
463463
}
464464

465465
return scriptKey, nil

tapdb/assets_store.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -727,7 +727,7 @@ func (a *AssetStore) dbAssetsToChainAssets(dbAssets []ConfirmedAsset,
727727
if err != nil {
728728
return nil, err
729729
}
730-
declaredKnown := sprout.ScriptKeyDeclaredKnown.Valid
730+
declaredKnown := extractBool(sprout.ScriptKeyDeclaredKnown)
731731
scriptKey := asset.ScriptKey{
732732
PubKey: scriptKeyPub,
733733
TweakedScriptKey: &asset.TweakedScriptKey{
@@ -2686,7 +2686,7 @@ func fetchAssetTransferOutputs(ctx context.Context, q ActiveAssetsStore,
26862686
err)
26872687
}
26882688

2689-
declaredKnown := dbOut.ScriptKeyDeclaredKnown.Valid
2689+
declaredKnown := extractBool(dbOut.ScriptKeyDeclaredKnown)
26902690
outputAnchor := tapfreighter.Anchor{
26912691
Value: btcutil.Amount(
26922692
dbOut.AnchorValue,
@@ -3035,7 +3035,7 @@ func (a *AssetStore) LogAnchorTxConfirm(ctx context.Context,
30353035
out.OutputType == int16(tappsbt.TypeSplitRoot)
30363036
isBurn := !isNumsKey && len(witnessData) > 0 &&
30373037
asset.IsBurnKey(scriptPubKey, witnessData[0])
3038-
isKnown := out.ScriptKeyDeclaredKnown.Valid
3038+
isKnown := extractBool(out.ScriptKeyDeclaredKnown)
30393039
skipAssetCreation := !isTombstone && !isBurn &&
30403040
!out.ScriptKeyLocal && !isKnown
30413041

0 commit comments

Comments
 (0)