
    tfǜ                        d dl Z d dlZd dlZd dlZd dlZd dlZd dlmZ d dlmZ d dl	Z	 e	j
        dd           d dlmZ d dlmZ d dlmZ  ej                     d dlZ ej                     d d	lmZ d d
lmZ d dlmZ d dlZd dlZd dlZd dlmZmZ d dl m!Z!m"Z"m#Z#m$Z$ d dl%m&Z& d dl'm(Z( d dl)m*Z* d dl+m,Z, d dl+m-Z-m.Z.m/Z/ d dl0m1Z1 d dl2m3Z3m4Z4  ej5        dd          Z6 e7e6e j8        9                    e6                      G d dej:                  Z; G d de1          Z< G d de=          Z>d Z?d Z@eAdk    r e@             dS dS )     N)pprint)time_nsGtkz3.0)r   )Color)gtk3reactor)react)inlineCallbacks)reactor)naturaldeltanaturaltime)parse_activation_codehltypehlidhlval)CBORSerializer)sleep)ApplicationRunner)unpack_uint256)account_from_seedphrasegenerate_seedphraseaccount_from_ethkey)Client)
UserConfigProfileautobahnzasset/xbr_gray.svgc                       e Zd ZdZ ej                    ZdZdZdZ	dZ
d Zed             Zd Zd	 Zd
 Zd Zd Zd ZdS )ApplicationWindowa  
    Main application window which provides UI for the following functions:

    * N) New account
    * R) Recover account:
       - R1) Backup cloud device in account enabled => download encrypted account data
           from cloud backup device, requires email (and 2FA) verification and password
       - R2) At least one device left in account and at hand => synchronize with existing device,
           direct device-to-device encrypted account data transfer
       - R3) Only cold storage recovery seed phrase left => account from seed-phrase full
           recovery, including new email and 2FA verification.

    See also:
    * https://python-gtk-3-tutorial.readthedocs.io/en/latest/
    * https://twistedmatrix.com/documents/current/core/howto/choosing-reactor.html
    r            c                    t           j                            |            || _        || _        || _        || _        || _        || _        d | _	        d | _
        d | _        d | _        d | _        d | _        d | _        t!          j        d          | _        |                     d           |                     dd           |                     d           |                     d           |                                  |                                  |                                  |                                  |                                  d S )Ns                   byteszXBR NetworkiX  2   F)r   	Assistant__init__r
   sessionconfigconfig_pathprofileprofile_nameinput_seedphraseinput_emailinput_passwordoutput_accountoutput_ethadroutput_ethadr_rawoutput_member_datauuidUUIDoutput_member_data_oid	set_titleset_default_sizeset_border_widthset_resizable_setup_page1_setup_page2_setup_page3_setup_page4_setup_page5)selfr
   r'   r(   r)   r*   r+   s          P/var/www/surfInsights/venv3-11/lib/python3.11/site-packages/autobahn/xbr/_gui.pyr&   zApplicationWindow.__init__`   sE   t$$$&( $""!!%"&&*il&C&C&C# 	}%%%c3'''b!!!5!!! 	    c              #   $  K   | j         rt          | j         j                  | _        t          j                            | j        j                  | _        t          j
        | j        dd                    | _        | j                                        V }|rt          t          j        t          j        |d         d         d          d                    }| j                            |           | j                            t          |d         d                              | j                            t          |d         d                              | j                            t          |d         d         d	                              | j                            t          |d         d         d
                              | j                            dt          j        |d         d         d                                                   z              | j                            t          |d         d         d                              t7          |           | j                            | j                  V }|s~| j                            d| j                   | j         j        r|                      d           d S | j         j        r|                      d           d S |                      d           d S | j                            d| j        |           || _!        tE          t          j        tG                      d          | j!        d         z
  dz            }tI          t          j        | j!        d         d                    }| j%                            t          | j!        d                              | j&                            t          | j!        d                              | j'                            d(                    ||                     | j)                            t          | j!        d                              | j*                            t          | j!        d         d                              | j+                            t          | j!        d         d                              |                      d           d S tY                      }| j-        |_.        d |_        d |_/        d |_0        d |_1        d|_2        d	|_3        d |_4        d |_        d |_5        d |_6        d |_7        d |_8        d |_9        d |_:        d |_;        d |_<        || _         |                      d            d S )!Nr   statusnownsschainr(   	contracts
