custom data can now be added to the block chain using OP_RETURN when building a transaction
This commit is contained in:
parent
fbb6f2d5b0
commit
72ee6b17d0
3 changed files with 73 additions and 17 deletions
10
index.html
10
index.html
|
@ -283,7 +283,7 @@
|
|||
|
||||
<div class="tab-pane tab-content" id="newTransaction">
|
||||
<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>:
|
||||
<div class="input-group">
|
||||
|
@ -311,6 +311,14 @@
|
|||
|
||||
<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>
|
||||
<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">
|
||||
|
|
16
js/coin.js
16
js/coin.js
|
@ -383,9 +383,25 @@
|
|||
o.value = new BigInteger('' + Math.round((value*1) * 1e8), 10);
|
||||
var s = coinjs.script();
|
||||
o.script = s.spendToScript(address);
|
||||
|
||||
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 */
|
||||
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");
|
||||
|
|
|
@ -361,9 +361,16 @@ $(document).ready(function() {
|
|||
}
|
||||
});
|
||||
|
||||
$("#recipients .row").removeClass('has-error');
|
||||
|
||||
$.each($("#recipients .row"), function(i,o){
|
||||
if($(".address",o).val()!="" && $(".amount",o).val()!=""){
|
||||
tx.addoutput($(".address",o).val(), $(".amount",o).val());
|
||||
var a = ($(".address",o).val()).substr(0,80);
|
||||
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,11 +596,28 @@ $(document).ready(function() {
|
|||
h += '</td>';
|
||||
h += '</tr>';
|
||||
});
|
||||
|
||||
$(h).appendTo("#verifyTransactionData .ins tbody");
|
||||
|
||||
h = '';
|
||||
$.each(decode.outs, function(i,o){
|
||||
|
||||
if(o.script.chunks.length==2 && o.script.chunks[0]==106){ // OP_RETURN
|
||||
|
||||
var data = Crypto.util.bytesToHex(o.script.chunks[1]);
|
||||
var dataascii = hex2ascii(data);
|
||||
|
||||
if(dataascii.match(/^[\s\d\w]+$/ig)){
|
||||
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]));
|
||||
|
@ -609,6 +633,7 @@ $(document).ready(function() {
|
|||
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");
|
||||
|
||||
|
@ -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(){
|
||||
var wif = $("#verifyScript").val();
|
||||
if(wif.length==51 || wif.length==52){
|
||||
|
|
Loading…
Reference in a new issue