Skip to content

Commit c7b0037

Browse files
authored
Merge pull request #296 from cosmos/upgrade
Upgrade
2 parents 1a12c99 + 71d8b36 commit c7b0037

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+301
-288
lines changed

app/app_test.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ func (at *appTest) reset() {
118118
at.initAccount(at.acctOut)
119119

120120
resabci := at.app.Commit()
121-
require.True(at.t, resabci.Code.IsOK(), resabci)
121+
require.True(at.t, resabci.IsOK(), resabci)
122122
}
123123

124124
func getBalance(key sdk.Actor, store state.SimpleDB) (coin.Coins, error) {
@@ -145,7 +145,7 @@ func (at *appTest) execDeliver(t *testing.T, tx sdk.Tx) (res abci.ResponseDelive
145145
res = at.app.DeliverTx(txBytes)
146146

147147
// check the tags
148-
if res.Code.IsOK() {
148+
if res.IsOK() {
149149
tags := res.Tags
150150
require.NotEmpty(tags)
151151
require.Equal("height", tags[0].Key)
@@ -270,13 +270,13 @@ func TestTx(t *testing.T) {
270270
//Regular CheckTx
271271
at.reset()
272272
cres, _, _ = at.execCheck(t, at.getTx(coin.Coins{{"mycoin", 5}}, 1))
273-
assert.True(cres.Code.IsOK(), "ExecTx/Good CheckTx: Expected OK return from ExecTx, Error: %v", cres)
273+
assert.True(cres.IsOK(), "ExecTx/Good CheckTx: Expected OK return from ExecTx, Error: %v", cres)
274274

275275
//Regular DeliverTx
276276
at.reset()
277277
amt := coin.Coins{{"mycoin", 3}}
278278
dres, diffIn, diffOut = at.execDeliver(t, at.getTx(amt, 1))
279-
assert.True(dres.Code.IsOK(), "ExecTx/Good DeliverTx: Expected OK return from ExecTx, Error: %v", dres)
279+
assert.True(dres.IsOK(), "ExecTx/Good DeliverTx: Expected OK return from ExecTx, Error: %v", dres)
280280
assert.Equal(amt.Negative(), diffIn)
281281
assert.Equal(amt, diffOut)
282282

@@ -285,7 +285,7 @@ func TestTx(t *testing.T) {
285285
amt = coin.Coins{{"mycoin", 4}}
286286
toll := coin.Coin{"mycoin", 1}
287287
dres, diffIn, diffOut = at.execDeliver(t, at.feeTx(amt, toll, 1))
288-
assert.True(dres.Code.IsOK(), "ExecTx/Good DeliverTx: Expected OK return from ExecTx, Error: %v", dres)
288+
assert.True(dres.IsOK(), "ExecTx/Good DeliverTx: Expected OK return from ExecTx, Error: %v", dres)
289289
payment := amt.Plus(coin.Coins{toll}).Negative()
290290
assert.Equal(payment, diffIn)
291291
assert.Equal(amt, diffOut)
@@ -297,15 +297,15 @@ func TestQuery(t *testing.T) {
297297
at := newAppTest(t)
298298

299299
dres, _, _ := at.execDeliver(t, at.getTx(coin.Coins{{"mycoin", 5}}, 1))
300-
assert.True(dres.Code.IsOK(), "Commit, DeliverTx: Expected OK return from DeliverTx, Error: %v", dres)
300+
assert.True(dres.IsOK(), "Commit, DeliverTx: Expected OK return from DeliverTx, Error: %v", dres)
301301

302302
resQueryPreCommit := at.app.Query(abci.RequestQuery{
303303
Path: "/account",
304304
Data: at.acctIn.Address(),
305305
})
306306

307307
cres := at.app.Commit()
308-
assert.True(cres.Code.IsOK(), cres)
308+
assert.True(cres.IsOK(), cres)
309309

310310
key := stack.PrefixedKey(coin.NameCoin, at.acctIn.Address())
311311
resQueryPostCommit := at.app.Query(abci.RequestQuery{

app/store.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ type StoreApp struct {
3737
pending []*abci.Validator
3838

3939
// height is last committed block, DeliverTx is the next one
40-
height uint64
40+
height int64
4141

4242
logger log.Logger
4343
}
@@ -99,12 +99,12 @@ func (app *StoreApp) Check() sm.SimpleDB {
9999

100100
// CommittedHeight gets the last block height committed
101101
// to the db
102-
func (app *StoreApp) CommittedHeight() uint64 {
102+
func (app *StoreApp) CommittedHeight() int64 {
103103
return app.height
104104
}
105105

106106
// WorkingHeight gets the current block we are writing
107-
func (app *StoreApp) WorkingHeight() uint64 {
107+
func (app *StoreApp) WorkingHeight() int64 {
108108
return app.height + 1
109109
}
110110

@@ -135,7 +135,7 @@ func (app *StoreApp) SetOption(res abci.RequestSetOption) abci.ResponseSetOption
135135
func (app *StoreApp) Query(reqQuery abci.RequestQuery) (resQuery abci.ResponseQuery) {
136136
if len(reqQuery.Data) == 0 {
137137
resQuery.Log = "Query cannot be zero length"
138-
resQuery.Code = abci.CodeType_EncodingError
138+
resQuery.Code = errors.CodeTypeEncodingErr
139139
return
140140
}
141141

@@ -150,7 +150,7 @@ func (app *StoreApp) Query(reqQuery abci.RequestQuery) (resQuery abci.ResponseQu
150150
// is not yet in the blockchain
151151

152152
withProof := app.CommittedHeight() - 1
153-
if tree.Tree.VersionExists(withProof) {
153+
if tree.Tree.VersionExists(uint64(withProof)) {
154154
height = withProof
155155
} else {
156156
height = app.CommittedHeight()
@@ -176,7 +176,7 @@ func (app *StoreApp) Query(reqQuery abci.RequestQuery) (resQuery abci.ResponseQu
176176
}
177177

178178
default:
179-
resQuery.Code = abci.CodeType_UnknownRequest
179+
resQuery.Code = errors.CodeTypeUnknownRequest
180180
resQuery.Log = cmn.Fmt("Unexpected Query path: %v", reqQuery.Path)
181181
}
182182
return
@@ -243,7 +243,7 @@ func pubKeyIndex(val *abci.Validator, list []*abci.Validator) int {
243243
return -1
244244
}
245245

246-
func loadState(dbName string, cacheSize int, historySize uint64) (*sm.State, error) {
246+
func loadState(dbName string, cacheSize int, historySize int64) (*sm.State, error) {
247247
// memory backed case, just for testing
248248
if dbName == "" {
249249
tree := iavl.NewVersionedTree(0, dbm.NewMemDB())

app/val_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ import (
1717
//-----------------------------------
1818
// Test cases start here
1919

20-
func randPower() uint64 {
21-
return uint64(cmn.RandInt()%50 + 60)
20+
func randPower() int64 {
21+
return int64(cmn.RandInt()%50 + 60)
2222
}
2323

2424
func makeVal() *abci.Validator {
@@ -79,7 +79,7 @@ func TestEndBlock(t *testing.T) {
7979
tx := base.ValChangeTx{c}.Wrap()
8080
txBytes := wire.BinaryBytes(tx)
8181
res := app.DeliverTx(txBytes)
82-
require.True(res.Code.IsOK(), "%#v", res)
82+
require.True(res.IsOK(), "%#v", res)
8383
}
8484
diff := app.EndBlock(abci.RequestEndBlock{app.height})
8585
// TODO: don't care about order here...

client/commands/commits/export.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func exportCommit(cmd *cobra.Command, args []string) error {
3434

3535
// load the seed as specified
3636
trust, _ := commands.GetProviders()
37-
h := viper.GetInt(heightFlag)
37+
h := int64(viper.GetInt(heightFlag))
3838
hash := viper.GetString(hashFlag)
3939
fc, err := loadCommit(trust, h, hash, "")
4040
if err != nil {

client/commands/commits/show.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func init() {
3737
RootCmd.AddCommand(showCmd)
3838
}
3939

40-
func loadCommit(p lite.Provider, h int, hash, file string) (fc lite.FullCommit, err error) {
40+
func loadCommit(p lite.Provider, h int64, hash, file string) (fc lite.FullCommit, err error) {
4141
// load the commit from the proper place
4242
if h != 0 {
4343
fc, err = p.GetByHeight(h)
@@ -59,7 +59,7 @@ func loadCommit(p lite.Provider, h int, hash, file string) (fc lite.FullCommit,
5959
func showCommit(cmd *cobra.Command, args []string) error {
6060
trust, _ := commands.GetProviders()
6161

62-
h := viper.GetInt(heightFlag)
62+
h := int64(viper.GetInt(heightFlag))
6363
hash := viper.GetString(hashFlag)
6464
file := viper.GetString(fileFlag)
6565
fc, err := loadCommit(trust, h, hash, file)

client/commands/commits/update.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func updateCommit(cmd *cobra.Command, args []string) error {
2929
return err
3030
}
3131

32-
h := viper.GetInt(heightFlag)
32+
h := int64(viper.GetInt(heightFlag))
3333
var fc lite.FullCommit
3434
if h <= 0 {
3535
// get the lastest from our source

client/commands/query/get.go

+13-10
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import (
2727
// It will try to get the proof for the given key. If it is successful,
2828
// it will return the height and also unserialize proof.Data into the data
2929
// argument (so pass in a pointer to the appropriate struct)
30-
func GetParsed(key []byte, data interface{}, height int, prove bool) (uint64, error) {
30+
func GetParsed(key []byte, data interface{}, height int64, prove bool) (int64, error) {
3131
bs, h, err := Get(key, height, prove)
3232
if err != nil {
3333
return 0, err
@@ -47,16 +47,19 @@ func GetParsed(key []byte, data interface{}, height int, prove bool) (uint64, er
4747
// we just repeat whatever any (potentially malicious) node gives us.
4848
// Only use that if you are running the full node yourself,
4949
// and it is localhost or you have a secure connection (not HTTP)
50-
func Get(key []byte, height int, prove bool) (data.Bytes, uint64, error) {
50+
func Get(key []byte, height int64, prove bool) (data.Bytes, int64, error) {
5151
if height < 0 {
5252
return nil, 0, fmt.Errorf("Height cannot be negative")
5353
}
5454

5555
if !prove {
5656
node := commands.GetNode()
5757
resp, err := node.ABCIQueryWithOptions("/key", key,
58-
rpcclient.ABCIQueryOptions{Trusted: true, Height: uint64(height)})
59-
return data.Bytes(resp.Value), resp.Height, err
58+
rpcclient.ABCIQueryOptions{Trusted: true, Height: int64(height)})
59+
if resp == nil {
60+
return nil, height, err
61+
}
62+
return data.Bytes(resp.Response.Value), resp.Response.Height, err
6063
}
6164
val, h, _, err := GetWithProof(key, height)
6265
return val, h, err
@@ -65,7 +68,7 @@ func Get(key []byte, height int, prove bool) (data.Bytes, uint64, error) {
6568
// GetWithProof returns the values stored under a given key at the named
6669
// height as in Get. Additionally, it will return a validated merkle
6770
// proof for the key-value pair if it exists, and all checks pass.
68-
func GetWithProof(key []byte, height int) (data.Bytes, uint64, iavl.KeyProof, error) {
71+
func GetWithProof(key []byte, height int64) (data.Bytes, int64, iavl.KeyProof, error) {
6972
node := commands.GetNode()
7073
cert, err := commands.GetCertifier()
7174
if err != nil {
@@ -93,19 +96,19 @@ func ParseHexKey(args []string, argname string) ([]byte, error) {
9396
}
9497

9598
// GetHeight reads the viper config for the query height
96-
func GetHeight() int {
97-
return viper.GetInt(FlagHeight)
99+
func GetHeight() int64 {
100+
return int64(viper.GetInt(FlagHeight))
98101
}
99102

100103
type proof struct {
101-
Height uint64 `json:"height"`
104+
Height int64 `json:"height"`
102105
Data interface{} `json:"data"`
103106
}
104107

105108
// FoutputProof writes the output of wrapping height and info
106109
// in the form {"data": <the_data>, "height": <the_height>}
107110
// to the provider io.Writer
108-
func FoutputProof(w io.Writer, v interface{}, height uint64) error {
111+
func FoutputProof(w io.Writer, v interface{}, height int64) error {
109112
wrap := &proof{height, v}
110113
blob, err := data.ToJSON(wrap)
111114
if err != nil {
@@ -118,6 +121,6 @@ func FoutputProof(w io.Writer, v interface{}, height uint64) error {
118121
// OutputProof prints the proof to stdout
119122
// reuse this for printing proofs and we should enhance this for text/json,
120123
// better presentation of height
121-
func OutputProof(data interface{}, height uint64) error {
124+
func OutputProof(data interface{}, height int64) error {
122125
return FoutputProof(os.Stdout, data, height)
123126
}

client/commands/query/tx.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func txQueryCmd(cmd *cobra.Command, args []string) error {
6767
}
6868

6969
// showTx parses anything that was previously registered as sdk.Tx
70-
func showTx(h uint64, tx types.Tx) error {
70+
func showTx(h int64, tx types.Tx) error {
7171
var info sdk.Tx
7272
err := wire.ReadBinaryBytes(tx, &info)
7373
if err != nil {

client/commands/rpc/helpers.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ func init() {
2525

2626
func runWait(cmd *cobra.Command, args []string) error {
2727
c := commands.GetNode()
28-
h := viper.GetInt(FlagHeight)
28+
h := int64(viper.GetInt(FlagHeight))
2929
if h == -1 {
3030
// read from delta
31-
d := viper.GetInt(FlagDelta)
31+
d := int64(viper.GetInt(FlagDelta))
3232
if d == -1 {
3333
return errors.New("Must set --height or --delta")
3434
}

client/commands/rpc/secure.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func runBlock(cmd *cobra.Command, args []string) error {
2626
return err
2727
}
2828

29-
h := viper.GetInt(FlagHeight)
29+
h := int64(viper.GetInt(FlagHeight))
3030
block, err := c.Block(&h)
3131
if err != nil {
3232
return err
@@ -46,7 +46,7 @@ func runCommit(cmd *cobra.Command, args []string) error {
4646
return err
4747
}
4848

49-
h := viper.GetInt(FlagHeight)
49+
h := int64(viper.GetInt(FlagHeight))
5050
commit, err := c.Commit(&h)
5151
if err != nil {
5252
return err
@@ -66,8 +66,8 @@ func runHeaders(cmd *cobra.Command, args []string) error {
6666
return err
6767
}
6868

69-
min := viper.GetInt(FlagMin)
70-
max := viper.GetInt(FlagMax)
69+
min := int64(viper.GetInt(FlagMin))
70+
max := int64(viper.GetInt(FlagMax))
7171
headers, err := c.BlockchainInfo(min, max)
7272
if err != nil {
7373
return err

client/proxy.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ func RPCRoutes(c rpcclient.Client) map[string]*rpc.RPCFunc {
4949
// Subscribe/unsubscribe are reserved for websocket events.
5050
// We can just use the core tendermint impl, which uses the
5151
// EventSwitch we registered in NewWebsocketManager above
52-
"subscribe": rpc.NewWSRPCFunc(core.Subscribe, "event"),
53-
"unsubscribe": rpc.NewWSRPCFunc(core.Unsubscribe, "event"),
52+
"subscribe": rpc.NewWSRPCFunc(core.Subscribe, "query"),
53+
"unsubscribe": rpc.NewWSRPCFunc(core.Unsubscribe, "query"),
5454

5555
// info API
5656
"status": rpc.NewRPCFunc(c.Status, ""),

0 commit comments

Comments
 (0)