mirror of
https://github.com/fluencelabs/tendermint
synced 2025-07-30 19:51:58 +00:00
First code from codegen... wrong names
This commit is contained in:
47
pub_key.go
47
pub_key.go
@@ -7,9 +7,9 @@ import (
|
||||
secp256k1 "github.com/btcsuite/btcd/btcec"
|
||||
"github.com/tendermint/ed25519"
|
||||
"github.com/tendermint/ed25519/extra25519"
|
||||
. "github.com/tendermint/tmlibs/common"
|
||||
data "github.com/tendermint/go-wire/data"
|
||||
"github.com/tendermint/go-wire"
|
||||
data "github.com/tendermint/go-wire/data"
|
||||
. "github.com/tendermint/tmlibs/common"
|
||||
"golang.org/x/crypto/ripemd160"
|
||||
)
|
||||
|
||||
@@ -20,12 +20,10 @@ func PubKeyFromBytes(pubKeyBytes []byte) (pubKey PubKey, err error) {
|
||||
|
||||
//----------------------------------------
|
||||
|
||||
type PubKey struct {
|
||||
PubKeyInner `json:"unwrap"`
|
||||
}
|
||||
|
||||
// DO NOT USE THIS INTERFACE.
|
||||
// You probably want to use PubKey
|
||||
|
||||
// +gen holder:"PubKey,Impl[PubKeyEd25519,PubKeySecp256k1]"
|
||||
type PubKeyInner interface {
|
||||
AssertIsPubKeyInner()
|
||||
Address() []byte
|
||||
@@ -36,35 +34,6 @@ type PubKeyInner interface {
|
||||
Wrap() PubKey
|
||||
}
|
||||
|
||||
func (pk PubKey) MarshalJSON() ([]byte, error) {
|
||||
return pubKeyMapper.ToJSON(pk.PubKeyInner)
|
||||
}
|
||||
|
||||
func (pk *PubKey) UnmarshalJSON(data []byte) (err error) {
|
||||
parsed, err := pubKeyMapper.FromJSON(data)
|
||||
if err == nil && parsed != nil {
|
||||
pk.PubKeyInner = parsed.(PubKeyInner)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Unwrap recovers the concrete interface safely (regardless of levels of embeds)
|
||||
func (pk PubKey) Unwrap() PubKeyInner {
|
||||
pkI := pk.PubKeyInner
|
||||
for wrap, ok := pkI.(PubKey); ok; wrap, ok = pkI.(PubKey) {
|
||||
pkI = wrap.PubKeyInner
|
||||
}
|
||||
return pkI
|
||||
}
|
||||
|
||||
func (p PubKey) Empty() bool {
|
||||
return p.PubKeyInner == nil
|
||||
}
|
||||
|
||||
var pubKeyMapper = data.NewMapper(PubKey{}).
|
||||
RegisterImplementation(PubKeyEd25519{}, NameEd25519, TypeEd25519).
|
||||
RegisterImplementation(PubKeySecp256k1{}, NameSecp256k1, TypeSecp256k1)
|
||||
|
||||
//-------------------------------------
|
||||
|
||||
var _ PubKeyInner = PubKeyEd25519{}
|
||||
@@ -142,10 +111,6 @@ func (pubKey PubKeyEd25519) Equals(other PubKey) bool {
|
||||
}
|
||||
}
|
||||
|
||||
func (pubKey PubKeyEd25519) Wrap() PubKey {
|
||||
return PubKey{pubKey}
|
||||
}
|
||||
|
||||
//-------------------------------------
|
||||
|
||||
var _ PubKeyInner = PubKeySecp256k1{}
|
||||
@@ -218,7 +183,3 @@ func (pubKey PubKeySecp256k1) Equals(other PubKey) bool {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
func (pubKey PubKeySecp256k1) Wrap() PubKey {
|
||||
return PubKey{pubKey}
|
||||
}
|
||||
|
62
pubkeyinner_holder.go
Normal file
62
pubkeyinner_holder.go
Normal file
@@ -0,0 +1,62 @@
|
||||
// Generated by: main
|
||||
// TypeWriter: holder
|
||||
// Directive: +gen on PubKeyInner
|
||||
|
||||
package crypto
|
||||
|
||||
import (
|
||||
"github.com/tendermint/go-wire/data"
|
||||
)
|
||||
|
||||
// Auto-generated adapters for happily unmarshaling interfaces
|
||||
// Apache License 2.0
|
||||
// Copyright (c) 2017 Ethan Frey (ethan.frey@tendermint.com)
|
||||
|
||||
type PubKey struct {
|
||||
PubKeyInner
|
||||
}
|
||||
|
||||
var PubKeyMapper = data.NewMapper(PubKey{})
|
||||
|
||||
func (h PubKey) MarshalJSON() ([]byte, error) {
|
||||
return PubKeyMapper.ToJSON(h.PubKeyInner)
|
||||
}
|
||||
|
||||
func (h *PubKey) UnmarshalJSON(data []byte) (err error) {
|
||||
parsed, err := PubKeyMapper.FromJSON(data)
|
||||
if err == nil && parsed != nil {
|
||||
h.PubKeyInner = parsed.(PubKeyInner)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
// Unwrap recovers the concrete interface safely (regardless of levels of embeds)
|
||||
func (h PubKey) Unwrap() PubKeyInner {
|
||||
hi := h.PubKeyInner
|
||||
for wrap, ok := hi.(PubKey); ok; wrap, ok = hi.(PubKey) {
|
||||
hi = wrap.PubKeyInner
|
||||
}
|
||||
return hi
|
||||
}
|
||||
|
||||
func (h PubKey) Empty() bool {
|
||||
return h.PubKeyInner == nil
|
||||
}
|
||||
|
||||
/*** below are bindings for each implementation ***/
|
||||
|
||||
func init() {
|
||||
PubKeyMapper.RegisterImplementation(PubKeyEd25519{}, "pubkeyed25519", 0x1)
|
||||
}
|
||||
|
||||
func (hi PubKeyEd25519) Wrap() PubKey {
|
||||
return PubKey{hi}
|
||||
}
|
||||
|
||||
func init() {
|
||||
PubKeyMapper.RegisterImplementation(PubKeySecp256k1{}, "pubkeysecp256k1", 0x2)
|
||||
}
|
||||
|
||||
func (hi PubKeySecp256k1) Wrap() PubKey {
|
||||
return PubKey{hi}
|
||||
}
|
Reference in New Issue
Block a user