xbrnetworkxbrtoken0xblockhashnumber*ethadr {output_ethadr} is NOT yet a memberr0   r    r   =ok, ethadr {output_ethadr} already is a member: {member_data}r0   member_datacreatedg    eAoidaddressz{} ({} ago)levelbalanceethxbr   ws://localhost:8090/wsr   )=r*   r   ethkeyr/   web3Web3toChecksumAddressrV   r0   binasciia2b_hexr1   r'   
get_statusstrnp
datetime64_label5_now	set_label_label5_chain_label5_status_label5_xbrnetwork_label5_xbrtoken_label5_blockhashb2a_hexdecode_label5_blocknumberr   
get_memberloginfovaction_oidset_current_pager2   r   r   r   _label2_label4_label6format_label8_label10_label12r   r)   pathcskeyusernameemailnetwork_urlnetwork_realm
member_oidvaction_requestedvaction_verifieddata_url
data_realm
infura_urlinfura_network
infura_keyinfura_secret)r?   rs   rD   rS   created_agorT   r*   s          r@   startzApplicationWindow.start   s      < C	%"5dl6I"J"JD!%!<!<T=P=X!Y!YD%-%5d6H6L%M%MD"002222D ["-d8nU6KT(R(RTWXXYY **3///",,Sh1H-I-IJJJ#--c$x.2J.K.KLLL'11#d8n[6QR^6_2`2`aaa%//DN;4OPZ4[0\0\]]]&008HhX_I`agIh8i8i8p8p8r8r1rsss(223tH~g7Nx7X3Y3YZZZ4LLL $ 7 78N O OOOK )J,0,>  @ @ @<+ 	1))!,,,,,|* 1--a00000 --a00000],0,>K  Y Y Y*5'*BM'))T,J,JTMdenMo,os~+~%bmD4KI4VX[&\&\]]&&s4+B5+I'J'JKKK&&s4+B9+M'N'NOOO&&}';';G['Q'QRRR&&s4+B7+K'L'LMMM''D,CI,Nu,U(V(VWWW''D,CI,Nu,U(V(VWWW %%a(((((iiG+GL!GN GM#G GM":G$0G!!%G"&G(,G%'+G$#G!%G!%G%)G"!%G$(G!"DL !!!$$$$$rA   c                 `    |                      | j        |                                           d S N)set_page_completecomplete
get_active)r?   checkbuttons     r@   on_complete_toggledz%ApplicationWindow.on_complete_toggled   s,    t}k.D.D.F.FGGGGGrA   c                 	    t          j                    }|                    d           |                    d           |                    d           |                    d           |                    d           |                    d           t          j                    }|	                    t                     |                    |dddd           t          j        d          }|                    dd           |                    |dddd           t          j        d          }|                    dd           |                    t           j        j                   |                    |dddd           t           j                            d	          } fd
}|                    d|           |                    |dddd           t          j        d          }|                    dd           |                    |dddd           t          j        d          }|                    dd           |                    t           j        j                   |                    d           |                    d           |                    |dddd           t           j                            d          }	 fd}
|	                    d|
           |                    |	dddd           t          j        d          }|                    dd           |                    t           j        j                   |                    d           |                    d           |                    |dddd           t           j                            d          } fd}|                    d|           |                    |dddd           t          j        d          }|                    dd           |                    t           j        j                   |                    d           |                    d           |                    |dddd           t           j                            d          } fd}|                    d|           |                    |dddd                                |           dS )z
        Setup page shown when no config/profile could be found. Allows to select from:

        * new account
        * synchronize device
        * recover account
           r   r   r   z+

I am new and do not have an account yet:
label      ?zMCreate a new account or start from fresh. You only need an email address. [N]zNew accountc                 j    j                             d|                                d           d S )NzSELECTED_NEW: {res}resr   rr   rs   ru   r   r?   s    r@   
on_button1z2ApplicationWindow._setup_page1.<locals>.on_button1   s6    HMM/SM999!!!$$$$$rA   clickedz;

