diff --git a/mobilesdk/sdk/sdk.go b/mobilesdk/sdk/sdk.go index 467ab0b49..eaab794ad 100644 --- a/mobilesdk/sdk/sdk.go +++ b/mobilesdk/sdk/sdk.go @@ -369,7 +369,7 @@ func (s *StorageSDK) UpdateAllocation(size int64, extend bool, allocationID stri return "", errors.Errorf("int64 overflow in lock") } - hash, _, err = sdk.UpdateAllocation(size, extend, allocationID, lock, "", "", "", "", false, &sdk.FileOptionsParameters{}) + hash, _, err = sdk.UpdateAllocation(size, extend, allocationID, lock, "", "", "", "", "", false, &sdk.FileOptionsParameters{}, "") return hash, err } diff --git a/wasmsdk/allocation.go b/wasmsdk/allocation.go index 5ee6458c6..17bbe3f58 100644 --- a/wasmsdk/allocation.go +++ b/wasmsdk/allocation.go @@ -168,8 +168,9 @@ func UpdateForbidAllocation(allocationID string, forbidupload, forbiddelete, for "", //addBlobberId, "", //addBlobberAuthTicket "", //removeBlobberId, - "", //thirdPartyExtendable, - false, // ownerSigninPublicKey + "", //owner, + "", //ownerSigninPublicKey + false, // thirdPartyExtendable &sdk.FileOptionsParameters{ ForbidUpload: sdk.FileOptionParam{Changed: forbidupload, Value: forbidupload}, ForbidDelete: sdk.FileOptionParam{Changed: forbiddelete, Value: forbiddelete}, @@ -178,6 +179,7 @@ func UpdateForbidAllocation(allocationID string, forbidupload, forbiddelete, for ForbidCopy: sdk.FileOptionParam{Changed: forbidcopy, Value: forbidcopy}, ForbidRename: sdk.FileOptionParam{Changed: forbidrename, Value: forbidrename}, }, + "", ) return hash, err @@ -197,8 +199,9 @@ func freezeAllocation(allocationID string) (string, error) { "", //addBlobberId, "", //addBlobberAuthTicket "", //removeBlobberId, - "", //thirdPartyExtendable, - false, // ownerSigninPublicKey + "", //owner, + "", //ownerSigninPublicKey + false, // thirdPartyExtendable &sdk.FileOptionsParameters{ ForbidUpload: sdk.FileOptionParam{Changed: true, Value: true}, ForbidDelete: sdk.FileOptionParam{Changed: true, Value: true}, @@ -207,6 +210,7 @@ func freezeAllocation(allocationID string) (string, error) { ForbidCopy: sdk.FileOptionParam{Changed: true, Value: true}, ForbidRename: sdk.FileOptionParam{Changed: true, Value: true}, }, + "", ) if err == nil { @@ -244,7 +248,7 @@ func updateAllocationWithRepair(allocationID string, size int64, extend bool, lock int64, - addBlobberId, addBlobberAuthTicket, removeBlobberId, ownerSigninPublicKey, callbackFuncName string) (string, error) { + addBlobberId, addBlobberAuthTicket, removeBlobberId, ownerSigninPublicKey, updateAllocTicket, callbackFuncName string) (string, error) { sdk.SetWasm() allocationObj, err := sdk.GetAllocation(allocationID) if err != nil { @@ -261,7 +265,7 @@ func updateAllocationWithRepair(allocationID string, } } - alloc, hash, isRepairRequired, err := allocationObj.UpdateWithStatus(size, extend, uint64(lock), addBlobberId, addBlobberAuthTicket, removeBlobberId, ownerSigninPublicKey, false, &sdk.FileOptionsParameters{}, statusBar) + alloc, hash, isRepairRequired, err := allocationObj.UpdateWithStatus(size, extend, uint64(lock), addBlobberId, addBlobberAuthTicket, removeBlobberId, ownerSigninPublicKey, false, &sdk.FileOptionsParameters{}, updateAllocTicket) if err != nil { return hash, err } @@ -298,7 +302,7 @@ func updateAllocation(allocationID string, size int64, extend bool, lock int64, addBlobberId, addBlobberAuthTicket, removeBlobberId, ownerSigninPublicKey string, setThirdPartyExtendable bool) (string, error) { - hash, _, err := sdk.UpdateAllocation(size, extend, allocationID, uint64(lock), addBlobberId, addBlobberAuthTicket, removeBlobberId, ownerSigninPublicKey, setThirdPartyExtendable, &sdk.FileOptionsParameters{}) + hash, _, err := sdk.UpdateAllocation(size, extend, allocationID, uint64(lock), addBlobberId, addBlobberAuthTicket, removeBlobberId, "", ownerSigninPublicKey, setThirdPartyExtendable, &sdk.FileOptionsParameters{}, "") if err == nil { clearAllocation(allocationID) @@ -307,6 +311,14 @@ func updateAllocation(allocationID string, return hash, err } +func getUpdateAllocTicket(allocationID, userID, operationType string, roundExpiry int64) (string, error) { + sign, err := sdk.GetUpdateAllocTicket(allocationID, userID, operationType, roundExpiry) + if err != nil { + return "", err + } + return sign, err +} + // getAllocationMinLock retrieves the minimum lock value for the allocation creation, as calculated by the network. // Lock value is the amount of tokens that the client needs to lock in the allocation's write pool // to be able to pay for the write operations. diff --git a/wasmsdk/proxy.go b/wasmsdk/proxy.go index 9826ac461..5ad947fd4 100644 --- a/wasmsdk/proxy.go +++ b/wasmsdk/proxy.go @@ -272,6 +272,7 @@ func main() { "getUpdateAllocationMinLock": getUpdateAllocationMinLock, "getAllocationWith": getAllocationWith, "createfreeallocation": createfreeallocation, + "getUpdateAllocTicket": getUpdateAllocTicket, // claim rewards "collectRewards": collectRewards, diff --git a/zboxcore/sdk/allocation.go b/zboxcore/sdk/allocation.go index 779930ebb..533cfd5f9 100644 --- a/zboxcore/sdk/allocation.go +++ b/zboxcore/sdk/allocation.go @@ -460,7 +460,7 @@ func (a *Allocation) generateAndSetOwnerSigningPublicKey() { if a.OwnerSigningPublicKey == "" && !a.Finalized && !a.Canceled && client.Wallet().IsSplit { pubKey := privateSigningKey.Public().(ed25519.PublicKey) a.OwnerSigningPublicKey = hex.EncodeToString(pubKey) - hash, _, err := UpdateAllocation(0, false, a.ID, 0, "", "", "", a.OwnerSigningPublicKey, false, nil) + hash, _, err := UpdateAllocation(0, false, a.ID, 0, "", "", "", "", a.OwnerSigningPublicKey, false, nil, "") if err != nil { l.Logger.Error("Failed to update owner signing public key ", err, " allocationID: ", a.ID, " hash: ", hash) return @@ -3184,10 +3184,10 @@ func (a *Allocation) UpdateWithRepair( extend bool, lock uint64, addBlobberId, addBlobberAuthTicket, removeBlobberId, ownerSigninPublicKey string, - setThirdPartyExtendable bool, fileOptionsParams *FileOptionsParameters, + setThirdPartyExtendable bool, fileOptionsParams *FileOptionsParameters, updateAllocTicket string, statusCB StatusCallback, ) (string, error) { - updatedAlloc, hash, isRepairRequired, err := a.UpdateWithStatus(size, extend, lock, addBlobberId, addBlobberAuthTicket, removeBlobberId, ownerSigninPublicKey, setThirdPartyExtendable, fileOptionsParams, statusCB) + updatedAlloc, hash, isRepairRequired, err := a.UpdateWithStatus(size, extend, lock, addBlobberId, addBlobberAuthTicket, removeBlobberId, ownerSigninPublicKey, setThirdPartyExtendable, fileOptionsParams, updateAllocTicket) if err != nil { return hash, err } @@ -3220,7 +3220,7 @@ func (a *Allocation) UpdateWithStatus( lock uint64, addBlobberId, addBlobberAuthTicket, removeBlobberId, ownerSigninPublicKey string, setThirdPartyExtendable bool, fileOptionsParams *FileOptionsParameters, - statusCB StatusCallback, + updateAllocTicket string, ) (*Allocation, string, bool, error) { var ( alloc *Allocation @@ -3231,7 +3231,7 @@ func (a *Allocation) UpdateWithStatus( } l.Logger.Info("Updating allocation") - hash, _, err := UpdateAllocation(size, extend, a.ID, lock, addBlobberId, addBlobberAuthTicket, removeBlobberId, ownerSigninPublicKey, setThirdPartyExtendable, fileOptionsParams) + hash, _, err := UpdateAllocation(size, extend, a.ID, lock, addBlobberId, addBlobberAuthTicket, removeBlobberId, "", ownerSigninPublicKey, setThirdPartyExtendable, fileOptionsParams, updateAllocTicket) if err != nil { return alloc, "", isRepairRequired, err } diff --git a/zboxcore/sdk/blobber_operations.go b/zboxcore/sdk/blobber_operations.go index e546d6cd8..ecf34f16c 100644 --- a/zboxcore/sdk/blobber_operations.go +++ b/zboxcore/sdk/blobber_operations.go @@ -130,9 +130,12 @@ func UpdateAllocation( extend bool, allocationID string, lock uint64, - addBlobberId, addBlobberAuthTicket, removeBlobberId, ownerSigninPublicKey string, - setThirdPartyExtendable bool, fileOptionsParams *FileOptionsParameters, + addBlobberId, addBlobberAuthTicket, removeBlobberId, ownerID, ownerSigninPublicKey string, + setThirdPartyExtendable bool, fileOptionsParams *FileOptionsParameters, ticket string, ) (hash string, nonce int64, err error) { + if ownerID == "" { + ownerID = client.Id() + } if lock > math.MaxInt64 { return "", 0, errors.New("invalid_lock", "int64 overflow on lock value") @@ -148,7 +151,7 @@ func UpdateAllocation( } updateAllocationRequest := make(map[string]interface{}) - updateAllocationRequest["owner_id"] = client.Id() + updateAllocationRequest["owner_id"] = ownerID updateAllocationRequest["owner_public_key"] = "" updateAllocationRequest["id"] = allocationID updateAllocationRequest["size"] = size @@ -160,6 +163,24 @@ func UpdateAllocation( updateAllocationRequest["owner_signing_public_key"] = ownerSigninPublicKey updateAllocationRequest["file_options_changed"], updateAllocationRequest["file_options"] = calculateAllocationFileOptions(alloc.FileOptions, fileOptionsParams) + if ticket != "" { + + type Ticket struct { + AllocationID string `json:"allocation_id"` + UserID string `json:"user_id"` + RoundExpiry int64 `json:"round_expiry"` + OperationType string `json:"operation_type"` + Signature string `json:"signature"` + } + + ticketData := &Ticket{} + err := json.Unmarshal([]byte(ticket), ticketData) + if err != nil { + return "", 0, errors.New("invalid_ticket", "invalid ticket") + } + updateAllocationRequest["update_ticket"] = ticketData + } + sn := transaction.SmartContractTxnData{ Name: transaction.STORAGESC_UPDATE_ALLOCATION, InputArgs: updateAllocationRequest, @@ -168,6 +189,17 @@ func UpdateAllocation( return } +func GetUpdateAllocTicket(allocationID, userID, operationType string, roundExpiry int64) (string, error) { + payload := fmt.Sprintf("%s:%d:%s:%s", allocationID, roundExpiry, userID, operationType) + + signature, err := client.Sign(hex.EncodeToString([]byte(payload))) + if err != nil { + return "", err + } + + return signature, nil +} + // StakePoolLock locks tokens in a stake pool. // This function is the entry point for the staking operation. // Provided the provider type and provider ID, the value is locked in the stake pool between the SDK client and the provider.