Created
November 2, 2016 00:43
-
-
Save JburkeRSAC/9e2924394965827bbbf7b76c9fecc93b to your computer and use it in GitHub Desktop.
decode bitcoin OP_RETURN
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$transaction_id = $argv[1]; | |
$url = "https://blockchain.info/tx/$transaction_id?show_adv=true&format=json"; | |
$result = file_get_contents($url); | |
$resultJSON = json_decode($result, true); | |
function hex2str($hex) { | |
$str = ''; | |
for($i=0;$i<strlen($hex);$i+=2) $str .= chr(hexdec(substr($hex,$i,2))); | |
return $str; | |
} | |
//zero false positives that there is a hidden message | |
function fetchZeroValMSG($resultJSON){ | |
$outgoing_transaction = $resultJSON['out']; | |
#print_r($outgoing_transaction); | |
foreach($outgoing_transaction AS $this_transaction){ | |
#print_r($this_transaction); | |
if($this_transaction['value'] == 0){ | |
$code = $this_transaction['script']; | |
echo hex2str($code)."\n"; | |
} | |
} | |
} | |
function fetchPotentialMSG($resultJSON){ | |
$outgoing_transaction = $resultJSON['out']; | |
foreach($outgoing_transaction AS $this_transaction){ | |
$code = $this_transaction['script']; | |
$str2 = substr($code, 6); | |
$code = $str2; | |
unset($str2); | |
$str3 = substr($code, 0, -4); | |
$code = hex2str($str3); | |
unset($str3); | |
echo $code; | |
} | |
} | |
fetchPotentialMSG($resultJSON); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment