func NewFBlockFromPreviousBlock(exchangeRate uint64, prev interfaces.IFBlock) interfaces.IFBlock { if prev != nil { newBlock := NewFBlock(exchangeRate, prev.GetDBHeight()+1) newBlock.SetPrevKeyMR(prev.GetKeyMR().Bytes()) newBlock.SetPrevLedgerKeyMR(prev.GetLedgerKeyMR().Bytes()) return newBlock } return NewFBlock(exchangeRate, 0) }
func NewFBlock(prev interfaces.IFBlock) interfaces.IFBlock { scb := new(FBlock) scb.BodyMR = new(primitives.Hash) if prev != nil { scb.PrevKeyMR = prev.GetKeyMR() scb.PrevLedgerKeyMR = prev.GetLedgerKeyMR() scb.ExchRate = prev.GetExchRate() scb.DBHeight = prev.GetDBHeight() + 1 } else { scb.PrevKeyMR = primitives.NewZeroHash() scb.PrevLedgerKeyMR = primitives.NewZeroHash() scb.ExchRate = 1 scb.DBHeight = 0 } return scb }
func CheckBlockPairIntegrity(block interfaces.IFBlock, prev interfaces.IFBlock) error { if block == nil { return fmt.Errorf("No block specified") } if prev == nil { if block.GetPrevKeyMR().IsZero() == false { return fmt.Errorf("Invalid PrevKeyMR") } if block.GetPrevLedgerKeyMR().IsZero() == false { return fmt.Errorf("Invalid PrevLedgerKeyMR") } if block.GetDBHeight() != 0 { return fmt.Errorf("Invalid DBHeight") } } else { if block.GetPrevKeyMR().IsSameAs(prev.GetKeyMR()) == false { return fmt.Errorf("Invalid PrevKeyMR") } if block.GetPrevLedgerKeyMR().IsSameAs(prev.GetLedgerKeyMR()) == false { return fmt.Errorf("Invalid PrevLedgerKeyMR") } if block.GetDBHeight() != (prev.GetDBHeight() + 1) { return fmt.Errorf("Invalid DBHeight") } } return nil }