Skip to content

Commit

Permalink
feat(alloc): added name field (#221)
Browse files Browse the repository at this point in the history
  • Loading branch information
cnlangzi authored Apr 25, 2022
1 parent 1e38524 commit 98dad22
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 7 deletions.
1 change: 1 addition & 0 deletions cmd/getallocation.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ 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))
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", "Size", "Expiration", "Datashards",
header := []string{"ID", "Name", "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, size, expStr, d, p,
allocation.ID, allocation.Name, size, expStr, d, p,
strconv.FormatBool(allocation.Finalized),
strconv.FormatBool(allocation.Canceled),
rp.String(), wp.String(),
Expand Down
15 changes: 13 additions & 2 deletions cmd/newallocation.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,18 @@ var newallocationCmd = &cobra.Command{
log.Fatal("invalid owner value: ", err)
}
}

var allocationName string
if flags.Changed("name") {
allocationName, err = flags.GetString("name")
if err != nil {
log.Fatal("invalid allocation name: ", err)
}
}

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

allocationID, err = sdk.CreateAllocationForOwner(owner, ownerPublicKey, *datashards, *parityshards,
allocationID, err = sdk.CreateAllocationForOwner(allocationName, owner, ownerPublicKey, *datashards, *parityshards,
*size, expireAt, readPrice, writePrice, mcct, lock, blockchain.GetPreferredBlobbers())
if err != nil {
log.Fatal("Error creating allocation: ", err)
Expand Down Expand Up @@ -263,6 +272,8 @@ func init() {
newallocationCmd.Flags().String("owner_public_key", "",
"public key of owner, user when creating an allocation for somone else")

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

}

func storeAllocation(allocationID string) {
Expand Down
11 changes: 11 additions & 0 deletions cmd/updateallocation.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,16 @@ var updateAllocationCmd = &cobra.Command{

setImmutable, _ := cmd.Flags().GetBool("set_immutable")

var allocationName string
if flags.Changed("name") {
allocationName, err = flags.GetString("name")
if err != nil {
log.Fatal("invalid allocation name: ", err)
}
}

txnHash, err := sdk.UpdateAllocation(
allocationName,
size,
int64(expiry/time.Second),
allocID,
Expand Down Expand Up @@ -128,4 +137,6 @@ func init() {

updateAllocationCmd.MarkFlagRequired("allocation")

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

}
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.2-0.20220423151921-75736d82dc53
github.com/0chain/gosdk v1.8.2-0.20220425031623-55bd6fee2f46
github.com/icza/bitio v1.1.0
github.com/olekukonko/tablewriter v0.0.5
github.com/spf13/cobra v1.4.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ collectd.org v0.3.0/go.mod h1:A/8DzQBkF6abtvrT2j/AU/4tiBgJWYyh0y/oB/4MlWE=
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
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.2-0.20220423151921-75736d82dc53 h1:xhldNdThQEU1+JPOg65avldOvPEQYeGByNeTvGMFM6I=
github.com/0chain/gosdk v1.8.2-0.20220423151921-75736d82dc53/go.mod h1:Ug0PnuaP1E7FmNrRrZ4/UaC6AveGqU/fDleVFRyFGYg=
github.com/0chain/gosdk v1.8.2-0.20220425031623-55bd6fee2f46 h1:sG8clBv7xgDyLFpzUPy4sjWvRqthxqp/ghNYp801NiA=
github.com/0chain/gosdk v1.8.2-0.20220425031623-55bd6fee2f46/go.mod h1:Ug0PnuaP1E7FmNrRrZ4/UaC6AveGqU/fDleVFRyFGYg=
github.com/Azure/azure-sdk-for-go/sdk/azcore v0.21.1/go.mod h1:fBF9PQNqB8scdgpZ3ufzaLntG0AG7C1WjPMsiFOmfHM=
github.com/Azure/azure-sdk-for-go/sdk/internal v0.8.3/go.mod h1:KLF4gFr6DcKFZwSuH8w8yEK6DpFl3LP5rhdvAb7Yz5I=
github.com/Azure/azure-sdk-for-go/sdk/storage/azblob v0.3.0/go.mod h1:tPaiy8S5bQ+S5sOiDlINkp7+Ef339+Nz5L5XO+cnOHo=
Expand Down

0 comments on commit 98dad22

Please sign in to comment.