)
func checkBlockTime(b *bc.Block, parent *state.BlockNode) error {
- if b.Timestamp > uint64(time.Now().Unix())+consensus.MaxTimeOffsetSeconds {
+ now := uint64(time.Now().UnixNano() / 1e6)
+ if b.Timestamp < (parent.Timestamp + consensus.BlockTimeInterval) {
return errBadTimestamp
}
-
- if b.Timestamp <= parent.CalcPastMedianTime() {
+ if b.Timestamp > (now + consensus.MaxTimeOffsetMs) {
return errBadTimestamp
}
+
return nil
}
return errors.Wrap(ErrWrongCoinbaseTransaction, "have more than 1 output")
}
- output, err := tx.IntraChainOutput(*tx.TxHeader.ResultIds[0])
- if err != nil {
- return err
+ var SourceAmount uint64
+ switch output := tx.Entries[*tx.TxHeader.ResultIds[0]].(type) {
+ case *bc.IntraChainOutput:
+ SourceAmount = output.Source.Value.Amount
+ case *bc.VoteOutput:
+ SourceAmount = output.Source.Value.Amount
+ default:
+ return errors.Wrapf(bc.ErrEntryType, "entry %x has unexpected type %T", tx.TxHeader.ResultIds[0].Bytes(), output)
}
- if output.Source.Value.Amount != amount {
+ if SourceAmount != amount {
return errors.Wrap(ErrWrongCoinbaseTransaction, "dismatch output amount")
}
return nil