/**
  * @param EcAdapterInterface $ecAdapter
  * @param ScriptInterface $outputScript
  * @param RedeemScript $redeemScript
  */
 public function __construct(EcAdapterInterface $ecAdapter, ScriptInterface $outputScript, RedeemScript $redeemScript = null)
 {
     $classifier = new OutputClassifier($outputScript);
     $this->scriptType = $this->prevOutType = $classifier->classify();
     // Reclassify if the output is P2SH, so we know how to sign it.
     if ($this->scriptType == OutputClassifier::PAYTOSCRIPTHASH) {
         if (null === $redeemScript) {
             throw new \InvalidArgumentException('Redeem script is required when output is P2SH');
         }
         $rsClassifier = new OutputClassifier($redeemScript);
         $this->scriptType = $rsClassifier->classify();
     }
     // Gather public keys from redeemScript / outputScript
     $this->ecAdapter = $ecAdapter;
     $this->redeemScript = $redeemScript;
     $this->prevOutScript = $outputScript;
     // According to scriptType, extract public keys
     $this->execForInputTypes(function () {
         // For pay to pub key hash - nothing useful in output script
         $this->publicKeys = [];
     }, function () {
         // For pay to pub key - we can extract this from the output script
         $chunks = $this->prevOutScript->getScriptParser()->parse();
         $this->publicKeys = [PublicKeyFactory::fromHex($chunks[0]->getHex(), $this->ecAdapter)];
     }, function () {
         // Multisig - refer to the redeemScript
         $this->publicKeys = $this->redeemScript->getKeys();
     });
 }