Browse Source

Merge pull request #189 from tendermint/no-wire-crypto

remove go-wire and go-crypto deps
pull/1780/head
Ethan Buchman 7 years ago
committed by GitHub
parent
commit
5a4f56056e
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 59 additions and 41 deletions
  1. +1
    -2
      example/dummy/helpers.go
  2. +2
    -3
      example/dummy/persistent_dummy.go
  3. +6
    -28
      glide.lock
  4. +0
    -4
      glide.yaml
  5. +1
    -2
      tests/server/client.go
  6. +21
    -2
      types/messages.go
  7. +28
    -0
      types/messages_test.go

+ 1
- 2
example/dummy/helpers.go View File

@ -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)}
}


+ 2
- 3
example/dummy/persistent_dummy.go View File

@ -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)


+ 6
- 28
glide.lock View File

@ -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:


+ 0
- 4
glide.yaml View File

@ -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:


+ 1
- 2
tests/server/client.go View File

@ -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)}
}


+ 21
- 2
types/messages.go View File

@ -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 {


+ 28
- 0
types/messages_test.go View File

@ -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)
}
}

Loading…
Cancel
Save