Browse Source

Fix unwrap for proper json format

pull/1782/head
Ethan Frey 8 years ago
parent
commit
ee200d998f
3 changed files with 6 additions and 7 deletions
  1. +2
    -2
      encode_test.go
  2. +1
    -2
      pub_key.go
  3. +3
    -3
      pubkeyinner_holder.go

+ 2
- 2
encode_test.go View File

@ -7,8 +7,8 @@ import (
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
data "github.com/tendermint/go-wire/data"
wire "github.com/tendermint/go-wire" wire "github.com/tendermint/go-wire"
data "github.com/tendermint/go-wire/data"
) )
type byter interface { type byter interface {
@ -58,7 +58,7 @@ func checkWireJSON(t *testing.T, in interface{}, reader interface{}, typ byte) {
var err error var err error
js := wire.JSONBytes(in) js := wire.JSONBytes(in)
btyp := fmt.Sprintf("[%d,", typ) btyp := fmt.Sprintf("[%d,", typ)
assert.True(t, strings.HasPrefix(string(js), btyp), string(js))
assert.True(t, strings.HasPrefix(string(js), btyp), string(js), btyp)
wire.ReadJSON(reader, js, &err) wire.ReadJSON(reader, js, &err)
require.Nil(t, err, "%+v", err) require.Nil(t, err, "%+v", err)


+ 1
- 2
pub_key.go View File

@ -22,8 +22,7 @@ func PubKeyFromBytes(pubKeyBytes []byte) (pubKey PubKey, err error) {
// DO NOT USE THIS INTERFACE. // DO NOT USE THIS INTERFACE.
// You probably want to use PubKey // You probably want to use PubKey
// +gen holder:"PubKey,Impl[PubKeyEd25519,PubKeySecp256k1]"
// +gen holder:"PubKey,Impl[PubKeyEd25519,PubKeySecp256k1],ed25519,secp256k1"
type PubKeyInner interface { type PubKeyInner interface {
AssertIsPubKeyInner() AssertIsPubKeyInner()
Address() []byte Address() []byte


+ 3
- 3
pubkeyinner_holder.go View File

@ -13,7 +13,7 @@ import (
// Copyright (c) 2017 Ethan Frey (ethan.frey@tendermint.com) // Copyright (c) 2017 Ethan Frey (ethan.frey@tendermint.com)
type PubKey struct { type PubKey struct {
PubKeyInner
PubKeyInner "json:\"unwrap\""
} }
var PubKeyMapper = data.NewMapper(PubKey{}) var PubKeyMapper = data.NewMapper(PubKey{})
@ -46,7 +46,7 @@ func (h PubKey) Empty() bool {
/*** below are bindings for each implementation ***/ /*** below are bindings for each implementation ***/
func init() { func init() {
PubKeyMapper.RegisterImplementation(PubKeyEd25519{}, "pubkeyed25519", 0x1)
PubKeyMapper.RegisterImplementation(PubKeyEd25519{}, "ed25519", 0x1)
} }
func (hi PubKeyEd25519) Wrap() PubKey { func (hi PubKeyEd25519) Wrap() PubKey {
@ -54,7 +54,7 @@ func (hi PubKeyEd25519) Wrap() PubKey {
} }
func init() { func init() {
PubKeyMapper.RegisterImplementation(PubKeySecp256k1{}, "pubkeysecp256k1", 0x2)
PubKeyMapper.RegisterImplementation(PubKeySecp256k1{}, "secp256k1", 0x2)
} }
func (hi PubKeySecp256k1) Wrap() PubKey { func (hi PubKeySecp256k1) Wrap() PubKey {


Loading…
Cancel
Save