1- package mptsqlite
1+ package prefixsqlite
22
33import (
44 "context"
55 "embed"
66 "errors"
77 "slices"
88
9- "filippo.io/torchwood/mpt "
9+ "filippo.io/torchwood/prefix "
1010 "zombiezen.com/go/sqlite"
1111 "zombiezen.com/go/sqlite/sqlitex"
1212)
@@ -33,11 +33,11 @@ func NewSQLiteStorage(ctx context.Context, dbPath string) (*Storage, error) {
3333 labelBytes , labelBitLen := args [0 ].Blob (), uint32 (args [1 ].Int64 ())
3434 prefixBytes , prefixBitLen := args [2 ].Blob (), uint32 (args [3 ].Int64 ())
3535
36- label , err := mpt .NewLabel (labelBitLen , labelBytes )
36+ label , err := prefix .NewLabel (labelBitLen , labelBytes )
3737 if err != nil {
3838 return sqlite.Value {}, err
3939 }
40- prefix , err := mpt .NewLabel (prefixBitLen , prefixBytes )
40+ prefix , err := prefix .NewLabel (prefixBitLen , prefixBytes )
4141 if err != nil {
4242 return sqlite.Value {}, err
4343 }
@@ -76,16 +76,16 @@ func (s *Storage) Close() error {
7676 return s .pool .Close ()
7777}
7878
79- var _ mpt .Storage = (* Storage )(nil )
79+ var _ prefix .Storage = (* Storage )(nil )
8080
81- func (s * Storage ) Load (ctx context.Context , label mpt .Label ) (* mpt .Node , error ) {
81+ func (s * Storage ) Load (ctx context.Context , label prefix .Label ) (* prefix .Node , error ) {
8282 conn , err := s .pool .Take (ctx )
8383 if err != nil {
8484 return nil , err
8585 }
8686 defer s .pool .Put (conn )
8787
88- var node * mpt .Node
88+ var node * prefix .Node
8989 if err := sqlitex .ExecuteFS (conn , sql , "load.sql" , & sqlitex.ExecOptions {
9090 Args : []any {
9191 label .Bytes (),
@@ -101,23 +101,23 @@ func (s *Storage) Load(ctx context.Context, label mpt.Label) (*mpt.Node, error)
101101 }
102102
103103 if node == nil {
104- return nil , mpt .ErrNodeNotFound
104+ return nil , prefix .ErrNodeNotFound
105105 }
106106 return node , nil
107107}
108108
109- func (s * Storage ) LoadPath (ctx context.Context , label mpt .Label ) ([]* mpt .Node , error ) {
109+ func (s * Storage ) LoadPath (ctx context.Context , label prefix .Label ) ([]* prefix .Node , error ) {
110110 conn , err := s .pool .Take (ctx )
111111 if err != nil {
112112 return nil , err
113113 }
114114 defer s .pool .Put (conn )
115115
116- var nodes []* mpt .Node
116+ var nodes []* prefix .Node
117117 if err := sqlitex .ExecuteFS (conn , sql , "path.sql" , & sqlitex.ExecOptions {
118118 Named : map [string ]any {
119- ":root_label" : mpt .RootLabel .Bytes (),
120- ":root_label_bit_len" : mpt .RootLabel .BitLen (),
119+ ":root_label" : prefix .RootLabel .Bytes (),
120+ ":root_label_bit_len" : prefix .RootLabel .BitLen (),
121121 ":label" : label .Bytes (),
122122 ":label_bit_len" : label .BitLen (),
123123 },
@@ -137,43 +137,43 @@ func (s *Storage) LoadPath(ctx context.Context, label mpt.Label) ([]*mpt.Node, e
137137 return nodes , nil
138138}
139139
140- func nodeFromRow (stmt * sqlite.Stmt ) (* mpt .Node , error ) {
140+ func nodeFromRow (stmt * sqlite.Stmt ) (* prefix .Node , error ) {
141141 labelBytes := make ([]byte , 32 )
142142 stmt .ColumnBytes (0 , labelBytes )
143143 labelBitLen := stmt .ColumnInt64 (1 )
144- label , err := mpt .NewLabel (uint32 (labelBitLen ), labelBytes )
144+ label , err := prefix .NewLabel (uint32 (labelBitLen ), labelBytes )
145145 if err != nil {
146146 return nil , err
147147 }
148148
149149 leftBytes := make ([]byte , 32 )
150150 stmt .ColumnBytes (2 , leftBytes )
151151 leftBitLen := stmt .ColumnInt64 (3 )
152- left , err := mpt .NewLabel (uint32 (leftBitLen ), leftBytes )
152+ left , err := prefix .NewLabel (uint32 (leftBitLen ), leftBytes )
153153 if err != nil {
154154 return nil , err
155155 }
156156
157157 rightBytes := make ([]byte , 32 )
158158 stmt .ColumnBytes (4 , rightBytes )
159159 rightBitLen := stmt .ColumnInt64 (5 )
160- right , err := mpt .NewLabel (uint32 (rightBitLen ), rightBytes )
160+ right , err := prefix .NewLabel (uint32 (rightBitLen ), rightBytes )
161161 if err != nil {
162162 return nil , err
163163 }
164164
165165 hashBytes := make ([]byte , 32 )
166166 stmt .ColumnBytes (6 , hashBytes )
167167
168- return & mpt .Node {
168+ return & prefix .Node {
169169 Label : label ,
170170 Left : left ,
171171 Right : right ,
172172 Hash : [32 ]byte (hashBytes ),
173173 }, nil
174174}
175175
176- func (s * Storage ) Store (ctx context.Context , nodes ... * mpt .Node ) error {
176+ func (s * Storage ) Store (ctx context.Context , nodes ... * prefix .Node ) error {
177177 conn , err := s .pool .Take (ctx )
178178 if err != nil {
179179 return err
0 commit comments