Skip to content

Commit

Permalink
#57 [RPC]Fix small finding
Browse files Browse the repository at this point in the history
  • Loading branch information
hleb-albau committed Oct 22, 2018
1 parent 6b2fd57 commit 0200c9a
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 19 deletions.
15 changes: 0 additions & 15 deletions cosmos/poc/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,18 +174,3 @@ func (app *CyberdApp) appHash() []byte {
}
return app.latestRankHash
}

func (app *CyberdApp) Search(cid string, page, perPage int) ([]RankedCid, int, error) {
if perPage == 0 {
perPage = 100
}
result, totalSize, err := app.memStorage.GetCidRankedLinks(Cid(cid), page, perPage)
if err != nil {
return nil, totalSize, err
}
return result, totalSize, nil
}

func (app *CyberdApp) Account(address sdk.AccAddress) auth.Account {
return app.accStorage.GetAccount(app.NewContext(true, abci.Header{}), address)
}
37 changes: 37 additions & 0 deletions cosmos/poc/app/rpc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package app

import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth"
. "github.com/cybercongress/cyberd/cosmos/poc/app/storage"
abci "github.com/tendermint/tendermint/abci/types"
)

func (app *CyberdApp) Search(cid string, page, perPage int) ([]RankedCid, int, error) {
if perPage == 0 {
perPage = 100
}
result, totalSize, err := app.memStorage.GetCidRankedLinks(Cid(cid), page, perPage)
if err != nil {
return nil, totalSize, err
}
return result, totalSize, nil
}

func (app *CyberdApp) Account(address sdk.AccAddress) auth.Account {

acc := app.accStorage.GetAccount(app.NewContext(true, abci.Header{}), address)

if acc != nil {
return acc
}

// no acc in chain, assume new one, so balance 0 and seq 0
// acc number -1 is for addresses not in chain
return &auth.BaseAccount{
Address: address,
Sequence: 0,
Coins: make(sdk.Coins, 0),
AccountNumber: -1,
}
}
17 changes: 13 additions & 4 deletions cosmos/poc/cyberdproxy/proxy/get.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package proxy

import "net/http"
import (
"errors"
"net/http"
)

func GetHandlerFn(ctx ProxyContext, endpoint string) func(http.ResponseWriter, *http.Request) {

Expand All @@ -24,12 +27,18 @@ func GetWithParamHandlerFn(ctx ProxyContext, endpoint string, param string) func

w.Header().Set("Content-Type", "application/json")

paramValue, err := getSingleParamValue(param, r)
if err != nil {
HandleError(err, w)
addresses, ok := r.URL.Query()[param]

if !ok || addresses == nil {
HandleError(errors.New("Cannot find param "+param), w)
return
}

paramValue := ""
if addresses != nil && len(addresses[0]) == 1 {
paramValue = addresses[0]
}

resp, err := ctx.Get(endpoint + "?" + param + "=\"" + paramValue + "\"")
if err != nil {
HandleError(err, w)
Expand Down

0 comments on commit 0200c9a

Please sign in to comment.