-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
EN-7804: api and components versioning #96
Conversation
# Conflicts: # api/api.go # cmd/proxy/main.go # process/baseProcessor.go # process/mock/processorStub.go
api/groups/v1_2/interface.go
Outdated
import "github.com/ElrondNetwork/elrond-proxy-go/data" | ||
|
||
// AccountsFacadeHandlerV1_2 interface defines methods that can be used from facade context variable | ||
type AccountsFacadeHandlerV1_2 interface { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need to have a single facade implementation that will satisfy all the interfaces?
The question arose from seeing the function GetShardIDForAddressV1_2
.
We can have multiple facade implementations that will be consumed by various endpoint versions. Having all functions in a single monstrous facade implementation will impact struct size (which should be kept as small as possible)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean that we should drop the facade
entity that holds all the processors and calls the appropriate methods of them?
versions/interface.go
Outdated
@@ -0,0 +1,8 @@ | |||
package versions | |||
|
|||
//// VersionManagerHandler defines the actions that a version manager implementation has to do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove or uncomment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor stuff remained. Code looks way better. GJ! 👍
api/apiHandler.go
Outdated
func NewCommonApiHandler() *commonApiHandler { | ||
return &commonApiHandler{ | ||
groups: initBaseGroups(), | ||
func NewApiHandler(facade data.FacadeHandler) (*commonApiHandler, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
api/groups/baseAccountsGroup.go
Outdated
@@ -58,8 +63,8 @@ func getTransactions(c *gin.Context) ([]data.DatabaseTransaction, int, error) { | |||
|
|||
// GetAccount returns an accountResponse containing information | |||
// about the account correlated with provided address | |||
func GetAccount(c *gin.Context) { | |||
account, status, err := getAccount(c) | |||
func (ag *accountsGroup) GetAccount(c *gin.Context) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wondering if we still need these methods exported.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
made them unexported
} | ||
|
||
baseRoutesHandlers := map[string]*data.EndpointHandlerData{ | ||
"/hex": {Handler: vvg.getHex, Method: http.MethodPost}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unexported methods 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
cmd/proxy/main.go
Outdated
} | ||
|
||
func createVersionManager( | ||
cfg *config.Config, | ||
ecConf *erdConfig.EconomicsConfig, | ||
exCfg *erdConfig.ExternalConfig, | ||
pemFileLocation string, | ||
isRosettaOn bool, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isRosettaEnabled (On can mean something else :D )
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
renamed to isRosettaModeEnabled
*facade.ElrondProxyFacade | ||
} | ||
|
||
func (epf *ElrondProxyFacadeV1_2) GetShardIDForAddressV1_2(address string, additionalField int) (uint32, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
"github.com/ElrondNetwork/elrond-proxy-go/process" | ||
) | ||
|
||
type TransactionProcessorV1_0 struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some elements without comments remained in this file
versions/versionManager.go
Outdated
} | ||
|
||
vm.mutVersions.Lock() | ||
vm.Lock() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
api/api.go
Outdated
@@ -35,7 +27,10 @@ func CreateServer(elrondProxyFacade ElrondProxyHandler, port int) (*http.Server, | |||
return nil, err | |||
} | |||
|
|||
registerRoutes(ws, elrondProxyFacade) | |||
err = registerRoutes(ws, versionManager) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Optionally, reorder the definitions of registerRoutes
, registerValidators
, with respect to the order of their usage.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now I see (older code) - why do we need skValidator
? CC: @iulianpascalau?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AFAIK, skValidator is used in the authentication & authorization process when accessing a REST API endpoint.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reordered. it's not used now, but can remain as a placeholder for further authorized requests
api/api.go
Outdated
blockAtlasRoutes := ws.Group("/block-atlas") | ||
blockAtlasRoutes.Use(WithElrondProxyFacade(elrondProxyFacade)) | ||
blockatlas.Routes(blockAtlasRoutes) | ||
for version, versionData := range versionsMap { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
api/api.go
Outdated
blockAtlasRoutes := ws.Group("/block-atlas") | ||
blockAtlasRoutes.Use(WithElrondProxyFacade(elrondProxyFacade)) | ||
blockatlas.Routes(blockAtlasRoutes) | ||
for version, versionData := range versionsMap { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Optionally, we can rename VersionData
(the struct, the variables) to VersionBundle
or VersionController
. But In this sense, perhaps also rename VersionManager
to ApiVersioningRegistry
or VersionsRegistry
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the current naming is better because VersionData
only holds the specific components for each version and it doesn't have any functions.
However, renamed VersionManager
to VersionsRegistry
api/api.go
Outdated
@@ -86,11 +85,3 @@ func skValidator( | |||
) bool { | |||
return true | |||
} | |||
|
|||
// WithElrondProxyFacade middleware will set up an ElrondFacade object in the gin context | |||
func WithElrondProxyFacade(elrondProxyFacade ElrondProxyHandler, version string) gin.HandlerFunc { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
8e2ad5e
}) | ||
} | ||
|
||
// GetShardForAccountV_next is an example of an updated endpoint in the version v_next |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
process/v_next/doc.go
Outdated
@@ -1,2 +1,2 @@ | |||
// Package v1.2 represents the processors needed for the version v1.2 of the API |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe update the comment?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
# Conflicts: # api/address/interface.go # api/groups/baseAccountsGroup.go # api/groups/baseTransactionGroup.go # api/transaction/interface.go
- `/v1.0/hyperblock/by-hash/:hash` (GET) --> returns a hyperblock by hash, with transactions included | ||
|
||
# V_next |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Docker/Dockerfile
Outdated
@@ -5,12 +5,13 @@ COPY . . | |||
# Proxy | |||
WORKDIR /elrond/cmd/proxy | |||
RUN go build | |||
# $(ls /go/pkg/mod/github.com/!elrond!network/ | grep arwen-wasm-vm | sed 's/.* //' | head -1) this command is required to be able to extract the full name of the directory that starts with 'arwen-wasm-wm' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure why Github picked these as PR changes.
api/errors/errors.go
Outdated
@@ -14,12 +14,21 @@ var ErrGetValueForKey = errors.New("get value for key error") | |||
// ErrComputeShardForAddress signals an error in computing the shard ID for a given address | |||
var ErrComputeShardForAddress = errors.New("compute shard ID for address error") | |||
|
|||
// ErrGetESDTTokenData signals an error in fetching an ESDT token data | |||
var ErrGetESDTTokenData = errors.New("cannot get ESDT token data") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure why Github picked these as PR changes.
data/transaction.go
Outdated
Status transaction.TxStatus `json:"status,omitempty"` | ||
HyperblockNonce uint64 `json:"hyperblockNonce,omitempty"` | ||
HyperblockHash string `json:"hyperblockHash,omitempty"` | ||
Type string `json:"type"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure why Github picked these as PR changes.
go.mod
Outdated
@@ -3,10 +3,9 @@ module github.com/ElrondNetwork/elrond-proxy-go | |||
go 1.12 | |||
|
|||
require ( | |||
github.com/ElrondNetwork/elrond-go v1.1.2-0.20201016080150-915a6ef433de | |||
github.com/ElrondNetwork/elrond-go v1.1.6-0.20201126175543-3e5a9696c46f |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
v1.1.10+
?
process/accountProcessor.go
Outdated
@@ -100,6 +100,67 @@ func (ap *AccountProcessor) GetValueForKey(address string, key string) (string, | |||
return "", ErrSendingRequest | |||
} | |||
|
|||
// GetESDTTokenData returns the token data for a token with the given name | |||
func (ap *AccountProcessor) GetESDTTokenData(address string, key string) (*data.GenericAPIResponse, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure why Github picked these as PR changes.
process/transactionProcessor.go
Outdated
@@ -455,19 +465,42 @@ func (tp *TransactionProcessor) getTxFromObservers(txHash string, reqType reques | |||
return nil, errors.ErrTransactionNotFound | |||
} | |||
|
|||
func (tp *TransactionProcessor) getTxWithSenderAddr(txHash, sender string) (*data.FullTransaction, error) { | |||
func (tp *TransactionProcessor) alterTxWithScResultsFromSourceIfNeeded(txHash string, tx *data.FullTransaction, withResults bool) *data.FullTransaction { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure why Github picked these as PR changes.
# Conflicts: # README.md
e3702a0
Testing procedure:
/v1.0
in the URL. Example:http://127.0.0.1:8080
=>http://127.0.0.1:8080/v1.0