neoneo-go/_pkg.dev/wire/payload/transaction/publickey.go
Roman Khimov ddd1d92ff1 pkg: hide it by moving to _pkg.dev
The idea here is to preserve the history of `dev` branch development and its
code when merging with the `master`. Later this code could be moved into the
masters code where appropriate.
2019-08-20 18:39:50 +03:00

38 lines
855 B
Go

package transaction
import (
"errors"
"github.com/CityOfZion/neo-go/pkg/wire/util"
)
// PublicKey represents a public key on the neo network
type PublicKey struct {
Key []byte
}
//Encode encodes a public key into a binary writer
func (p *PublicKey) Encode(bw *util.BinWriter) {
bw.Write(p.Key)
}
// Decode decodes a bianry reader into a public key
func (p *PublicKey) Decode(br *util.BinReader) {
var prefix uint8
br.Read(&prefix)
// Compressed public keys.
if prefix == 0x02 || prefix == 0x03 {
p.Key = make([]byte, 32)
br.Read(p.Key)
} else if prefix == 0x04 {
p.Key = make([]byte, 65)
br.Read(p.Key)
} else if prefix == 0x00 {
// do nothing, For infinity, the p.Key == 0x00, included in the prefix
} else {
br.Err = errors.New("Prefix not recognised for public key")
return
}
p.Key = append([]byte{prefix}, p.Key...)
}