custom data can now be added to the block chain using OP_RETURN when building a transaction

This commit is contained in:
OutCast3k 2014-12-29 22:55:28 +00:00
parent fbb6f2d5b0
commit 72ee6b17d0
3 changed files with 73 additions and 17 deletions

View file

@ -283,7 +283,7 @@
<div class="tab-pane tab-content" id="newTransaction"> <div class="tab-pane tab-content" id="newTransaction">
<h2>Transaction <small>Create a new transaction</small></h2> <h2>Transaction <small>Create a new transaction</small></h2>
<p>Use this page to create to create a raw transaction</p> <p>Use this page to create a raw transaction</p>
<b>Address, WIF key or Multisig Redeem Script</b>: <b>Address, WIF key or Multisig Redeem Script</b>:
<div class="input-group"> <div class="input-group">
@ -311,6 +311,14 @@
<hr> <hr>
<label>Null Data</label> <span class="text-muted text-normal">(40 byte limit)</span>
<p class="checkbox">
<label><input type="checkbox" id="opReturn" class="checkbox-inline"> Allow data to be sent within the transaction and stored in the blockchain by using <a href="https://bitcoin.org/en/developer-guide#null-data" target="_"blank">OP_RETURN</a>.</label>
<div class="text-muted">When using this option you may enter a hex string or address into the address field on the output tab.</div>
</p>
<hr>
<label>Lock Time</label> <label>Lock Time</label>
<p>The <a href="https://bitcoin.org/en/developer-guide#locktime-and-sequence-number">locktime</a> indicates the earliest time a transaction can be added to the block chain.</p> <p>The <a href="https://bitcoin.org/en/developer-guide#locktime-and-sequence-number">locktime</a> indicates the earliest time a transaction can be added to the block chain.</p>
<input type="text" class="form-control" value="0" id="nLockTime"> <input type="text" class="form-control" value="0" id="nLockTime">

View file

@ -383,9 +383,25 @@
o.value = new BigInteger('' + Math.round((value*1) * 1e8), 10); o.value = new BigInteger('' + Math.round((value*1) * 1e8), 10);
var s = coinjs.script(); var s = coinjs.script();
o.script = s.spendToScript(address); o.script = s.spendToScript(address);
return this.outs.push(o); return this.outs.push(o);
} }
/* add data to a transaction */
r.adddata = function(data){
var r = false;
if(((data.match(/^[a-f0-9]+$/gi)) && data.length<80) && (data.length%2)==0) {
var s = coinjs.script();
s.writeOp(106); // OP_RETURN
s.writeBytes(Crypto.util.hexToBytes(data));
o = {};
o.value = 0;
o.script = s;
return this.outs.push(o);
}
return r;
}
/* list unspent transactions */ /* list unspent transactions */
r.listUnspent = function(address, callback) { r.listUnspent = function(address, callback) {
coinjs.ajax(coinjs.host+'?uid='+coinjs.uid+'&key='+coinjs.key+'&setmodule=addresses&request=unspent&address='+address+'&r='+Math.random(), callback, "GET"); coinjs.ajax(coinjs.host+'?uid='+coinjs.uid+'&key='+coinjs.key+'&setmodule=addresses&request=unspent&address='+address+'&r='+Math.random(), callback, "GET");

View file

@ -361,9 +361,16 @@ $(document).ready(function() {
} }
}); });
$("#recipients .row").removeClass('has-error');
$.each($("#recipients .row"), function(i,o){ $.each($("#recipients .row"), function(i,o){
if($(".address",o).val()!="" && $(".amount",o).val()!=""){ var a = ($(".address",o).val()).substr(0,80);
tx.addoutput($(".address",o).val(), $(".amount",o).val()); if(((a!="") && coinjs.addressDecode(a)) && $(".amount",o).val()!=""){ // address
tx.addoutput(a, $(".amount",o).val());
} else if (((($("#opReturn").is(":checked")) && a.match(/^[a-f0-9]+$/ig)) && a.length<80) && (a.length%2)==0) { // data
tx.adddata(a);
} else { // neither address nor data
$(o).addClass('has-error');
} }
}); });
@ -589,26 +596,44 @@ $(document).ready(function() {
h += '</td>'; h += '</td>';
h += '</tr>'; h += '</tr>';
}); });
$(h).appendTo("#verifyTransactionData .ins tbody"); $(h).appendTo("#verifyTransactionData .ins tbody");
h = ''; h = '';
$.each(decode.outs, function(i,o){ $.each(decode.outs, function(i,o){
var addr = ''; if(o.script.chunks.length==2 && o.script.chunks[0]==106){ // OP_RETURN
if(o.script.chunks.length==5){
addr = coinjs.scripthash2address(Crypto.util.bytesToHex(o.script.chunks[2]));
} else {
var pub = coinjs.pub;
coinjs.pub = coinjs.multisig;
addr = coinjs.scripthash2address(Crypto.util.bytesToHex(o.script.chunks[1]));
coinjs.pub = pub;
}
h += '<tr>'; var data = Crypto.util.bytesToHex(o.script.chunks[1]);
h += '<td><input class="form-control" type="text" value="'+addr+'" readonly></td>'; var dataascii = hex2ascii(data);
h += '<td class="col-xs-1">'+(o.value/100000000).toFixed(8)+'</td>';
h += '<td class="col-xs-2"><input class="form-control" type="text" value="'+Crypto.util.bytesToHex(o.script.buffer)+'" readonly></td>'; if(dataascii.match(/^[\s\d\w]+$/ig)){
h += '</tr>'; data = dataascii;
}
h += '<tr>';
h += '<td><input type="text" class="form-control" value="(OP_RETURN) '+data+'" readonly></td>';
h += '<td class="col-xs-1">'+(o.value/100000000).toFixed(8)+'</td>';
h += '<td class="col-xs-2"><input class="form-control" type="text" value="'+Crypto.util.bytesToHex(o.script.buffer)+'" readonly></td>';
h += '</tr>';
} else {
var addr = '';
if(o.script.chunks.length==5){
addr = coinjs.scripthash2address(Crypto.util.bytesToHex(o.script.chunks[2]));
} else {
var pub = coinjs.pub;
coinjs.pub = coinjs.multisig;
addr = coinjs.scripthash2address(Crypto.util.bytesToHex(o.script.chunks[1]));
coinjs.pub = pub;
}
h += '<tr>';
h += '<td><input class="form-control" type="text" value="'+addr+'" readonly></td>';
h += '<td class="col-xs-1">'+(o.value/100000000).toFixed(8)+'</td>';
h += '<td class="col-xs-2"><input class="form-control" type="text" value="'+Crypto.util.bytesToHex(o.script.buffer)+'" readonly></td>';
h += '</tr>';
}
}); });
$(h).appendTo("#verifyTransactionData .outs tbody"); $(h).appendTo("#verifyTransactionData .outs tbody");
@ -618,6 +643,13 @@ $(document).ready(function() {
} }
} }
function hex2ascii(hex) {
var str = '';
for (var i = 0; i < hex.length; i += 2)
str += String.fromCharCode(parseInt(hex.substr(i, 2), 16));
return str;
}
function decodePrivKey(){ function decodePrivKey(){
var wif = $("#verifyScript").val(); var wif = $("#verifyScript").val();
if(wif.length==51 || wif.length==52){ if(wif.length==51 || wif.length==52){