1
1
package tapdb
2
2
3
3
import (
4
+ "bytes"
4
5
"context"
5
6
"database/sql"
6
7
"encoding/binary"
@@ -14,7 +15,9 @@ import (
14
15
"github.com/btcsuite/btcd/wire"
15
16
"github.com/lightninglabs/taproot-assets/fn"
16
17
"github.com/lightninglabs/taproot-assets/internal/test"
18
+ "github.com/lightninglabs/taproot-assets/proof"
17
19
"github.com/lightninglabs/taproot-assets/tapdb/sqlc"
20
+ lfn "github.com/lightningnetwork/lnd/fn/v2"
18
21
"github.com/stretchr/testify/require"
19
22
"golang.org/x/exp/constraints"
20
23
)
@@ -94,6 +97,25 @@ func sqlStr(s string) sql.NullString {
94
97
}
95
98
}
96
99
100
+ // SparseDecodeBlockHeight sparse decodes a proof to extract the block height.
101
+ func SparseDecodeBlockHeight (rawProof []byte ) (lfn.Option [uint32 ], error ) {
102
+ var blockHeightVal uint32
103
+ err := proof .SparseDecode (
104
+ bytes .NewReader (rawProof ),
105
+ proof .BlockHeightRecord (& blockHeightVal ),
106
+ )
107
+ if err != nil {
108
+ return lfn .None [uint32 ](), fmt .Errorf ("unable to " +
109
+ "sparse decode proof: %w" , err )
110
+ }
111
+
112
+ if blockHeightVal == 0 {
113
+ return lfn .None [uint32 ](), nil
114
+ }
115
+
116
+ return lfn .Some (blockHeightVal ), nil
117
+ }
118
+
97
119
// extractSqlInt64 turns a NullInt64 into a numerical type. This can be useful
98
120
// when reading directly from the database, as this function handles extracting
99
121
// the inner value from the "option"-like struct.
0 commit comments