Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NFT changes #335

Merged
merged 20 commits into from
Feb 7, 2023
Merged
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
17 changes: 15 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,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 +337,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
3 changes: 2 additions & 1 deletion cmd/getallocation.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ var getallocationCmd = &cobra.Command{
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
65 changes: 63 additions & 2 deletions cmd/newallocation.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,64 @@ var newallocationCmd = &cobra.Command{
}
}

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 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)
*size, expireAt, readPrice, writePrice, lock, thirdPartyExtendable, &fileOptionParams)

if err != nil {
log.Fatal("Error creating allocation: ", err)
}
Expand All @@ -185,7 +239,7 @@ var newallocationCmd = &cobra.Command{
}

allocationID, _, _, err = sdk.CreateAllocationForOwner(allocationName, owner, ownerPublicKey, *datashards, *parityshards,
*size, expireAt, readPrice, writePrice, lock, blockchain.GetPreferredBlobbers())
*size, expireAt, readPrice, writePrice, lock, blockchain.GetPreferredBlobbers(), thirdPartyExtendable, &fileOptionParams)
if err != nil {
log.Fatal("Error creating allocation: ", err)
}
Expand Down Expand Up @@ -256,6 +310,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
65 changes: 62 additions & 3 deletions cmd/updateallocation.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,58 @@ var updateAllocationCmd = &cobra.Command{
log.Fatal("invalid 'expiry' flag: ", err)
}

setImmutable, _ := cmd.Flags().GetBool("set_immutable")
setThirdPartyExtendable, _ := cmd.Flags().GetBool("set_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 forbid_upload: ", err)
}
fileOptionParams.ForbidRename.Changed = true
fileOptionParams.ForbidRename.Value = forbidRename
}

var allocationName string
if flags.Changed("name") {
Expand All @@ -100,10 +151,11 @@ var updateAllocationCmd = &cobra.Command{
int64(expiry/time.Second),
allocID,
lock,
setImmutable,
updateTerms,
addBlobberId,
removeBlobberId,
setThirdPartyExtendable,
&fileOptionParams,
)
if err != nil {
log.Fatal("Error updating allocation:", err)
Expand All @@ -126,7 +178,6 @@ func init() {
"adjust allocation size, bytes")
updateAllocationCmd.PersistentFlags().Duration("expiry", 0,
"adjust storage expiration time, duration")
updateAllocationCmd.Flags().Bool("set_immutable", false, "set the allocation's data to be immutable")
updateAllocationCmd.Flags().String("free_storage", "",
"json file containing marker for free storage")
updateAllocationCmd.Flags().Bool("update_terms", false,
Expand All @@ -136,4 +187,12 @@ func init() {

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

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

}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.18

require (
github.com/0chain/errors v1.0.3
github.com/0chain/gosdk v1.8.12
github.com/0chain/gosdk v1.8.13-0.20230203220446-8d6f5a3f4893
github.com/icza/bitio v1.1.0
github.com/olekukonko/tablewriter v0.0.5
github.com/spf13/cobra v1.6.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ github.com/0chain/common v0.0.5 h1:E5JM9YjftfFrlMlrKKNuoWJLxmUMrNnm7ERslPbgJm4=
github.com/0chain/common v0.0.5/go.mod h1:OxV9kVgVzAPgGHHPcS/aUSL2ZxNvKDU6jPoggKMbqns=
github.com/0chain/errors v1.0.3 h1:QQZPFxTfnMcRdt32DXbzRQIfGWmBsKoEdszKQDb0rRM=
github.com/0chain/errors v1.0.3/go.mod h1:xymD6nVgrbgttWwkpSCfLLEJbFO6iHGQwk/yeSuYkIc=
github.com/0chain/gosdk v1.8.12 h1:esUDZpFtcL3MGhHawwv3t9suGbt1tvt06PMKubek+wI=
github.com/0chain/gosdk v1.8.12/go.mod h1:tAJVrpK3Uz0+6V1s9juWOrK3jPkzcr/4APqSaZgSFes=
github.com/0chain/gosdk v1.8.13-0.20230203220446-8d6f5a3f4893 h1:2935rp/bhKiGMdGlHtENjZmbyaQ3Yz/Dw+iXahT5vFI=
github.com/0chain/gosdk v1.8.13-0.20230203220446-8d6f5a3f4893/go.mod h1:tAJVrpK3Uz0+6V1s9juWOrK3jPkzcr/4APqSaZgSFes=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/Luzifer/go-openssl/v3 v3.1.0 h1:QqKqo6kYXGGUsvtUoCpRZm8lHw+jDfhbzr36gVj+/gw=
Expand Down