Skip to content

Commit

Permalink
Merge branch 'refs/heads/rc/v1.7.next1' into fix-transcation-endpoint
Browse files Browse the repository at this point in the history
# Conflicts:
#	process/transactionProcessor.go
  • Loading branch information
miiu96 committed Aug 6, 2024
2 parents e23a42f + ceb38a0 commit 2b6d0a7
Show file tree
Hide file tree
Showing 28 changed files with 542 additions and 368 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@

.idea/
vendor/
cmd/proxy/proxy
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ For more details, go [here](https://docs.multiversx.com/sdk-and-tools/proxy/).
- `/v1.0/address/:address/shard` (GET) --> returns the shard of an :address based on current proxy's configuration.
- `/v1.0/address/:address/keys ` (GET) --> returns the key-value pairs of an :address.
- `/v1.0/address/:address/storage/:key` (GET) --> returns the value for a given key for an account.
- `/v1.0/address/:address/transactions` (GET) --> returns the transactions stored in indexer for a given :address.
- `/v1.0/address/:address/esdt` (GET) --> returns the account's ESDT tokens list for the given :address.
- `/v1.0/address/:address/esdt/:tokenIdentifier` (GET) --> returns the token data for a given :address and ESDT token, such as balance and properties.
- `/v1.0/address/:address/esdts-with-role/:role` (GET) --> returns the token identifiers for a given :address and the provided role.
Expand Down
22 changes: 0 additions & 22 deletions api/groups/baseAccountsGroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ func NewAccountsGroup(facadeHandler data.FacadeHandler) (*accountsGroup, error)
{Path: "/:address/nonce", Handler: ag.getNonce, Method: http.MethodGet},
{Path: "/:address/shard", Handler: ag.getShard, Method: http.MethodGet},
{Path: "/:address/code-hash", Handler: ag.getCodeHash, Method: http.MethodGet},
{Path: "/:address/transactions", Handler: ag.getTransactions, Method: http.MethodGet},
{Path: "/:address/keys", Handler: ag.getKeyValuePairs, Method: http.MethodGet},
{Path: "/:address/key/:key", Handler: ag.getValueForKey, Method: http.MethodGet},
{Path: "/:address/esdt", Handler: ag.getESDTTokens, Method: http.MethodGet},
Expand Down Expand Up @@ -71,16 +70,6 @@ func (group *accountsGroup) respondWithAccount(c *gin.Context, transform func(*d
shared.RespondWith(c, http.StatusOK, response, "", data.ReturnCodeSuccess)
}

func (group *accountsGroup) getTransactionsFromFacade(c *gin.Context) ([]data.DatabaseTransaction, int, error) {
addr := c.Param("address")
transactions, err := group.facade.GetTransactions(addr)
if err != nil {
return nil, http.StatusInternalServerError, err
}

return transactions, http.StatusOK, nil
}

// getAccount returns an accountResponse containing information
// about the account correlated with provided address
func (group *accountsGroup) getAccount(c *gin.Context) {
Expand Down Expand Up @@ -157,17 +146,6 @@ func (group *accountsGroup) getAccounts(c *gin.Context) {
shared.RespondWith(c, http.StatusOK, response, "", data.ReturnCodeSuccess)
}

// getTransactions returns the transactions for the address parameter
func (group *accountsGroup) getTransactions(c *gin.Context) {
transactions, status, err := group.getTransactionsFromFacade(c)
if err != nil {
shared.RespondWith(c, status, nil, err.Error(), data.ReturnCodeInternalError)
return
}

shared.RespondWith(c, http.StatusOK, gin.H{"transactions": transactions}, "", data.ReturnCodeSuccess)
}

// getKeyValuePairs returns the key-value pairs for the address parameter
func (group *accountsGroup) getKeyValuePairs(c *gin.Context) {
addr := c.Param("address")
Expand Down
4 changes: 4 additions & 0 deletions api/groups/baseTransactionGroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,10 @@ func validateOptions(options common.TransactionsPoolOptions) error {
return errors.ErrEmptySenderToGetNonceGaps
}

if options.Fields == "*" {
return nil
}

if options.Fields != "" {
return validateFields(options.Fields)
}
Expand Down
1 change: 1 addition & 0 deletions api/groups/baseTransactionGroup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,7 @@ func TestGetTransactionsPool_InvalidOptions(t *testing.T) {
t.Run("empty sender when fetching nonce gaps", testInvalidParameters("?nonce-gaps=true", apiErrors.ErrEmptySenderToGetNonceGaps))
t.Run("invalid fields - numeric", testInvalidParameters("?fields=123", apiErrors.ErrInvalidFields))
t.Run("invalid characters on fields", testInvalidParameters("?fields=_/+", apiErrors.ErrInvalidFields))
t.Run("fields + wild card", testInvalidParameters("?fields=nonce,sender,*", apiErrors.ErrInvalidFields))
}

func testInvalidParameters(path string, expectedErr error) func(t *testing.T) {
Expand Down
1 change: 0 additions & 1 deletion api/groups/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
type AccountsFacadeHandler interface {
GetAccount(address string, options common.AccountQueryOptions) (*data.AccountModel, error)
GetCodeHash(address string, options common.AccountQueryOptions) (*data.GenericAPIResponse, error)
GetTransactions(address string) ([]data.DatabaseTransaction, error)
GetShardIDForAddress(address string) (uint32, error)
GetValueForKey(address string, key string, options common.AccountQueryOptions) (string, error)
GetAllESDTTokens(address string, options common.AccountQueryOptions) (*data.GenericAPIResponse, error)
Expand Down
1 change: 0 additions & 1 deletion cmd/proxy/config/apiConfig/v1_0.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ Routes = [
{ Name = "/:address/registered-nfts", Open = true, Secured = false, RateLimit = 0 },
{ Name = "/:address/nft/:tokenIdentifier/nonce/:nonce", Open = true, Secured = false, RateLimit = 0 },
{ Name = "/:address/shard", Open = true, Secured = false, RateLimit = 0 },
{ Name = "/:address/transactions", Open = true, Secured = false, RateLimit = 0 },
{ Name = "/:address/guardian-data", Open = true, Secured = false, RateLimit = 0 },
{ Name = "/:address/is-data-trie-migrated", Open = true, Secured = false, RateLimit = 0 }
]
Expand Down
1 change: 0 additions & 1 deletion cmd/proxy/config/apiConfig/v_next.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ Routes = [
{ Name = "/:address/registered-nfts", Open = true, Secured = false, RateLimit = 0 },
{ Name = "/:address/nft/:tokenIdentifier/nonce/:nonce", Open = true, Secured = false, RateLimit = 0 },
{ Name = "/:address/shard", Open = true, Secured = false, RateLimit = 0 },
{ Name = "/:address/transactions", Open = true, Secured = false, RateLimit = 0 },
{ Name = "/:address/guardian-data", Open = true, Secured = false, RateLimit = 0 },
{ Name = "/:address/is-data-trie-migrated", Open = true, Secured = false, RateLimit = 0 }
]
Expand Down
44 changes: 6 additions & 38 deletions cmd/proxy/config/swagger/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -270,38 +270,6 @@
}
}
},
"/address/{address}/transactions": {
"get": {
"tags": [
"address"
],
"summary": "returns the transactions of the provided address",
"parameters": [
{
"name": "address",
"in": "path",
"description": "the address in bech32 format",
"required": true,
"schema": {
"type": "string",
"default": null
}
}
],
"responses": {
"200": {
"description": "successful operation",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/AddressTransactions"
}
}
}
}
}
}
},
"/address/{address}/key/{key}": {
"get": {
"tags": [
Expand Down Expand Up @@ -375,7 +343,7 @@
}
}
},
"/address/{address}/esdt/roles": {
"/address/{address}/esdts/roles": {
"get": {
"tags": [
"address"
Expand Down Expand Up @@ -2671,7 +2639,7 @@
"name": "fields",
"in": "query",
"description": "the requested transaction fields, comma sepparated. If none provided, only hash is returned. Possible values are: hash, nonce, sender, receiver, gaslimit, gasprice, receiverusername, data, value",
"schema" : {
"schema": {
"type": "string",
"default": null
}
Expand All @@ -2680,7 +2648,7 @@
"name": "shard-id",
"in": "query",
"description": "the shard id to return transactions pool",
"schema" : {
"schema": {
"type": "string",
"default": null
}
Expand All @@ -2689,7 +2657,7 @@
"name": "by-sender",
"in": "query",
"description": "the bech32 address of transactions' sender",
"schema" : {
"schema": {
"type": "string",
"default": null
}
Expand All @@ -2698,7 +2666,7 @@
"name": "last-nonce",
"in": "query",
"description": "returns the last nonce from pool. This parameter requires by-sender and does not work with fields",
"schema" : {
"schema": {
"type": "boolean",
"default": false
}
Expand All @@ -2707,7 +2675,7 @@
"name": "nonce-gaps",
"in": "query",
"description": "returns the nonce gaps from pool. This parameter requires by-sender and does not work with fields",
"schema" : {
"schema": {
"type": "boolean",
"default": false
}
Expand Down
34 changes: 18 additions & 16 deletions data/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,24 @@ import (
// Transaction represents the structure that maps and validates user input for publishing a new transaction
type Transaction struct {
// This field is used to tag transactions for send-multiple route
Index int `json:"-"`
Nonce uint64 `json:"nonce"`
Value string `json:"value"`
Receiver string `json:"receiver"`
Sender string `json:"sender"`
SenderUsername []byte `json:"senderUsername,omitempty"`
ReceiverUsername []byte `json:"receiverUsername,omitempty"`
GasPrice uint64 `json:"gasPrice"`
GasLimit uint64 `json:"gasLimit"`
Data []byte `json:"data,omitempty"`
Signature string `json:"signature,omitempty"`
ChainID string `json:"chainID"`
Version uint32 `json:"version"`
Options uint32 `json:"options,omitempty"`
GuardianAddr string `json:"guardian,omitempty"`
GuardianSignature string `json:"guardianSignature,omitempty"`
Index int `json:"-"`
Nonce uint64 `json:"nonce"`
Value string `json:"value"`
Receiver string `json:"receiver"`
Sender string `json:"sender"`
SenderUsername []byte `json:"senderUsername,omitempty"`
ReceiverUsername []byte `json:"receiverUsername,omitempty"`
GasPrice uint64 `json:"gasPrice"`
GasLimit uint64 `json:"gasLimit"`
Data []byte `json:"data,omitempty"`
Signature string `json:"signature,omitempty"`
ChainID string `json:"chainID"`
Version uint32 `json:"version"`
Options uint32 `json:"options,omitempty"`
GuardianAddr string `json:"guardian,omitempty"`
GuardianSignature string `json:"guardianSignature,omitempty"`
Relayer string `json:"relayer,omitempty"`
InnerTransactions []*Transaction `json:"innerTransactions,omitempty"`
}

// GetTransactionResponseData follows the format of the data field of get transaction response
Expand Down
5 changes: 0 additions & 5 deletions facade/baseFacade.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,6 @@ func (pf *ProxyFacade) GetShardIDForAddress(address string) (uint32, error) {
return pf.accountProc.GetShardIDForAddress(address)
}

// GetTransactions returns transactions by address
func (pf *ProxyFacade) GetTransactions(address string) ([]data.DatabaseTransaction, error) {
return pf.accountProc.GetTransactions(address)
}

// GetESDTTokenData returns the token data for a given token name
func (pf *ProxyFacade) GetESDTTokenData(address string, key string, options common.AccountQueryOptions) (*data.GenericAPIResponse, error) {
return pf.accountProc.GetESDTTokenData(address, key, options)
Expand Down
1 change: 0 additions & 1 deletion facade/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ type AccountProcessor interface {
GetAccounts(addresses []string, options common.AccountQueryOptions) (*data.AccountsModel, error)
GetShardIDForAddress(address string) (uint32, error)
GetValueForKey(address string, key string, options common.AccountQueryOptions) (string, error)
GetTransactions(address string) ([]data.DatabaseTransaction, error)
GetAllESDTTokens(address string, options common.AccountQueryOptions) (*data.GenericAPIResponse, error)
GetKeyValuePairs(address string, options common.AccountQueryOptions) (*data.GenericAPIResponse, error)
GetESDTTokenData(address string, key string, options common.AccountQueryOptions) (*data.GenericAPIResponse, error)
Expand Down
5 changes: 0 additions & 5 deletions facade/mock/accountProccessorStub.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,6 @@ func (aps *AccountProcessorStub) GetShardIDForAddress(address string) (uint32, e
return aps.GetShardIDForAddressCalled(address)
}

// GetTransactions -
func (aps *AccountProcessorStub) GetTransactions(address string) ([]data.DatabaseTransaction, error) {
return aps.GetTransactionsCalled(address)
}

// GetCodeHash -
func (aps *AccountProcessorStub) GetCodeHash(address string, options common.AccountQueryOptions) (*data.GenericAPIResponse, error) {
return aps.GetCodeHashCalled(address, options)
Expand Down
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ require (
github.com/gin-contrib/pprof v1.4.0
github.com/gin-contrib/static v0.0.1
github.com/gin-gonic/gin v1.9.1
github.com/multiversx/mx-chain-core-go v1.2.19-0.20231208083458-cdde72601592
github.com/multiversx/mx-chain-crypto-go v1.2.9
github.com/multiversx/mx-chain-es-indexer-go v1.4.13
github.com/multiversx/mx-chain-logger-go v1.0.13
github.com/multiversx/mx-chain-core-go v1.2.21
github.com/multiversx/mx-chain-crypto-go v1.2.12
github.com/multiversx/mx-chain-es-indexer-go v1.7.4
github.com/multiversx/mx-chain-logger-go v1.0.15
github.com/pkg/errors v0.9.1
github.com/stretchr/testify v1.8.4
github.com/urfave/cli v1.22.10
Expand Down
16 changes: 8 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -131,14 +131,14 @@ github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9G
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
github.com/mr-tron/base58 v1.2.0 h1:T/HDJBh4ZCPbU39/+c3rRvE0uKBQlU27+QI8LJ4t64o=
github.com/mr-tron/base58 v1.2.0/go.mod h1:BinMc/sQntlIE1frQmRFPUoPA1Zkr8VRgBdjWI2mNwc=
github.com/multiversx/mx-chain-core-go v1.2.19-0.20231208083458-cdde72601592 h1:fXpqfN64mLKvJycf5doOhvFRLM06eaMi7Ag3mO1fsbg=
github.com/multiversx/mx-chain-core-go v1.2.19-0.20231208083458-cdde72601592/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE=
github.com/multiversx/mx-chain-crypto-go v1.2.9 h1:OEfF2kOQrtzUl273Z3DEcshjlTVUfPpJMd0R0SvTrlU=
github.com/multiversx/mx-chain-crypto-go v1.2.9/go.mod h1:fkaWKp1rbQN9wPKya5jeoRyC+c/SyN/NfggreyeBw+8=
github.com/multiversx/mx-chain-es-indexer-go v1.4.13 h1:3Ayaw9bSpeNOF+Z3L/11MN1rIJH8Rc6dqtt+o4Wfdno=
github.com/multiversx/mx-chain-es-indexer-go v1.4.13/go.mod h1:g0REyU8rqJfoBq6mIfqEi6IdpLofECLEvKKGMJO8ZhM=
github.com/multiversx/mx-chain-logger-go v1.0.13 h1:eru/TETo0MkO4ZTnXsQDKf4PBRpAXmqjT02klNT/JnY=
github.com/multiversx/mx-chain-logger-go v1.0.13/go.mod h1:MZJhTAtZTJxT+yK2EHc4ZW3YOHUc1UdjCD0iahRNBZk=
github.com/multiversx/mx-chain-core-go v1.2.21 h1:+XVKznPTlUU5EFS1A8chtS8fStW60upRIyF4Pgml19I=
github.com/multiversx/mx-chain-core-go v1.2.21/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE=
github.com/multiversx/mx-chain-crypto-go v1.2.12 h1:zWip7rpUS4CGthJxfKn5MZfMfYPjVjIiCID6uX5BSOk=
github.com/multiversx/mx-chain-crypto-go v1.2.12/go.mod h1:HzcPpCm1zanNct/6h2rIh+MFrlXbjA5C8+uMyXj3LI4=
github.com/multiversx/mx-chain-es-indexer-go v1.7.4 h1:SjJk9G9SN8baz0sFIU2jymYCfx3XiikGEB2wW0jwvfw=
github.com/multiversx/mx-chain-es-indexer-go v1.7.4/go.mod h1:oGcRK2E3Syv6vRTszWrrb/TqD8akq0yeoMr1wPPiTO4=
github.com/multiversx/mx-chain-logger-go v1.0.15 h1:HlNdK8etyJyL9NQ+6mIXyKPEBo+wRqOwi3n+m2QIHXc=
github.com/multiversx/mx-chain-logger-go v1.0.15/go.mod h1:t3PRKaWB1M+i6gUfD27KXgzLJJC+mAQiN+FLlL1yoGQ=
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
Expand Down
9 changes: 0 additions & 9 deletions process/accountProcessor.go
Original file line number Diff line number Diff line change
Expand Up @@ -452,15 +452,6 @@ func (ap *AccountProcessor) GetGuardianData(address string, options common.Accou
return nil, WrapObserversError(apiResponse.Error)
}

// GetTransactions resolves the request and returns a slice of transaction for the specific address
func (ap *AccountProcessor) GetTransactions(address string) ([]data.DatabaseTransaction, error) {
if _, err := ap.pubKeyConverter.Decode(address); err != nil {
return nil, fmt.Errorf("%w, %v", ErrInvalidAddress, err)
}

return ap.connector.GetTransactionsByAddress(address)
}

// GetCodeHash returns the code hash for a given address
func (ap *AccountProcessor) GetCodeHash(address string, options common.AccountQueryOptions) (*data.GenericAPIResponse, error) {
availability := ap.availabilityProvider.AvailabilityForAccountQueryOptions(options)
Expand Down
20 changes: 0 additions & 20 deletions process/accountProcessor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,26 +286,6 @@ func TestAccountProcessor_GetShardIDForAddressShouldError(t *testing.T) {
assert.Equal(t, expectedError, err)
}

func TestAccountProcessor_GetTransactions(t *testing.T) {
t.Parallel()

converter, _ := pubkeyConverter.NewBech32PubkeyConverter(32, "erd")
ap, _ := process.NewAccountProcessor(
&mock.ProcessorStub{},
converter,
&mock.ElasticSearchConnectorMock{},
)

_, err := ap.GetTransactions("invalidAddress")
assert.True(t, errors.Is(err, process.ErrInvalidAddress))

_, err = ap.GetTransactions("")
assert.True(t, errors.Is(err, process.ErrInvalidAddress))

_, err = ap.GetTransactions("erd1ycega644rvjtgtyd8hfzt6hl5ymaa8ml2nhhs5cv045cz5vxm00q022myr")
assert.Nil(t, err)
}

func TestAccountProcessor_GetESDTsWithRoleGetObserversFails(t *testing.T) {
t.Parallel()

Expand Down
10 changes: 0 additions & 10 deletions process/database/elasticSearchConnector.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,6 @@ func NewElasticSearchConnector(url, username, password string) (*elasticSearchCo
}, nil
}

// GetTransactionsByAddress gets transactions TO or FROM the specified address
func (esc *elasticSearchConnector) GetTransactionsByAddress(address string) ([]data.DatabaseTransaction, error) {
decodedBody, err := esc.doSearchRequestTx(address, "transactions", numTopTransactions)
if err != nil {
return nil, err
}

return convertObjectToTransactions(decodedBody)
}

// GetAtlasBlockByShardIDAndNonce gets from database a block with the specified shardID and nonce
func (esc *elasticSearchConnector) GetAtlasBlockByShardIDAndNonce(shardID uint32, nonce uint64) (data.AtlasBlock, error) {
query := blockByNonceAndShardIDQuery(nonce, shardID)
Expand Down
14 changes: 0 additions & 14 deletions process/database/elasticSearchConnector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,6 @@ import (
"github.com/stretchr/testify/require"
)

func TestDatabaseReader(t *testing.T) {
t.Skip("this test queries Elastic Search")

url := "https://elastic-aws.multiversx.com"
user := ""
password := ""
reader, err := NewElasticSearchConnector(url, user, password)
require.Nil(t, err)

addr := "erd1ewshdn9yv0wx38xgs5cdhvcq4dz0n7tdlgh8wfj9nxugwmyunnyqpkpzal"
txs, err := reader.GetTransactionsByAddress(addr)
fmt.Println(txs)
require.Nil(t, err)
}

func TestDatabaseReader_GetBlockByShardIDAndNonce(t *testing.T) {
t.Skip("this test queries Elastic Search")
Expand Down
3 changes: 0 additions & 3 deletions process/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ import (
proxyData "github.com/multiversx/mx-chain-proxy-go/data"
)

// RelayedTxV2DataMarker -
const RelayedTxV2DataMarker = relayedTxV2DataMarker

// SetDelayForCheckingNodesSyncState -
func (bp *BaseProcessor) SetDelayForCheckingNodesSyncState(delay time.Duration) {
bp.delayForCheckingNodesSyncState = delay
Expand Down
Loading

0 comments on commit 2b6d0a7

Please sign in to comment.