aboutsummaryrefslogtreecommitdiffstats
path: root/core/types/dkg.go
diff options
context:
space:
mode:
authorSonic <sonic@dexon.org>2018-10-20 16:07:37 +0800
committerWei-Ning Huang <aitjcize@gmail.com>2018-10-20 16:07:37 +0800
commit9fbe8f9e561a64429eb15431782eb4280d0ffbad (patch)
tree035495fdc970b7ad6f2cb1c6b9cc42cbd36526cb /core/types/dkg.go
parent1f7491df37caf974ffa0c824c4c02a8fe2aafcd9 (diff)
downloadtangerine-consensus-9fbe8f9e561a64429eb15431782eb4280d0ffbad.tar
tangerine-consensus-9fbe8f9e561a64429eb15431782eb4280d0ffbad.tar.gz
tangerine-consensus-9fbe8f9e561a64429eb15431782eb4280d0ffbad.tar.bz2
tangerine-consensus-9fbe8f9e561a64429eb15431782eb4280d0ffbad.tar.lz
tangerine-consensus-9fbe8f9e561a64429eb15431782eb4280d0ffbad.tar.xz
tangerine-consensus-9fbe8f9e561a64429eb15431782eb4280d0ffbad.tar.zst
tangerine-consensus-9fbe8f9e561a64429eb15431782eb4280d0ffbad.zip
core: types: implement rlp.Encoder and rlp.Decoder (#232)
* core: types: implement rlp.Encoder and rlp.Decoder * crypto: dkg: fix PublicKey.Bytes
Diffstat (limited to 'core/types/dkg.go')
-rw-r--r--core/types/dkg.go44
1 files changed, 44 insertions, 0 deletions
diff --git a/core/types/dkg.go b/core/types/dkg.go
index 6018ebd..c0a42ee 100644
--- a/core/types/dkg.go
+++ b/core/types/dkg.go
@@ -20,6 +20,9 @@ package types
import (
"encoding/json"
"fmt"
+ "io"
+
+ "github.com/dexon-foundation/dexon/rlp"
"github.com/dexon-foundation/dexon-consensus-core/common"
"github.com/dexon-foundation/dexon-consensus-core/core/crypto"
@@ -59,6 +62,47 @@ func (d *DKGMasterPublicKey) String() string {
d.Round)
}
+type rlpDKGMasterPublicKey struct {
+ ProposerID NodeID
+ Round uint64
+ DKGID []byte
+ PublicKeyShares *dkg.PublicKeyShares
+ Signature crypto.Signature
+}
+
+// EncodeRLP implements rlp.Encoder
+func (d *DKGMasterPublicKey) EncodeRLP(w io.Writer) error {
+ return rlp.Encode(w, rlpDKGMasterPublicKey{
+ ProposerID: d.ProposerID,
+ Round: d.Round,
+ DKGID: d.DKGID.GetLittleEndian(),
+ PublicKeyShares: &d.PublicKeyShares,
+ Signature: d.Signature,
+ })
+}
+
+// DecodeRLP implements rlp.Decoder
+func (d *DKGMasterPublicKey) DecodeRLP(s *rlp.Stream) error {
+ var dec rlpDKGMasterPublicKey
+ if err := s.Decode(&dec); err != nil {
+ return err
+ }
+
+ id, err := dkg.BytesID(dec.DKGID)
+ if err != nil {
+ return err
+ }
+
+ *d = DKGMasterPublicKey{
+ ProposerID: dec.ProposerID,
+ Round: dec.Round,
+ DKGID: id,
+ PublicKeyShares: *dec.PublicKeyShares,
+ Signature: dec.Signature,
+ }
+ return err
+}
+
// NewDKGMasterPublicKey returns a new DKGMasterPublicKey instance.
func NewDKGMasterPublicKey() *DKGMasterPublicKey {
return &DKGMasterPublicKey{