I already have an existing account and want to use that:
r    zRestore account from cloud backup to this device. You will need access to
your account password and access to your account email address. [R1]T   r[   zRestore accountc                 j    j                             d|                                d           d S )NzSELECTED_RESTORE: {res}r   r   r   r   s    r@   on_button22z3ApplicationWindow._setup_page1.<locals>.on_button22  6    HMM3M===!!!$$$$$rA   zSynchronize device with other device in account. You will need access to
another device currently connected to your account. [R2]   zSynchronize accountc                 j    j                             d|                                d           d S )NzSELECTED_SYNCRONIZE: {res}r   r   r   r   s    r@   
on_button2z2ApplicationWindow._setup_page1.<locals>.on_button2  s6    HMM6CM@@@!!!$$$$$rA   ztRecover account from account seed phrase. You only need access to
your 12-24 word account recovery seed phrase. [R3]   zRecover accountc                 j    j                             d|                                d           d S )NzSELECTED_RECOVER: {res}r   r    r   r   s    r@   
on_button3z2ApplicationWindow._setup_page1.<locals>.on_button3$  r   rA   N)r   Gridset_row_spacingset_column_spacingset_margin_topset_margin_bottomset_margin_startset_margin_endImageset_from_fileLOGO_RESOURCEattachLabelset_alignmentset_justifyJustificationLEFTButtonnew_with_labelconnectset_line_wrapset_width_charsappend_page)r?   grid1image1label0label1button1r   label12label22button22r   label2button2r   label3button3r   s   `                r@   r:   zApplicationWindow._setup_page1   s    

b!!!  $$$R   ###r"""R   ]+++VQ1a(((!QRRRQ$$$VQ1a(((!pqqqQ$$$3,1222VQ1a(((*++M::	% 	% 	% 	% 	% 		:...WaAq))))"bccca%%%WaAq)))) #i j j ja%%%C-2333d######WaAq))):,,->??	% 	% 	% 	% 	% 	K000Xq!Q*** "\ ] ] ]Q$$$3,1222T"""r"""VQ1a(((*++,ABB	% 	% 	% 	% 	% 		:...WaAq))) "V W W WQ$$$3,1222T"""r"""VQ1a(((*++,=>>	% 	% 	% 	% 	% 		:...WaAq)))rA   c                 D   
 t          j                    }t          j                    }t          j                    }|                    t
                     |                    |           |                    |           t           j                            d          } fd}|	                    d|           |                    |           t          j
        d          }|                    dd           |                    t           j        j                   |                    |           t          j                    }|                                                    d           |                    d	           |                    t           j        j                   |                    d
           |                    t           j        j                   |                    |           t          j                    }t          j        d                              d	                               d	           
fd}		                    d|	           |                               t           j                            d          

                    d	           t8           fd             fd
	                    d           |                    
           |                    |                                |           dS )zA
        Setup page shown to generate a new seed phrase.
        zGenerate seedphrasec                     t          dd          _                            j                                       d           d S )N   english)strengthlanguageT)r   r,   set_textset_sensitive)_checkbutton2_1r?   textbuffer2_1s    r@   on_button2_1z4ApplicationWindow._setup_page2.<locals>.on_button2_1<  sI    $7y$Y$Y$YD!""4#8999((.....rA   r   zQBackup your new seed phrase in a secure offline location (e.g. on printed paper):r   r   r   z




FTzI have backed up my seed phrasec                 2                         d           d S NT)r   )r   	button2_2s    r@   on_checkbutton2_1z9ApplicationWindow._setup_page2.<locals>.on_checkbutton2_1X  s    ##D)))))rA   toggledContinuec              3   J  K   t          j        d          _        t          j                            j        j                  _        t          j	        j        dd                    _
        t          j        j                  j        _        t          j        j                  j        _        j                            j                   j        j        j        j        <   j                            j                   j                            dj        j                   j                            j
                  V }t7          |           |s8j                            dj                                       d           d S j                            dj        |	           t;          j        |d
                   j        _        j        j        _         |d         j        _!        |d         j        _"        j        j        j        j        <   j                            j                   |_#        j$        %                    tM          j'        d                                                  d           d S )Nr   )indexr   zVXBR ETH key at address {ethadr} set from seed phrase (BIP39 account 0): "{seedphrase}")ethadr
seedphraserO   rP   rQ   rR   r   r"   r   r   rU   r[   )(r   r,   r/   r^   r_   r`   rV   r0   ra   rb   r1   r#   keyr*   r]   r'   
_cskey_rawr~   set_ethkey_from_profiler(   profilesr+   saver.   rr   rs   rq   r   ru   r3   r4   r   
member_adrr   r   r2   rv   rh   rd   _member_data)r   rS   r?   s     r@   on_button2_2z4ApplicationWindow._setup_page2.<locals>.on_button2_2a  sg     "9$:OWX"Y"Y"YD!%!<!<T=P=X!Y!YD%-%5d6H6L%M%MD" #((;(?"@"@DL!&t|'>!?!?DL L00>>> 7;lDK !23KT0111HMMr!%!3%)%:  < < < !% 7 78N O OOOK; )J,0,>  @ @ @%%a(((((],0,>K  Y Y Y +/)+l:S*T*T*T'*.*<'%0%9"(3J(?% ;?,$T%67  !4555*5'&&s4+<U+C'D'DEEE%%a(((((rA   c                     j                             dt                    |            t          j        d|            d S Nz{func}({widget}))funcwidgetr   rr   rs   r   r
   	callLater)r   r   run_on_button2_2r?   s    r@   r   z8ApplicationWindow._setup_page2.<locals>.run_on_button2_2  sC    HMM,6:J3K3KTZM[[[av66666rA   N)r   VBoxHBoxr   r   r   addr   r   r   r   r   r   r   r   TextView
get_bufferr   set_editableset_justificationCENTERset_monospaceset_wrap_modeWrapModeWORDCheckButton
set_activer   r	   r   )r?   box2_1box2_2image2_1	button2_1r   label2_1textview2_1box2_3r   r   r   r   r   r   s   `         @@@@@r@   r;   zApplicationWindow._setup_page2.  s	    9;;}---

8

6J--.CDD		/ 	/ 	/ 	/ 	/ 	/ 	/
 	)\222

99#vwwwq#&&&S.3444

8lnn#..00x(((  '''%%c&7&>???!!$'''!!#,"3444

;/PQQQ!!%((($$U+++	* 	* 	* 	* 	* 	y*;<<<

>"""J--j99	&&&	)	) )	) )	) )	) 
)	)V	7 	7 	7 	7 	7 	7 	7 	)%5666

9

6     rA   c                 
    t          j                    }t          j                    }t          j                    }|                    t
                     |                    |           |                    |           t          j                    }|                    d           |	                    d           |
                    d           |                    d           |                    d           |                    d           t          j        d          }|                    |dddd           t          j                                        d                               d                               d           |                    dddd           d	d	d	d
fdd d fd}                    d|           t          j        d          }|                    |dddd           t          j                                        d                               d                               d                               d           |                    dddd           t          j        d          }|                    |dddd           t          j                                        d                               d                               d                               d           |                    dddd           fd}                    d|                               d|           t          j        d          }	|                    |	dddd           t          j        d          }
|
                    d           |
                    d           fd}|
                    d|           |                    |
dddd           t          j        d          }	|                    |	dddd           t          j        d                              d                               d           fd}                    d|           |                    dddd           t           j                            d                              d           t6           fd              fd!                    d"           |                    dddd           |                    |                                |           d	S )#z

        :return:
        r   zYour email address:r   r   r       (   N)r   passwordeulac                      t          d           D ]2} |          (t          d|                                d            d S 3                    d           d S )N	check_allzcheck failedFT)printr   )cr   checkss    r@   r  z1ApplicationWindow._setup_page3.<locals>.check_all  sv    +  !9$.!,,,))%000FF % !!$'''''rA   c                     d| v r| S d S )N@ )r   s    r@   check_emailz3ApplicationWindow._setup_page3.<locals>.check_email  s    e||trA   c                     dS r   r  )r  s    r@   check_passwordz6ApplicationWindow._setup_page3.<locals>.check_password  s    4rA   c                      |                                            d<   d         r&                    t          j        j        d            n4                    t          j        j        t          ddd                                   d S )Nr   P  r   get_text	modify_fgr   
StateFlagsNORMALr   )entryr  r  r  entry1s    r@   	on_entry1z1ApplicationWindow._setup_page3.<locals>.on_entry1  s    )k%..*:*:;;F7Og L  !6====  !6eQ8J8JKKKIKKKKKrA   changedzNew password:FzRepeat new password:r   c                    d}                                            r(d}                    t          j        j        d            n4                    t          j        j        t          ddd                     d}                                            r(d}                    t          j        j        d            n4                    t          j        j        t          ddd                     |ra|r_                                                                  k    r5                                            r                                 d<   nd d<                 d S )NFTr  r   r  r  )r   pw1_okpw2_okr  r  r  entry2entry3s      r@   
on_entry23z2ApplicationWindow._setup_page3.<locals>.on_entry23  sV   F~foo//00 L  !6====  !6eQ8J8JKKKF~foo//00 L  !6====  !6eQ8J8JKKK *& *V__%6%6&//:K:K%K%KP^P^_e_n_n_p_pPqPq%K%+__%6%6z""%)z"IKKKKKrA   zEULA:r    z"I accept the EULA and terms of useTc                 Z    |                                  rdd<   ndd<                 d S )NTr  F)r   )buttonr  r  s    r@   r   z2ApplicationWindow._setup_page3.<locals>.on_button1  s:      "" '!%v!&vIKKKKKrA   r   zCloud backup:r[   z5Yes, enable encrypted cloud backup of my private keysc                                   d S r   r  )r*  r  s    r@   r   z2ApplicationWindow._setup_page3.<locals>.on_button2  s    IKKKKKrA   zRegister accountc              3     K   d         _         d         _                                        _        d_        d                    j        t          j        dd                    _        j        	                    j
                   j                            dj                    j                            d	j        
           j                            dj                   j                            j        j                   V }t          |           j         j
        _        j        j
        _        t#          t%          j        |d                             j
        _        t#          t+          j        |d         d                    j
        _        j
        j        j        j        <   j                            j                                       d           d S )Nr   r  	anonymousz{}{}r   i'  zinput_email: {input_email})r-   z input_username: {input_username})input_usernamez input_password: {input_password})r.   rt   r"   	timestamprE   r    )r-   r.   r   input_backup_enabledr.  ry   randomrandintr'   r   r*   rr   rs   _do_onboard_memberr   r   r   rd   r3   r4   rt   re   rf   r   r(   r   r+   r   ru   )r   resultr   r  r?   s     r@   r   z2ApplicationWindow._setup_page3.<locals>.on_button3(  s     %gD"("4D(/(:(:(<(<D%"-D"(--0CV^TUW\E]E]"^"^DL00>>>HMM6DDTMUUUHMM<TM`MaaaHMM<TM`Maaa<::4;NPTP`aaaaF6NNN!%!1DL$($7DL!'*496-;P+Q+Q+Q'R'RDL$-0vk?RTX1Y1Y-Z-ZDL*6:lDK !23KT0111!!!$$$$$rA   c                     j                             dt                    |            t          j        d|            d S r   r   )r   r   run_on_button3r?   s    r@   r6  z6ApplicationWindow._setup_page3.<locals>.run_on_button3B  B    HMM,6.3I3IRXMYYYaV44444rA   r   )r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   Entryr   set_max_lengthset_max_width_charsr   set_visibilityr   r   r   r   r   r	   r   )r?   box1box2r   r   r   r!  r   r(  r   r   r   r   r   r   r  r  r  r  r   r&  r'  r   r6  s   `            @@@@@@@@@@@r@   r<   zApplicationWindow._setup_page3  s   
 xzzxzz]+++

b!!!  $$$R   ###r"""R   !6777VQ1a(((c"""""2&&&VQ1a((( 
 
	( 	( 	( 	( 	( 	(	 	 		 	 		 	 	 	 	 	 	 	 	y),,,111VQ1a(((b!!!""2&&&e$$$VQ1a(((!7888VQ1a(((b!!!""2&&&e$$$VQ1a(((	 	 	 	 	 	 	 	 	, 	y*---y*---)))VQ1a(((/(LMMM5!!!d###	 	 	 	 	 	 		:...WaAq)))111VQ1a(((/(_```5!!!d###	 	 	 	 	 		:...WaAq)))*++,>??e$$$		% 	% 	% 	% 	% 	% 
	%2	5 	5 	5 	5 	5 	5 	5 		>222WaAq)))rA   c                 x   	
 t          j                    }t          j                    }t          j                    }|                    t
                     |                    |           |                    |           t          j                    }t          j        d          }t          j        d          }|                    |           |                    |           |                    |           t          j        d          }|                    |           t          j                    

	                    d           

                    d           
                    d           |                    
           	
