@@ -35,7 +35,7 @@ type disperserClientV2 struct {
35
35
conn * grpc.ClientConn
36
36
client disperser_rpc.DisperserClient
37
37
prover encoding.Prover
38
- accountant Accountant
38
+ accountant * accountant
39
39
}
40
40
41
41
var _ DisperserClientV2 = & disperserClientV2 {}
@@ -60,7 +60,7 @@ var _ DisperserClientV2 = &disperserClientV2{}
60
60
//
61
61
// // Subsequent calls will use the existing connection
62
62
// status2, blobKey2, err := client.DisperseBlob(ctx, data, blobHeader)
63
- func NewDisperserClientV2 (config * DisperserClientV2Config , signer corev2.BlobRequestSigner , prover encoding.Prover , accountant Accountant ) (* disperserClientV2 , error ) {
63
+ func NewDisperserClientV2 (config * DisperserClientV2Config , signer corev2.BlobRequestSigner , prover encoding.Prover , accountant * accountant ) (* disperserClientV2 , error ) {
64
64
if config == nil {
65
65
return nil , api .NewErrorInvalidArg ("config must be provided" )
66
66
}
@@ -83,6 +83,17 @@ func NewDisperserClientV2(config *DisperserClientV2Config, signer corev2.BlobReq
83
83
}, nil
84
84
}
85
85
86
+ // PopulateAccountant populates the accountant with the payment state from the disperser.
87
+ // This function is required to be called before using the accountant. Perhaps rename to Start()?
88
+ func (c * disperserClientV2 ) PopulateAccountant (ctx context.Context ) error {
89
+ paymentState , err := c .GetPaymentState (ctx )
90
+ if err != nil {
91
+ return fmt .Errorf ("error getting payment state for initializing accountant: %w" , err )
92
+ }
93
+ c .accountant .SetPaymentState (paymentState )
94
+ return nil
95
+ }
96
+
86
97
// Close closes the grpc connection to the disperser server.
87
98
// It is thread safe and can be called multiple times.
88
99
func (c * disperserClientV2 ) Close () error {
@@ -199,6 +210,30 @@ func (c *disperserClientV2) GetBlobStatus(ctx context.Context, blobKey corev2.Bl
199
210
return c .client .GetBlobStatus (ctx , request )
200
211
}
201
212
213
+ // GetPaymentState returns the payment state of the disperser client
214
+ func (c * disperserClientV2 ) GetPaymentState (ctx context.Context ) (* disperser_rpc.GetPaymentStateReply , error ) {
215
+ err := c .initOnceGrpcConnection ()
216
+ if err != nil {
217
+ return nil , api .NewErrorInternal (err .Error ())
218
+ }
219
+
220
+ accountID , err := c .signer .GetAccountID ()
221
+ if err != nil {
222
+ return nil , fmt .Errorf ("error getting signer's account ID: %w" , err )
223
+ }
224
+
225
+ signature , err := c .signer .SignPaymentStateRequest ()
226
+ if err != nil {
227
+ return nil , fmt .Errorf ("error signing payment state request: %w" , err )
228
+ }
229
+
230
+ request := & disperser_rpc.GetPaymentStateRequest {
231
+ AccountId : accountID ,
232
+ Signature : signature ,
233
+ }
234
+ return c .client .GetPaymentState (ctx , request )
235
+ }
236
+
202
237
// GetBlobCommitment is a utility method that calculates commitment for a blob payload.
203
238
// While the blob commitment can be calculated by anyone, it requires SRS points to
204
239
// be loaded. For service that does not have access to SRS points, this method can be
0 commit comments