github.com/annchain/OG@v0.0.9/consensus/annsensus/message.go (about) 1 package annsensus 2 3 import ( 4 "github.com/annchain/OG/common/hexutil" 5 ) 6 7 //go:generate msgp 8 type AnnsensusMessageType uint16 9 10 // all message type that is supported by annsensus should be listed here 11 const ( 12 AnnsensusMessageTypeBftPlain AnnsensusMessageType = iota + 100 13 AnnsensusMessageTypeBftSigned 14 AnnsensusMessageTypeBftEncrypted 15 AnnsensusMessageTypeDkgPlain 16 AnnsensusMessageTypeDkgSigned 17 AnnsensusMessageTypeDkgEncrypted 18 ) 19 20 //msgp:tuple AnnsensusMessageBftPlain 21 type AnnsensusMessageBftPlain struct { 22 InnerMessageType uint16 // either bft or dkg type, use uint16 to generalize it 23 InnerMessage []byte 24 } 25 26 func (z *AnnsensusMessageBftPlain) GetBytes() []byte { 27 b, err := z.MarshalMsg(nil) 28 if err != nil { 29 panic(err) 30 } 31 return b 32 } 33 34 func (z *AnnsensusMessageBftPlain) GetType() AnnsensusMessageType { 35 return AnnsensusMessageTypeBftPlain 36 } 37 38 func (z *AnnsensusMessageBftPlain) String() string { 39 return "AnnsensusMessageTypeBftPlain" 40 } 41 42 //msgp:tuple AnnsensusMessageBftSigned 43 type AnnsensusMessageBftSigned struct { 44 InnerMessageType uint16 // either bft or dkg type, use uint16 to generalize it 45 InnerMessage []byte 46 Signature hexutil.Bytes 47 PublicKey hexutil.Bytes 48 TermId uint32 49 } 50 51 func (m *AnnsensusMessageBftSigned) GetType() AnnsensusMessageType { 52 return AnnsensusMessageTypeBftSigned 53 } 54 55 func (m *AnnsensusMessageBftSigned) GetBytes() []byte { 56 b, err := m.MarshalMsg(nil) 57 if err != nil { 58 panic(err) 59 } 60 return b 61 } 62 63 func (m *AnnsensusMessageBftSigned) String() string { 64 return "AnnsensusMessageBftSigned" 65 } 66 67 //msgp:tuple AnnsensusMessageEncrypted 68 type AnnsensusMessageBftEncrypted struct { 69 InnerMessageType uint16 // either bft or dkg type, use uint16 to generalize it 70 InnerMessageEncrypted []byte 71 PublicKey hexutil.Bytes 72 } 73 74 func (m *AnnsensusMessageBftEncrypted) GetType() AnnsensusMessageType { 75 return AnnsensusMessageTypeBftEncrypted 76 } 77 78 func (m *AnnsensusMessageBftEncrypted) GetBytes() []byte { 79 b, err := m.MarshalMsg(nil) 80 if err != nil { 81 panic(err) 82 } 83 return b 84 } 85 86 func (m *AnnsensusMessageBftEncrypted) String() string { 87 return "AnnsensusMessageBftEncrypted " + hexutil.Encode(m.InnerMessageEncrypted) 88 } 89 90 //msgp:tuple AnnsensusMessageDkgPlain 91 type AnnsensusMessageDkgPlain struct { 92 InnerMessageType uint16 // either bft or dkg type, use uint16 to generalize it 93 InnerMessage []byte 94 } 95 96 func (z *AnnsensusMessageDkgPlain) GetBytes() []byte { 97 b, err := z.MarshalMsg(nil) 98 if err != nil { 99 panic(err) 100 } 101 return b 102 } 103 104 func (z *AnnsensusMessageDkgPlain) GetType() AnnsensusMessageType { 105 return AnnsensusMessageTypeDkgPlain 106 } 107 108 func (z *AnnsensusMessageDkgPlain) String() string { 109 return "AnnsensusMessageTypeDkgPlain" 110 } 111 112 //msgp:tuple AnnsensusMessageDkgSigned 113 type AnnsensusMessageDkgSigned struct { 114 InnerMessageType uint16 // either bft or dkg type, use uint16 to generalize it 115 InnerMessage []byte 116 Signature hexutil.Bytes 117 PublicKey hexutil.Bytes 118 TermId uint32 119 } 120 121 func (m *AnnsensusMessageDkgSigned) GetType() AnnsensusMessageType { 122 return AnnsensusMessageTypeDkgSigned 123 } 124 125 func (m *AnnsensusMessageDkgSigned) GetBytes() []byte { 126 b, err := m.MarshalMsg(nil) 127 if err != nil { 128 panic(err) 129 } 130 return b 131 } 132 133 func (m *AnnsensusMessageDkgSigned) String() string { 134 return "AnnsensusMessageDkgSigned" 135 } 136 137 //msgp:tuple AnnsensusMessageEncrypted 138 type AnnsensusMessageDkgEncrypted struct { 139 InnerMessageType uint16 // either bft or dkg type, use uint16 to generalize it 140 InnerMessageEncrypted []byte 141 PublicKey hexutil.Bytes 142 } 143 144 func (m *AnnsensusMessageDkgEncrypted) GetType() AnnsensusMessageType { 145 return AnnsensusMessageTypeDkgEncrypted 146 } 147 148 func (m *AnnsensusMessageDkgEncrypted) GetBytes() []byte { 149 b, err := m.MarshalMsg(nil) 150 if err != nil { 151 panic(err) 152 } 153 return b 154 } 155 156 func (m *AnnsensusMessageDkgEncrypted) String() string { 157 return "AnnsensusMessageDkgEncrypted " + hexutil.Encode(m.InnerMessageEncrypted) 158 }