@@ -32,15 +32,22 @@ func (c *EBlock) MarshalledSize() uint64 {
3232// Its PrevKeyMR and PrevLedgerKeyMR are populated by the provided previous Entry
3333// Block. If The previous Entry Block is nil (the new Entry Block is first in
3434// the Chain) the relevent Entry Block Header fields will contain zeroed Hashes.
35- func MakeEBlock (echain * EChain , prev * EBlock ) * EBlock {
35+ func MakeEBlock (echain * EChain , prev * EBlock ) ( * EBlock , error ) {
3636 e := NewEBlock ()
3737 e .Header .ChainID = echain .ChainID
3838 if prev != nil {
39- e .Header .PrevKeyMR = prev .KeyMR ()
40- e .Header .PrevLedgerKeyMR = prev .Hash ()
39+ var err error
40+ e .Header .PrevKeyMR , err = prev .KeyMR ()
41+ if err != nil {
42+ return nil , err
43+ }
44+ e .Header .PrevLedgerKeyMR , err = prev .Hash ()
45+ if err != nil {
46+ return nil , err
47+ }
4148 }
4249 e .Header .EBSequence = echain .NextBlockHeight
43- return e
50+ return e , nil
4451}
4552
4653// NewEBlock returns a blank initialized Entry Block with all of its fields
@@ -81,27 +88,27 @@ func (e *EBlock) BuildHeader() error {
8188
8289// Hash returns the simple Sha256 hash of the serialized Entry Block. Hash is
8390// used to provide the PrevLedgerKeyMR to the next Entry Block in a Chain.
84- func (e * EBlock ) Hash () * Hash {
91+ func (e * EBlock ) Hash () ( * Hash , error ) {
8592 p , err := e .MarshalBinary ()
8693 if err != nil {
87- return NewHash ()
94+ return nil , err
8895 }
89- return Sha (p )
96+ return Sha (p ), nil
9097}
9198
9299// KeyMR returns the hash of the hash of the Entry Block Header concatinated
93100// with the Merkle Root of the Entry Block Body. The Body Merkle Root is
94101// calculated by the func (e *EBlockBody) MR() which is called by the func
95102// (e *EBlock) BuildHeader().
96- func (e * EBlock ) KeyMR () * Hash {
103+ func (e * EBlock ) KeyMR () ( * Hash , error ) {
97104 // Sha(Sha(header) + BodyMR)
98105 e .BuildHeader ()
99106 header , err := e .marshalHeaderBinary ()
100107 if err != nil {
101- return NewHash ()
108+ return nil , err
102109 }
103110 h := Sha (header )
104- return Sha (append (h .Bytes (), e .Header .BodyMR .Bytes ()... ))
111+ return Sha (append (h .Bytes (), e .Header .BodyMR .Bytes ()... )), nil
105112}
106113
107114// MarshalBinary returns the serialized binary form of the Entry Block.
0 commit comments