Created
February 7, 2015 20:47
-
-
Save Biersteker/9b3b7719d0f94369062a to your computer and use it in GitHub Desktop.
Cordova OP_return scanner. (testtool)
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
<!DOCTYPE html> | |
<!-- | |
Needs Cordova, Node, Ant, Android SDK and com.phonegap.plugins.barcodescanner=https://github.com/wildabeast/BarcodeScanner.git in plugins.properties or add by commandline cordava plugins add com.phonegap.plugins.barcodescanner. | |
And as usual, Have fun. | |
Regards GielBier | |
--> | |
<html> | |
<head> | |
<title>Easy op_return</title> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<script type="text/javascript" charset="utf-8" src="cordova.js"></script> | |
<script src="js/libs/jquery/jquery.js" type="text/javascript"></script> | |
<style> | |
header { | |
width:100%; | |
background-color: orange; | |
text-align: center; | |
height: 40px; | |
min-height: 40px; | |
position:fixed; | |
color:white; | |
font-family: monospace; | |
font-size: 16px; | |
font-weight: bold; | |
z-index:9; | |
} | |
html, body { | |
margin: 0px 0px 0px 0px; | |
} | |
.left { | |
float:left; | |
} | |
.myul { | |
top:40px; | |
position:relative; | |
} | |
ul,li { | |
font-family: monospace; | |
margin: 0px 0px 0px 0px; | |
padding: 0px 0px 0px 0px; | |
list-style-type: none; | |
text-align: center; | |
word-wrap: break-word; | |
} | |
.smallmenu { | |
width: 100%; | |
position:fixed; | |
right: 0px; | |
top:40px; | |
text-align: center; | |
background: #cccccc; | |
z-index: 10; | |
display:none; | |
padding: 10px; | |
} | |
.shiv { | |
height:40px; | |
} | |
header li { | |
display: inline-block; | |
width: auto; | |
font-size: 14px; | |
padding: 0px 10px; | |
height:100%; | |
} | |
</style> | |
</head> | |
<body> | |
<header> | |
<div class="left"> </div> | |
<span onclick="about();">OP_Return Scanner v0.01</span> | |
<ul> | |
<li onclick="scanqr()">Scan</li> | |
<li onclick="history()">History</li> | |
<li class="right" onclick="showmenu();">Network</li> | |
</ul> | |
</header> | |
<div class="content"> | |
<div class="smallmenu"> | |
<ul> | |
<li onclick="setbtc();">Bitcoin</li> | |
<li><hr></li> | |
<li onclick="settbtc();">Testnet Bitcoin</li> | |
<li><hr></li> | |
<li onclick="setskc();">Skeincoin</li> | |
</ul> | |
</div> | |
<ul class="myul"></ul> | |
</div> | |
<script> | |
var networks = { | |
bitcoin: "https://insight.bitpay.com/api/txs/?address=", | |
tbitcoin: "https://test-insight.bitpay.com/api/txs/?address=", | |
skeincoin: "http://explorer.skeincoin.org/api/txs/?address=" | |
}; | |
function showmenu() { | |
$(".smallmenu").toggle(); | |
} | |
function deletehistory() { | |
if (confirm("Delete History?") == true) { | |
localStorage.clear(); | |
history(); | |
} | |
} | |
function history() { | |
var hist = localStorage.getItem('history'); | |
if (hist == null) { | |
$(".myul").empty(); | |
$(".myul").append('<li>There is no history</li><hr>'); | |
} else { | |
//alert(hist); | |
var histarr = JSON.parse(hist); | |
$(".myul").empty(); | |
$(".myul").append('<li onclick="deletehistory();"><b>Delete History</b></li><hr>'); | |
$.each(histarr, function (key, val) { | |
var onclick = 'onclick=GetData(\'' + val + '\')'; | |
$(".myul").append('<li ' + onclick + '>' + val + '</li><hr>'); | |
}); | |
} | |
} | |
function about(){ | |
$(".myul").empty(); | |
$(".myul").append('<li>OP_return scanner is a simple application I use for testing</li>'); | |
$(".myul").append('<li>It uses the Insight blockexplorer api</li>'); | |
$(".myul").append('<li></li>'); | |
$(".myul").append('<li>Have fun - GielBier / @Strikerbee </li>'); | |
} | |
function unique(list) { | |
var result = []; | |
$.each(list, function (i, e) { | |
if ($.inArray(e, result) == -1) | |
result.push(e); | |
}); | |
return result; | |
} | |
function saveaddress(address) { | |
var hist = localStorage.getItem('history'); | |
if (hist == null) { | |
var hist = []; | |
} else { | |
var hist = JSON.parse(hist); | |
} | |
hist.push(address); | |
var hist = unique(hist); | |
localStorage.setItem('history', JSON.stringify(hist)); | |
//alert("saved:" + address); | |
} | |
function setbtc() { | |
localStorage.setItem('item', "bitcoin"); | |
$(".right").text("bitcoin"); | |
} | |
function settbtc() { | |
localStorage.setItem('item', "tbitcoin"); | |
$(".right").text("tbitcoin"); | |
} | |
function setskc() { | |
localStorage.setItem('item', "skeincoin"); | |
$(".right").text("skeincoin"); | |
} | |
$(document).ready(function () { | |
var a = localStorage.getItem('item'); | |
if (a == null) { | |
localStorage.setItem('item', "tbitcoin"); | |
$(".right").text("tbitcoin"); | |
} else { | |
$(".right").text(a); | |
} | |
GetData('1JttRRdtAi6cDNM23Uq4BEU61R8kJeANJs'); | |
}); | |
function scanqr() { | |
cordova.plugins.barcodeScanner.scan( | |
function (result) { | |
var address = result.text | |
if (address.length >= 26 && address.length <= 35) { | |
GetData(result.text); | |
saveaddress(result.text); | |
} | |
}, | |
function (error) { | |
alert("Scanning failed: " + error); | |
} | |
); | |
} | |
function GetData(address) { | |
var lazy = address.substring(0, 1); | |
switch (lazy) { | |
case '1': | |
setbtc(); | |
break; | |
case '3': | |
setbtc(); | |
break; | |
case '2': | |
settbtc(); | |
break; | |
case 'm': | |
settbtc(); | |
break; | |
case 'S': | |
setskc(); | |
break; | |
default: | |
alert('Unknown address;'); | |
return; | |
break; | |
} | |
$(".myul").empty(); | |
var explorer = localStorage.getItem('item'); | |
var url = networks[explorer]; | |
console.log(url + address); | |
var count = 0; | |
var count2 = 0; | |
$.getJSON(url + address, function (data) { | |
console.log(JSON.stringify(data)); | |
var data = data['txs']; | |
$.each(data, function (key, val) { | |
count2++; | |
var timestamp = new Date(parseInt(val.time*1000)); | |
var data2 = val.vout; | |
$.each(data2, function (key2, val2) { | |
var opreturn = val2.scriptPubKey.asm; | |
if (opreturn.substring(0, 9) == "OP_RETURN") { | |
count++; | |
var hex = opreturn.slice(10); | |
$(".myul").append('<li>' + timestamp +'<b>('+val.confirmations+')</b><br>' + val.txid + '<br><b>' + hex2a(hex) + '</b></li><hr>'); | |
} | |
}); | |
}); | |
$(".myul").prepend('<li>Found: '+count+' use(s) OP_RETURN in '+count2+' transactions</li><hr>'); | |
$(".myul").prepend('<li>Network:'+explorer+'<br>'+address+'</li>'); | |
}); | |
} | |
function hex2a(hexx) { | |
var hex = hexx.toString(); //force conversion | |
var str = ''; | |
for (var i = 0; i < hex.length; i += 2) | |
str += String.fromCharCode(parseInt(hex.substr(i, 2), 16)); | |
return str; | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment