diff --git a/mobilesdk/sdk/sdk.go b/mobilesdk/sdk/sdk.go index 8ce6558c9..538ec4f13 100644 --- a/mobilesdk/sdk/sdk.go +++ b/mobilesdk/sdk/sdk.go @@ -117,7 +117,7 @@ func InitStorageSDK(clientJson string, configJson string) (*StorageSDK, error) { l.Logger.Error(err) return nil, err } - err = Init(configObj.BlockWorker) + err = Init(configJson) if err != nil { l.Logger.Error(err) return nil, err @@ -413,6 +413,11 @@ func (s *StorageSDK) GetVersion() string { return version.VERSIONSTR } +// GetVersion getting current version for gomobile lib (standalone function) +func GetVersion() string { + return version.VERSIONSTR +} + // UpdateAllocation update allocation settings with new expiry and size // - size: size of space reserved on blobbers // - extend: extend allocation @@ -427,6 +432,24 @@ func (s *StorageSDK) UpdateAllocation(size, authRoundExpiry int64, extend bool, return hash, err } +// UpdateAllocationWithBlobbers update allocation settings with new expiry, size, and blobber changes +// - size: size of space reserved on blobbers +// - authRoundExpiry: auth round expiry duration +// - extend: extend allocation +// - allocationID: allocation ID +// - lock: Number of tokens to lock to the allocation after the update +// - addBlobberId: blobber ID to add to the allocation (empty string to skip) +// - addBlobberAuthTicket: blobber auth ticket for the blobber to add, required if adding a restricted blobber (empty string if not needed) +// - removeBlobberId: blobber ID to remove from the allocation (empty string to skip) +func (s *StorageSDK) UpdateAllocationWithBlobbers(size, authRoundExpiry int64, extend bool, allocationID string, lock uint64, addBlobberId, addBlobberAuthTicket, removeBlobberId string) (hash string, err error) { + if lock > math.MaxInt64 { + return "", errors.Errorf("int64 overflow in lock") + } + + hash, _, err = sdk.UpdateAllocation(size, authRoundExpiry, extend, allocationID, lock, addBlobberId, addBlobberAuthTicket, removeBlobberId, "", "", false, &sdk.FileOptionsParameters{}, "") + return hash, err +} + // GetBlobbersList get list of active blobbers, and format them as array json string func (s *StorageSDK) GetBlobbersList() (string, error) { blobbs, err := sdk.GetBlobbers(true, false) @@ -454,6 +477,22 @@ func GetAllocations() (string, error) { return string(retBytes), nil } +// GetAllocationsOfClient retrieve list of allocations for a specific client ID +// - clientID: the client ID to get allocations for +func GetAllocationsOfClient(clientID string) (string, error) { + allocs, err := sdk.GetAllocationsForClient(clientID) + if err != nil { + return "", err + } + + retBytes, err := json.Marshal(allocs) + if err != nil { + return "", err + } + + return string(retBytes), nil +} + // RedeeemFreeStorage given a free storage ticket, create a new free allocation // - ticket: free storage ticket func (s *StorageSDK) RedeemFreeStorage(ticket string) (string, error) { diff --git a/mobilesdk/sdk/thumbnail.go b/mobilesdk/sdk/thumbnail.go new file mode 100644 index 000000000..fa350093b --- /dev/null +++ b/mobilesdk/sdk/thumbnail.go @@ -0,0 +1,33 @@ +//go:build mobile +// +build mobile + +package sdk + +import ( + "github.com/0chain/gosdk/core/imageutil" +) + +// CreateThumbnail create thumbnail of an image buffer. It supports +// - png +// - jpeg +// - gif +// - bmp +// - ccitt +// - riff +// - tiff +// - vector +// - vp8 +// - vp8l +// - webp +// +// ## Inputs +// - buf: image buffer as byte array +// - width: thumbnail width +// - height: thumbnail height +// +// ## Outputs +// - thumbnail image buffer as byte array +// - error +func CreateThumbnail(buf []byte, width, height int) ([]byte, error) { + return imageutil.CreateThumbnail(buf, width, height) +} diff --git a/mobilesdk/zbox/storage.go b/mobilesdk/zbox/storage.go index bb8ca5028..50999ac25 100644 --- a/mobilesdk/zbox/storage.go +++ b/mobilesdk/zbox/storage.go @@ -1,3 +1,6 @@ +//go:build mobile +// +build mobile + package zbox import ( @@ -915,3 +918,37 @@ func SetUploadMode(mode int) { sdk.SetUploadMode(sdk.UploadModeHigh) } } + +// ListObjects - listing objects from path with advanced filtering options +// ## Inputs +// - allocationID: allocation id +// - path: remote path to list +// - offsetPath: path to start listing from (for pagination) +// - updatedDate: filter by updated date (optional, empty string to ignore) +// - offsetDate: offset date for pagination (optional, empty string to ignore) +// - fileType: filter by file type (optional, empty string for all) +// - refType: filter by reference type (optional, empty string for all) +// - level: directory level to list (0 for all levels) +// - pageLimit: maximum number of results per page +// +// ## Outputs +// - the json string of object tree results +// - error +func ListObjects(allocationID, path, offsetPath, updatedDate, offsetDate, fileType, refType string, level, pageLimit int) (string, error) { + a, err := getAllocation(allocationID) + if err != nil { + return "", err + } + + // Use GetRefs which is simpler and returns results directly + objectTreeResult, err := a.GetRefs(path, offsetPath, updatedDate, offsetDate, fileType, refType, level, pageLimit) + if err != nil { + return "", err + } + + retBytes, err := json.Marshal(objectTreeResult) + if err != nil { + return "", err + } + return string(retBytes), nil +} diff --git a/mobilesdk/zcn/writepool.go b/mobilesdk/zcn/writepool.go index e69513a65..40ba14605 100644 --- a/mobilesdk/zcn/writepool.go +++ b/mobilesdk/zcn/writepool.go @@ -4,8 +4,10 @@ package zcn import ( - "github.com/0chain/gosdk/zboxcore/sdk" "strconv" + + "github.com/0chain/gosdk/zboxcore/sdk" + "github.com/0chain/gosdk/zcncore" ) // WritePoolLock locks given number of tokes for given duration in read pool. @@ -34,3 +36,13 @@ func WritePoolLock(allocID string, tokens, fee string) (string, error) { return hash, err } + +// ConvertToValueMobile converts ZCN tokens to SAS tokens (mobile wrapper) +// ## Inputs +// - token: ZCN tokens as float64 +// +// ## Outputs +// - SAS tokens as uint64 +func ConvertToValueMobile(token float64) uint64 { + return zcncore.ConvertToValue(token) +}