From 1148027bafff36fafa52b329e84822e2c8cf1b9a Mon Sep 17 00:00:00 2001 From: Ethan Buchman Date: Sat, 3 Feb 2018 02:39:34 -0500 Subject: [PATCH] remove go-wire and go-crypto deps --- example/dummy/helpers.go | 3 +-- example/dummy/persistent_dummy.go | 5 ++--- glide.lock | 34 ++++++------------------------- glide.yaml | 4 ---- tests/server/client.go | 3 +-- types/messages.go | 23 +++++++++++++++++++-- types/messages_test.go | 28 +++++++++++++++++++++++++ 7 files changed, 59 insertions(+), 41 deletions(-) diff --git a/example/dummy/helpers.go b/example/dummy/helpers.go index 80f94ade2..915fc7638 100644 --- a/example/dummy/helpers.go +++ b/example/dummy/helpers.go @@ -2,14 +2,13 @@ package dummy import ( "github.com/tendermint/abci/types" - crypto "github.com/tendermint/go-crypto" cmn "github.com/tendermint/tmlibs/common" ) // RandVal creates one random validator, with a key derived // from the input value func RandVal(i int) types.Validator { - pubkey := crypto.GenPrivKeyEd25519FromSecret([]byte(cmn.Fmt("test%d", i))).PubKey().Bytes() + pubkey := cmn.RandBytes(33) power := cmn.RandUint16() + 1 return types.Validator{pubkey, int64(power)} } diff --git a/example/dummy/persistent_dummy.go b/example/dummy/persistent_dummy.go index 54548a471..30885bc1e 100644 --- a/example/dummy/persistent_dummy.go +++ b/example/dummy/persistent_dummy.go @@ -9,7 +9,6 @@ import ( "github.com/tendermint/abci/example/code" "github.com/tendermint/abci/types" - crypto "github.com/tendermint/go-crypto" cmn "github.com/tendermint/tmlibs/common" dbm "github.com/tendermint/tmlibs/db" "github.com/tendermint/tmlibs/log" @@ -158,12 +157,12 @@ func (app *PersistentDummyApplication) execValidatorTx(tx []byte) types.Response Code: code.CodeTypeEncodingError, Log: fmt.Sprintf("Pubkey (%s) is invalid hex", pubkeyS)} } - _, err = crypto.PubKeyFromBytes(pubkey) + /*_, err = crypto.PubKeyFromBytes(pubkey) if err != nil { return types.ResponseDeliverTx{ Code: code.CodeTypeEncodingError, Log: fmt.Sprintf("Pubkey (%X) is invalid go-crypto encoded", pubkey)} - } + }*/ // decode the power power, err := strconv.ParseInt(powerS, 10, 64) diff --git a/glide.lock b/glide.lock index 96ee37852..7bcb114a6 100644 --- a/glide.lock +++ b/glide.lock @@ -1,14 +1,6 @@ -hash: 68167c37a0b261e0adc172c3d92d943da89ff41112043d59ac60844ef8edd882 -updated: 2018-02-03T02:00:50.200133389-05:00 +hash: 304088ee640b9e5897ece75503d07f800aabba0618bd668bf1144f478809b646 +updated: 2018-02-03T02:38:14.152640307-05:00 imports: -- name: github.com/btcsuite/btcd - version: 2e60448ffcc6bf78332d1fe590260095f554dd78 - subpackages: - - btcec -- name: github.com/davecgh/go-spew - version: 346938d642f2ec3594ed81d874461961cd0faa76 - subpackages: - - spew - name: github.com/go-kit/kit version: 4dc7be5d2d12881735283bcab7352178e190fc71 subpackages: @@ -65,15 +57,6 @@ imports: - leveldb/storage - leveldb/table - leveldb/util -- name: github.com/tendermint/ed25519 - version: d8387025d2b9d158cf4efb07e7ebf814bcce2057 - subpackages: - - edwards25519 - - extra25519 -- name: github.com/tendermint/go-crypto - version: 4fc3055dbd17aa1203d0abc64b9293f378da22ec -- name: github.com/tendermint/go-wire - version: dec83f641903b22f039da3974607859715d0377e - name: github.com/tendermint/tmlibs version: deaaf014d8b8d1095054380a38b1b00e293f725f subpackages: @@ -81,15 +64,6 @@ imports: - db - log - process -- name: golang.org/x/crypto - version: edd5e9b0879d13ee6970a50153d85b8fec9f7686 - subpackages: - - nacl/secretbox - - openpgp/armor - - openpgp/errors - - poly1305 - - ripemd160 - - salsa20/salsa - name: golang.org/x/net version: d866cfc389cec985d6fda2859936a575a55a3ab6 subpackages: @@ -131,6 +105,10 @@ imports: - tap - transport testImports: +- name: github.com/davecgh/go-spew + version: 346938d642f2ec3594ed81d874461961cd0faa76 + subpackages: + - spew - name: github.com/pmezard/go-difflib version: d8ed2627bdf02c080bf22230dbb337003b7aba2d subpackages: diff --git a/glide.yaml b/glide.yaml index 47876621d..ec713c56c 100644 --- a/glide.yaml +++ b/glide.yaml @@ -8,10 +8,6 @@ import: version: v0.8.0 - package: github.com/spf13/cobra version: v0.0.1 -- package: github.com/tendermint/go-crypto - version: develop -- package: github.com/tendermint/go-wire - version: develop - package: github.com/tendermint/tmlibs version: develop subpackages: diff --git a/tests/server/client.go b/tests/server/client.go index 75100a72c..e19167e34 100644 --- a/tests/server/client.go +++ b/tests/server/client.go @@ -7,7 +7,6 @@ import ( abcicli "github.com/tendermint/abci/client" "github.com/tendermint/abci/types" - crypto "github.com/tendermint/go-crypto" cmn "github.com/tendermint/tmlibs/common" ) @@ -15,7 +14,7 @@ func InitChain(client abcicli.Client) error { total := 10 vals := make([]types.Validator, total) for i := 0; i < total; i++ { - pubkey := crypto.GenPrivKeyEd25519FromSecret([]byte(cmn.Fmt("test%d", i))).PubKey().Bytes() + pubkey := cmn.RandBytes(33) power := cmn.RandInt() vals[i] = types.Validator{pubkey, int64(power)} } diff --git a/types/messages.go b/types/messages.go index 2a7568d9f..52e4b6758 100644 --- a/types/messages.go +++ b/types/messages.go @@ -6,7 +6,6 @@ import ( "io" "github.com/gogo/protobuf/proto" - wire "github.com/tendermint/go-wire" ) const ( @@ -19,7 +18,7 @@ func WriteMessage(msg proto.Message, w io.Writer) error { if err != nil { return err } - return wire.EncodeByteSlice(w, bz) + return encodeByteSlice(w, bz) } // ReadMessage reads a varint length-delimited protobuf message. @@ -48,6 +47,26 @@ func readProtoMsg(r io.Reader, msg proto.Message, maxSize int) error { return proto.Unmarshal(buf, msg) } +//----------------------------------------------------------------------- +// NOTE: we copied wire.EncodeByteSlice from go-wire rather than keep +// go-wire as a dep + +func encodeByteSlice(w io.Writer, bz []byte) (err error) { + err = encodeVarint(w, int64(len(bz))) + if err != nil { + return + } + _, err = w.Write(bz) + return +} + +func encodeVarint(w io.Writer, i int64) (err error) { + var buf [10]byte + n := binary.PutVarint(buf[:], i) + _, err = w.Write(buf[0:n]) + return +} + //---------------------------------------- func ToRequestEcho(message string) *Request { diff --git a/types/messages_test.go b/types/messages_test.go index 990a81483..53e1a0cac 100644 --- a/types/messages_test.go +++ b/types/messages_test.go @@ -72,3 +72,31 @@ func TestWriteReadMessage(t *testing.T) { assert.Equal(t, c, msg) } } + +func TestWriteReadMessage2(t *testing.T) { + phrase := "hello-world" + cases := []proto.Message{ + &ResponseCheckTx{ + Data: []byte(phrase), + Log: phrase, + GasWanted: 10, + Tags: []cmn.KVPair{ + cmn.KVPair{[]byte("abc"), []byte("def")}, + }, + // Fee: cmn.KI64Pair{ + }, + // TODO: add the rest + } + + for _, c := range cases { + buf := new(bytes.Buffer) + err := WriteMessage(c, buf) + assert.Nil(t, err) + + msg := new(ResponseCheckTx) + err = ReadMessage(buf, msg) + assert.Nil(t, err) + + assert.Equal(t, c, msg) + } +}