Skip to content

Commit

Permalink
feat(act): addgrantees with history address
Browse files Browse the repository at this point in the history
  • Loading branch information
Ferenc Sárai committed Jul 29, 2024
1 parent 9ae8345 commit 7e6c7ae
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 28 deletions.
3 changes: 3 additions & 0 deletions pkg/bee/api/act.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ func (a *ActService) AddGrantees(ctx context.Context, name string, data io.Reade
var resp ActGranteesResponse
h := http.Header{}
h.Add("swarm-postage-batch-id", o.BatchID)
if o.ActHistoryAddress != nil {
h.Add("swarm-act-history-address", o.ActHistoryAddress.String())
}
err := a.client.requestWithHeader(ctx, http.MethodPost, "/"+apiVersion+"/grantee", h, data, &resp)
return resp, err
}
Expand Down
11 changes: 6 additions & 5 deletions pkg/bee/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,11 +313,12 @@ func (f roundTripperFunc) RoundTrip(r *http.Request) (*http.Response, error) {
}

type UploadOptions struct {
Act bool
Pin bool
Tag uint64
BatchID string
Direct bool
Act bool
Pin bool
Tag uint64
BatchID string
Direct bool
ActHistoryAddress *swarm.Address
}

type DownloadOptions struct {
Expand Down
47 changes: 24 additions & 23 deletions pkg/check/act/act.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ func (c *Check) Run(ctx context.Context, cluster orchestration.Cluster, opts int
]
}`)))

err = upClient.AddActGrantees(ctx, &gFile, api.UploadOptions{BatchID: batchID})
fileHis := file.HistroryAddress()
err = upClient.AddActGrantees(ctx, &gFile, api.UploadOptions{BatchID: batchID, ActHistoryAddress: &fileHis})
if err != nil {
return fmt.Errorf("node %s: add grantees error: %w", upNodeName, err)
}
Expand Down Expand Up @@ -175,28 +176,28 @@ func (c *Check) Run(ctx context.Context, cluster orchestration.Cluster, opts int
"`+pubk3.String()+`"
]
}`)))

pErr := upClient.PatchActGrantees(ctx, &pFile, gFile.Address(), file.HistroryAddress(), batchID)
if pErr != nil {
return fmt.Errorf("node %s: PatchActGrantees: %w", upNodeName, pErr)
}

c.logger.Info("ACT grantees patched")
c.logger.Infof("ACT file uploaded. patch History: %v", pFile.HistroryAddress())

// list grantees after patch
patchAddresses, patchErr := upClient.GetActGrantees(ctx, pFile.Address())
if patchErr != nil {
return fmt.Errorf("node %s: GetActGrantees after patch: %w", upNodeName, patchErr)
}
if patchAddresses == nil {
return fmt.Errorf("node %s: GetActGrantees after patch: addresses is nil", upNodeName)
}
if len(patchAddresses) != 1 {
return fmt.Errorf("node %s: GetActGrantees after patch: addresses length is not 1", upNodeName)
}
c.logger.Info("ACT grantees listed after patch")

/*
pErr := upClient.PatchActGrantees(ctx, &pFile, gFile.Address(), file.HistroryAddress(), batchID)
if pErr != nil {
return fmt.Errorf("node %s: PatchActGrantees: %w", upNodeName, pErr)
}
c.logger.Info("ACT grantees patched")
c.logger.Infof("ACT file uploaded. patch History: %v", pFile.HistroryAddress())
// list grantees after patch
patchAddresses, patchErr := upClient.GetActGrantees(ctx, pFile.Address())
if patchErr != nil {
return fmt.Errorf("node %s: GetActGrantees after patch: %w", upNodeName, patchErr)
}
if patchAddresses == nil {
return fmt.Errorf("node %s: GetActGrantees after patch: addresses is nil", upNodeName)
}
if len(patchAddresses) != 1 {
return fmt.Errorf("node %s: GetActGrantees after patch: addresses length is not 1", upNodeName)
}
c.logger.Info("ACT grantees listed after patch")
*/
// download act file
his := pFile.HistroryAddress()
c.logger.Infof("ref: %v, act: %v, pubk: %v, history: %v", fileAddress, act, publisher, his)
Expand Down

0 comments on commit 7e6c7ae

Please sign in to comment.