Skip to content

Commit

Permalink
Merge pull request #178 from bnb-chain/develop
Browse files Browse the repository at this point in the history
release: prepare for release v0.2.5
  • Loading branch information
alexgao001 authored Sep 13, 2023
2 parents 0660be8 + cf9f37d commit 46c652e
Show file tree
Hide file tree
Showing 16 changed files with 433 additions and 68 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.5-alpha.1
GreenfieldStorageProviderTag: v0.2.4-hf.4
GreenfieldTag: v0.2.5
GreenfieldStorageProviderTag: v0.2.5-alpha.3
GOPRIVATE: github.com/bnb-chain
GH_ACCESS_TOKEN: ${{ secrets.GH_TOKEN }}
MYSQL_USER: root
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ cosmossdk.io/api => github.com/bnb-chain/greenfield-cosmos-sdk/api v0.0.0-202308
cosmossdk.io/math => github.com/bnb-chain/greenfield-cosmos-sdk/math v0.0.0-20230816082903-b48770f5e210
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/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
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
github.com/consensys/gnark-crypto => github.com/consensys/gnark-crypto v0.7.0
Expand Down
81 changes: 78 additions & 3 deletions client/api_bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ type Bucket interface {
GetMigrateBucketApproval(ctx context.Context, migrateBucketMsg *storageTypes.MsgMigrateBucket) (*storageTypes.MsgMigrateBucket, error)
MigrateBucket(ctx context.Context, bucketName string, opts types.MigrateBucketOptions) (string, error)
CancelMigrateBucket(ctx context.Context, bucketName string, opts types.CancelMigrateBucketOptions) (uint64, string, error)
// ListBucketsByPaymentAccount list buckets by payment account
ListBucketsByPaymentAccount(ctx context.Context, paymentAccount string, opts types.ListBucketsByPaymentAccountOptions) (types.ListBucketsByPaymentAccountResult, error)
}

// GetCreateBucketApproval returns the signature info for the approval of preCreating resources
Expand Down Expand Up @@ -400,18 +402,37 @@ func (m *GfSpListBucketsByIDsResponse) UnmarshalXML(d *xml.Decoder, start xml.St
func (c *client) ListBuckets(ctx context.Context, opts types.ListBucketsOptions) (types.ListBucketsResult, error) {
params := url.Values{}
params.Set("include-removed", strconv.FormatBool(opts.ShowRemovedBucket))

account := opts.Account
if account == "" {
acc, err := c.GetDefaultAccount()
if err != nil {
log.Error().Msg(fmt.Sprintf("failed to get default account: %s", err.Error()))
return types.ListBucketsResult{}, err
}
account = acc.GetAddress().String()
} else {
_, err := sdk.AccAddressFromHexUnsafe(account)
if err != nil {
return types.ListBucketsResult{}, err
}
}

reqMeta := requestMeta{
urlValues: params,
contentSHA256: types.EmptyStringSHA256,
userAddress: c.MustGetDefaultAccount().GetAddress().String(),
userAddress: account,
}

sendOpt := sendOptions{
method: http.MethodGet,
disableCloseBody: true,
}

endpoint, err := c.getEndpointByOpt(opts.EndPointOptions)
endpoint, err := c.getEndpointByOpt(&types.EndPointOptions{
Endpoint: opts.Endpoint,
SPAddress: opts.SPAddress,
})
if err != nil {
log.Error().Msg(fmt.Sprintf("get endpoint by option failed %s", err.Error()))
return types.ListBucketsResult{}, err
Expand All @@ -437,7 +458,7 @@ func (c *client) ListBuckets(ctx context.Context, opts types.ListBucketsOptions)
err = xml.Unmarshal([]byte(bufStr), &listBucketsResult)

// TODO(annie) remove tolerance for unmarshal err after structs got stabilized
if err != nil && listBucketsResult.Buckets == nil {
if err != nil {
return types.ListBucketsResult{}, err
}

Expand Down Expand Up @@ -773,3 +794,57 @@ func (c *client) CancelMigrateBucket(ctx context.Context, bucketName string, opt

return c.SubmitProposal(ctx, []sdk.Msg{cancelBucketMsg}, opts.ProposalDepositAmount, opts.ProposalTitle, opts.ProposalSummary, types.SubmitProposalOptions{Metadata: opts.ProposalMetaData, TxOption: opts.TxOpts})
}

// ListBucketsByPaymentAccount list bucket by payment account
func (c *client) ListBucketsByPaymentAccount(ctx context.Context, paymentAccount string, opts types.ListBucketsByPaymentAccountOptions) (types.ListBucketsByPaymentAccountResult, error) {

_, err := sdk.AccAddressFromHexUnsafe(paymentAccount)
if err != nil {
return types.ListBucketsByPaymentAccountResult{}, err
}

params := url.Values{}
params.Set("payment-buckets", "")
params.Set("payment-account", paymentAccount)

reqMeta := requestMeta{
urlValues: params,
contentSHA256: types.EmptyStringSHA256,
}

sendOpt := sendOptions{
method: http.MethodGet,
disableCloseBody: true,
}

endpoint, err := c.getEndpointByOpt(&types.EndPointOptions{
Endpoint: opts.Endpoint,
SPAddress: opts.SPAddress,
})
if err != nil {
log.Error().Msg(fmt.Sprintf("get endpoint by option failed %s", err.Error()))
return types.ListBucketsByPaymentAccountResult{}, err

}

resp, err := c.sendReq(ctx, reqMeta, &sendOpt, endpoint)
if err != nil {
return types.ListBucketsByPaymentAccountResult{}, err
}
defer utils.CloseResponse(resp)

buf := new(strings.Builder)
_, err = io.Copy(buf, resp.Body)
if err != nil {
return types.ListBucketsByPaymentAccountResult{}, errors.New("copy the response error" + err.Error())
}

buckets := types.ListBucketsByPaymentAccountResult{}
bufStr := buf.String()
err = xml.Unmarshal([]byte(bufStr), &buckets)
if err != nil {
return types.ListBucketsByPaymentAccountResult{}, errors.New("unmarshal response error" + err.Error())
}

return buckets, nil
}
24 changes: 18 additions & 6 deletions client/api_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,10 @@ func (c *client) ListGroup(ctx context.Context, name, prefix string, opts types.
disableCloseBody: true,
}

endpoint, err := c.getEndpointByOpt(opts.EndPointOptions)
endpoint, err := c.getEndpointByOpt(&types.EndPointOptions{
Endpoint: opts.Endpoint,
SPAddress: opts.SPAddress,
})
if err != nil {
log.Error().Msg(fmt.Sprintf("get endpoint by option failed %s", err.Error()))
return types.ListGroupsResult{}, err
Expand All @@ -342,7 +345,7 @@ func (c *client) ListGroup(ctx context.Context, name, prefix string, opts types.
listGroupsResult := types.ListGroupsResult{}
bufStr := buf.String()
err = xml.Unmarshal([]byte(bufStr), &listGroupsResult)
if err != nil && listGroupsResult.Groups == nil {
if err != nil {
log.Error().Msg("the list of groups failed: " + err.Error())
return types.ListGroupsResult{}, err
}
Expand Down Expand Up @@ -403,7 +406,10 @@ func (c *client) ListGroupMembers(ctx context.Context, groupID int64, opts types
disableCloseBody: true,
}

endpoint, err := c.getEndpointByOpt(opts.EndPointOptions)
endpoint, err := c.getEndpointByOpt(&types.EndPointOptions{
Endpoint: opts.Endpoint,
SPAddress: opts.SPAddress,
})
if err != nil {
log.Error().Msg(fmt.Sprintf("get endpoint by option failed %s", err.Error()))
return &types.GroupMembersResult{}, err
Expand Down Expand Up @@ -447,7 +453,7 @@ func (c *client) ListGroupsByAccount(ctx context.Context, opts types.GroupsPagin
if account == "" {
acc, err := c.GetDefaultAccount()
if err != nil {
log.Error().Msg(fmt.Sprintf("get default account failed %s", err.Error()))
log.Error().Msg(fmt.Sprintf("failed to get default account: %s", err.Error()))
return &types.GroupsResult{}, err
}
account = acc.GetAddress().String()
Expand All @@ -464,7 +470,10 @@ func (c *client) ListGroupsByAccount(ctx context.Context, opts types.GroupsPagin
disableCloseBody: true,
}

endpoint, err := c.getEndpointByOpt(opts.EndPointOptions)
endpoint, err := c.getEndpointByOpt(&types.EndPointOptions{
Endpoint: opts.Endpoint,
SPAddress: opts.SPAddress,
})
if err != nil {
log.Error().Msg(fmt.Sprintf("get endpoint by option failed %s", err.Error()))
return &types.GroupsResult{}, err
Expand Down Expand Up @@ -525,7 +534,10 @@ func (c *client) ListGroupsByOwner(ctx context.Context, opts types.GroupsOwnerPa
disableCloseBody: true,
}

endpoint, err := c.getEndpointByOpt(opts.EndPointOptions)
endpoint, err := c.getEndpointByOpt(&types.EndPointOptions{
Endpoint: opts.Endpoint,
SPAddress: opts.SPAddress,
})
if err != nil {
log.Error().Msg(fmt.Sprintf("get endpoint by option failed %s", err.Error()))
return &types.GroupsResult{}, err
Expand Down
64 changes: 63 additions & 1 deletion client/api_object.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ type Object interface {
GetObjectResumableUploadOffset(ctx context.Context, bucketName, objectName string) (uint64, error)
// ListObjectsByObjectID list objects by object ids
ListObjectsByObjectID(ctx context.Context, objectIds []uint64, opts types.EndPointOptions) (types.ListObjectsByObjectIDResponse, error)
// ListObjectPolicies list object policies by object info and action type
ListObjectPolicies(ctx context.Context, objectName, bucketName string, actionType uint32, opts types.ListObjectPoliciesOptions) (types.ListObjectPoliciesResponse, error)
}

// GetRedundancyParams query and return the data shards, parity shards and segment size of redundancy
Expand Down Expand Up @@ -920,7 +922,10 @@ func (c *client) ListObjects(ctx context.Context, bucketName string, opts types.
disableCloseBody: true,
}

endpoint, err := c.getEndpointByOpt(opts.EndPointOptions)
endpoint, err := c.getEndpointByOpt(&types.EndPointOptions{
Endpoint: opts.Endpoint,
SPAddress: opts.SPAddress,
})
if err != nil {
log.Error().Msg(fmt.Sprintf("get endpoint by option failed %s", err.Error()))
return types.ListObjectsResult{}, err
Expand Down Expand Up @@ -1265,3 +1270,60 @@ func (c *client) ListObjectsByObjectID(ctx context.Context, objectIds []uint64,

return objects, nil
}

// ListObjectPolicies list object policies by object info and action type
func (c *client) ListObjectPolicies(ctx context.Context, objectName, bucketName string, actionType uint32, opts types.ListObjectPoliciesOptions) (types.ListObjectPoliciesResponse, error) {
params := url.Values{}
params.Set("object-policies", "")
// StartAfter is used to input the policy id for pagination purposes
params.Set("start-after", opts.StartAfter)
// If the limit is set to 0, it will default to 50.
// If the limit exceeds 1000, only 1000 records will be returned.
params.Set("limit", strconv.FormatInt(opts.Limit, 10))
params.Set("action-type", strconv.FormatUint(uint64(actionType), 10))

reqMeta := requestMeta{
urlValues: params,
bucketName: bucketName,
objectName: objectName,
contentSHA256: types.EmptyStringSHA256,
}

sendOpt := sendOptions{
method: http.MethodGet,
disableCloseBody: true,
}

endpoint, err := c.getEndpointByOpt(&types.EndPointOptions{
Endpoint: opts.Endpoint,
SPAddress: opts.SPAddress,
})
if err != nil {
log.Error().Msg(fmt.Sprintf("get endpoint by option failed %s", err.Error()))
return types.ListObjectPoliciesResponse{}, err
}

resp, err := c.sendReq(ctx, reqMeta, &sendOpt, endpoint)
if err != nil {
return types.ListObjectPoliciesResponse{}, err
}
defer utils.CloseResponse(resp)

// unmarshal the json content from response body
buf := new(strings.Builder)
_, err = io.Copy(buf, resp.Body)
if err != nil {
log.Error().Msgf("the list object policies in bucket name:%s, object name:%s failed: %s", bucketName, objectName, err.Error())
return types.ListObjectPoliciesResponse{}, err
}

policies := types.ListObjectPoliciesResponse{}
bufStr := buf.String()
err = xml.Unmarshal([]byte(bufStr), &policies.Policies)
if err != nil {
log.Error().Msgf("the list object policies in bucket name:%s, object name:%s failed: %s", bucketName, objectName, err.Error())
return types.ListObjectPoliciesResponse{}, err
}

return policies, nil
}
72 changes: 71 additions & 1 deletion client/api_payment.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,22 @@ package client

import (
"context"
"encoding/xml"
"errors"
"fmt"
"io"
"net/http"
"net/url"
"strings"

"cosmossdk.io/math"
gnfdSdkTypes "github.com/bnb-chain/greenfield/sdk/types"
paymentTypes "github.com/bnb-chain/greenfield/x/payment/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/rs/zerolog/log"

paymentTypes "github.com/bnb-chain/greenfield/x/payment/types"
"github.com/bnb-chain/greenfield-go-sdk/pkg/utils"
"github.com/bnb-chain/greenfield-go-sdk/types"
)

type Payment interface {
Expand All @@ -16,6 +26,7 @@ type Payment interface {
Deposit(ctx context.Context, toAddress string, amount math.Int, txOption gnfdSdkTypes.TxOption) (string, error)
Withdraw(ctx context.Context, fromAddress string, amount math.Int, txOption gnfdSdkTypes.TxOption) (string, error)
DisableRefund(ctx context.Context, paymentAddress string, txOption gnfdSdkTypes.TxOption) (string, error)
ListUserPaymentAccounts(ctx context.Context, opts types.ListUserPaymentAccountsOptions) (types.ListUserPaymentAccountsResult, error)
}

// GetStreamRecord retrieves stream record information for a given stream address.
Expand Down Expand Up @@ -83,3 +94,62 @@ func (c *client) DisableRefund(ctx context.Context, paymentAddress string, txOpt
}
return tx.TxResponse.TxHash, nil
}

// ListUserPaymentAccounts list payment info by user address
func (c *client) ListUserPaymentAccounts(ctx context.Context, opts types.ListUserPaymentAccountsOptions) (types.ListUserPaymentAccountsResult, error) {
params := url.Values{}
params.Set("user-payments", "")

account := opts.Account
if account == "" {
acc, err := c.GetDefaultAccount()
if err != nil {
log.Error().Msg(fmt.Sprintf("failed to get default account: %s", err.Error()))
return types.ListUserPaymentAccountsResult{}, err
}
account = acc.GetAddress().String()
}

reqMeta := requestMeta{
urlValues: params,
contentSHA256: types.EmptyStringSHA256,
userAddress: account,
}

sendOpt := sendOptions{
method: http.MethodGet,
disableCloseBody: true,
}

endpoint, err := c.getEndpointByOpt(&types.EndPointOptions{
Endpoint: opts.Endpoint,
SPAddress: opts.SPAddress,
})
if err != nil {
log.Error().Msg(fmt.Sprintf("get endpoint by option failed %s", err.Error()))
return types.ListUserPaymentAccountsResult{}, err
}

resp, err := c.sendReq(ctx, reqMeta, &sendOpt, endpoint)
if err != nil {
return types.ListUserPaymentAccountsResult{}, errors.New("send request error" + err.Error())
}
defer utils.CloseResponse(resp)

paymentAccounts := types.ListUserPaymentAccountsResult{}
// unmarshal the json content from response body
buf := new(strings.Builder)
_, err = io.Copy(buf, resp.Body)
if err != nil {
return types.ListUserPaymentAccountsResult{}, errors.New("unmarshal response error" + err.Error())
}

bufStr := buf.String()
err = xml.Unmarshal([]byte(bufStr), &paymentAccounts)

if err != nil {
return types.ListUserPaymentAccountsResult{}, err
}

return paymentAccounts, nil
}
1 change: 1 addition & 0 deletions examples/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const (
groupName = "test-group"
toAddress = "0x.." // used for cross chain transfer
httpsAddr = ""
paymentAddr = ""
)

func handleErr(err error, funcName string) {
Expand Down
Loading

0 comments on commit 46c652e

Please sign in to comment.