convert method

  1. @override
SegwitInput convert(
  1. Segwit input
)
override

Converts input and returns the result of the conversion.

Implementation

@override
SegwitInput convert(Segwit input) {
  var version = input.version;
  var program = input.program;

  if (isInvalidVersion(version)) {
    throw InvalidWitnessVersion(version);
  }

  if (isTooShortProgram(program)) {
    throw InvalidProgramLength('too short');
  }

  if (isTooLongProgram(program)) {
    throw InvalidProgramLength('too long');
  }

  if (isWrongVersion0Program(version, program)) {
    throw InvalidProgramLength('version $version invalid with length ${program.length}');
  }

  var data = _convertBits(program, 8, 5, true);

  var encoded = bech32.encode(Bech32(input.hrp, [version] + data));
  return SegwitInput(input.hrp, encoded);
}