Skip to content

Commit

Permalink
Merge pull request #440 from multiversx/MX-15381-add-withKeys-on-api-…
Browse files Browse the repository at this point in the history
…address

added withKeys on /address
  • Loading branch information
raduchis authored Apr 24, 2024
2 parents 55707c1 + 3c47c27 commit 5815d8d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
6 changes: 6 additions & 0 deletions api/groups/urlParams.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ func parseAccountQueryOptions(c *gin.Context, address string) (common.AccountQue
return common.AccountQueryOptions{}, err
}

withKeys, err := parseBoolUrlParam(c, common.UrlParameterWithKeys)
if err != nil {
return common.AccountQueryOptions{}, err
}

if shardID.HasValue && address != SystemAccountAddressBech {
return common.AccountQueryOptions{}, ErrForcedShardIDCannotBeProvided
}
Expand All @@ -107,6 +112,7 @@ func parseAccountQueryOptions(c *gin.Context, address string) (common.AccountQue
BlockRootHash: blockRootHash,
HintEpoch: hintEpoch,
ForcedShardID: shardID,
WithKeys: withKeys,
}

return options, nil
Expand Down
6 changes: 6 additions & 0 deletions common/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ const (
UrlParameterTokensFilter = "tokens"
// UrlParameterWithAlteredAccounts represents the name of an URL parameter
UrlParameterWithAlteredAccounts = "withAlteredAccounts"
// UrlParameterWithKeys represents the name of an URL parameter
UrlParameterWithKeys = "withKeys"
)

// BlockQueryOptions holds options for block queries
Expand Down Expand Up @@ -112,6 +114,7 @@ type AccountQueryOptions struct {
BlockHash []byte
BlockRootHash []byte
HintEpoch core.OptionalUint32
WithKeys bool
}

// AreHistoricalCoordinatesSet returns true if historical block coordinates are set
Expand Down Expand Up @@ -146,6 +149,9 @@ func BuildUrlWithAccountQueryOptions(path string, options AccountQueryOptions) s
if options.HintEpoch.HasValue {
query.Set(UrlParameterHintEpoch, strconv.Itoa(int(options.HintEpoch.Value)))
}
if options.WithKeys {
query.Set(UrlParameterWithKeys, "true")
}

u.RawQuery = query.Encode()
return u.String()
Expand Down
21 changes: 11 additions & 10 deletions data/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,17 @@ type AccountsModel struct {

// Account defines the data structure for an account
type Account struct {
Address string `json:"address"`
Nonce uint64 `json:"nonce"`
Balance string `json:"balance"`
Username string `json:"username"`
Code string `json:"code"`
CodeHash []byte `json:"codeHash"`
RootHash []byte `json:"rootHash"`
CodeMetadata []byte `json:"codeMetadata"`
DeveloperReward string `json:"developerReward"`
OwnerAddress string `json:"ownerAddress"`
Address string `json:"address"`
Nonce uint64 `json:"nonce"`
Balance string `json:"balance"`
Username string `json:"username"`
Code string `json:"code"`
CodeHash []byte `json:"codeHash"`
RootHash []byte `json:"rootHash"`
CodeMetadata []byte `json:"codeMetadata"`
DeveloperReward string `json:"developerReward"`
OwnerAddress string `json:"ownerAddress"`
Pairs map[string]string `json:"pairs,omitempty"`
}

// ValidatorApiResponse represents the data which is fetched from each validator for returning it in API call
Expand Down

0 comments on commit 5815d8d

Please sign in to comment.