@@ -10,6 +10,7 @@ import (
1010 logging "github.com/ipfs/go-log/v2"
1111
1212 appfibre "github.com/celestiaorg/celestia-app/v8/fibre"
13+ "github.com/celestiaorg/celestia-app/v8/pkg/user"
1314 fibretypes "github.com/celestiaorg/celestia-app/v8/x/fibre/types"
1415 libshare "github.com/celestiaorg/go-square/v4/share"
1516
@@ -46,7 +47,7 @@ func (s *Service) Submit(
4647 ns libshare.Namespace ,
4748 data []byte ,
4849 options * txclient.TxConfig ,
49- ) (_ * appfibre. PutResult , _ * appfibre.PaymentPromise , err error ) {
50+ ) (_ * user. TxResponse , _ * appfibre.SignedPaymentPromise , _ appfibre. BlobID , err error ) {
5051 start := time .Now ()
5152 defer func () {
5253 s .metrics .observeSubmit (ctx , time .Since (start ), len (data ), err )
@@ -56,23 +57,23 @@ func (s *Service) Submit(
5657
5758 blob , err := appfibre .NewBlob (data , appfibre .DefaultBlobConfigV0 ())
5859 if err != nil {
59- return nil , nil , err
60+ return nil , nil , nil , err
6061 }
6162
6263 promise , err := s .upload (ctx , ns , blob )
6364 if err != nil {
6465 log .Errorw ("uploading blob" , "err" , err , "namespace" , ns .ID ())
65- return nil , nil , err
66+ return nil , nil , nil , err
6667 }
6768
6869 protoPromise , err := promise .ToProto ()
6970 if err != nil {
70- return nil , nil , err
71+ return nil , nil , nil , err
7172 }
7273
7374 signer , err := s .txClient .GetTxAuthorAccAddress (options )
7475 if err != nil {
75- return nil , nil , fmt .Errorf ("getting signer address: %w" , err )
76+ return nil , nil , nil , fmt .Errorf ("getting signer address: %w" , err )
7677 }
7778
7879 msg := & fibretypes.MsgPayForFibre {
@@ -83,34 +84,27 @@ func (s *Service) Submit(
8384 resp , err := s .txClient .SubmitMessage (ctx , msg , options )
8485 if err != nil {
8586 log .Errorw ("submitting blob" , "err" , err , "namespace" , promise .Namespace )
86- return nil , nil , err
87- }
88-
89- putRes := & appfibre.PutResult {
90- BlobID : blob .ID (),
91- ValidatorSignatures : promise .ValidatorSignatures ,
92- TxHash : resp .TxHash ,
93- Height : uint64 (resp .Height ),
87+ return nil , nil , nil , err
9488 }
9589
9690 // go does not allow slicing a function return value directly (e.g., f()[:]).
97- commitment := putRes . BlobID .Commitment ()
91+ commitment := blob . ID () .Commitment ()
9892 log .Debugw ("blob submitted" ,
9993 "namespace" , promise .Namespace ,
10094 "commitment" , hex .EncodeToString (commitment [:]),
101- "height" , putRes .Height ,
102- "tx-hash" , putRes .TxHash ,
103- "signatures" , len (putRes .ValidatorSignatures ),
95+ "height" , resp .Height ,
96+ "tx-hash" , resp .TxHash ,
97+ "signatures" , len (promise .ValidatorSignatures ),
10498 )
105- return putRes , promise . PaymentPromise , nil
99+ return resp , promise , blob . ID () , nil
106100}
107101
108102func (s * Service ) Upload (
109103 ctx context.Context ,
110104 ns libshare.Namespace ,
111105 data []byte ,
112106 _ * txclient.TxConfig ,
113- ) (_ * appfibre.SignedPaymentPromise , err error ) {
107+ ) (_ * appfibre.SignedPaymentPromise , _ appfibre. BlobID , err error ) {
114108 start := time .Now ()
115109 defer func () {
116110 s .metrics .observeUpload (ctx , time .Since (start ), len (data ), err )
@@ -120,25 +114,26 @@ func (s *Service) Upload(
120114
121115 blob , err := appfibre .NewBlob (data , appfibre .DefaultBlobConfigV0 ())
122116 if err != nil {
123- return nil , err
117+ return nil , nil , err
124118 }
125119 promise , err := s .upload (ctx , ns , blob )
126120 if err != nil {
127121 log .Errorw ("uploading blob" , "err" , err , "namespace" , ns .ID ())
128- return nil , err
122+ return nil , nil , err
129123 }
130124 // TODO: add async fibre submit
131- return promise , nil
125+ return promise , blob . ID (), nil
132126}
133127
134- func (s * Service ) Get (ctx context.Context , ns libshare.Namespace , commitment []byte ) (* appfibre.Blob , error ) {
135- log .Debugw ("getting blob" , "namespace" , ns .ID (), "commitment" , hex .EncodeToString (commitment ))
136- if len (commitment ) != appfibre .CommitmentSize {
137- return nil , fmt .Errorf ("commitment size does not match. want:%d got:%d" , appfibre .CommitmentSize , len (commitment ))
128+ func (s * Service ) Get (ctx context.Context , blobID []byte ) (* appfibre.Blob , error ) {
129+ blbID := appfibre .BlobID (blobID )
130+ err := blbID .Validate ()
131+ if err != nil {
132+ return nil , fmt .Errorf ("invalid blob ID: %w" , err )
138133 }
134+ log .Debugw ("downloading fibre blob" , "commitment" , blbID .Commitment ())
139135
140- blobID := appfibre .NewBlobID (ns .Version (), appfibre .Commitment (commitment ))
141- return s .fibreClient .Download (ctx , blobID )
136+ return s .fibreClient .Download (ctx , blbID )
142137}
143138
144139func (s * Service ) upload (
0 commit comments