fd}
                    d	|           t           j                            d
          		                    d           t           
 fd             fd	                    d           |                    	                                |           dS )a*  
        Page shown when member registration request was submitted, a verification email
        sent, and the verification request ID returned.
        The user now should check the email inbox for the received verification code,
        and continue verifying the code.

        :return:
        z4Member registration submitted, verification request:r   z$8d5d7ffd-23d9-45a0-a686-00a49f29d3cdzMPlease check your email inbox, and enter the verification code received here:r  r	  r
  c                 X   t          |                                           }|r<                    t          j        j        d                                d           d S                     t          j        j        t          ddd                                         d           d S )NTr  r   F)r   r  r  r   r  r  r   r   )r  vaction_coder   r   s     r@   r!  z1ApplicationWindow._setup_page4.<locals>.on_entry1o  s    01A1ABBL -  !6===%%d+++++  !6eQ8J8JKKK%%e,,,,,rA   r"  VerifyFc              3   V  K   t                                                    }|r'd                    |                                          }t	          j        j                  t          k    rt          j	        j        j                  }nj        j        }j
                            ||          V }t          |           t          t          j        |d         d                    j        _        dt          t!          j        |d                                                             z   j        _        t          t          j	        |d                             j        _        j        j        j        j        <   j                            j                   d S )N-rT   rE   rK   transactionr   r"   )r   r  joingroupstyper*   rt   rd   r3   r4   r'   _do_onboard_member_verifyr   re   rf   r   ra   rn   ro   vaction_transactionr   r(   r   r+   r   r.   )r   r@  rt   r4  r   r?   s       r@   r   z2ApplicationWindow._setup_page4.<locals>.on_button1~  sR     01B1BCCL ?"xx(;(;(=(=>>DL,--44"i(@AA"l6<AA+|\\\\F6NNN,/fY>OQU0V0V,W,WDL)/3c(:J6R_K`:a:a:h:h:j:j6k6k/kDL,&)$)&:N*O*O*O&P&PDL#6:lDK !23KT011111rA   c                     j                             dt                    |            t          j        d|            d S r   r   )r   r   run_on_button1r?   s    r@   rK  z6ApplicationWindow._setup_page4.<locals>.run_on_button1  r7  rA   r   N)r   r   r   r   r   r   r   r   r8  r   r9  r:  r   r   r   r   r	   r   )r?   r<  r=  r   box3r   r   r   r!  r   r   r   rK  s   `        @@@@r@   r=   zApplicationWindow._setup_page4N  s)    xzzxzz]+++xzz!WXXX!GHHH!pqqqc"""""2&&&	- 	- 	- 	- 	- 	- 	y),,,*++H55e$$$		2 	2 	2 	2 	2 
	2"	5 	5 	5 	5 	5 	5 	5 		>222rA   c                    t          j                    }t          j                    }t          j                    }|                    t
                     |                    |           |                    |           t          j                    }|                    d           |	                    d           |
                    d           |                    d           |                    d           |                    d           d}t          j        d          }|                    dd           |                    |d|dd           t          j                    | _        | j                            dd           | j                            d           |                    | j        d|dd           |dz  }t          j        d          }|                    dd           |                    |d|dd           t          j                    | _        | j                            dd           | j                            d	           |                    | j        d|dd           |dz  }t          j        d
          }|                    dd           |                    |d|dd           t          j                    | _        | j                            dd           | j                            d           |                    | j        d|dd           |dz  }t          j        d          }	|	                    dd           |                    |	d|dd           t          j                    | _        | j                            dd           | j                            d	           |                    | j        d|dd           |dz  }t          j        d          }
|
                    dd           |                    |
d|dd           t          j                    | _        | j                            dd           | j                            d	           |                    | j        d|dd           |dz  }t          j        d          }|                    dd           |                    |d|dd           t          j                    | _        | j                            dd           | j                            d	           |                    | j        d|dd           |dz  }t          j        d          }|                    dd           |                    |d|dd           t          j                    | _        | j                            dd           | j                            d	           |                    | j        d|dd           |dz  }|                    |           t          j                    }|                    d           |	                    d           |
                    d           |                    d           |                    d           |                    d           t          j        d          }|                    dd           |                    |dddd           t          j                    | _        | j                            dd           | j                            d	           |                    | j        dddd           t          j        d          }|                    dd           |                    |dddd           t          j                    | _        | j                            dd           | j                            d	           |                    | j        dddd           t          j        d          }|                    dd           |                    |dddd           t          j                    | _        | j                            dd           |                    | j        dddd           t          j        d          }|                    dd           |                    |dddd           t          j                    | _        | j                            dd           |                    | j        dddd           t          j        d          }|                    dd           |                    |dddd           t          j                    | _        | j                            dd           |                    | j        dddd           t          j        d          }|                    dd           |                    |dddd           t          j                    | _        | j                            dd           |                    | j        dddd           |                    |           |                     |           dS )zc
        Page shown for a user (private eth key) that already is member.

        :return:
        r   r   zCurrent server time:r   r   r   FzBlockchain ID:TzService status:zXBRNetwork contract:zXBRToken contract:zCurrent block hash:zCurrent block number:zUser ID:zEth Address:zAccount Created:r   zMembership:r    zETH Balance:r[   zXBR Balance:r   N) r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rg   set_selectableri   rj   rk   rl   rm   rp   rv   rw   rx   rz   r{   r|   r   )r?   r<  r=  r   grid2grid2_ylabel5_now_titlelabel5_chain_titlelabel5_status_titlelabel5_xbrnetwork_titlelabel5_xbrtoken_titlelabel5_blockhash_titlelabel5_blocknumber_titler   r   r   label5label7label9label11s                       r@   r>   zApplicationWindow._setup_page5  s	    xzzxzz]+++

b!!!  $$$R   ###r"""R    9+ABBB&&q#...%q'1a8889;;&&q#...''...T%q'1a8881 !Y-=>>>((C000'GQ::: Y[[((C000))$///T'GQ:::1 "i.?@@@))!S111(!Wa;;;!ikk))!S111**5111T(!Wa;;;1 #&)2H"I"I"I--a555,a!Q???"%)++--a555..t444T,a!Q???1 !$	0D E E E++As333*Aw1=== #	++As333,,T222T*Aw1===1 "%1F!G!G!G,,Q444+QA>>>!$,,Q444--d333T+QA>>>1 $'93J#K#K#K  ..q#666-q'1a@@@#&9;;  ..q#666 //555T-q'1a@@@1

b!!!  $$$R   ###r"""R   ,,,Q$$$VQ1a(((y{{""1c***##D)))T\1aA...000Q$$$VQ1a(((y{{""1c***##D)))T\1aA...!3444Q$$$VQ1a(((y{{""1c***T\1aA...///Q$$$VQ1a(((y{{""1c***T\1aA...000Q$$$VQ1a(((	##As+++T]Aq!Q///).111a%%%WaAq)))	##As+++T]Aq!Q///rA   N)__name__
__module____qualname____doc__txaiomake_loggerrr   SELECTED_NONESELECTED_NEWSELECTED_SYNCRONIZESELECTED_RECOVERr&   r	   r   r   r:   r;   r<   r=   r>   r  rA   r@   r   r   H   s           %


CML  B E% E% _E%NH H H^  ^  ^ Bh! h! h!Vr r rjI I IXc c c c crA   r   c                   @    e Zd Zd Zed             Zed             ZdS )ApplicationClientc           	      H  K   | j                             dt          |j                  t          |j                  t          |j                  t          |j                  |           d| j        j        v r)t          j
        | j        j        d         | |f           d S d S )NzbOk, client joined on realm "{realm}" [session={session}, authid="{authid}", authrole="{authrole}"])realmr'   authidauthroledetailsready)rr   rs   r   ri  r'   rj  rk  r(   extrar`  resolve)r?   rl  s     r@   onJoinzApplicationClient.onJoinA  s      z //"7?33!'.11#G$455% 	 	' 	' 	' dk'''M$++G4tWoFFFFF ('rA   c              #      K   |                                  r3|                     d          V }|                     d          V }||dS | j                            d           d S )Nzxbr.network.get_configzxbr.network.get_status)r(   rC   z(not connected: could not retrieve status)is_attachedcallrr   warn)r?   r(   rC   s      r@   rc   zApplicationClient.get_statusK  st       	F99%=>>>>F99%=>>>>F$777HMMDEEEEErA   c           	   #     K   |                                  r|                     d|          V }|r|                     d|          V }t          j                            |d                   |d<   t          j        |d                   |d<   t          j                            t          |d         d                   d          |d         d<   t          j                            t          |d         d	                   d          |d         d	<   t          j
        |d
         d          |d
<   |d         }dddddd                    |d           |d<   | j                            dt          |d                   t          |d                   t          |d                              |S | j                            d|           d S | j                            d|           d S )Nzxbr.network.is_memberz xbr.network.get_member_by_walletrV   rU   r"   rX   rY   etherrZ   rT   rE   rW   ACTIVEVERIFIEDRETIREDPENALTYBLOCKED)r   r   r    r[   r   zZMember {member_oid} found for address 0x{member_adr} - current member level {member_level})member_levelr   r   z:Address {output_ethadr} is not a member in the XBR networkrP   zInot connected: could not retrieve member data for address {output_ethadr})rr  rs  r^   r_   r`   r3   r4   fromWeir   re   rf   getrr   rs   r   r   rt  )r?   
ethadr_raw	is_memberrS   r|  s        r@   rq   zApplicationClient.get_memberT  s      '	4"ii(?LLLLI "8$(II.PR\$]$]]])-)D)D[QZE[)\)\I&%)Y[5G%H%H%HE"04	0A0A.Q\]fQghmQnBoBoBI1K 1KI&u-04	0A0A.Q\]fQghmQnBoBoBI1K 1KI&u-)+{97Mt)T)TI&*73  !   ( ( #lD)) G$ p!&{7';!<!<#K$677$[%;<<	  > > > #"Z,6  8 8 8 8 8 HMMe(2  4 4 4 4 4rA   N)r\  r]  r^  rp  r	   rc   rq   r  rA   r@   rg  rg  @  s_        G G G F F _F (4 (4 _(4 (4 (4rA   rg  c                       e Zd ZdZ ej                    Zej        	                    ej        
                    d                    ZdZddZdS )Applicationz&
    Main XBR member application.
    z~/.xbrnetworkz
