mirror of
https://github.com/fluencelabs/tendermint
synced 2025-06-26 03:01:42 +00:00
fixed-length arrays cleanup
This commit is contained in:
2
Makefile
2
Makefile
@ -27,6 +27,8 @@ build_race:
|
|||||||
go build -race -o build/logjack github.com/tendermint/tendermint/cmd/logjack
|
go build -race -o build/logjack github.com/tendermint/tendermint/cmd/logjack
|
||||||
|
|
||||||
test: build
|
test: build
|
||||||
|
-rm -rf ~/.tendermint_test_bak
|
||||||
|
mv ~/.tendermint_test ~/.tendermint_test_bak
|
||||||
go test github.com/tendermint/tendermint/...
|
go test github.com/tendermint/tendermint/...
|
||||||
|
|
||||||
draw_deps:
|
draw_deps:
|
||||||
|
@ -2,7 +2,6 @@ package account
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"errors"
|
|
||||||
|
|
||||||
"github.com/tendermint/tendermint/Godeps/_workspace/src/github.com/tendermint/ed25519"
|
"github.com/tendermint/tendermint/Godeps/_workspace/src/github.com/tendermint/ed25519"
|
||||||
"github.com/tendermint/tendermint/Godeps/_workspace/src/github.com/tendermint/ed25519/extra25519"
|
"github.com/tendermint/tendermint/Godeps/_workspace/src/github.com/tendermint/ed25519/extra25519"
|
||||||
@ -12,7 +11,6 @@ import (
|
|||||||
|
|
||||||
// PubKey is part of Account and Validator.
|
// PubKey is part of Account and Validator.
|
||||||
type PubKey interface {
|
type PubKey interface {
|
||||||
IsNil() bool
|
|
||||||
Address() []byte
|
Address() []byte
|
||||||
VerifyBytes(msg []byte, sig Signature) bool
|
VerifyBytes(msg []byte, sig Signature) bool
|
||||||
}
|
}
|
||||||
@ -33,8 +31,6 @@ var _ = binary.RegisterInterface(
|
|||||||
// Implements PubKey
|
// Implements PubKey
|
||||||
type PubKeyEd25519 [32]byte
|
type PubKeyEd25519 [32]byte
|
||||||
|
|
||||||
func (pubKey PubKeyEd25519) IsNil() bool { return false }
|
|
||||||
|
|
||||||
// TODO: Or should this just be BinaryRipemd160(key)? (The difference is the TypeByte.)
|
// TODO: Or should this just be BinaryRipemd160(key)? (The difference is the TypeByte.)
|
||||||
func (pubKey PubKeyEd25519) Address() []byte { return binary.BinaryRipemd160(pubKey[:]) }
|
func (pubKey PubKeyEd25519) Address() []byte { return binary.BinaryRipemd160(pubKey[:]) }
|
||||||
|
|
||||||
@ -60,14 +56,6 @@ func (pubKey PubKeyEd25519) ToCurve25519() *[32]byte {
|
|||||||
return keyCurve25519
|
return keyCurve25519
|
||||||
}
|
}
|
||||||
|
|
||||||
// redundant: compiler does it for us
|
|
||||||
func (pubKey PubKeyEd25519) ValidateBasic() error {
|
|
||||||
if len(pubKey) != ed25519.PublicKeySize {
|
|
||||||
return errors.New("Invalid PubKeyEd25519 key size")
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (pubKey PubKeyEd25519) String() string {
|
func (pubKey PubKeyEd25519) String() string {
|
||||||
return Fmt("PubKeyEd25519{%X}", pubKey[:])
|
return Fmt("PubKeyEd25519{%X}", pubKey[:])
|
||||||
}
|
}
|
||||||
|
@ -27,8 +27,6 @@ var _ = binary.RegisterInterface(
|
|||||||
// Implements Signature
|
// Implements Signature
|
||||||
type SignatureEd25519 [64]byte
|
type SignatureEd25519 [64]byte
|
||||||
|
|
||||||
func (sig SignatureEd25519) IsNil() bool { return false }
|
|
||||||
|
|
||||||
func (sig SignatureEd25519) IsZero() bool { return len(sig) == 0 }
|
func (sig SignatureEd25519) IsZero() bool { return len(sig) == 0 }
|
||||||
|
|
||||||
func (sig SignatureEd25519) String() string { return fmt.Sprintf("/%X.../", Fingerprint(sig[:])) }
|
func (sig SignatureEd25519) String() string { return fmt.Sprintf("/%X.../", Fingerprint(sig[:])) }
|
||||||
|
@ -670,7 +670,6 @@ func readReflectJSON(rv reflect.Value, rt reflect.Type, o interface{}, err *erro
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
log.Debug("Read bytearray", "bytes", buf)
|
log.Debug("Read bytearray", "bytes", buf)
|
||||||
|
|
||||||
reflect.Copy(rv, reflect.ValueOf(buf))
|
reflect.Copy(rv, reflect.ValueOf(buf))
|
||||||
} else {
|
} else {
|
||||||
oSlice, ok := o.([]interface{})
|
oSlice, ok := o.([]interface{})
|
||||||
|
@ -16,40 +16,6 @@ type SimpleStruct struct {
|
|||||||
Time time.Time
|
Time time.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
type SimpleArray [5]byte
|
|
||||||
|
|
||||||
func TestSimpleArray(t *testing.T) {
|
|
||||||
var foo SimpleArray
|
|
||||||
|
|
||||||
// Type of pointer to array
|
|
||||||
rt := reflect.TypeOf(&foo)
|
|
||||||
fmt.Printf("rt: %v\n", rt)
|
|
||||||
|
|
||||||
// Type of array itself.
|
|
||||||
// NOTE: normally this is acquired through other means
|
|
||||||
// like introspecting on method signatures, or struct fields.
|
|
||||||
rte := rt.Elem()
|
|
||||||
fmt.Printf("rte: %v\n", rte)
|
|
||||||
|
|
||||||
// Get a new pointer to the array
|
|
||||||
// NOTE: calling .Interface() is to get the actual value,
|
|
||||||
// instead of reflection values.
|
|
||||||
ptr := reflect.New(rte).Interface()
|
|
||||||
fmt.Printf("ptr: %v", ptr)
|
|
||||||
|
|
||||||
// Make a simple int aray
|
|
||||||
fooArray := SimpleArray([5]byte{1, 10, 50, 100, 200})
|
|
||||||
fooBytes := BinaryBytes(fooArray)
|
|
||||||
fooReader := bytes.NewReader(fooBytes)
|
|
||||||
|
|
||||||
// Now you can read it.
|
|
||||||
n, err := new(int64), new(error)
|
|
||||||
it := ReadBinary(foo, fooReader, n, err)
|
|
||||||
fmt.Println(it, reflect.TypeOf(it))
|
|
||||||
}
|
|
||||||
|
|
||||||
//-------------------------------------
|
|
||||||
|
|
||||||
type Animal interface{}
|
type Animal interface{}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -502,3 +468,40 @@ func TestBadAlloc(t *testing.T) {
|
|||||||
res := ReadBinary(instance, b, n, err)
|
res := ReadBinary(instance, b, n, err)
|
||||||
fmt.Println(res, *err)
|
fmt.Println(res, *err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
type SimpleArray [5]byte
|
||||||
|
|
||||||
|
func TestSimpleArray(t *testing.T) {
|
||||||
|
var foo SimpleArray
|
||||||
|
|
||||||
|
// Type of pointer to array
|
||||||
|
rt := reflect.TypeOf(&foo)
|
||||||
|
fmt.Printf("rt: %v\n", rt) // *binary.SimpleArray
|
||||||
|
|
||||||
|
// Type of array itself.
|
||||||
|
// NOTE: normally this is acquired through other means
|
||||||
|
// like introspecting on method signatures, or struct fields.
|
||||||
|
rte := rt.Elem()
|
||||||
|
fmt.Printf("rte: %v\n", rte) // binary.SimpleArray
|
||||||
|
|
||||||
|
// Get a new pointer to the array
|
||||||
|
// NOTE: calling .Interface() is to get the actual value,
|
||||||
|
// instead of reflection values.
|
||||||
|
ptr := reflect.New(rte).Interface()
|
||||||
|
fmt.Printf("ptr: %v\n", ptr) // &[0 0 0 0 0]
|
||||||
|
|
||||||
|
// Make a simple int aray
|
||||||
|
fooArray := SimpleArray([5]byte{1, 10, 50, 100, 200})
|
||||||
|
fooBytes := BinaryBytes(fooArray)
|
||||||
|
fooReader := bytes.NewReader(fooBytes)
|
||||||
|
|
||||||
|
// Now you can read it.
|
||||||
|
n, err := new(int64), new(error)
|
||||||
|
it := ReadBinary(foo, fooReader, n, err).(SimpleArray)
|
||||||
|
|
||||||
|
if !bytes.Equal(it[:], fooArray[:]) {
|
||||||
|
t.Errorf("Expected %v but got %v", fooArray, it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -666,9 +666,6 @@ func ExecTx(blockCache *BlockCache, tx types.Tx, runCall bool, evc events.Fireab
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := tx.PubKey.ValidateBasic(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if !tx.PubKey.VerifyBytes(signBytes, tx.Signature) {
|
if !tx.PubKey.VerifyBytes(signBytes, tx.Signature) {
|
||||||
return types.ErrTxInvalidSignature
|
return types.ErrTxInvalidSignature
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user