From 4226e203923d3173228442df78b551e1824fee7b Mon Sep 17 00:00:00 2001 From: Alexgao001 Date: Wed, 6 Sep 2023 16:01:40 +0800 Subject: [PATCH 1/2] add crosschain gov example --- examples/crosschain_gov.go | 75 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 examples/crosschain_gov.go diff --git a/examples/crosschain_gov.go b/examples/crosschain_gov.go new file mode 100644 index 00000000..d22fa60a --- /dev/null +++ b/examples/crosschain_gov.go @@ -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 +} From c9ee26a1ebdbf28dd1c6806ed5f83c934af324a8 Mon Sep 17 00:00:00 2001 From: Alexxxxxx <118710506+alexgao001@users.noreply.github.com> Date: Wed, 6 Sep 2023 20:45:16 +0800 Subject: [PATCH 2/2] chore: bump version (#173) * bump version * add api and fix e2e * fix: fix e2e and common lib --------- Co-authored-by: flywukong <2229306838@qq.com> --- .github/workflows/e2e.yml | 4 ++-- client/api_bucket.go | 12 ++++++++++++ e2e/e2e_storage_test.go | 2 -- go.mod | 6 +++--- go.sum | 10 ++++++---- 5 files changed, 23 insertions(+), 11 deletions(-) diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index b37dcb8e..d75b2c2d4 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -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 diff --git a/client/api_bucket.go b/client/api_bucket.go index f50cc653..4494e2de 100644 --- a/client/api_bucket.go +++ b/client/api_bucket.go @@ -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) @@ -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) { diff --git a/e2e/e2e_storage_test.go b/e2e/e2e_storage_test.go index 70fe9d57..1e8614d1 100644 --- a/e2e/e2e_storage_test.go +++ b/e2e/e2e_storage_test.go @@ -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 <---") diff --git a/go.mod b/go.mod index 5e5e417a..c2e413b4 100644 --- a/go.mod +++ b/go.mod @@ -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 @@ -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 ) diff --git a/go.sum b/go.sum index b5fd3ce2..53b05f5d 100644 --- a/go.sum +++ b/go.sum @@ -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=