Skip to content

Commit

Permalink
Merge pull request #616 from 0chain/sprint-1.14
Browse files Browse the repository at this point in the history
Sprint 1.14
  • Loading branch information
dabasov committed May 5, 2024
2 parents 9310b43 + 5ec6811 commit dc2fbc7
Show file tree
Hide file tree
Showing 17 changed files with 829 additions and 443 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/gosdk.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,5 @@ jobs:
0Chain GoSDK `${{ github.event.inputs.gosdk }}` is released.
see full changelog on https://github.com/0chain/gosdk/releases/tag/${{ github.event.inputs.gosdk }}
draft: false
reviewers: cnlangzi
reviewers: guruhubb
labels: GoSDK
907 changes: 521 additions & 386 deletions README.md

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions cmd/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ var addCmd = &cobra.Command{
Short: "Adds free storage assigner",
Long: "Adds free storage assigner",
Args: cobra.MinimumNArgs(0),
Hidden: true,
Run: func(cmd *cobra.Command, args []string) {
var err error
var flags = cmd.Flags()
Expand Down
1 change: 1 addition & 0 deletions cmd/fileRefs.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ var fileRefsCmd = &cobra.Command{
Short: "get list of recently added refs",
Long: `get list of recently added refs`,
Args: cobra.MinimumNArgs(0),
Hidden: true,
Run: func(cmd *cobra.Command, args []string) {
page, err := cmd.Flags().GetUint("page")
checkError(err)
Expand Down
1 change: 1 addition & 0 deletions cmd/getmpt.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ var getMptKeyCommand = &cobra.Command{
Short: "Directly view blockchain data",
Long: `Directly view blockchain data from MPT key`,
Args: cobra.MinimumNArgs(0),
Hidden: true,
Run: func(cmd *cobra.Command, args []string) {
if cmd.Flags().Changed("key") == false {
log.Fatal("Required Mpt key missing\n")
Expand Down
27 changes: 22 additions & 5 deletions cmd/newallocation.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ var (
size *int64
allocationFileName *string
preferred_blobbers []string
blobber_auth_tickets []string
)

func getPriceRange(val string) (pr sdk.PriceRange, err error) {
Expand Down Expand Up @@ -119,6 +120,17 @@ var newallocationCmd = &cobra.Command{
}
}

if flags.Changed("blobber_auth_tickets") {
b, err := flags.GetString("blobber_auth_tickets")
if err != nil {
log.Fatal("invalid read_price value: ", err)
}
blobber_auth_tickets = strings.Split(b, ",")
for i, id := range blobber_auth_tickets {
blobber_auth_tickets[i] = strings.TrimSpace(id)
}
}

if flags.Changed("read_price") {
rps, err := flags.GetString("read_price")
if err != nil {
Expand Down Expand Up @@ -171,6 +183,7 @@ var newallocationCmd = &cobra.Command{
}

thirdPartyExtendable, _ := flags.GetBool("third_party_extendable")
force, _ := flags.GetBool("force")

// Read the file options flags
var fileOptionParams sdk.FileOptionsParameters
Expand Down Expand Up @@ -230,17 +243,19 @@ var newallocationCmd = &cobra.Command{
ParityShards: *parityshards,
Size: *size,
ReadPrice: sdk.PriceRange{
Min: uint64(readPrice.Min),
Max: uint64(readPrice.Max),
Min: readPrice.Min,
Max: readPrice.Max,
},
WritePrice: sdk.PriceRange{
Min: uint64(writePrice.Min),
Max: uint64(writePrice.Max),
Min: writePrice.Min,
Max: writePrice.Max,
},
Lock: uint64(lock),
BlobberIds: preferred_blobbers,
BlobberAuthTickets: blobber_auth_tickets,
FileOptionsParams: &fileOptionParams,
ThirdPartyExtendable: thirdPartyExtendable,
Force: force,
}
allocationID, _, _, err = sdk.CreateAllocationWith(options)
if err != nil {
Expand All @@ -258,7 +273,7 @@ var newallocationCmd = &cobra.Command{
}

allocationID, _, _, err = sdk.CreateAllocationForOwner(owner, ownerPublicKey, *datashards, *parityshards,
*size, readPrice, writePrice, lock, preferred_blobbers, thirdPartyExtendable, &fileOptionParams)
*size, readPrice, writePrice, lock, preferred_blobbers, blobber_auth_tickets, thirdPartyExtendable, force, &fileOptionParams)
if err != nil {
log.Fatal("Error creating allocation: ", err)
}
Expand Down Expand Up @@ -327,7 +342,9 @@ func init() {

newallocationCmd.Flags().String("name", "", "allocation name")
newallocationCmd.Flags().String("preferred_blobbers", "", "coma seperated list of preferred blobbers")
newallocationCmd.Flags().String("blobber_auth_tickets", "", "coma seperated list of blobber auth tickets")

newallocationCmd.Flags().Bool("force", false, "(default false) force to get blobbers even if required number of blobbers are not available (should be passed true in case of restricted blobbers)")
newallocationCmd.Flags().Bool("third_party_extendable", false, "(default false) specify if the allocation can be extended by users other than the owner")
newallocationCmd.Flags().Bool("forbid_upload", false, "(default false) specify if users cannot upload to this allocation")
newallocationCmd.Flags().Bool("forbid_delete", false, "(default false) specify if the users cannot delete objects from this allocation")
Expand Down
1 change: 1 addition & 0 deletions cmd/rolllback.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ var rollbackCmd = &cobra.Command{
Short: "rollback file to previous version",
Long: `rollback file to previous version`,
Args: cobra.MinimumNArgs(0),
Hidden: true,
Run: func(cmd *cobra.Command, args []string) {
fflags := cmd.Flags()
if !fflags.Changed("allocation") {
Expand Down
2 changes: 1 addition & 1 deletion cmd/share.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func init() {
rootCmd.AddCommand(shareCmd)
shareCmd.PersistentFlags().String("allocation", "", "Allocation ID")
shareCmd.PersistentFlags().String("remotepath", "", "Remote path to share")
shareCmd.PersistentFlags().String("clientid", "", "ClientID of the user to share with. Leave blank for public share")
shareCmd.PersistentFlags().String("clientid", "", "ClientID of the user to share with (or revoke share from). Leave blank for public share (or revoking public access).")
shareCmd.PersistentFlags().String("encryptionpublickey", "", "Encryption public key of the client you want to share with. Can be retrieved by the getwallet command")
shareCmd.PersistentFlags().Int64("expiration-seconds", 0, "Authticket will expire when the seconds specified have elapsed after the instant of its creation")
shareCmd.PersistentFlags().String("available-after", "", "Timelock for private file that makes the file available for download at certain time. 4 input formats are supported: +1h30m, +30, 1647858200 and 2022-03-21 10:21:38. Default value is current local time.")
Expand Down
4 changes: 2 additions & 2 deletions cmd/stakepool.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ func printStakePoolInfo(info *sdk.StakePoolInfo) {
// settings
fmt.Println("settings:")
fmt.Println(" delegate_wallet: ", info.Settings.DelegateWallet)
fmt.Println(" min_stake: ", info.Settings.MinStake.String())
fmt.Println(" max_stake: ", info.Settings.MaxStake.String())
//fmt.Println(" min_stake: ", info.Settings.MinStake.String())
//fmt.Println(" max_stake: ", info.Settings.MaxStake.String())
fmt.Println(" num_delegates: ", info.Settings.NumDelegates)
}

Expand Down
76 changes: 36 additions & 40 deletions cmd/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,16 @@ var lsBlobers = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) {
doJSON, _ := cmd.Flags().GetBool("json")
doAll, _ := cmd.Flags().GetBool("all")

isStakable, err := cmd.Flags().GetBool("stakable")
if err != nil {
log.Fatalf("err parsing in stakable flag: %v", err)
}
// set is_active=true to get only active blobbers
isActive := true
if doAll {
isActive = false
}
var list, err = sdk.GetBlobbers(isActive)
list, err := sdk.GetBlobbers(isActive, isStakable)
if err != nil {
log.Fatalf("Failed to get storage SC configurations: %v", err)
}
Expand Down Expand Up @@ -133,14 +136,15 @@ var blobberInfoCmd = &cobra.Command{
fmt.Println("capacity_used: ", blob.Allocated)
fmt.Println("total_stake: ", blob.TotalStake)
fmt.Println("not_available: ", blob.NotAvailable)
fmt.Println("is_restricted: ", blob.IsRestricted)
fmt.Println("terms:")
fmt.Println(" read_price: ", blob.Terms.ReadPrice, "/ GB")
fmt.Println(" write_price: ", blob.Terms.WritePrice, "/ GB")
fmt.Println(" max_offer_duration:", blob.Terms.MaxOfferDuration)
fmt.Println("settings:")
fmt.Println(" delegate_wallet:", blob.StakePoolSettings.DelegateWallet)
fmt.Println(" min_stake: ", blob.StakePoolSettings.MinStake)
fmt.Println(" max_stake: ", blob.StakePoolSettings.MaxStake)
//fmt.Println(" min_stake: ", blob.StakePoolSettings.MinStake)
//fmt.Println(" max_stake: ", blob.StakePoolSettings.MaxStake)
fmt.Println(" num_delegates: ", blob.StakePoolSettings.NumDelegates)
fmt.Println(" service_charge: ", blob.StakePoolSettings.ServiceCharge*100, "%")
},
Expand Down Expand Up @@ -221,32 +225,6 @@ var blobberUpdateCmd = &cobra.Command{

stakePoolSettings := &blockchain.UpdateStakePoolSettings{}
var stakePoolSettingChanged bool
if flags.Changed("min_stake") {
var minStake float64
if minStake, err = flags.GetFloat64("min_stake"); err != nil {
log.Fatal(err)
}
stake, err := common.ToBalance(minStake)
if err != nil {
log.Fatal(err)
}
stakePoolSettings.MinStake = &stake
stakePoolSettingChanged = true
}

if flags.Changed("max_stake") {
var maxStake float64
if maxStake, err = flags.GetFloat64("max_stake"); err != nil {
log.Fatal(err)
}
stake, err := common.ToBalance(maxStake)
if err != nil {
log.Fatal(err)
}
stakePoolSettings.MaxStake = &stake
stakePoolSettingChanged = true
}

if flags.Changed("num_delegates") {
var nd int
if nd, err = flags.GetInt("num_delegates"); err != nil {
Expand Down Expand Up @@ -274,11 +252,26 @@ var blobberUpdateCmd = &cobra.Command{
}

if flags.Changed("not_available") {
var na bool
if na, err = flags.GetBool("not_available"); err != nil {
log.Fatal(err)
}
if !na {
na = false
}
updateBlobber.NotAvailable = &na
}

if flags.Changed("is_restricted") {
var ia bool
if ia, err = flags.GetBool("not_available"); err != nil {
// Check if the flag is set to true
if ia, err = flags.GetBool("is_restricted"); err != nil {
log.Fatal(err)
}
updateBlobber.NotAvailable = &ia
if !ia {
ia = false
}
updateBlobber.IsRestricted = &ia
}

if termsChanged {
Expand All @@ -301,16 +294,17 @@ var resetBlobberStatsCmd = &cobra.Command{
Short: "Reset blobber stats",
Long: `Reset blobber stats`,
Args: cobra.MinimumNArgs(0),
Hidden: true,
Run: func(cmd *cobra.Command, args []string) {
var (
flags = cmd.Flags()

blobberID string
blobberID string
prevAllocated int64
prevSavedData int64
newAllocated int64
newSavedData int64
err error
newAllocated int64
newSavedData int64
err error
)

if !flags.Changed("blobber_id") {
Expand Down Expand Up @@ -348,12 +342,12 @@ var resetBlobberStatsCmd = &cobra.Command{
log.Fatal("error in 'new_saved_data' flag: ", err)
}

resetBlobberStatsDto := &sdk.ResetBlobberStatsDto {
BlobberID: blobberID,
resetBlobberStatsDto := &sdk.ResetBlobberStatsDto{
BlobberID: blobberID,
PrevAllocated: prevAllocated,
PrevSavedData: prevSavedData,
NewAllocated: newAllocated,
NewSavedData: newSavedData,
NewAllocated: newAllocated,
NewSavedData: newSavedData,
}
fmt.Println(*resetBlobberStatsDto)

Expand All @@ -375,6 +369,7 @@ func init() {
scConfig.Flags().Bool("json", false, "(default false) pass this option to print response as json data")
lsBlobers.Flags().Bool("json", false, "(default false) pass this option to print response as json data")
lsBlobers.Flags().Bool("all", false, "(default false) shows active and non active list of blobbers on ls-blobbers")
lsBlobers.Flags().Bool("stakable", false, "(default false) gets only stakable list of blobbers if set to true")

blobberInfoCmd.Flags().String("blobber_id", "", "blobber ID, required")
blobberInfoCmd.Flags().Bool("json", false,
Expand All @@ -392,6 +387,7 @@ func init() {
buf.Int("num_delegates", 0, "update num_delegates, optional")
buf.Float64("service_charge", 0.0, "update service_charge, optional")
buf.Bool("not_available", true, "(default false) set blobber's availability for new allocations")
buf.Bool("is_restricted", true, "(default false) set is_restricted")
buf.String("url", "", "update the url of the blobber, optional")
blobberUpdateCmd.MarkFlagRequired("blobber_id")

Expand Down
2 changes: 1 addition & 1 deletion cmd/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ var streamCmd = &cobra.Command{
Short: "capture video and audio streaming form local devices, and upload",
Long: "capture video and audio streaming form local devices, and upload",
Args: cobra.MinimumNArgs(0),
Hidden: true,
Run: func(cmd *cobra.Command, args []string) {
fflags := cmd.Flags() // fflags is a *flag.FlagSet
if !fflags.Changed("allocation") { // check if the flag "path" is set
Expand Down Expand Up @@ -114,7 +115,6 @@ func init() {
streamCmd.PersistentFlags().String("allocation", "", "Allocation ID")
streamCmd.PersistentFlags().String("remotepath", "", "Remote path to upload")
streamCmd.PersistentFlags().String("localpath", "", "Local path of file to upload")
streamCmd.PersistentFlags().String("thumbnailpath", "", "Local thumbnail path of file to upload")
streamCmd.PersistentFlags().String("attr-who-pays-for-reads", "owner", "Who pays for reads: owner or 3rd_party")
streamCmd.Flags().Bool("encrypt", false, "(default false) pass this option to encrypt and upload the file")

Expand Down
5 changes: 4 additions & 1 deletion cmd/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cmd
import (
"fmt"
"os"
"path"
"runtime"
"strings"
"sync"
Expand Down Expand Up @@ -101,7 +102,7 @@ func startMultiUploadUpdate(allocationObj *sdk.Allocation, argsSlice []chunkedUp
return err
}

mimeType, err := zboxutil.GetFileContentType(fileReader)
mimeType, err := zboxutil.GetFileContentType(path.Ext(args.localPath), fileReader)
if err != nil {
return err
}
Expand Down Expand Up @@ -151,6 +152,7 @@ var syncCmd = &cobra.Command{
Short: "Sync files to/from blobbers",
Long: `Sync all files to/from blobbers from/to a localpath`,
Args: cobra.MinimumNArgs(0),
Hidden: true,
Run: func(cmd *cobra.Command, args []string) {
fflags := cmd.Flags() // fflags is a *flag.FlagSet
if fflags.Changed("localpath") == false {
Expand Down Expand Up @@ -332,6 +334,7 @@ var getDiffCmd = &cobra.Command{
Short: "Get difference of local and allocation root",
Long: `Get difference of local and allocation root`,
Args: cobra.MinimumNArgs(0),
Hidden: true,
Run: func(cmd *cobra.Command, args []string) {

fflags := cmd.Flags() // fflags is a *flag.FlagSet
Expand Down
9 changes: 8 additions & 1 deletion cmd/updateallocation.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,15 @@ var updateAllocationCmd = &cobra.Command{
log.Fatal("invalid 'allocation_id' flag: ", err)
}

var addBlobberId, removeBlobberId string
var addBlobberId, addBlobberAuthTicket, removeBlobberId string
if flags.Changed("add_blobber") {
addBlobberId, err = flags.GetString("add_blobber")
if err != nil {
log.Fatal("invalid 'add_blobber' flag: ", err)
}

addBlobberAuthTicket, _ = flags.GetString("add_blobber_auth_ticket")

if flags.Changed("remove_blobber") {
removeBlobberId, err = flags.GetString("remove_blobber")
if err != nil {
Expand Down Expand Up @@ -130,6 +133,7 @@ var updateAllocationCmd = &cobra.Command{
extend,
lock,
addBlobberId,
addBlobberAuthTicket,
removeBlobberId,
setThirdPartyExtendable,
&fileOptionParams,
Expand All @@ -151,6 +155,7 @@ var updateAllocationCmd = &cobra.Command{
allocID,
lock,
addBlobberId,
addBlobberAuthTicket,
removeBlobberId,
setThirdPartyExtendable,
&fileOptionParams,
Expand All @@ -169,6 +174,8 @@ func init() {
"Allocation ID")
updateAllocationCmd.PersistentFlags().String("add_blobber", "",
"ID of blobber to add to the allocation")
updateAllocationCmd.PersistentFlags().String("add_blobber_auth_ticket", "",
"Auth ticket of blobber to add to the allocation")
updateAllocationCmd.PersistentFlags().String("remove_blobber", "",
"ID of blobber to remove from the allocation")
updateAllocationCmd.PersistentFlags().Float64("lock", 0.0,
Expand Down

0 comments on commit dc2fbc7

Please sign in to comment.