@@ -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 ) (* disperserClientV2 , error ) {
64
64
if config == nil {
65
65
return nil , api .NewErrorInvalidArg ("config must be provided" )
66
66
}
@@ -74,6 +74,8 @@ func NewDisperserClientV2(config *DisperserClientV2Config, signer corev2.BlobReq
74
74
return nil , api .NewErrorInvalidArg ("signer must be provided" )
75
75
}
76
76
77
+ accountant := & accountant {}
78
+
77
79
return & disperserClientV2 {
78
80
config : config ,
79
81
signer : signer ,
@@ -83,6 +85,17 @@ func NewDisperserClientV2(config *DisperserClientV2Config, signer corev2.BlobReq
83
85
}, nil
84
86
}
85
87
88
+ // PopulateAccountant populates the accountant with the payment state from the disperser.
89
+ // This function is required to be called before using the accountant. Perhaps rename to Start()?
90
+ func (c * disperserClientV2 ) PopulateAccountant (ctx context.Context ) error {
91
+ paymentState , err := c .GetPaymentState (ctx )
92
+ if err != nil {
93
+ return fmt .Errorf ("error getting payment state for initializing accountant: %w" , err )
94
+ }
95
+ c .accountant .SetPaymentState (paymentState )
96
+ return nil
97
+ }
98
+
86
99
// Close closes the grpc connection to the disperser server.
87
100
// It is thread safe and can be called multiple times.
88
101
func (c * disperserClientV2 ) Close () error {
@@ -199,6 +212,30 @@ func (c *disperserClientV2) GetBlobStatus(ctx context.Context, blobKey corev2.Bl
199
212
return c .client .GetBlobStatus (ctx , request )
200
213
}
201
214
215
+ // GetPaymentState returns the payment state of the disperser client
216
+ func (c * disperserClientV2 ) GetPaymentState (ctx context.Context ) (* disperser_rpc.GetPaymentStateReply , error ) {
217
+ err := c .initOnceGrpcConnection ()
218
+ if err != nil {
219
+ return nil , api .NewErrorInternal (err .Error ())
220
+ }
221
+
222
+ accountID , err := c .signer .GetAccountID ()
223
+ if err != nil {
224
+ return nil , fmt .Errorf ("error getting signer's account ID: %w" , err )
225
+ }
226
+
227
+ signature , err := c .signer .SignPaymentStateRequest ()
228
+ if err != nil {
229
+ return nil , fmt .Errorf ("error signing payment state request: %w" , err )
230
+ }
231
+
232
+ request := & disperser_rpc.GetPaymentStateRequest {
233
+ AccountId : accountID ,
234
+ Signature : signature ,
235
+ }
236
+ return c .client .GetPaymentState (ctx , request )
237
+ }
238
+
202
239
// GetBlobCommitment is a utility method that calculates commitment for a blob payload.
203
240
// While the blob commitment can be calculated by anyone, it requires SRS points to
204
241
// be loaded. For service that does not have access to SRS points, this method can be
0 commit comments