mirror of
https://github.com/ok2/coinbin.git
synced 2026-05-09 18:15:23 +02:00
added feature to rebuild a transaction from the txid, useful for RBF and double spending :o. Changed donation address. Released as version 1.6
This commit is contained in:
+6
-1
@@ -19,7 +19,7 @@
|
||||
coinjs.compressed = false;
|
||||
|
||||
/* other vars */
|
||||
coinjs.developer = '3K1oFZMks41C7qDYBsr72SYjapLqDuSYuN'; //bitcoin
|
||||
coinjs.developer = '33tht1bKDgZVxb39MnZsWa8oxHXHvUYE4G'; //bitcoin
|
||||
|
||||
/* bit(coinb.in) api vars */
|
||||
coinjs.hostname = ((document.location.hostname.split(".")[(document.location.hostname.split(".")).length-1]) == 'onion') ? '4zpinp6gdkjfplhk.onion' : 'coinb.in';
|
||||
@@ -1067,6 +1067,11 @@
|
||||
coinjs.ajax(coinjs.host+'?uid='+coinjs.uid+'&key='+coinjs.key+'&setmodule=addresses&request=unspent&address='+address+'&r='+Math.random(), callback, "GET");
|
||||
}
|
||||
|
||||
/* list transaction data */
|
||||
r.getTransaction = function(txid, callback) {
|
||||
coinjs.ajax(coinjs.host+'?uid='+coinjs.uid+'&key='+coinjs.key+'&setmodule=bitcoin&request=gettransaction&txid='+txid+'&r='+Math.random(), callback, "GET");
|
||||
}
|
||||
|
||||
/* add unspent to transaction */
|
||||
r.addUnspent = function(address, callback, script, segwit, sequence){
|
||||
var self = this;
|
||||
|
||||
+64
-7
@@ -881,7 +881,7 @@ $(document).ready(function() {
|
||||
$("#redeemFromStatus, #redeemFromAddress").addClass('hidden');
|
||||
|
||||
if(redeem.from=='multisigAddress'){
|
||||
$("#redeemFromStatus").removeClass('hidden').html('<span class="glyphicon glyphicon-exclamation-sign"></span> You should use the redeem script, not the multisig address!');
|
||||
$("#redeemFromStatus").removeClass('hidden').html('<span class="glyphicon glyphicon-exclamation-sign"></span> You should use the redeem script, not its address!');
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -973,9 +973,15 @@ $(document).ready(function() {
|
||||
r.redeemscript = true;
|
||||
r.decodescript = decodeRs;
|
||||
} else { // something else
|
||||
r.addr = '';
|
||||
r.from = 'other';
|
||||
r.redeemscript = false;
|
||||
if(string.match(/^[a-f0-9]{64}$/i)){
|
||||
r.addr = string;
|
||||
r.from = 'txid';
|
||||
r.redeemscript = false;
|
||||
} else {
|
||||
r.addr = '';
|
||||
r.from = 'other';
|
||||
r.redeemscript = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return r;
|
||||
@@ -1042,9 +1048,61 @@ $(document).ready(function() {
|
||||
}
|
||||
}
|
||||
|
||||
/* global function to add inputs to page */
|
||||
function addInput(address, amount) {
|
||||
if($("#recipients .recipient:last .address:last").val() != ""){
|
||||
$("#recipients .addressAddTo:first").click();
|
||||
};
|
||||
|
||||
$("#recipients .address:last").val(address);
|
||||
$("#recipients .amount:last").val(amount);
|
||||
}
|
||||
|
||||
|
||||
/* default function to retreive unspent outputs*/
|
||||
function listUnspentDefault(redeem){
|
||||
|
||||
var tx = coinjs.transaction();
|
||||
|
||||
// unspent from transaction; double spend and RBF.
|
||||
|
||||
if(redeem.from == 'txid'){
|
||||
tx.getTransaction(redeem.addr, function(data){
|
||||
|
||||
$("#redeemFromAddress").removeClass('hidden').html('<span class="glyphicon glyphicon-info-sign"></span> Attempted to rebuild transaction id <a href="'+explorer_tx+redeem.addr+'" target="_blank">'+redeem.addr+'</a>');
|
||||
|
||||
$.each($(data).find("inputs").children(), function(i,o){
|
||||
var tx = $(o).find("txid").text();
|
||||
var n = $(o).find("output_no").text();
|
||||
var amount = (($(o).find("value").text()*1)).toFixed(8);
|
||||
|
||||
var script = coinjs.script();
|
||||
var s = script.spendToScript($(o).find("address").text());
|
||||
var scr = Crypto.util.bytesToHex(s.buffer);
|
||||
|
||||
addOutput(tx, n, scr, amount);
|
||||
|
||||
});
|
||||
|
||||
$("#recipients .addressRemoveTo").click();
|
||||
$("#recipients .address").val("");
|
||||
$("#recipients .amount").val("");
|
||||
|
||||
$.each($(data).find("outputs").children(), function(i,o){
|
||||
addInput($(o).find("address").text(), $(o).find("value").text());
|
||||
});
|
||||
|
||||
$("#redeemFromBtn").html("Load").attr('disabled',false);
|
||||
totalInputAmount();
|
||||
validateOutputAmount();
|
||||
|
||||
});
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// unspent from address
|
||||
|
||||
tx.listUnspent(redeem.addr, function(data){
|
||||
if(redeem.addr) {
|
||||
$("#redeemFromAddress").removeClass('hidden').html('<span class="glyphicon glyphicon-info-sign"></span> Retrieved unspent inputs from address <a href="'+explorer_addr+redeem.addr+'" target="_blank">'+redeem.addr+'</a>');
|
||||
@@ -1078,10 +1136,9 @@ $(document).ready(function() {
|
||||
},
|
||||
success: function(data) {
|
||||
if (data.address) { // address field will always be present, txrefs is only present if there are UTXOs
|
||||
$("#redeemFromAddress").removeClass('hidden').html(
|
||||
'<span class="glyphicon glyphicon-info-sign"></span> Retrieved unspent inputs from address <a href="'+explorer_addr+redeem.addr+'" target="_blank">'+redeem.addr+'</a>');
|
||||
$("#redeemFromAddress").removeClass('hidden').html('<span class="glyphicon glyphicon-info-sign"></span> Retrieved unspent inputs from address <a href="'+explorer_addr+redeem.addr+'" target="_blank">'+redeem.addr+'</a>');
|
||||
for(var i in data.txrefs){
|
||||
var o = data.txrefs[i]
|
||||
var o = data.txrefs[i];
|
||||
var tx = ((""+o.tx_hash).match(/.{1,2}/g).reverse()).join("")+'';
|
||||
if(tx.match(/^[a-f0-9]+$/)){
|
||||
var n = o.tx_output_n;
|
||||
|
||||
Reference in New Issue
Block a user