Пример #1
0
 /**
  * get a new BIP32 derivation for the next (unused) address
  *  by requesting it from the API
  *
  * @return string
  * @throws \Exception
  */
 protected function getNewDerivation()
 {
     $path = $this->walletPath->path()->last("*");
     if (self::VERIFY_NEW_DERIVATION) {
         $new = $this->sdk->_getNewDerivation($this->identifier, (string) $path);
         $path = $new['path'];
         $address = $new['address'];
         $redeemScript = $new['redeem_script'];
         list($checkAddress, $checkRedeemScript) = $this->getRedeemScriptByPath($path);
         if ($checkAddress != $address) {
             throw new \Exception("Failed to verify that address from API [{$address}] matches address locally [{$checkAddress}]");
         }
         if ($checkRedeemScript != $redeemScript) {
             throw new \Exception("Failed to verify that redeemScript from API [{$redeemScript}] matches address locally [{$checkRedeemScript}]");
         }
     } else {
         $path = $this->sdk->getNewDerivation($this->identifier, (string) $path);
     }
     return (string) $path;
 }