Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CPUchain support #203

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Add CPUchain support
  • Loading branch information
Min Khang Aung committed Nov 18, 2019
commit b564774aa24be68c90729f376dedf3ac6e4e6228
3 changes: 3 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1357,6 +1357,7 @@ <h2>Settings <small> making coinb.in even better!</small></h2>
<option value="dogecoin_mainnet" rel="0x1e;0x9e;0x16;0x0827421e;0x089944e4;blockcypher_dogecoin;blockcypher_dogecoin">Dogecoin (mainnet)</option>
<option value="carboncoin_mainnet" rel="0x2f;0xaf;0x05;0x488b21e;0x488ade4;cryptoid.info_carboncoin;cryptoid.info_carboncoin">Carboncoin (mainnet)</option>
<option value="shadowcash_mainnet" rel="0x3f;0xbf;0x7d;0xee80286a;0xee8031e8;false;false">ShadowCash (mainnet)</option>
<option value="cpuchain_mainnet" rel="0x1c;0x80;0x1e;0x488b21e;0x488ade4;cpuchain;cpuchain">CPUchain (mainnet)</option>
<option value="bitcoin_testnet" rel="0x6f;0xef;0xc4;0x043587cf;0x04358394;false;false">Bitcoin (testnet)</option>

<option value="custom" rel="0x00;0x80;0x05;0x488b21e;0x488ade4;false;false">Custom</option>
Expand Down Expand Up @@ -1421,6 +1422,7 @@ <h2>Settings <small> making coinb.in even better!</small></h2>
<option value="chain.so_litecoin"> Chain.so (Litecoin)</option>
<option value="chain.so_dogecoin"> Chain.so (Dogecoin)</option>
<option value="cryptoid.info_carboncoin"> Cryptoid.info (Carboncoin)</option>
<option value="cpuchain"> CPUchain (CPUchain)</option>
</select>
</div>
</div>
Expand All @@ -1443,6 +1445,7 @@ <h2>Settings <small> making coinb.in even better!</small></h2>
<option value="chain.so_litecoin"> Chain.so (Litecoin)</option>
<option value="chain.so_dogecoin"> Chain.so (Dogecoin)</option>
<option value="cryptoid.info_carboncoin"> Cryptoid.info (Carboncoin)</option>
<option value="cpuchain"> CPUchain (CPUchain)</option>
</select>
</div>
</div>
Expand Down
73 changes: 73 additions & 0 deletions js/coinbin.js
Original file line number Diff line number Diff line change
Expand Up @@ -935,6 +935,8 @@ $(document).ready(function() {

} else if(host=='cryptoid.info_carboncoin'){
listUnspentCryptoidinfo_Carboncoin(redeem);
} else if(host=='cpuchain'){
listUnspentCPUchain(redeem);
} else {
listUnspentDefault(redeem);
}
Expand Down Expand Up @@ -1213,6 +1215,39 @@ $(document).ready(function() {
});
}

/* retrieve unspent data from cpuchain api */
function listUnspentCPUchain(redeem){
$.ajax ({
type: "GET",
url: "https://api.cpuchain.org/unspent/"+redeem.addr,
dataType: "json",
error: function(data) {
$("#redeemFromStatus").removeClass('hidden').html('<span class="glyphicon glyphicon-exclamation-sign"></span> Unexpected error, unable to retrieve unspent outputs!');
},
success: function(data) {
if(data.result){
$("#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.result){
var o = data.result[i];
var tx = ((""+o.txid).match(/.{1,2}/g).reverse()).join("")+'';
if(tx.match(/^[a-f0-9]+$/)){
var n = o.index;
var script = (redeem.redeemscript==true) ? redeem.decodedRs : o.script;
var amount = ((o.value.toString()*1)/100000000).toFixed(8);
addOutput(tx, n, script, amount);
}
}
} else {
$("#redeemFromStatus").removeClass('hidden').html('<span class="glyphicon glyphicon-exclamation-sign"></span> Unexpected error, unable to retrieve unspent outputs.');
}
},
complete: function(data, status) {
$("#redeemFromBtn").html("Load").attr('disabled',false);
totalInputAmount();
}
});
}


/* math to calculate the inputs and outputs */

Expand Down Expand Up @@ -1410,6 +1445,35 @@ $(document).ready(function() {
});
}

// broadcast transaction via cpuchain api
function rawSubmitCPUchain(thisbtn){
$(thisbtn).val('Please wait, loading...').attr('disabled',true);
$.ajax ({
type: "POST",
url: "https://api.cpuchain.org/broadcast",
data: {"raw":$("#rawTransaction").val()},
dataType: "json",
error: function(data) {
var obj = $.parseJSON(data.responseText);
var r = ' ';
r += (obj.data.raw) ? obj.data.raw : '';
r = (r!='') ? r : ' Failed to broadcast'; // build response
$("#rawTransactionStatus").addClass('alert-danger').removeClass('alert-success').removeClass("hidden").html(r).prepend('<span class="glyphicon glyphicon-exclamation-sign"></span>');
},
success: function(data) {
if(data.result){
$("#rawTransactionStatus").addClass('alert-success').removeClass('alert-danger').removeClass("hidden").html(' TXID: ' + data.result + '<br> <a href="'+explorer_tx+data.result+'" target="_blank">View on Blockchain Explorer</a>');
} else {
$("#rawTransactionStatus").addClass('alert-danger').removeClass('alert-success').removeClass("hidden").html(' Unexpected error, please try again').prepend('<span class="glyphicon glyphicon-exclamation-sign"></span>');
}
},
complete: function(data, status) {
$("#rawTransactionStatus").fadeOut().fadeIn();
$(thisbtn).val('Submit').attr('disabled',false);
}
});
}




Expand Down Expand Up @@ -1865,6 +1929,11 @@ $(document).ready(function() {
else if (coinjs.pub == 0x1e){ // DOGE
explorer_addr = "https://chain.so/address/DOGE/";
}
else if (coinjs.pub == 0x1c){ // CPU
explorer_addr = "https://explorer.cpuchain.org/address/";
explorer_tx = "https://explorer.cpuchain.org/tx/";
coinjs.bech32.hrp = "cpu";
}

$("#statusSettings").addClass("alert-success").removeClass("hidden").html("<span class=\"glyphicon glyphicon-ok\"></span> Settings updates successfully").fadeOut().fadeIn();
} else {
Expand Down Expand Up @@ -1958,6 +2027,10 @@ $(document).ready(function() {
$("#rawSubmitBtn").click(function(){
rawSubmitcryptoid_Carboncoin(this);
});
} else if(host=="cpuchain"){
$("#rawSubmitBtn").click(function(){
rawSubmitCPUchain(this);
});
} else {
$("#rawSubmitBtn").click(function(){
rawSubmitDefault(this); // revert to default
Expand Down