"use strict";

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

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

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

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

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

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }

// SignedExtra adds the following fields to the payload
const SignedExtraV2 = {
  // system::CheckEra<Runtime>
  blockHash: 'Hash' // system::CheckNonce<Runtime>
  // system::CheckWeight<Runtime>
  // balances::TakeFees<Runtime>

}; // the base definition (excluding extras)

const SignedPayloadBaseV2 = {
  method: 'Bytes',
  era: 'ExtrinsicEra',
  nonce: 'Compact<Index>',
  tip: 'Compact<Balance>'
}; // the full definition for the payload

exports.SignedPayloadBaseV2 = SignedPayloadBaseV2;

const SignedPayloadDefV2 = _objectSpread({}, SignedPayloadBaseV2, {}, SignedExtraV2);
/**
 * @name ExtrinsicPayloadV2
 * @description
 * A signing payload for an [[Extrinsic]]. For the final encoding, it is variable length based
 * on the contents included
 */


class ExtrinsicPayloadV2 extends _Struct.default {
  constructor(value) {
    super(SignedPayloadDefV2, 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 [[Bytes]] contained in the payload
   */


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


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


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


  sign(signerPair) {
    return (0, _util.sign)(signerPair, this.toU8a(true));
  }

}

exports.default = ExtrinsicPayloadV2;