BlockOnly performs those parts of block validation that depend only on the block and not on the previous block header. TODO(eric): consider another name
(b *bc.UnsignedBlock)
| 98 | // on the block and not on the previous block header. |
| 99 | // TODO(eric): consider another name |
| 100 | func BlockOnly(b *bc.UnsignedBlock) error { |
| 101 | // TODO(bobg): check version >= 3? |
| 102 | |
| 103 | runlimit := b.Runlimit |
| 104 | for _, tx := range b.Transactions { |
| 105 | if b.Version == 3 && tx.Version != 3 { |
| 106 | return errors.WithDetailf(errTxVersion, "block version %d, transaction version %d", b.Version, tx.Version) |
| 107 | } |
| 108 | |
| 109 | runlimit -= tx.Runlimit |
| 110 | if runlimit < 0 { |
| 111 | return errors.Wrap(errRunlimit) |
| 112 | } |
| 113 | } |
| 114 | |
| 115 | txRoot := bc.TxMerkleRoot(b.Transactions) |
| 116 | if txRoot != *b.TransactionsRoot { |
| 117 | return errors.WithDetailf(errMismatchedMerkleRoot, "computed %x, current block wants %x", txRoot.Bytes(), b.TransactionsRoot.Bytes()) |
| 118 | } |
| 119 | |
| 120 | if b.Version == 3 && len(b.ExtraFields) > 0 { |
| 121 | return errExtraFields |
| 122 | } |
| 123 | |
| 124 | return nil |
| 125 | } |
| 126 | |
| 127 | // BlockPrev performs those parts of block validation that require the |
| 128 | // previous block's header. |