def __init__(self, *args, **kwargs): Frame.__init__(self, *args, **kwargs) self.configuration = Configuration() self.api = WalletAPI() self.wallet = None if self.configuration.is_configuration(): screen = HomePage(self) else: screen = NewWalletPage(self) container = Frame(self) container.pack(side="top", fill="both", expand=True) screen.place(in_=container, x=0, y=0, relwidth=1, relheight=1) screen.show()
def send_transaction(to, value, password, token): """Sends transaction.""" configuration = Configuration().load_configuration() api = get_api() try: if token is None: # send ETH transaction tx_hash, tx_cost_eth = api.send_transaction( configuration, password, to, value) else: # send erc20 transaction tx_hash, tx_cost_eth = api.send_transaction( configuration, password, to, value, token) click.echo('Hash of the transaction: %s' % str(tx_hash.hex())) click.echo('Transaction cost was: %sETH' % str(tx_cost_eth)) except InsufficientFundsException: click.echo('Insufficient ETH funds! Check balance on your address.') except InsufficientERC20FundsException: click.echo( 'Insufficient ERC20 token funds! Check balance on your address.') except InvalidAddress: click.echo('Invalid recipient(to) address!') except InvalidValueException: click.echo('Invalid value to send!') except InvalidPasswordException: click.echo('Incorrect password!') except InfuraErrorException: click.echo('Wallet is not connected to Ethereum network!') except ERC20NotExistsException: click.echo('This token is not added to the wallet!')
def prepare_conf(tmp_path): """ Prepare configuration file for tests :param tmp_path: pytest tmp_path fixture :return: configuration for tests """ test_config = dict( keystore_location=str(tmp_path), keystore_filename='/keystore', eth_address='', public_key='', network=3, ) test_config = Configuration(config_dir=str(tmp_path), initial_config=test_config) return test_config.load_configuration()
def network(): """Get connected network (Mainnet, Ropsten) defined in EIP155.""" configuration = Configuration().load_configuration() api = get_api() chain_id = api.get_network(configuration) if chain_id == 1: click.echo('You are connected to the Mainnet network!') if chain_id == 3: click.echo('You are connected to the Ropsten network!')
def list_tokens(): """List all added tokens.""" configuration = Configuration().load_configuration() api = get_api() tokens = api.list_tokens(configuration) click.echo('ETH') for token in tokens: click.echo('%s' % token)
def get_wallet(): """Get wallet account from encrypted keystore.""" configuration = Configuration().load_configuration() api = get_api() address, pub_key = api.get_wallet(configuration) click.echo('Account address: %s' % str(address)) click.echo('Account pub key: %s' % str(pub_key))
def reveal_seed(password): """Reveals private key from encrypted keystore.""" configuration = Configuration().load_configuration() api = get_api() try: wallet = api.get_private_key(configuration, password) click.echo('Account prv key: %s' % str(wallet.get_private_key().hex())) except InvalidPasswordException: click.echo('Incorrect password!')
def get_wallet(): """Get wallet account from encrypted keystore.""" configuration = Configuration().load_configuration() api = get_api() try: address, pub_key = api.get_wallet(configuration) click.echo('Account address: %s' % str(address)) click.echo('Account pub key: %s' % str(pub_key)) except ValueError: click.echo('Incorrect password!')
def add_token(contract, symbol): """Add new ERC20 contract.""" configuration = Configuration().load_configuration() api = get_api() # fitcoin_address = '0x19896cB57Bc5B4cb92dbC7D389DBa6290AF505Ce' try: api.add_contract(configuration, symbol, contract) click.echo('New coin was added! %s %s' % (symbol, contract)) except InvalidAddress: click.echo('Invalid address or wallet does not exist!') except InfuraErrorException: click.echo('Wallet is not connected to Ethereum network!')
def reveal_seed(): """Reveals private key from encrypted keystore.""" password = getpass.getpass('Password from keystore: ') # Prompt the user for a password of keystore file configuration = Configuration().load_configuration() api = get_api() try: wallet = api.get_private_key(configuration, password) click.echo('Account prv key: %s' % str(wallet.get_private_key().hex())) except InvalidPasswordException: click.echo('Incorrect password!')
def new_wallet(): """Creates new wallet and store encrypted keystore file.""" password = getpass.getpass('Passphrase from keystore: ') # Prompt the user for a password of keystore file configuration = Configuration().load_configuration() api = get_api() wallet = api.new_wallet(configuration, password) click.echo('Account address: %s' % str(wallet.get_address())) click.echo('Account pub key: %s' % str(wallet.get_public_key())) click.echo('Keystore path: %s' % configuration.keystore_location + configuration.keystore_filename) click.echo('Remember these words to restore eth-wallet: %s' % wallet.get_mnemonic())
def add_token(contract, symbol): """Add new ERC20 contract.""" configuration = Configuration().load_configuration() api = get_api() # TODO: test with bad contract and wallet address # fitcoin_address = '0x19896cB57Bc5B4cb92dbC7D389DBa6290AF505Ce' # binancecoin_address = '0x64BBF67A8251F7482330C33E65b08B835125e018' try: api.add_contract(configuration, symbol, contract) click.echo('New coin was added! %s %s' % (symbol, contract)) except InvalidAddress: click.echo('Invalid address or wallet does not exist!') except InfuraErrorException: click.echo('Wallet is not connected to Ethereum network!')
def get_balance(token): """Get address balance.""" configuration = Configuration().load_configuration() api = get_api() try: if token is None: eth_balance, address = api.get_balance(configuration) click.echo('Balance on address %s is: %sETH' % (address, eth_balance)) else: # TODO keyerror when token doesnt' exists token_balance, address = api.get_balance(configuration, token) click.echo('Balance on address %s is: %s%s' % (address, token_balance, token)) except InvalidAddress: click.echo('Invalid address or wallet does not exist!') except InfuraErrorException: click.echo('Wallet is not connected to Ethereum network!')
def __init__(self, *args, **kwargs): Page.__init__(self, *args, **kwargs) self.configuration = Configuration().load_configuration() self.api = WalletAPI() lbl_symbol = Label(self, text="Contract's symbol:", width=60, font=(None, 20)) lbl_symbol.pack() entry_symbol = Entry(self, font=(None, 20), width=60, justify=CENTER) entry_symbol.pack() lbl_address = Label(self, text="Contract's address:", width=60, font=(None, 20)) lbl_address.pack() entry_address = Entry(self, font=(None, 20), width=60, justify=CENTER) entry_address.pack() btn_back = Button(self, text="Add", font=(None, 16), width=60, command=lambda: self.add_token(entry_symbol.get(), entry_address.get())) btn_back.pack() btn_back = Button(self, text="Back", font=(None, 16), width=60, command=self.navigate_home_page) btn_back.pack()
def create_wallet(self, btn_create_wallet, password): """ Create new wallet :param btn_create_wallet: generate button which change text and functionality :param password: passphrase from the user :return: """ self.configuration = Configuration().load_configuration() self.wallet = self.api.new_wallet(self.configuration, password) lbl_remember_words = Label(self, text='Restore sentence:', width=60) lbl_remember_words.pack() lbl_mnemonic = Message(self, text=self.wallet.get_mnemonic(), justify=CENTER, borderwidth=10, background='light blue') lbl_mnemonic.pack() btn_create_wallet.configure(text="Continue", command=self.navigate_home_page)
def send_transaction(to, value, token): """Sends transaction.""" password = getpass.getpass( 'Password from keystore: ' ) # Prompt the user for a password of keystore file configuration = Configuration().load_configuration() api = get_api() # TODO: check if token symbol exists try: if token is None: # send ETH transaction tx_hash, tx_cost_eth = api.send_transaction( configuration, password, to, value) else: # send erc20 transaction tx_hash, tx_cost_eth = api.send_transaction( configuration, password, to, value, token) click.echo('Hash of the transaction: %s' % str(tx_hash.hex())) click.echo('Transaction cost was: %sETH' % str(tx_cost_eth)) except InsufficientFundsException: click.echo('Insufficient ETH funds! Check balance on your address.') except InsufficientERC20FundsException: click.echo( 'Insufficient ERC20 token funds! Check balance on your address.') except InvalidAddress: click.echo('Invalid recipient(to) address!') except InvalidValueException: click.echo('Invalid value to send!') except InvalidPasswordException: click.echo('Incorrect password!') except InfuraErrorException: click.echo('Wallet is not connected to Ethereum network!')
def __init__(self, *args, **kwargs): Page.__init__(self, *args, **kwargs) self.configuration = Configuration().load_configuration() self.api = WalletAPI() self.tokens = self.api.list_tokens(self.configuration) self.eth_balance, _ = self.api.get_balance(self.configuration) def change_token(token): if token == 'ETH': self.eth_balance, _ = self.api.get_balance(self.configuration) else: self.eth_balance, _ = self.api.get_balance(self.configuration, token) balance.set(str(self.eth_balance) + ' ' + token) token_symbol = StringVar() token_symbol.set('ETH') balance = StringVar() balance.set(str(self.eth_balance) + ' ' + token_symbol.get()) mb = Menubutton(self, width=60, textvariable=token_symbol, relief=RAISED) mb.grid() mb.menu = Menu(mb, tearoff=0) mb["menu"] = mb.menu mb.menu.add_radiobutton(label="ETH", variable=token_symbol, value='ETH', command=lambda: change_token(token_symbol.get())) for token in self.tokens: mb.menu.add_radiobutton(label=token, variable=token_symbol, value=token, command=lambda: change_token(token_symbol.get())) mb.pack() label = Label(self, textvariable=balance, width=60, font=(None, 30)) label.pack() lbl_address = Label(self, text="To address:", width=60, font=(None, 20)) lbl_address.pack() entry_address = Entry(self, font=(None, 20), width=60, justify=CENTER) entry_address.pack() lbl_amount = Label(self, text="Amount:", width=60, font=(None, 20)) lbl_amount.pack() entry_amount = Entry(self, font=(None, 20), width=60, justify=CENTER) entry_amount.pack() lbl_passphrase = Label(self, text="Passphrase:", width=60, font=(None, 20)) lbl_passphrase.pack() entry_passphrase = Entry(self, font=(None, 20), width=60, justify=CENTER) entry_passphrase.pack() btn_send = Button(self, text="Send", width=60, font=(None, 16), command=lambda: self.send_transaction(entry_address.get(), entry_amount.get(), entry_passphrase.get(), token_symbol.get())) btn_send.pack() btn_back = Button(self, text="Back", width=60, font=(None, 16), command=self.navigate_home_page) btn_back.pack()
def __init__(self, *args, **kwargs): Page.__init__(self, *args, **kwargs) self.configuration = Configuration().load_configuration() self.api = WalletAPI() self.tokens = self.api.list_tokens(self.configuration) self.eth_balance, self.address = self.api.get_balance(self.configuration) def refresh(): change_token(token_symbol.get()) def change_token(token): if token == 'ETH': self.eth_balance, self.address = self.api.get_balance(self.configuration) else: self.eth_balance, self.address = self.api.get_balance(self.configuration, token) balance.set(str(self.eth_balance) + ' ' + token) token_symbol = StringVar() token_symbol.set('ETH') balance = StringVar() balance.set(str(self.eth_balance) + ' ' + token_symbol.get()) mb = Menubutton(self, width=60, textvariable=token_symbol, relief=RAISED) mb.grid() mb.menu = Menu(mb, tearoff=0) mb["menu"] = mb.menu mb.menu.add_radiobutton(label="ETH", variable=token_symbol, value='ETH', command=lambda: change_token(token_symbol.get())) for token in self.tokens: mb.menu.add_radiobutton(label=token, variable=token_symbol, value=token, command=lambda: change_token(token_symbol.get())) mb.menu.add_radiobutton(label="Add new token ...", command=self.navigate_add_token_page) mb.pack() label_address_lbl = Label(self, text='Address:', width=60, font=(None, 10, "bold")) label_address_lbl.pack() label_address = Label(self, text=self.address, width=60, font=(None, 10)) label_address.pack() label_balance = Label(self, textvariable=balance, width=60, font=(None, 30)) label_balance.pack() btn_refresh = Button(self, text="Refresh", command=refresh, width=60, font=(None, 16)) btn_refresh.pack() btn_copy_address = Button(self, text="Copy address", command=self.copy_address, width=60, font=(None, 16)) btn_copy_address.pack() btn_send_transaction = Button(self, text="Send Transaction", command=self.navigate_transaction_page, width=60, font=(None, 16)) btn_send_transaction.pack()