public function testBinaryDataToBitcoinAddress()
 {
     $converter = new AddressConverter();
     $result = $converter->binaryDataToBitcoinAddress('00c56cb39f9b289c0ec4ef6943fa107c904820fe0980df2772');
     PHPUnit::assertEquals('1JztLWos5K7LsqW5E78EASgiVBaCe6f7cD', $result);
     $result = $converter->binaryDataToBitcoinAddress('0001fb0c86969f0ec7c3137ef692ed24da94d5bb29600f4679');
     PHPUnit::assertEquals('1BURNsssssssssssssssssssssstsp2x8', $result);
     $result = $converter->binaryDataToBitcoinAddress('0001c5a6dc8dd376ab0a6c27f872f4fd6965fa795c6f0c7fe7');
     PHPUnit::assertEquals('1ANTHERXXXXXXXXXXXXXXXXXXXXVA2ynW', $result);
 }
 /**
  * Decodes OP_RETURN data to trigger an alternate swapbot receipt destination
  * returns an array of the operation and the base58 encoded bitcoin address on success
  * @param  string $op_return_string the hexadecimal encoded OP_RETURN value
  * @return mixed null if not a valid OP_RETURN or an array of ['operation' => 'destination, 'address' => $address_string] on success
  */
 public function decodeInstruction($raw_op_return_string)
 {
     $op_return_string = strtolower($raw_op_return_string);
     $prefix_length = strlen(Constants::PREFIX);
     if (substr($op_return_string, 0, $prefix_length) == Constants::PREFIX) {
         // check operation byte
         if (substr($op_return_string, $prefix_length, 1) != Constants::OP_DESTINATION) {
             throw new Exception("Unknown operation byte", 1);
         }
         $operation = 'destination';
         // get the address
         $address_hex = substr($op_return_string, $prefix_length + 2);
         if (strlen($address_hex) != 50) {
             throw new Exception("Invalid address length", 1);
         }
         $address_converter = new AddressConverter();
         $address = $address_converter->binaryDataToBitcoinAddress($address_hex);
         return ['operation' => $operation, 'address' => $address];
     }
     return null;
 }
 /**
  * builds the OP_RETURN data to trigger an alternate swapbot receipt destination
  * @param  string $bitcoin_address a base58 encoded bitcoin address
  * @return string a hexadecimal representation of the OP_RETURN value
  */
 public function buildDestinationInstruction($bitcoin_address)
 {
     $address_converter = new AddressConverter();
     return Constants::PREFIX . Constants::OP_DESTINATION . $address_converter->bitcoinAddressToHexadecimal($bitcoin_address);
 }