-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Bianjie/lcd implementation #2118
Closed
abelliumnt
wants to merge
26
commits into
cosmos:bianjie/lcd
from
irisnet:bianjie/lcd-implementation
Closed
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
6aa8309
Merge pull request #8 from cosmos/master
21e36b5
Merge branch 'master' of https://github.com/cosmos/cosmos-sdk
22161af
Merge branch 'master' of https://github.com/cosmos/cosmos-sdk
4e61859
Merge branch 'master' of https://github.com/cosmos/cosmos-sdk
170daf3
Merge branch 'master' of https://github.com/cosmos/cosmos-sdk
34548db
lcd implemeation
eccb889
Add golang dependency for swagger
2047673
Add key rest api
85f47d2
Add stake query api to lcd swagger
8e0ca8d
Merge branch 'master' of https://github.com/cosmos/cosmos-sdk
wukongcheng 60acd5c
Merge branch 'bianjie/lcd' of https://github.com/cosmos/cosmos-sdk in…
wukongcheng 187dda4
Merge branch 'bianjie/lcd' of https://github.com/cosmos/cosmos-sdk in…
22495e9
Merge pull request #58 from HaoyangLiu/haoyang/lcd-implementation
wukongcheng 26af936
Refactor code according to lint result
4a0d1c5
Merge pull request #63 from HaoyangLiu/haoyang/lcd-implementation
wukongcheng 4607ca9
Refactor comment and fix test failure
7528534
Add lcd test for swagger lcd
473fe21
Fix for test lint warnning
95e367a
Refactor comment
9d944b0
Add new test for lcd with swagger
fc40419
Merge pull request #66 from HaoyangLiu/haoyang/lcd-implementation
wukongcheng f266472
Refactor lcd according to code review
6cdf21d
Refactor code according to code review
79ec713
Merge pull request #73 from HaoyangLiu/haoyang/lcd-implementation-new
wukongcheng 9409e73
Fix errors in test_cover and test_lint
9ff57af
Merge pull request #77 from HaoyangLiu/haoyang/lcd-implementation-new
wukongcheng File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package context | ||
|
||
import ( | ||
rpcclient "github.com/tendermint/tendermint/rpc/client" | ||
"strings" | ||
"sync" | ||
"github.com/pkg/errors" | ||
) | ||
|
||
// ClientManager is a manager of a set of rpc clients to full nodes. | ||
// This manager can do load balancing upon these rpc clients. | ||
type ClientManager struct { | ||
clients []rpcclient.Client | ||
currentIndex int | ||
mutex sync.RWMutex | ||
} | ||
|
||
// NewClientManager create a new ClientManager | ||
func NewClientManager(nodeURIs string) (*ClientManager,error) { | ||
if nodeURIs != "" { | ||
nodeURLArray := strings.Split(nodeURIs, ",") | ||
var clients []rpcclient.Client | ||
for _, url := range nodeURLArray { | ||
client := rpcclient.NewHTTP(url, "/websocket") | ||
clients = append(clients, client) | ||
} | ||
mgr := &ClientManager{ | ||
currentIndex: 0, | ||
clients: clients, | ||
} | ||
return mgr, nil | ||
} | ||
return nil, errors.New("missing node URIs") | ||
} | ||
|
||
func (mgr *ClientManager) getClient() rpcclient.Client { | ||
mgr.mutex.Lock() | ||
defer mgr.mutex.Unlock() | ||
|
||
client := mgr.clients[mgr.currentIndex] | ||
mgr.currentIndex++ | ||
if mgr.currentIndex >= len(mgr.clients){ | ||
mgr.currentIndex = 0 | ||
} | ||
return client | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package context | ||
|
||
import ( | ||
"testing" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestLoadBalancing(t *testing.T) { | ||
nodeURIs := "10.10.10.10:26657,20.20.20.20:26657,30.30.30.30:26657" | ||
clientMgr,err := NewClientManager(nodeURIs) | ||
assert.Empty(t,err) | ||
endpoint := clientMgr.getClient() | ||
assert.NotEqual(t,endpoint,clientMgr.getClient()) | ||
clientMgr.getClient() | ||
assert.Equal(t,endpoint,clientMgr.getClient()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package httputils | ||
|
||
import ( | ||
"github.com/gin-gonic/gin" | ||
"net/http" | ||
) | ||
|
||
// NewError create error http response | ||
func NewError(ctx *gin.Context, errCode int, err error) { | ||
errorResponse := HTTPError{ | ||
API: "2.0", | ||
Code: errCode, | ||
} | ||
if err != nil { | ||
errorResponse.ErrMsg = err.Error() | ||
} | ||
|
||
ctx.JSON(errCode, errorResponse) | ||
} | ||
|
||
// NormalResponse create normal http response | ||
func NormalResponse(ctx *gin.Context, data []byte) { | ||
ctx.Status(http.StatusOK) | ||
ctx.Writer.Write(data) | ||
} | ||
|
||
// HTTPError is http response with error | ||
type HTTPError struct { | ||
API string `json:"rest api" example:"2.0"` | ||
Code int `json:"code" example:"500"` | ||
ErrMsg string `json:"error message"` | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
(mgr *ClientManager)
––>(manager *ClientManager)