Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_valid_address_testnet(self, address, expected, description):
helpers.configurationhelpers.get_use_testnet = mock.MagicMock(return_value=True)
print(description)
assert validators.valid_address(address) == expected, description
def get_lal(address, xpub, block_height=0):
if not valid_address(address):
return {'error': 'Invalid address: %s' % address}
if not valid_xpub(xpub):
return {'error': 'Invalid xpub: %s' % xpub}
sil_data = get_sil(address, block_height)
if 'SIL' in sil_data:
sil = sil_data['SIL']
linked_addresses = get_addresses_from_xpub(xpub, len(sil))
lal = []
for i in range(0, len(sil)):
lal.append([sil[i][0], linked_addresses[i]])
return {'LAL': lal}
def random_address_from_sul(address, rng_block_height=0):
if not valid_address(address):
return {'error': 'Invalid address: %s' % address}
return RandomAddress(address=address).get(source='SUL', rng_block_height=rng_block_height)
def get_profile(address, block_height=0):
"""
Get the profile of an address
:param address: The address
:param block_height: A block height (optional)
:return: A dict containing the profile and the explorer that provided the data
"""
if not valid_address(address):
return {'error': 'Invalid address: ' + address}
txs_data = data.transactions(address)
if 'transactions' in txs_data:
return {'profile': txs_to_profile(txs_data['transactions'], address, block_height)}
else:
return {'error': 'Unable to retrieve transactions of address %s' % address}
def configure(self, **config):
super(ReceivedTrigger, self).configure(**config)
if 'address' in config and valid_address(config['address']):
self.address = config['address']
if 'amount' in config and valid_amount(config['amount']):
self.amount = config['amount']
raise Exception('Unable to get distribution: invalid registration_address: %s' % self.registration_address)
if not valid_xpub(self.registration_xpub):
LOG.error('Unable to get distribution: invalid registration_xpub: %s' % self.registration_xpub)
raise Exception('Unable to get distribution: invalid registration_xpub: %s' % self.registration_xpub)
if not valid_block_height(self.registration_block_height):
LOG.error('Unable to get distribution: invalid registration_block_height: %s' % self.registration_block_height)
raise Exception('Unable to get distribution: invalid registration_block_height: %s' % self.registration_block_height)
data = get_lbl(address=self.registration_address, xpub=self.registration_xpub, block_height=self.registration_block_height)
if 'LBL' not in data:
LOG.error('Unable to get distribution: invalid LBL data: %s' % data)
raise Exception('Unable to get distribution: invalid LBL: %s' % data)
distribution = {recipient[0]: recipient[1] for recipient in data['LBL']}
elif transaction_type == 'Send2LRL':
if not valid_address(self.registration_address):
LOG.error('Unable to get distribution: invalid registration_address: %s' % self.registration_address)
raise Exception('Unable to get distribution: invalid registration_address: %s' % self.registration_address)
if not valid_xpub(self.registration_xpub):
LOG.error('Unable to get distribution: invalid registration_xpub: %s' % self.registration_xpub)
raise Exception('Unable to get distribution: invalid registration_xpub: %s' % self.registration_xpub)
if not valid_block_height(self.registration_block_height):
LOG.error('Unable to get distribution: invalid registration_block_height: %s' % self.registration_block_height)
raise Exception('Unable to get distribution: invalid registration_block_height: %s' % self.registration_block_height)
data = get_lrl(address=self.registration_address, xpub=self.registration_xpub, block_height=self.registration_block_height)
if 'LRL' not in data:
LOG.error('Unable to get distribution: invalid LRL data: %s' % data)
raise Exception('Unable to get distribution: invalid LRL: %s' % data)
distribution = {recipient[0]: recipient[1] for recipient in data['LRL']}
elif transaction_type == 'Send2LSL':
def random_address_from_lbl(address, xpub, sil_block_height=0, rng_block_height=0):
if not valid_address(address):
return {'error': 'Invalid address: %s' % address}
if not valid_xpub(xpub):
return {'error': 'Invalid xpub: %s' % xpub}
return RandomAddress(address=address,
xpub=xpub,
sil_block_height=sil_block_height).get(source='LBL',
rng_block_height=rng_block_height)
if 'fee_percentage' in config and valid_percentage(config['fee_percentage']):
self.fee_percentage = config['fee_percentage']
if 'wallet_type' in config and config['wallet_type'] in ['Single', 'BIP44']:
self.wallet_type = config['wallet_type']
if 'sending_address' in config and valid_address(config['sending_address']):
self.sending_address = config['sending_address']
if 'bip44_account' in config:
self.bip44_account = config['bip44_account']
if 'bip44_index' in config:
self.bip44_index = config['bip44_index']
if 'receiving_address' in config and valid_address(config['receiving_address']):
self.receiving_address = config['receiving_address']
if 'receiving_xpub' in config and valid_xpub(config['receiving_xpub']):
self.receiving_xpub = config['receiving_xpub']
if 'amount' in config and valid_amount(config['amount']):
self.amount = config['amount']
if 'minimum_amount' in config and valid_amount(config['minimum_amount']):
self.minimum_amount = config['minimum_amount']
if 'op_return_data' in config and valid_op_return(config['op_return_data']):
self.op_return_data = config['op_return_data']
if 'change_address' in config and valid_address(config['change_address']):
self.receiving_address = config['change_address']
def get_sul(address, confirmations=1):
if not valid_address(address):
return {'error': 'Invalid address: ' + address}
utxos_data = data.utxos(address=address, confirmations=confirmations)
if 'utxos' in utxos_data:
sul = utxos_to_sul(utxos_data['utxos'])
return {'SUL': sul} if 'error' not in sul else {'error': sul['error']}
else:
return {'error': 'Unable to retrieve utxos of address %s' % address}