Python ethereum.utils.checksum_encode() Examples

The following are 9 code examples of ethereum.utils.checksum_encode(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module ethereum.utils , or try the search function .
Example #1
Source File: ethereum_processor.py    From SempoBlockchain with GNU General Public License v3.0 6 votes vote down vote up
def __init__(self,
                     contract_address,
                     contract_abi_string,
                     ethereum_chain_id,
                     http_provider,
                     websocket_provider,
                     gas_price_gwei,
                     gas_limit,):

            self.abi_dict = json.loads(contract_abi_string)
            self.contract_address = utils.checksum_encode(contract_address)
            self.ethereum_chain_id = int(ethereum_chain_id)

            self.w3 = Web3(HTTPProvider(http_provider))
            # self.wsw3 = Web3(WebsocketProvider(websocket_provider))

            self.contract = self.w3.eth.contract(address=self.contract_address, abi=self.abi_dict)
            self.decimals = self.get_decimals()

            self.gas_price = self.w3.toWei(gas_price_gwei, 'gwei')
            self.gas_limit = gas_limit
            self.transaction_max_value = self.gas_price * self.gas_limit 
Example #2
Source File: create_multiple_safes.py    From safe-relay-service with MIT License 6 votes vote down vote up
def deploy_safes(number, owners, private_key):
    safes = []
    funding_public_key = checksum_encode(privtoaddr(private_key))
    funding_nonce = w3.eth.getTransactionCount(funding_public_key, 'pending')
    for _ in range(number):
        payload_json = generate_payload(owners)
        r = requests.post(SAFES_URL, json=payload_json)
        assert r.ok
        safe_created = r.json()
        safe_address = safe_created['safe']
        payment = int(safe_created['payment'])

        logging.info('Created safe=%s, need payment=%d', safe_address, payment)
        send_eth(private_key, safe_address, payment, funding_nonce)
        logging.info('Sent payment=%s to safe=%s', payment, safe_address)
        r = requests.put(get_safes_notify_url(safe_address))
        assert r.ok
        funding_nonce += 1
        safes.append(safe_address)

    with open('safes.txt', mode='a') as safes_file:
        safes_file.write('\n'.join(safes))


# notify_safes() 
Example #3
Source File: ethereum_processor.py    From SempoBlockchain with GNU General Public License v3.0 5 votes vote down vote up
def generate_approval_txn(self):

        sender_address = utils.checksum_encode(self.master_wallet_address)

        approve_amount = self.cents_to_native_amount(10 ** 8)

        transfer_approval_txn = self.contract.functions.approve(sender_address, approve_amount)

        return transfer_approval_txn 
Example #4
Source File: update_tokens.py    From safe-relay-service with MIT License 5 votes vote down vote up
def handle(self, *args, **options):
        pages = options['pages'] or 3
        download = options['download_icons'] or options['download_folder']
        download_folder = options['download_folder'] or os.path.join(settings.STATIC_ROOT, 'tokens')
        store_db = options['store_db']
        token_repository = TokenRepository()
        tokens = token_repository.get_tokens(pages=pages)
        self.stdout.write(self.style.SUCCESS(str(tokens)))
        if store_db:
            for i, token in enumerate(tokens):
                symbol = token['symbol']
                relevance = 0 if symbol == 'GNO' else i + 1
                token_db, created = Token.objects.get_or_create(
                    address=checksum_encode(token['address']),
                    defaults={
                        'name': token['name'],
                        'symbol': symbol,
                        'description': token['description'],
                        'decimals': token['decimals'],
                        'logo_uri': token['logo_url'] if token['logo_url'] else '',
                        'website_uri': token['website_url'],
                        'gas': False,
                        'relevance': relevance
                    }
                )
                if token_db.relevance != relevance:
                    token_db.relevance = relevance
                    token_db.save(update_fields=['relevance'])
                    self.stdout.write(self.style.SUCCESS('%s changed relevance to %d' % (token['name'], relevance)))

                if created:
                    self.stdout.write(self.style.SUCCESS('Inserted new token %s' % token['name']))

        if download:
            token_repository.download_images_for_tokens(folder=download_folder,
                                                        token_addresses=[token['address'] for token in tokens]) 
Example #5
Source File: wallet.py    From clove with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, private_key=None):
        self.private_key = private_key
        if private_key is None:
            self.private_key = SigningKey.generate(curve=SECP256k1).to_string().hex()
        self._raw_address = utils.privtoaddr(self.private_key)
        self.address = utils.checksum_encode(self._raw_address) 
