@@ -101,16 +101,13 @@ type SupportedHeaderBytesResult struct {
101101}
102102
103103func (c * Client ) GetSupportedHeaderBytes () containers.PromiseInterface [SupportedHeaderBytesResult ] {
104- promise , ctx := containers.NewPromiseWithContext [SupportedHeaderBytesResult ](context .Background ())
105- go func () {
104+ return containers .DoPromise (context .Background (), func (ctx context.Context ) (SupportedHeaderBytesResult , error ) {
106105 var result server_api.SupportedHeaderBytesResult
107106 if err := c .CallContext (ctx , & result , "daprovider_getSupportedHeaderBytes" ); err != nil {
108- promise .ProduceError (fmt .Errorf ("error returned from daprovider_getSupportedHeaderBytes rpc method: %w" , err ))
109- } else {
110- promise .Produce (SupportedHeaderBytesResult {HeaderBytes : result .HeaderBytes })
107+ return SupportedHeaderBytesResult {}, fmt .Errorf ("error returned from daprovider_getSupportedHeaderBytes rpc method: %w" , err )
111108 }
112- }()
113- return promise
109+ return SupportedHeaderBytesResult { HeaderBytes : result . HeaderBytes }, nil
110+ })
114111}
115112
116113// RecoverPayload fetches the underlying payload from the DA provider
@@ -119,16 +116,14 @@ func (c *Client) RecoverPayload(
119116 batchBlockHash common.Hash ,
120117 sequencerMsg []byte ,
121118) containers.PromiseInterface [daprovider.PayloadResult ] {
122- promise , ctx := containers.NewPromiseWithContext [daprovider.PayloadResult ](context .Background ())
123- go func () {
119+ return containers .DoPromise (context .Background (), func (ctx context.Context ) (daprovider.PayloadResult , error ) {
124120 var result daprovider.PayloadResult
125- if err := c .CallContext (ctx , & result , "daprovider_recoverPayload" , hexutil .Uint64 (batchNum ), batchBlockHash , hexutil .Bytes (sequencerMsg )); err != nil {
126- promise .ProduceError (fmt .Errorf ("error returned from daprovider_recoverPayload rpc method, err: %w" , err ))
127- } else {
128- promise .Produce (result )
121+ err := c .CallContext (ctx , & result , "daprovider_recoverPayload" , hexutil .Uint64 (batchNum ), batchBlockHash , hexutil .Bytes (sequencerMsg ))
122+ if err != nil {
123+ err = fmt .Errorf ("error returned from daprovider_recoverPayload rpc method, err: %w" , err )
129124 }
130- }()
131- return promise
125+ return result , err
126+ })
132127}
133128
134129// CollectPreimages collects preimages from the DA provider
@@ -137,32 +132,27 @@ func (c *Client) CollectPreimages(
137132 batchBlockHash common.Hash ,
138133 sequencerMsg []byte ,
139134) containers.PromiseInterface [daprovider.PreimagesResult ] {
140- promise , ctx := containers.NewPromiseWithContext [daprovider.PreimagesResult ](context .Background ())
141- go func () {
135+ return containers .DoPromise (context .Background (), func (ctx context.Context ) (daprovider.PreimagesResult , error ) {
142136 var result daprovider.PreimagesResult
143- if err := c .CallContext (ctx , & result , "daprovider_collectPreimages" , hexutil .Uint64 (batchNum ), batchBlockHash , hexutil .Bytes (sequencerMsg )); err != nil {
144- promise .ProduceError (fmt .Errorf ("error returned from daprovider_collectPreimages rpc method, err: %w" , err ))
145- } else {
146- promise .Produce (result )
137+ err := c .CallContext (ctx , & result , "daprovider_collectPreimages" , hexutil .Uint64 (batchNum ), batchBlockHash , hexutil .Bytes (sequencerMsg ))
138+ if err != nil {
139+ err = fmt .Errorf ("error returned from daprovider_collectPreimages rpc method, err: %w" , err )
147140 }
148- }()
149- return promise
141+ return result , err
142+ })
150143}
151144
152145func (c * Client ) Store (
153146 message []byte ,
154147 timeout uint64 ,
155148) containers.PromiseInterface [[]byte ] {
156- promise , ctx := containers.NewPromiseWithContext [[]byte ](context .Background ())
157- go func () {
149+ return containers .DoPromise (context .Background (), func (ctx context.Context ) ([]byte , error ) {
158150 storeResult , err := c .store (ctx , message , timeout )
159151 if err != nil {
160- promise .ProduceError (err )
161- } else {
162- promise .Produce (storeResult .SerializedDACert )
152+ return nil , err
163153 }
164- }()
165- return promise
154+ return storeResult . SerializedDACert , nil
155+ })
166156}
167157
168158func (c * Client ) store (ctx context.Context , message []byte , timeout uint64 ) (* server_api.StoreResult , error ) {
@@ -192,29 +182,23 @@ func (c *Client) GenerateReadPreimageProof(
192182 offset uint64 ,
193183 certificate []byte ,
194184) containers.PromiseInterface [daprovider.PreimageProofResult ] {
195- promise , ctx := containers.NewPromiseWithContext [daprovider.PreimageProofResult ](context .Background ())
196- go func () {
185+ return containers .DoPromise (context .Background (), func (ctx context.Context ) (daprovider.PreimageProofResult , error ) {
197186 var generateProofResult server_api.GenerateReadPreimageProofResult
198187 if err := c .CallContext (ctx , & generateProofResult , "daprovider_generateReadPreimageProof" , certHash , hexutil .Uint64 (offset ), hexutil .Bytes (certificate )); err != nil {
199- promise .ProduceError (fmt .Errorf ("error returned from daprovider_generateProof rpc method, err: %w" , err ))
200- } else {
201- promise .Produce (daprovider.PreimageProofResult {Proof : generateProofResult .Proof })
188+ return daprovider.PreimageProofResult {}, fmt .Errorf ("error returned from daprovider_generateProof rpc method, err: %w" , err )
202189 }
203- }()
204- return promise
190+ return daprovider. PreimageProofResult { Proof : generateProofResult . Proof }, nil
191+ })
205192}
206193
207194func (c * Client ) GenerateCertificateValidityProof (
208195 certificate []byte ,
209196) containers.PromiseInterface [daprovider.ValidityProofResult ] {
210- promise , ctx := containers.NewPromiseWithContext [daprovider.ValidityProofResult ](context .Background ())
211- go func () {
197+ return containers .DoPromise (context .Background (), func (ctx context.Context ) (daprovider.ValidityProofResult , error ) {
212198 var generateCertificateValidityProofResult server_api.GenerateCertificateValidityProofResult
213199 if err := c .CallContext (ctx , & generateCertificateValidityProofResult , "daprovider_generateCertificateValidityProof" , hexutil .Bytes (certificate )); err != nil {
214- promise .ProduceError (fmt .Errorf ("error returned from daprovider_generateCertificateValidityProof rpc method, err: %w" , err ))
215- } else {
216- promise .Produce (daprovider.ValidityProofResult {Proof : generateCertificateValidityProofResult .Proof })
200+ return daprovider.ValidityProofResult {}, fmt .Errorf ("error returned from daprovider_generateCertificateValidityProof rpc method, err: %w" , err )
217201 }
218- }()
219- return promise
202+ return daprovider. ValidityProofResult { Proof : generateCertificateValidityProofResult . Proof }, nil
203+ })
220204}
0 commit comments