Skip to content

Commit 84a708c

Browse files
authored
Merge pull request #1785 from 0chain/feature/gomobile_repair_function
Exposed functionality to initiate and cancel reapair for mobile
2 parents 9d9daa9 + 09e8809 commit 84a708c

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

mobilesdk/sdk/sdk.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ import (
3030

3131
var nonce = int64(0)
3232

33+
var allocationIDRequired = errors.Errorf("Allocation ID is required")
34+
3335
type Autorizer interface {
3436
Auth(msg string) (string, error)
3537
}
@@ -327,6 +329,49 @@ func (s *StorageSDK) FinalizeAllocation(allocationID string) (string, error) {
327329
return hash, err
328330
}
329331

332+
// RepairAllocation repair allocation
333+
// - allocationID: allocation ID
334+
func (s *StorageSDK) RepairAllocation(allocationID string) error {
335+
// Validate allocation ID
336+
if allocationID == "" {
337+
return allocationIDRequired
338+
}
339+
340+
// Get allocation
341+
alloc, err := sdk.GetAllocation(allocationID)
342+
if err != nil {
343+
return err
344+
}
345+
346+
// returns an error if allocation is not found or caller is not the owner
347+
if alloc.Owner != client.Id() {
348+
return errors.Errorf("Allocation access denied for repair: %s", alloc.Owner)
349+
}
350+
351+
// Call repair with nil StatusCallback (no progress updates for mobile, ios implementation provides statusUpdates)
352+
return alloc.RepairAlloc(nil)
353+
}
354+
355+
// CancelRepair cancel repair for allocation
356+
// - allocationID: allocation ID
357+
func (s *StorageSDK) CancelRepair(allocationID string) error {
358+
if allocationID == "" {
359+
return allocationIDRequired
360+
}
361+
362+
alloc, err := sdk.GetAllocation(allocationID)
363+
if err != nil {
364+
return err
365+
}
366+
367+
//returns an error if allocation is not found or caller is not the owner
368+
if alloc.Owner != client.Id() {
369+
return errors.Errorf("Allocation access denied for cancelling the repair: %s", alloc.Owner)
370+
}
371+
372+
return alloc.CancelRepair()
373+
}
374+
330375
// CancelAllocation cancel allocation by ID
331376
// - allocationID: allocation ID
332377
func (s *StorageSDK) CancelAllocation(allocationID string) (string, error) {

0 commit comments

Comments
 (0)