config.iniNc           	         K   t          j        d            j                            d|           t          j                             j                  s:t	          j         j                    j                            d j                   t          j        	                     j         j
                  x _        }|pd _        t          j                             j                  sC j                            d j        	           t           j                   _        d
 _        nt           j                   _        d } j                            |            j         j        j        vrEt'          j        d                     j        |t-           j        j                                       j        j         j                  _         j                            d j         j                   t/           j                                                   t3          d           t          j                    t          j                    d j         j         j         j        d|p  j        r j        j        r j        j        nd}|p  j        r j        j        r j        j        nd}t;          ||t=                      g          }	 j                            d||           |	                    t@          |dd           d
{V   j                            d           d          d
{V \  }
} j                            d|            fd}tC          ||
 j         j         j         j                  }|"                    d|           |"                    d |           |#                                 |$                                 d
{V  d!}d"         r>|d#z  } j                            d$|%           tK          d&           d
{V  d"         > j                            d'           d
S )(a  
        Start main application. This will read the user configuration, potentially asking
        for a user password.

        :param reactor: Twisted reactor to use.
        :param url: Optionally override network URL as defined in profile.
        :param realm: Optionally override network URL as defined in profile.
        :param profile: User profile name to load.
        :return:
        rs   )rW   z5ok, application starting for user profile "{profile}")r*   zdotdir created: "{dotdir}")dotdirdefaultz%no config exist under "{config_path}")r)   Nc                      dS )N	123secretr  r  rA   r@   getpwz Application.start.<locals>.getpw  s    "{rA   )cb_get_passwordz4no such profile "{}" in config "{}" with {} profilesz<user profile "{profile_name}" loaded from "{config_path}":

)r)   r+   z

