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 15 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
16 changes: 15 additions & 1 deletion 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 |

| immutable | specify if the allocation is immutable | 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 @@ -336,6 +343,13 @@ An increase in blobber count will increment the parity shards.
| 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
2 changes: 2 additions & 0 deletions cmd/getallocation.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ var getallocationCmd = &cobra.Command{
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
67 changes: 65 additions & 2 deletions cmd/newallocation.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,65 @@ var newallocationCmd = &cobra.Command{
}
}

isImmutable, _ := flags.GetBool("immutable")
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, isImmutable, thirdPartyExtendable, &fileOptionParams)

if err != nil {
log.Fatal("Error creating allocation: ", err)
}
Expand All @@ -185,7 +240,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(), isImmutable, thirdPartyExtendable, &fileOptionParams)
if err != nil {
log.Fatal("Error creating allocation: ", err)
}
Expand Down Expand Up @@ -256,6 +311,14 @@ func init() {

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

newallocationCmd.Flags().Bool("immutable", false, "specify if the allocation is immutable")
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
62 changes: 62 additions & 0 deletions cmd/updateallocation.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,58 @@ var updateAllocationCmd = &cobra.Command{
}

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 @@ -104,6 +156,8 @@ var updateAllocationCmd = &cobra.Command{
updateTerms,
addBlobberId,
removeBlobberId,
setThirdPartyExtendable,
&fileOptionParams,
)
if err != nil {
log.Fatal("Error updating allocation:", err)
Expand Down Expand Up @@ -136,4 +190,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.20230202191640-4052d0fe63f8
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.20230202191640-4052d0fe63f8 h1:3keCGSOiUiRsWGVuAZvDEras2K3p0LtnueVEwWt53Jk=
github.com/0chain/gosdk v1.8.13-0.20230202191640-4052d0fe63f8/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