Skip to content

Commit

Permalink
Merge pull request #174 from bnb-chain/develop
Browse files Browse the repository at this point in the history
release: prepare for release v0.2.5-alpha.1
  • Loading branch information
alexgao001 authored Sep 6, 2023
2 parents eb87889 + fba42a1 commit 0660be8
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 11 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ on:
- develop

env:
GreenfieldTag: v0.2.4
GreenfieldStorageProviderTag: develop
GreenfieldTag: v0.2.5-alpha.1
GreenfieldStorageProviderTag: v0.2.4-hf.4
GOPRIVATE: github.com/bnb-chain
GH_ACCESS_TOKEN: ${{ secrets.GH_TOKEN }}
MYSQL_USER: root
Expand Down
12 changes: 12 additions & 0 deletions client/api_bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,10 @@ type Bucket interface {
ListBuckets(ctx context.Context, opts types.ListBucketsOptions) (types.ListBucketsResult, error)
ListBucketReadRecord(ctx context.Context, bucketName string, opts types.ListReadRecordOptions) (types.QuotaRecordInfo, error)

GetQuotaUpdateTime(ctx context.Context, bucketName string) (int64, error)
BuyQuotaForBucket(ctx context.Context, bucketName string, targetQuota uint64, opt types.BuyQuotaOption) (string, error)
GetBucketReadQuota(ctx context.Context, bucketName string) (types.QuotaInfo, error)

// ListBucketsByBucketID list buckets by bucket ids
ListBucketsByBucketID(ctx context.Context, bucketIds []uint64, opts types.EndPointOptions) (types.ListBucketsByBucketIDResponse, error)
GetMigrateBucketApproval(ctx context.Context, migrateBucketMsg *storageTypes.MsgMigrateBucket) (*storageTypes.MsgMigrateBucket, error)
Expand Down Expand Up @@ -562,6 +564,16 @@ func (c *client) GetBucketReadQuota(ctx context.Context, bucketName string) (typ
return QuotaResult, nil
}

func (c *client) GetQuotaUpdateTime(ctx context.Context, bucketName string) (int64, error) {
resp, err := c.chainClient.QueryQuotaUpdateTime(ctx, &storageTypes.QueryQuoteUpdateTimeRequest{
BucketName: bucketName,
})
if err != nil {
return 0, err
}
return resp.UpdateAt, nil
}

// BuyQuotaForBucket buy the target quota of the specific bucket
// targetQuota indicates the target quota to set for the bucket
func (c *client) BuyQuotaForBucket(ctx context.Context, bucketName string, targetQuota uint64, opt types.BuyQuotaOption) (string, error) {
Expand Down
2 changes: 0 additions & 2 deletions e2e/e2e_storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,10 +207,8 @@ func (s *StorageTestSuite) Test_Object() {
expectQuotaUsed := int(objectSize) * concurrentNumber * downloadCount
quota1, err := s.Client.GetBucketReadQuota(s.ClientContext, bucketName)
s.Require().NoError(err)
consumedQuota := quota1.ReadConsumedSize - quota0.ReadConsumedSize
freeQuotaConsumed := quota1.FreeConsumedSize - quota0.FreeConsumedSize
// the consumed quota and free quota should be right
s.Require().Equal(uint64(expectQuotaUsed), consumedQuota)
s.Require().Equal(uint64(expectQuotaUsed), freeQuotaConsumed)

s.T().Log("---> PutObjectPolicy <---")
Expand Down
75 changes: 75 additions & 0 deletions examples/crosschain_gov.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package main

import (
"context"
"cosmossdk.io/math"
"github.com/bnb-chain/greenfield-go-sdk/client"
"github.com/bnb-chain/greenfield-go-sdk/types"
gnfdSdkTypes "github.com/bnb-chain/greenfield/sdk/types"
sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
govv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1"
"log"
)

func main() {
account, _ := types.NewAccountFromPrivateKey("proposer", privateKey)
cli, _ := client.New(chainId, rpcAddr, client.Option{DefaultAccount: account})
ctx := context.Background()

// The example below is for parameter change, each proposal can have only 1 msg, either change parameter or upgrade contract
proposalID, txHash, err := cli.SubmitProposal(
ctx,
[]sdk.Msg{parameterChange()}, // or upgradeContract() for upgrading contract
math.NewIntWithDecimal(1000, gnfdSdkTypes.DecimalBNB), // deposit, various from different env
"Change BSC contract parameter",
"Change BSC contract parameter",
types.SubmitProposalOptions{TxOption: gnfdSdkTypes.TxOption{}},
)
if err != nil {
log.Fatalf("unable to submit proposal , %v", err)
}
cli.WaitForTx(ctx, txHash)

// Have validators to vote for the proposal
// there should be enough validators to vote for the proposal
validatorPrivKey := "0x..."
validatorAcct, _ := types.NewAccountFromPrivateKey("validator", validatorPrivKey)
cli.SetDefaultAccount(validatorAcct)
voteTxHash, err := cli.VoteProposal(ctx, proposalID, govv1.OptionYes, types.VoteProposalOptions{})
cli.WaitForTx(ctx, voteTxHash)
}

// Suppose we want to modify a parameter of contract 0x40eC91B82D7aCAA065d54B08D751505D479b0E43, fillin CrossChainParamsChange as below
// note: Values if a slice of hex representation of the value you want to modify to(must not include 0x prefix), Targets defines the target contract address(es).
func parameterChange() sdk.Msg {
govAcctAddress := authtypes.NewModuleAddress(govtypes.ModuleName).String()
msgUpdateParams := &govv1.MsgUpdateCrossChainParams{
Authority: govAcctAddress,
Params: govv1.CrossChainParamsChange{
Key: "batchSizeForOracle", // The parameter name.
Values: []string{"0000000000000000000000000000000000000000000000000000000000000034"}, // the value in hex format. The length might vary depend on the exact parameter you want to change.
Targets: []string{"0x40eC91B82D7aCAA065d54B08D751505D479b0E43"}, // the contract's address
},
DestChainId: 97, // Dest BSC chain ID
}
return msgUpdateParams
}

// Suppose the current bucketHub contract is 0x111568F484E4b8759a3aeC6aF11EA17BC18479A8, objectHub 0x2F0cf555a0E1dAE8CDacef66D8244E49Ee72Ad2D, grouphub 0x40eC91B82D7aCAA065d54B08D751505D479b0E43.
// respectively, we want to upgrade to 0x82CDc0BDb92Af93F301332Ed05F4F844c7c74FD6, 0xd00137EABe7CC9434EA70Cde29f9DB5f65a335f7, 0xc11bFABfFE9e1A4A1557f1494cb74Cc86AB69441.
// fill this the MsgUpdateCrossChainParams as below
func upgradeContract() sdk.Msg {
govAcctAddress := authtypes.NewModuleAddress(govtypes.ModuleName).String()
msgUpdateParams := &govv1.MsgUpdateCrossChainParams{
Authority: govAcctAddress,
Params: govv1.CrossChainParamsChange{
Key: "upgrade", // The key specify the purpose of the governance. It must be ""upgrade" for upgrade contract
Values: []string{"0x82CDc0BDb92Af93F301332Ed05F4F844c7c74FD6", "0xd00137EABe7CC9434EA70Cde29f9DB5f65a335f7", "0xc11bFABfFE9e1A4A1557f1494cb74Cc86AB69441"},
Targets: []string{"0x111568F484E4b8759a3aeC6aF11EA17BC18479A8", "0x2F0cf555a0E1dAE8CDacef66D8244E49Ee72Ad2D", "0x40eC91B82D7aCAA065d54B08D751505D479b0E43"},
},
DestChainId: 97, // Dest BSC chain ID
}
return msgUpdateParams
}
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ go 1.20
require (
cosmossdk.io/errors v1.0.0-beta.7
cosmossdk.io/math v1.0.1
github.com/bnb-chain/greenfield v0.2.4
github.com/bnb-chain/greenfield-common/go v0.0.0-20230809025353-fd0519705054
github.com/bnb-chain/greenfield v0.2.5-alpha.1
github.com/bnb-chain/greenfield-common/go v0.0.0-20230830120314-a54ffd6da39f
github.com/cometbft/cometbft v0.37.2
github.com/consensys/gnark-crypto v0.7.0
github.com/cosmos/cosmos-sdk v0.47.3
Expand Down Expand Up @@ -147,7 +147,7 @@ replace (
github.com/cometbft/cometbft => github.com/bnb-chain/greenfield-cometbft v0.0.3
github.com/cometbft/cometbft-db => github.com/bnb-chain/greenfield-cometbft-db v0.8.1-alpha.1
github.com/confio/ics23/go => github.com/cosmos/cosmos-sdk/ics23/go v0.8.0
github.com/cosmos/cosmos-sdk => github.com/bnb-chain/greenfield-cosmos-sdk v0.2.4
github.com/cosmos/cosmos-sdk => github.com/bnb-chain/greenfield-cosmos-sdk v0.2.5-alpha.1
github.com/cosmos/iavl => github.com/bnb-chain/greenfield-iavl v0.20.1
github.com/syndtr/goleveldb => github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7
)
10 changes: 6 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -152,16 +152,18 @@ github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kB
github.com/bgentry/speakeasy v0.1.1-0.20220910012023-760eaf8b6816 h1:41iFGWnSlI2gVpmOtVTJZNodLdLQLn/KsJqFvXwnd/s=
github.com/bgentry/speakeasy v0.1.1-0.20220910012023-760eaf8b6816/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs=
github.com/bmizerany/pat v0.0.0-20170815010413-6226ea591a40/go.mod h1:8rLXio+WjiTceGBHIoTvn60HIbs7Hm7bcHjyrSqYB9c=
github.com/bnb-chain/greenfield v0.2.4 h1:3knYY3KbEYoysnTAp3+oh2YyeWG2Au0kXYSdZHyzV+k=
github.com/bnb-chain/greenfield v0.2.4/go.mod h1:7FzduaDVOXpbiWMo0JoH8odXgwEfGJ3ug20BIgPDVKE=
github.com/bnb-chain/greenfield v0.2.5-alpha.1 h1:oUBuimPbcs95pXFXWvD8fZ9L1yJm23JxigNXX8AUT3s=
github.com/bnb-chain/greenfield v0.2.5-alpha.1/go.mod h1:/EubHc4hKZqGRwxHgKNZA5twFBYOW74+gM6lQz5bZP8=
github.com/bnb-chain/greenfield-cometbft v0.0.3 h1:tv8NMy3bzX/1urqXGQIIAZSLy83loiI+dG0VKeyh1CY=
github.com/bnb-chain/greenfield-cometbft v0.0.3/go.mod h1:f35mk/r5ab6yvzlqEWZt68LfUje68sYgMpVlt2CUYMk=
github.com/bnb-chain/greenfield-cometbft-db v0.8.1-alpha.1 h1:XcWulGacHVRiSCx90Q8Y//ajOrLNBQWR/KDB89dy3cU=
github.com/bnb-chain/greenfield-cometbft-db v0.8.1-alpha.1/go.mod h1:ey1CiK4bYo1RBNJLRiVbYr5CMdSxci9S/AZRINLtppI=
github.com/bnb-chain/greenfield-common/go v0.0.0-20230809025353-fd0519705054 h1:74pdUdHjo9QNgjSifIgzbDcloqFJ2I+qo715tOXy/oM=
github.com/bnb-chain/greenfield-common/go v0.0.0-20230809025353-fd0519705054/go.mod h1:GEjCahULmz99qx5k8WGWa7cTXIUjoNMNW+J92I+kTWg=
github.com/bnb-chain/greenfield-cosmos-sdk v0.2.4 h1:09ST+MTEAyjyBSc4ZjZzHxpNLMnIIkZ518jJVRtrKFc=
github.com/bnb-chain/greenfield-cosmos-sdk v0.2.4/go.mod h1:y3hDhQhil5hMIhwBTpu07RZBF30ZITkoE+GHhVZChtY=
github.com/bnb-chain/greenfield-common/go v0.0.0-20230830120314-a54ffd6da39f h1:zJvB2wCd80DQ9Nh/ZNQiP8MrHygSpDoav7OzHyIi/pM=
github.com/bnb-chain/greenfield-common/go v0.0.0-20230830120314-a54ffd6da39f/go.mod h1:it3JJVHeG9Wp4QED2GkY/7V9Qo3BuPdoC5/4/U6ecJM=
github.com/bnb-chain/greenfield-cosmos-sdk v0.2.5-alpha.1 h1:E6AOXDWIcFC6e4KAqI7XzMWn8nZQcGjl1ESBRwrhVh8=
github.com/bnb-chain/greenfield-cosmos-sdk v0.2.5-alpha.1/go.mod h1:y3hDhQhil5hMIhwBTpu07RZBF30ZITkoE+GHhVZChtY=
github.com/bnb-chain/greenfield-cosmos-sdk/api v0.0.0-20230816082903-b48770f5e210 h1:GHPbV2bC+gmuO6/sG0Tm8oGal3KKSRlyE+zPscDjlA8=
github.com/bnb-chain/greenfield-cosmos-sdk/api v0.0.0-20230816082903-b48770f5e210/go.mod h1:vhsZxXE9tYJeYB5JR4hPhd6Pc/uPf7j1T8IJ7p9FdeM=
github.com/bnb-chain/greenfield-cosmos-sdk/math v0.0.0-20230816082903-b48770f5e210 h1:FLVOn4+OVbsKi2+YJX5kmD27/4dRu4FW7xCXFhzDO5s=
Expand Down

0 comments on commit 0660be8

Please sign in to comment.