@@ -18,12 +18,25 @@ import (
1818 "scroll-tech/coordinator/internal/types"
1919)
2020
21+ type ProxyCli interface {
22+ Login (ctx context.Context , genLogin func (string ) (* types.LoginParameter , error )) (* ctypes.Response , error )
23+ ProxyLogin (ctx context.Context , param * types.LoginParameter ) (* ctypes.Response , error )
24+ Token () string
25+ Reset ()
26+ }
27+
28+ type ProverCli interface {
29+ GetTask (ctx context.Context , param * types.GetTaskParameter ) (* ctypes.Response , error )
30+ SubmitProof (ctx context.Context , param * types.SubmitProofParameter ) (* ctypes.Response , error )
31+ }
32+
2133// Client wraps an http client with a preset host for coordinator API calls
2234type upClient struct {
2335 httpClient * http.Client
2436 baseURL string
2537 loginToken string
2638 compatibileMode bool
39+ resetFromMgr func ()
2740}
2841
2942// NewClient creates a new Client with the specified host
@@ -37,6 +50,12 @@ func newUpClient(cfg *config.UpStream) *upClient {
3750 }
3851}
3952
53+ func (c * upClient ) Reset () {
54+ if c .resetFromMgr != nil {
55+ c .resetFromMgr ()
56+ }
57+ }
58+
4059func (c * upClient ) Token () string {
4160 return c .loginToken
4261}
@@ -175,7 +194,7 @@ func (c *upClient) ProxyLogin(ctx context.Context, param *types.LoginParameter)
175194}
176195
177196// GetTask makes a POST request to /v1/get_task with GetTaskParameter
178- func (c * upClient ) GetTask (ctx context.Context , param * types.GetTaskParameter , token string ) (* ctypes.Response , error ) {
197+ func (c * upClient ) GetTask (ctx context.Context , param * types.GetTaskParameter ) (* ctypes.Response , error ) {
179198 url := fmt .Sprintf ("%s/coordinator/v1/get_task" , c .baseURL )
180199
181200 jsonData , err := json .Marshal (param )
@@ -189,8 +208,8 @@ func (c *upClient) GetTask(ctx context.Context, param *types.GetTaskParameter, t
189208 }
190209
191210 req .Header .Set ("Content-Type" , "application/json" )
192- if token != "" {
193- req .Header .Set ("Authorization" , "Bearer " + token )
211+ if c . loginToken != "" {
212+ req .Header .Set ("Authorization" , "Bearer " + c . loginToken )
194213 }
195214
196215 resp , err := c .httpClient .Do (req )
@@ -201,7 +220,7 @@ func (c *upClient) GetTask(ctx context.Context, param *types.GetTaskParameter, t
201220}
202221
203222// SubmitProof makes a POST request to /v1/submit_proof with SubmitProofParameter
204- func (c * upClient ) SubmitProof (ctx context.Context , param * types.SubmitProofParameter , token string ) (* ctypes.Response , error ) {
223+ func (c * upClient ) SubmitProof (ctx context.Context , param * types.SubmitProofParameter ) (* ctypes.Response , error ) {
205224 url := fmt .Sprintf ("%s/coordinator/v1/submit_proof" , c .baseURL )
206225
207226 jsonData , err := json .Marshal (param )
@@ -215,8 +234,8 @@ func (c *upClient) SubmitProof(ctx context.Context, param *types.SubmitProofPara
215234 }
216235
217236 req .Header .Set ("Content-Type" , "application/json" )
218- if token != "" {
219- req .Header .Set ("Authorization" , "Bearer " + token )
237+ if c . loginToken != "" {
238+ req .Header .Set ("Authorization" , "Bearer " + c . loginToken )
220239 }
221240
222241 resp , err := c .httpClient .Do (req )
0 commit comments