@@ -10,21 +10,28 @@ import (
1010 "github.com/ipfs/go-cid"
1111 "github.com/ipld/go-ipld-prime/linking"
1212 cidlink "github.com/ipld/go-ipld-prime/linking/cid"
13- "github.com/ipld/go-ipld-prime/node/bindnode"
1413 "github.com/sourcenetwork/corekv"
1514 "github.com/sourcenetwork/corekv/blockstore"
1615 "github.com/sourcenetwork/corekv/namespace"
16+ "github.com/sourcenetwork/lens/host-go/repository"
1717 "github.com/sourcenetwork/lens/host-go/store"
1818)
1919
2020type P2P struct {
2121 Host Host
22+ repository repository.Repository
2223 indexstore corekv.ReaderWriter
2324}
2425
25- func New (host Host , rootstore corekv.ReaderWriter , indexNamespace string ) * P2P {
26+ func New (
27+ host Host ,
28+ repository repository.Repository ,
29+ rootstore corekv.ReaderWriter ,
30+ indexNamespace string ,
31+ ) * P2P {
2632 return & P2P {
2733 Host : host ,
34+ repository : repository ,
2835 indexstore : namespace .Wrap (rootstore , []byte (indexNamespace )),
2936 }
3037}
@@ -42,24 +49,14 @@ func (p *P2P) SyncLens(ctx context.Context, id string) error {
4249
4350 linkSys := makeLinkSystem (p .Host .IPLDStore ())
4451
45- configNode , err := linkSys . Load (linking. LinkContext { Ctx : ctx }, cidlink. Link { Cid : cid }, store . ConfigBlockSchemaPrototype )
52+ model , err := store . LoadLensModel ( ctx , & linkSys , cid )
4653 if err != nil {
4754 return err
4855 }
4956
50- configBlock := bindnode .Unwrap (configNode ).(* store.ConfigBlock )
51-
52- for _ , moduleLink := range configBlock .Modules {
53- moduleNode , err := linkSys .Load (linking.LinkContext {Ctx : ctx }, moduleLink , store .ModuleBlockSchemaPrototype )
54- if err != nil {
55- return err
56- }
57- moduleBlock := bindnode .Unwrap (moduleNode ).(* store.ModuleBlock )
58-
59- _ , err = linkSys .Load (linking.LinkContext {Ctx : ctx }, moduleBlock .Lens , store .LensBlockSchemaPrototype )
60- if err != nil {
61- return err
62- }
57+ err = p .repository .Add (ctx , id , model )
58+ if err != nil {
59+ return err
6360 }
6461
6562 // Store the top level index so that it may be fetched efficiently from the Store
0 commit comments