コード例 #1
0
 /**
  * Redeem Scripts To Wallet
  *
  * This function extends on whatever data is in the $wallet array, by
  * adding script hash addresses to the wallet, and linking keys in the
  * multisignature address with keys in the wallet.
  * Adds each redeemScript to the referenced $wallet.
  *
  * @param array $wallet
  * @param array $redeem_scripts
  * @param null  $magic_p2sh_byte
  */
 public static function redeem_scripts_to_wallet(&$wallet, array $redeem_scripts = array(), $magic_p2sh_byte = null)
 {
     $magic_p2sh_byte = BitcoinLib::magicP2SHByte($magic_p2sh_byte);
     if (count($redeem_scripts) > 0) {
         foreach ($redeem_scripts as $script) {
             $decode = self::decode_redeem_script($script);
             if ($decode == false) {
                 continue;
             }
             $scripthash = BitcoinLib::hash160($script);
             $keys = array();
             foreach ($decode['keys'] as $key) {
                 $keyhash = BitcoinLib::hash160($key);
                 if (isset($wallet[$keyhash])) {
                     $keys[] = $wallet[$keyhash];
                 }
             }
             $wallet[$scripthash] = array('type' => 'scripthash', 'script' => $script, 'required_signature_count' => $decode['m'], 'address' => BitcoinLib::hash160_to_address($scripthash, $magic_p2sh_byte), 'public_keys' => $decode['keys'], 'keys' => $keys);
         }
     }
 }