|
201 | 201 | var addr = eckey.getBitcoinAddress(); |
202 | 202 | setErrorState($('#hash'), false); |
203 | 203 | } catch (err) { |
204 | | - console.info(err); |
| 204 | + //console.info(err); |
205 | 205 | setErrorState($('#hash'), true, 'Invalid secret exponent (must be non-zero value)'); |
206 | 206 | return; |
207 | 207 | } |
|
669 | 669 |
|
670 | 670 | // -- transactions -- |
671 | 671 |
|
| 672 | + var txType = 'txBCI'; |
| 673 | + |
672 | 674 | function txGenSrcAddr() { |
673 | 675 | var sec = $('#txSec').val(); |
674 | 676 | var addr = ''; |
|
699 | 701 | } |
700 | 702 |
|
701 | 703 | function txSetUnspent(text) { |
702 | | - |
703 | | - if (text.length == 0) { |
704 | | - txUnspent = '{"unspent_outputs":[]}'; |
705 | | - var value = 0; |
706 | | - } else { |
707 | | - var r = jQuery.parseJSON(text); |
708 | | - txUnspent = JSON.stringify(r, null, 4); |
709 | | - var value = TX.getBalance(txUnspent); |
710 | | - } |
711 | | - |
| 704 | + var r = JSON.parse(text); |
| 705 | + txUnspent = JSON.stringify(r, null, 4); |
712 | 706 | $('#txUnspent').val(txUnspent); |
713 | | - |
| 707 | + TX.parseInputs(txUnspent, addr); |
| 708 | + var value = TX.getBalance(); |
714 | 709 | var fval = Bitcoin.Util.formatValue(value); |
715 | | - |
716 | 710 | $('#txBalance').val(fval); |
717 | 711 | $('#txValue').val(fval); |
718 | | - |
719 | 712 | txRebuild(); |
720 | 713 | } |
721 | 714 |
|
|
729 | 722 | } |
730 | 723 |
|
731 | 724 | function txParseUnspent(text) { |
732 | | - alert(text == '' ? 'No unspent outputs' : text); |
| 725 | + if (text == '') |
| 726 | + alert('No data'); |
733 | 727 | txSetUnspent(text); |
734 | 728 | } |
735 | 729 |
|
736 | 730 | function txGetUnspent() { |
737 | 731 | var addr = $('#txAddr').val(); |
738 | | - var url = 'http://blockchain.info/unspent?address=' + addr; |
739 | | - url = prompt('Fetching unspent outputs:', url); |
| 732 | + |
| 733 | + var url = (txType == 'txBCI') ? 'http://blockchain.info/unspent?address=' + addr : |
| 734 | + 'http://blockexplorer.com/q/mytransactions/' + addr; |
| 735 | + |
| 736 | + url = prompt('Download transaction history:', url); |
740 | 737 | if (url != null && url != "") { |
741 | 738 | $('#txUnspent').val(''); |
742 | 739 | tx_fetch(url, txParseUnspent); |
|
773 | 770 | function txSend() { |
774 | 771 | var tx = $('#txHex').val(); |
775 | 772 | url = 'http://bitsend.rowit.co.uk/?transaction=' + tx; |
776 | | - url = prompt('Sending transaction:', url); |
| 773 | + url = prompt('Send transaction:', url); |
777 | 774 | if (url != null && url != "") { |
778 | 775 | tx_fetch(url, txSent); |
779 | 776 | } |
780 | 777 | return false; |
781 | 778 | } |
782 | 779 |
|
783 | 780 | function txRebuild() { |
| 781 | + |
784 | 782 | var sec = $('#txSec').val(); |
| 783 | + var addr = $('#txAddr').val(); |
785 | 784 | var dest = $('#txDest').val(); |
786 | 785 | var unspent = $('#txUnspent').val(); |
787 | 786 | var fval = parseFloat($('#txValue').val()); |
|
793 | 792 | } catch (err) { |
794 | 793 | $('#txJSON').val(''); |
795 | 794 | $('#txHex').val(''); |
796 | | - return |
| 795 | + return; |
797 | 796 | } |
798 | 797 |
|
799 | 798 | var eckey = new Bitcoin.ECKey(payload); |
800 | 799 |
|
801 | 800 | TX.init(eckey); |
802 | 801 | TX.addOutput(dest, fval); |
803 | 802 |
|
804 | | - try { |
805 | | - var r = jQuery.parseJSON(unspent); |
806 | | - var unspent = r.unspent_outputs; |
807 | | - } catch (err) { |
808 | | - var unspent = {}; |
809 | | - } |
810 | | - |
811 | | - var sendTx = TX.construct(unspent); |
| 803 | + var sendTx = TX.construct(); |
812 | 804 | var txJSON = TX.toBBE(sendTx); |
813 | 805 | var buf = sendTx.serialize(); |
814 | 806 | var txHex = Crypto.util.bytesToHex(buf); |
|
833 | 825 | } |
834 | 826 | } |
835 | 827 |
|
| 828 | + function txChangeType() { |
| 829 | + txType = $(this).attr('id'); |
| 830 | + txGetUnspent(); |
| 831 | + } |
| 832 | + |
836 | 833 | $(document).ready( function() { |
837 | 834 |
|
838 | 835 | onInput('#pass', onChangePass); |
|
887 | 884 |
|
888 | 885 | $('#txGetUnspent').click(txGetUnspent); |
889 | 886 |
|
| 887 | + $('#txBCI').click(txChangeType); |
| 888 | + $('#txBBE').click(txChangeType); |
| 889 | + |
890 | 890 | onInput($('#txSec'), txOnChangeSec); |
891 | 891 | onInput($('#txUnspent'), txOnChangeUnspent); |
892 | 892 | onInput($('#txHex'), txOnChangeHex); |
|
0 commit comments