Example #6
Source File: event_listener.py    From django-eth-events with MIT License 5 votes vote down vote up
def get_watched_contract_addresses(self, contract) -> Set[str]:
        addresses = None
        try:
            if contract.get('ADDRESSES'):
                addresses = contract['ADDRESSES']
            elif contract.get('ADDRESSES_GETTER_CLASS'):
                addresses = contract['ADDRESSES_GETTER_CLASS'].get_addresses()
        except Exception as e:
            raise LookupError("Could not retrieve watched addresses for contract {}".format(contract['NAME'])) from e

        normalized_addresses = {checksum_encode(address) for address in addresses}
        return normalized_addresses 
Example #7
Source File: simple_casper_tester.py    From research with MIT License 5 votes vote down vote up
def mk_validation_code(address):
    return serpent.compile(code_template % (utils.checksum_encode(address)))

# Install RLP decoder library 
Example #8
Source File: factories.py    From pm-trading-db with MIT License 5 votes vote down vote up
def generate_key_pair() -> Tuple[str, str]:
    private_key = utils.sha3(os.urandom(4096))
    public_key = utils.checksum_encode(utils.privtoaddr(private_key))
    return private_key, public_key 
Example #9
Source File: ethereum_processor.py    From SempoBlockchain with GNU General Public License v3.0 4 votes vote down vote up
def parse_blockchain_task(self, task):

        print('-----------------------------------------------------------------')
        print('{} parsing task:'.format(datetime.datetime.utcnow()))
        print(task)

        type = task.get('type')
        transfer_amount = task.get('transfer_amount')
        sender = task.get('sender')
        recipient = task.get('recipient')
        account_to_approve_encoded_pk = task.get('account_to_approve_pk')
        credit_transfer_id = task.get('credit_transfer_id')
        master_wallet_approval_status = task.get('master_wallet_approval_status')
        uncompleted_tasks = task.get('uncompleted_tasks')
        is_retry = task.get('is_retry')

        if sender:
            sender = utils.checksum_encode(sender)

        if recipient:
            recipient = utils.checksum_encode(recipient)

        if type == 'DISBURSEMENT':
            self.make_disbursement(transfer_amount=transfer_amount,
                                   recipient_address=recipient,
                                   account_to_approve_encoded_pk=account_to_approve_encoded_pk,
                                   master_wallet_approval_status=master_wallet_approval_status,
                                   uncompleted_tasks=uncompleted_tasks,
                                   is_retry=is_retry,
                                   credit_transfer_id=credit_transfer_id)

        elif type == 'WITHDRAWAL':

            self.make_withdrawal(transfer_amount=transfer_amount,
                                 sender_address=sender,
                                 recipient_address=recipient,
                                 account_to_approve_encoded_pk=account_to_approve_encoded_pk,
                                 master_wallet_approval_status=master_wallet_approval_status,
                                 uncompleted_tasks=uncompleted_tasks,
                                 is_retry=is_retry,
                                 credit_transfer_id=credit_transfer_id)


        else:

            self.make_payment(transfer_amount=transfer_amount,
                              sender_address=sender,
                              recipient_address=recipient,
                              account_to_approve_encoded_pk=account_to_approve_encoded_pk,
                              master_wallet_approval_status=master_wallet_approval_status,
                              uncompleted_tasks=uncompleted_tasks,
                              is_retry=is_retry,
                              credit_transfer_id=credit_transfer_id)