1- function Wallet ( )
2- {
3- this . keys = [ ] ;
4- this . balances = [ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ] ;
5-
6- // Methods
7- this . textToBytes = function ( text ) {
8- return Crypto . SHA256 ( text , { asBytes : true } ) ;
9- } ;
10-
11- this . getKeys = function ( ) {
12- return this . keys ;
13- } ;
14-
15- this . getBalances = function ( ) {
16- return this . balances ;
17- }
18-
19- this . createBalanceFunction = function ( i ) {
20- return function ( text ) {
21- wallet . getBalances ( ) [ i ] = parseInt ( text ) ;
22-
23- // TODO, disconnect GUI code from backend.
24- $ ( '#balance' + i ) . text (
25- Bitcoin . Util . formatValue ( wallet . getBalances ( ) [ i ] ) ) ;
26- } ;
27- }
28-
29- this . updateAllBalances = function ( ) {
30-
31- url = 'http://blockchain.info/q/addressbalance/' ;
32- var funcs = [ ] ;
33-
34- for ( i = 0 ; i < wallet . getKeys ( ) . length ; i ++ )
35- {
36- funcs [ i ] = this . createBalanceFunction ( i ) ;
37- tx_fetch ( url + wallet . getKeys ( ) [ i ] . getBitcoinAddress ( ) . toString ( ) , funcs [ i ] ) ;
38- }
39- }
40- }
41-
42-
431// Global, hmmm.
44- var wallet = new Wallet ( ) ;
45- var txType = 'txBCI' ;
462var timeout ;
473
484$ ( document ) . ready ( function ( ) {
@@ -61,8 +17,8 @@ $(document).ready(function() {
6117 } ,
6218 function ( privKey ) {
6319 Electrum . gen ( 10 , function ( r ) {
64- wallet . getKeys ( ) . push ( new Bitcoin . ECKey ( r [ 1 ] ) ) ;
65- if ( wallet . getKeys ( ) . length == 10 )
20+ WALLET . getKeys ( ) . push ( new Bitcoin . ECKey ( r [ 1 ] ) ) ;
21+ if ( WALLET . getKeys ( ) . length == 10 )
6622 login_success ( ) ;
6723 } ) ;
6824 }
@@ -107,9 +63,8 @@ $(document).ready(function() {
10763 $ ( '#password' ) . val ( '' ) ;
10864 $ ( '#site' ) . hide ( ) ;
10965 $ ( '#create-keys' ) . collapse ( 'hide' ) ;
110- $ ( '#create-wallet ' ) . collapse ( 'hide' ) ;
66+ $ ( '#create-WALLET ' ) . collapse ( 'hide' ) ;
11167 $ ( '#logout-menu' ) . hide ( ) ;
112- wallet = new Wallet ( ) ;
11368 checkValidPassword ( ) ;
11469 $ ( '#logon' ) . show ( ) ;
11570 return false ;
@@ -142,15 +97,15 @@ $(document).ready(function() {
14297 $ ( '#site' ) . show ( ) ;
14398 $ ( '#logout-menu' ) . show ( ) ;
14499
145- wallet . updateAllBalances ( ) ;
100+ WALLET . updateAllBalances ( ) ;
146101 $ ( "#txDropAddr" ) . find ( "option" ) . remove ( ) ;
147102
148- for ( i = 0 ; i < wallet . getKeys ( ) . length ; i ++ )
103+ for ( i = 0 ; i < WALLET . getKeys ( ) . length ; i ++ )
149104 {
150- var addr = wallet . getKeys ( ) [ i ] . getBitcoinAddress ( ) . toString ( ) ;
105+ var addr = WALLET . getKeys ( ) [ i ] . getBitcoinAddress ( ) . toString ( ) ;
151106 $ ( '#address' + i ) . text ( addr ) ;
152107 $ ( "#txDropAddr" ) . append ( '<option value=' + i + '>' + addr + '</option>' ) ;
153- $ ( '#balance' + i ) . text ( Bitcoin . Util . formatValue ( wallet . getBalances ( ) [ i ] ) ) ;
108+ $ ( '#balance' + i ) . text ( Bitcoin . Util . formatValue ( WALLET . getBalances ( ) [ i ] ) ) ;
154109 var qrcode = makeQRCode ( addr ) ;
155110 $ ( '#qrcode' + i ) . popover ( { title : 'QRCode' , html : true , content : qrcode , placement : 'bottom' } ) ;
156111 }
@@ -187,7 +142,7 @@ $(document).ready(function() {
187142 }
188143 }
189144
190- // -- Wallet Creation --
145+ // -- WALLET Creation --
191146 function regeneratePassword ( ) {
192147 $ ( '#generated' ) . val ( '' ) ;
193148 return generatePassword ( ) ;
@@ -216,7 +171,7 @@ $(document).ready(function() {
216171
217172 function txOnChangeSource ( ) {
218173 var i = $ ( '#txDropAddr option:selected' ) . prop ( 'index' ) ;
219- $ ( '#txSec' ) . val ( wallet . getKeys ( ) [ i ] . getExportedPrivateKey ( ) ) ;
174+ $ ( '#txSec' ) . val ( WALLET . getKeys ( ) [ i ] . getExportedPrivateKey ( ) ) ;
220175 txDropGetUnspent ( ) ;
221176 }
222177
@@ -247,16 +202,10 @@ $(document).ready(function() {
247202 }
248203
249204 function txDropGetUnspent ( ) {
250- var addr = wallet . getKeys ( ) [ $ ( '#txDropAddr' ) . val ( ) ] . getBitcoinAddress ( ) . toString ( ) ;
205+ var addr = WALLET . getKeys ( ) [ $ ( '#txDropAddr' ) . val ( ) ] . getBitcoinAddress ( ) . toString ( ) ;
251206
252- var url = ( txType == 'txBCI' ) ? 'http://blockchain.info/unspent?address=' + addr :
253- 'http://blockexplorer.com/q/mytransactions/' + addr ;
254-
255- //url = prompt('Download transaction history:', url);
256- if ( url != null && url != "" ) {
257- $ ( '#txUnspent' ) . val ( '' ) ;
258- tx_fetch ( url , txParseUnspent ) ;
259- }
207+ $ ( '#txUnspent' ) . val ( '' ) ;
208+ BLOCKCHAIN . getUnspentOutputs ( addr , txParseUnspent ) ;
260209 }
261210
262211 function txOnChangeDest ( ) {
@@ -316,7 +265,7 @@ $(document).ready(function() {
316265 function txSent ( text ) {
317266 alertModal ( text ? text : 'No response!' ) ;
318267
319- wallet . updateAllBalances ( ) ;
268+ WALLET . updateAllBalances ( ) ;
320269 }
321270
322271 function txVerify ( ) {
@@ -355,12 +304,8 @@ $(document).ready(function() {
355304 r += 'Warning! Source address does not match private key.\n\n' ;
356305
357306 var tx = $ ( '#txHex' ) . val ( ) ;
358-
359- url = 'http://blockchain.info/pushtx' ;
360- postdata = 'tx=' + tx ;
361- if ( url != null && url != "" ) {
362- tx_fetch ( url , txSent , txSent , postdata ) ;
363- }
307+
308+ BLOCKCHAIN . sendTX ( tx , txSent ) ;
364309 return true ;
365310 }
366311
0 commit comments