"use strict";

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

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

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

var _util = require("../util");

var _ExtrinsicPayload = require("../v3/ExtrinsicPayload");

// 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 ExtrinsicPayloadV4
 * @description
 * A signing payload for an [[Extrinsic]]. For the final encoding, it is variable length based
 * on the contents included
 */
class ExtrinsicPayloadV4 extends _Struct.default {
  constructor(value) {
    super(_ExtrinsicPayload.SignedPayloadDefV3, value);
  }
  /**
   * @description The block [[Hash]] the signature applies to (mortal/immortal)
   */


  get blockHash() {
    return this.get('blockHash');
  }
  /**
   * @description The [[ExtrinsicEra]]
   */


  get era() {
    return this.get('era');
  }
  /**
   * @description The genesis [[Hash]] the signature applies to (mortal/immortal)
   */


  get genesisHash() {
    return this.get('genesisHash');
  }
  /**
   * @description The [[Bytes]] contained in the payload
   */


  get method() {
    return this.get('method');
  }
  /**
   * @description The [[Index]]
   */


  get nonce() {
    return this.get('nonce');
  }
  /**
   * @description The specVersion for this signature
   */


  get specVersion() {
    return this.get('specVersion');
  }
  /**
   * @description The tip [[Balance]]
   */


  get tip() {
    return this.get('tip');
  }
  /**
   * @description Sign the payload with the keypair
   */


  sign(signerPair) {
    // NOTE The `toU8a(true)` argument is absolutely critical - we don't want the method (Bytes)
    // to have the length prefix included. This means that the data-as-signed is un-decodable,
    // but is also doesn't need the extra information, only the pure data (and is not decoded)
    // ... The same applies to V1..V3, if we have a V5, carry move this comment to latest
    return (0, _util.sign)(signerPair, this.toU8a(true), {
      withType: true
    });
  }

}

exports.default = ExtrinsicPayloadV4;