T)rm  donerunningr(   r)   r*   r+   r\   rI   )urlri  rn  serializerszIok, now connecting to "{network_url}", joining realm "{network_realm}" ..)r   r   F)r
   auto_reconnectstart_reactorz!ok, application client connected!rm  z)ok, application session joined: {details})rl  c                 |    j                             d           dd<   t          j        d         d            d S )Nzexiting application ..Fr  r  )rr   rs   r`  ro  )r   rn  r?   s    r@   on_exitz"Application.start.<locals>.on_exit  s>    HMM2333$E)M%-.....rA   canceldestroyr   r  r   z7ok, application main task still running at tick {ticks})ticksr   z ok, application main task ended!)&r`  start_loggingrr   rs   osr}   isdirDOTDIRmkdirrE  DOTFILE_config_path_profile_nameisfiler   _config_profileloadr   clickClickExceptionry   lenr   marshalr  create_futurer   r   r   r   runrg  r   r   show_allr   r   )r?   r
   r  ri  r*   r)   r  r   r   runnerr'   rl  r  winr  rn  s   `              @r@   r   zApplication.start  s      	&))))MW^___w}}T[)) 	LHT[!!!HMM6t{MKKK*,',,t{DL*Q*QQK$1	w~~d/00 	HMMAtO`Maaa%d&788DL DMM%d&788DL# # # Le444!)>>>*+a+h+himi{  ~I  KN  OS  O[  Od  Ke  Ke  ,f  ,f  g  g  g $ 5d6H I^*.*;$J\  ^ ^ ^t},,..///f (**'))l,} .
 
   F4=  ET]Mf  Edm77  mE   B  #ASWS`Sn  #A$-"="=  uA"{)6).0>0@0@/AC C C
 	a"-$1 	 	3 	3 	3 jj*!((,',  . . 	. 	. 	. 	. 	. 	. 	. 	9:::!&w//////A7SSS	/ 	/ 	/ 	/ 	/ 	/
  $,@QSWS`bfbtuuHg&&&Iw'''iikkI 	QJEHMMS[`Maaa((NNNNNNN I 	
 	899999rA   )NNN)r\  r]  r^  r_  r`  ra  rr   r  r}   abspath
expanduserr  r  r   r  rA   r@   r  r    sr          %


CW__RW//@@AAFG\: \: \: \: \: \:rA   r  c                 d   K   t                      }|                    | |||           d{V  dS )aG  
    Load the named user profile (or create a new one), overriding URL/realm,
    connect to a network node, and start the network member on-boarding.

    If the user credentials are already for a member, fetch member information
    and display member page.

    :param reactor: Twisted reactor to use.
    :param url: Override network URL from user profile with this value.
    :param realm: Override network realm from user profile with this value.
    :param profile: Name of user profile within user
        configuration to load (eg from ``$HOME/.xbrnetwork/config.ini``)
    )r  ri  r*   N)r  r   )r
   r  ri  r*   apps        r@   mainr    sC       --C
))GE7)
C
CCCCCCCCCCrA   c                  \   t          j                    } |                     ddt          dd           |                     ddt          dd           |                     d	d
t          dd           |                                 }t          t          |j        |j        |j	        f           dS )a  
    GUI entry point, parsing command line arguments and then starting the
    actual main GUI program with parsed parameters.

    To use, run:

    .. code:: console

        xbrnetwork-ui --profile default --url ws://localhost:8090/ws --realm xbrnetwork

    This will load the user profile ``"default"`` from the user configuration, but
    overriding any network URL and realm found therin.
    z--urlr  Nz;The router URL to connect to, e.g. "ws://localhost:8090/ws")destrG  r  helpz--realmri  z$The realm to join, e.g. "xbrnetwork"z	--profiler*   r  z'The user profile to use, e.g. "default")
argparseArgumentParseradd_argumentrd   
parse_argsr   r  r  ri  r*   )parserargss     r@   _mainr    s     $&&F
"  $Z	  \ \ \ 	$  $C	  E E E &  )F	  H H H D	$4:t|566666rA   __main__)Br  r  r3   ra   r1  pkg_resourcesr   timer   girequire_versiongi.repositoryr   gi.repository.Gdkr   twisted.internetr   installr`  use_twistedtwisted.internet.taskr   twisted.internet.deferr	   r
   r^   numpyre   r  humanizer   r   autobahn.utilr   r   r   r   autobahn.wamp.serializerr   autobahn.twisted.utilr   autobahn.twisted.wampr   autobahn.xbrr   r   r   r   autobahn.xbr._clir   autobahn.xbr._configr   r   resource_filenamer   r  r}   r  r%   r   rg  objectr  r  r  r\  r  rA   r@   <module>r     s  6 
			                     				  5%             # # # # # # ( ( ( ( ( (            ' ' ' ' ' ' 2 2 2 2 2 2 $ $ $ $ $ $       . . . . . . . . D D D D D D D D D D D D 3 3 3 3 3 3 ' ' ' ' ' ' 3 3 3 3 3 3 ' ' ' ' ' ' Z Z Z Z Z Z Z Z Z Z $ $ $ $ $ $ 4 4 4 4 4 4 4 4//
<PQQ mRW^^M22 3 3 3u u u u u u u up=4 =4 =4 =4 =4 =4 =4 =4@e: e: e: e: e:& e: e: e:PD D D$$7 $7 $7N z	EGGGGG rA   