"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;

var _utilCrypto = require("@polkadot/util-crypto");

var _create = require("../../codec/create");

var _Struct = _interopRequireDefault(require("../../codec/Struct"));

// Copyright 2017-2019 @polkadot/types authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.

/**
 * @name Block
 * @description
 * A block encoded with header and extrinsics
 */
class Block extends _Struct.default {
  constructor(value) {
    super({
      header: 'Header',
      extrinsics: 'Vec<Extrinsic>'
    }, value);
  }
  /**
   * @description Encodes a content [[Hash]] for the block
   */


  get contentHash() {
    return (0, _create.createType)('Hash', (0, _utilCrypto.blake2AsU8a)(this.toU8a(), 256));
  }
  /**
   * @description The [[Extrinsic]] contained in the block
   */


  get extrinsics() {
    return this.get('extrinsics');
  }
  /**
   * @description Block/header [[Hash]]
   */


  get hash() {
    return this.header.hash;
  }
  /**
   * @description The [[Header]] of the block
   */


  get header() {
    return this.get('header');
  }

}

exports.default = Block;