Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 40 additions & 1 deletion mobilesdk/sdk/sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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) {
Expand Down
33 changes: 33 additions & 0 deletions mobilesdk/sdk/thumbnail.go
Original file line number Diff line number Diff line change
@@ -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)
}
37 changes: 37 additions & 0 deletions mobilesdk/zbox/storage.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
//go:build mobile
// +build mobile

package zbox

import (
Expand Down Expand Up @@ -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
}
14 changes: 13 additions & 1 deletion mobilesdk/zcn/writepool.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
}
Loading