Skip to content

Commit

Permalink
Merge branch 'staging' into chain-fee
Browse files Browse the repository at this point in the history
* staging:
  update gosdk to staging
  Fix incorrect timestamp convert
  Update gosdk
  debugged
  made common.TimeStamp to time.Time for stakedAt
  converted StakedAt to time.Time
  Fix/file options not supported by some sdk clients (#353)
  Remove allocation name (#346)
  NFT changes (#335)
  clean up: collab command
  fix(listall): fixed json output (#348)
  upgrade GoSDK to v1.8.12 (#349)
  fix(zcncore): used zcncore.MakeSCRestAPICall instead of zboxutil.Make… (#342)
  feat(list): exported created_at and updated_at (#345)
  • Loading branch information
peterlimg committed Feb 16, 2023
2 parents 6c6476c + 87c6599 commit 4dd977d
Show file tree
Hide file tree
Showing 10 changed files with 165 additions and 180 deletions.
57 changes: 19 additions & 38 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ zbox is a command line interface (CLI) tool to understand the capabilities of 0C
- [Stats](#stats)
- [Repair](#repair)
- [Add collaborator](#add-collaborator)
- [Delete collaborator](#delete-collaborator)
- [Sign data](#sign-data)
- [Streaming](#streaming)
- [How it works:](#how-it-works)
Expand Down Expand Up @@ -125,7 +124,6 @@ When you run the `zbox` command in terminal with no arguments, it will list all
[copy](#copy)|copy an object(file/folder) to another folder on blobbers
[cp-info](#challenge-pool-information)|Challenge pool information.
[delete](#delete)|delete file from blobbers
[delete-collab](#delete-collaborator)|delete collaborator for a file
[download](#download)|download file from blobbers
[get](#get)|Gets the allocation info
[get-diff](#get-differences)|Get difference of local and allocation root
Expand Down Expand Up @@ -241,7 +239,14 @@ and `free_storage` parameters.
| size | size of space reserved on blobbers | 2147483648 | bytes |
| usd | give token value in USD | | flag |
| write_price | filter blobbers by write price range | 0-inf | range |

false | bool
| third_party_extendable | specify if the allocation can be extended by users other than the owner | false | bool
| forbid_upload | specify if users cannot upload to this allocation |false | bool
| forbid_delete | specify if the users cannot delete objects from this allocation | false | bool
| forbid_update | specify if the users cannot update objects in this allocation |false | bool
| forbid_move | specify if the users cannot move objects from this allocation |false | bool
| forbid_copy | specify if the users cannot copy object from this allocation |false | bool
| forbid_rename | specify if the users cannot rename objects in this allocation |false | bool

<details>
<summary>newallocation </summary>
Expand Down Expand Up @@ -330,12 +335,18 @@ An increase in blobber count will increment the parity shards.
| expiry | | adjust storage expiration time | duration |
| free_storage | | free storage marker file | string |
| lock | yes* | lock additional tokens in write pool | int |
| set_immutable | | sets allocation so that data can no longer be modified | boolean |
| update_terms | | will update the allocation with the latest blobber terms | boolean |
| size | | adjust allocation size | bytes |
| add_blobber | | add a new blobber to the allocation, required for remove_blobber | string |
| remove_blobber | | remove a blobber from the allocation, requires an add_blobber option | string2 |
`*` only required if free_storage not set.
| third_party_extendable | specify if the allocation can be extended by users other than the owner | false | bool
| forbid_upload | specify if users cannot upload to this allocation |false | bool
| forbid_delete | specify if the users cannot delete objects from this allocation | false | bool
| forbid_update | specify if the users cannot update objects in this allocation |false | bool
| forbid_move | specify if the users cannot move objects from this allocation |false | bool
| forbid_copy | specify if the users cannot copy object from this allocation |false | bool
| forbid_rename | specify if the users cannot rename objects in this allocation |false | bool

<details>
<summary>updateallocation </summary>
Expand Down Expand Up @@ -1495,36 +1506,6 @@ Collaborator d477d12134c2d7ba5ab71ac8ad37f244224695ef3215be990c3215d531c5a329 ad

You can check all collaborators for a file in metadata json response.

#### Delete collaborator

Use command delete-collab to remove a collaborator for a file

| Parameter | Required | Description | default | Valid values |
|------------|----------|------------------------------|---------|--------------|
| allocation | yes | allocation id | | string |
| collabid | yes | id of collaberator | | string |
| remotepath | yes | file on which to collaberate | | string |

<details>
<summary>delete-collab</summary>

![image](https://user-images.githubusercontent.com/6240686/124505356-3571a900-ddc1-11eb-9dd8-72927cefa790.png)

</details>

Example

```
./zbox delete-collab --allocation 8695b9e7f986d4a447b64de020ba86f53b3b5e2c442abceb6cd65742702067dc --remotepath /1.txt --collabid d477d12134c2d7ba5ab71ac8ad37f244224695ef3215be990c3215d531c5a329
```

Response will be a confirmation that collaborator is removed on all blobbers for the given file.

```
Collaborator d477d12134c2d7ba5ab71ac8ad37f244224695ef3215be990c3215d531c5a329 removed successfully for the file /1.txt
```


#### Sign data

`sign-data` uses the information from your wallet to sign the input data string
Expand Down Expand Up @@ -1776,10 +1757,10 @@ Use `sp-info` to get your stake pool information and settings.

#### Lock tokens into stake pool

Lock creates delegate pool for current client and a given provider (blobber or validator).
The tokens locked for the provider stake can be unlocked any time, excluding times
when the tokens held by opened offers. These tokens will earn rewards depending on the
actions of the linked provider.
Lock creates delegate pool for current client and a given provider (blobber or validator).
The tokens locked for the provider stake can be unlocked any time, excluding times
when the tokens held by opened offers. These tokens will earn rewards depending on the
actions of the linked provider.

`sp-lock` returns the id of the new stake pool, this will be needed to reference
to stake pool later.
Expand Down
107 changes: 0 additions & 107 deletions cmd/collaborators.go

This file was deleted.

4 changes: 2 additions & 2 deletions cmd/getallocation.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,12 @@ var getallocationCmd = &cobra.Command{
fmt.Println("allocation:")
fmt.Println(" id: ", alloc.ID)
fmt.Println(" tx: ", alloc.Tx, "(latest create/update allocation transaction hash)")
fmt.Println(" name: ", alloc.Name)
fmt.Println(" data_shards: ", alloc.DataShards)
fmt.Println(" parity_shards: ", alloc.ParityShards)
fmt.Println(" size: ", common.Size(alloc.Size))
fmt.Println(" expiration_date:", common.Timestamp(alloc.Expiration).ToTime())
fmt.Println(" immutable: ", alloc.IsImmutable)
fmt.Println(" third_party_extendable: ", alloc.ThirdPartyExtendable)
fmt.Printf(" file_options: %08b\n", alloc.FileOptions)
fmt.Println(" write pool ", alloc.WritePool)
fmt.Println(" blobbers:")

Expand Down
19 changes: 12 additions & 7 deletions cmd/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"strconv"
"strings"

"github.com/0chain/gosdk/core/common"
"github.com/0chain/gosdk/zboxcore/fileref"
"github.com/0chain/gosdk/zboxcore/sdk"
"github.com/0chain/zboxcli/util"
Expand Down Expand Up @@ -106,13 +107,15 @@ var listAllCmd = &cobra.Command{
}

type fileResp struct {
Name string `json:"name"`
Path string `json:"path"`
Type string `json:"type"`
Size int64 `json:"size"`
Hash string `json:"hash,omitempty"`
LookupHash string `json:"lookup_hash"`
EncryptedKey string `json:"encrypted_key,omitempty" `
Name string `json:"name"`
Path string `json:"path"`
Type string `json:"type"`
Size int64 `json:"size"`
Hash string `json:"hash,omitempty"`
LookupHash string `json:"lookup_hash"`
EncryptedKey string `json:"encrypted_key,omitempty" `
CreatedAt common.Timestamp `json:"created_at"`
UpdatedAt common.Timestamp `json:"updated_at"`
}

fileResps := make([]fileResp, 0)
Expand All @@ -126,6 +129,8 @@ var listAllCmd = &cobra.Command{
Hash: data.Hash,
EncryptedKey: data.EncryptedKey,
LookupHash: data.LookupHash,
CreatedAt: common.Timestamp(data.CreatedAt.Unix()),
UpdatedAt: common.Timestamp(data.UpdatedAt.Unix()),
}
fileResps = append(fileResps, resp)
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/listallocations.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ var listallocationsCmd = &cobra.Command{
util.PrintJSON(allocations)
return
}
header := []string{"ID", "Name", "Size", "Expiration", "Datashards",
header := []string{"ID", "Size", "Expiration", "Datashards",
"Parityshards", "Finalized", "Canceled", "R. Price", "W. Price"}
data := make([][]string, len(allocations))
for idx, allocation := range allocations {
Expand All @@ -51,7 +51,7 @@ var listallocationsCmd = &cobra.Command{
}

data[idx] = []string{
allocation.ID, allocation.Name, size, expStr, d, p,
allocation.ID, size, expStr, d, p,
strconv.FormatBool(allocation.Finalized),
strconv.FormatBool(allocation.Canceled),
rp.String(), wp.String(),
Expand Down
68 changes: 60 additions & 8 deletions cmd/newallocation.go
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -158,18 +158,63 @@ var newallocationCmd = &cobra.Command{
}
}

var allocationName string
if flags.Changed("name") {
allocationName, err = flags.GetString("name")
thirdPartyExtendable, _ := flags.GetBool("third_party_extendable")

// Read the file options flags
var fileOptionParams sdk.FileOptionsParameters
if flags.Changed("forbid_upload") {
forbidUpload, err := flags.GetBool("forbid_upload")
if err != nil {
log.Fatal("invalid forbid_upload: ", err)
}
fileOptionParams.ForbidUpload.Changed = true
fileOptionParams.ForbidUpload.Value = forbidUpload
}
if flags.Changed("forbid_delete") {
forbidDelete, err := flags.GetBool("forbid_delete")
if err != nil {
log.Fatal("invalid forbid_upload: ", err)
}
fileOptionParams.ForbidDelete.Changed = true
fileOptionParams.ForbidDelete.Value = forbidDelete
}
if flags.Changed("forbid_update") {
forbidUpdate, err := flags.GetBool("forbid_update")
if err != nil {
log.Fatal("invalid forbid_upload: ", err)
}
fileOptionParams.ForbidUpdate.Changed = true
fileOptionParams.ForbidUpdate.Value = forbidUpdate
}
if flags.Changed("forbid_move") {
forbidMove, err := flags.GetBool("forbid_move")
if err != nil {
log.Fatal("invalid forbid_upload: ", err)
}
fileOptionParams.ForbidMove.Changed = true
fileOptionParams.ForbidMove.Value = forbidMove
}
if flags.Changed("forbid_copy") {
forbidCopy, err := flags.GetBool("forbid_copy")
if err != nil {
log.Fatal("invalid forbid_upload: ", err)
}
fileOptionParams.ForbidCopy.Changed = true
fileOptionParams.ForbidCopy.Value = forbidCopy
}
if flags.Changed("forbid_rename") {
forbidRename, err := flags.GetBool("forbid_rename")
if err != nil {
log.Fatal("invalid allocation name: ", err)
log.Fatal("invalid forbid_upload: ", err)
}
fileOptionParams.ForbidRename.Changed = true
fileOptionParams.ForbidRename.Value = forbidRename
}

var allocationID string
if len(owner) == 0 {
allocationID, _, _, err = sdk.CreateAllocation(allocationName, *datashards, *parityshards,
*size, expireAt, readPrice, writePrice, lock)
allocationID, _, _, err = sdk.CreateAllocation(*datashards, *parityshards,
*size, expireAt, readPrice, writePrice, lock, thirdPartyExtendable, &fileOptionParams)
if err != nil {
log.Fatal("Error creating allocation: ", err)
}
Expand All @@ -184,8 +229,8 @@ var newallocationCmd = &cobra.Command{
}
}

allocationID, _, _, err = sdk.CreateAllocationForOwner(allocationName, owner, ownerPublicKey, *datashards, *parityshards,
*size, expireAt, readPrice, writePrice, lock, blockchain.GetPreferredBlobbers())
allocationID, _, _, err = sdk.CreateAllocationForOwner(owner, ownerPublicKey, *datashards, *parityshards,
*size, expireAt, readPrice, writePrice, lock, blockchain.GetPreferredBlobbers(), thirdPartyExtendable, &fileOptionParams)
if err != nil {
log.Fatal("Error creating allocation: ", err)
}
Expand Down Expand Up @@ -256,6 +301,13 @@ func init() {

newallocationCmd.Flags().String("name", "", "allocation name")

newallocationCmd.Flags().Bool("third_party_extendable", false, "specify if the allocation can be extended by users other than the owner")
newallocationCmd.Flags().Bool("forbid_upload", false, "specify if users cannot upload to this allocation")
newallocationCmd.Flags().Bool("forbid_delete", false, "specify if the users cannot delete objects from this allocation")
newallocationCmd.Flags().Bool("forbid_update", false, "specify if the users cannot update objects in this allocation")
newallocationCmd.Flags().Bool("forbid_move", false, "specify if the users cannot move objects from this allocation")
newallocationCmd.Flags().Bool("forbid_copy", false, "specify if the users cannot copy object from this allocation")
newallocationCmd.Flags().Bool("forbid_rename", false, "specify if the users cannot rename objects in this allocation")
}

func storeAllocation(allocationID string) {
Expand Down
4 changes: 2 additions & 2 deletions cmd/stakepool.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func printStakePoolInfo(info *sdk.StakePoolInfo) {
fmt.Println(" status: ", dp.Status)
fmt.Println(" round_created: ", dp.RoundCreated)
fmt.Println(" unstake: ", dp.UnStake)
fmt.Println(" staked_at: ", dp.StakedAt.String())
fmt.Println(" staked_at: ", dp.StakedAt.ToTime().String())
}
}
// settings
Expand Down Expand Up @@ -59,7 +59,7 @@ func printStakePoolUserInfo(info *sdk.StakePoolUserInfo) {
fmt.Println(" status: ", dp.Status)
fmt.Println(" round_created: ", dp.RoundCreated)
fmt.Println(" unstake: ", dp.UnStake)
fmt.Println(" staked_at: ", dp.StakedAt.String())
fmt.Println(" staked_at: ", dp.StakedAt.ToTime().String())
}
}
}
Expand Down
Loading

0 comments on commit 4dd977d

Please sign in to comment.