def _load_multi_sig_spend_txn_hashes(self, address: bytes, item_per_page: int, page_number: int, mode: int) -> list: if OptimizedAddressState.address_is_valid(address): address_state = self._chain_manager.get_optimized_address_state(address) elif MultiSigAddressState.address_is_valid(address): address_state = self._chain_manager.get_multi_sig_address_state(address) else: return [] start_item_index = max(0, address_state.multi_sig_spend_count() - item_per_page * page_number) end_item_index = min(address_state.multi_sig_spend_count(), start_item_index + item_per_page) if mode > 0: start_item_index = 0 end_item_index = address_state.multi_sig_spend_count() transaction_hashes = self._chain_manager.get_multi_sig_spend_txn_hashes(address, start_item_index) actual_start_item_index = (start_item_index // config.dev.data_per_page) * config.dev.data_per_page multi_sig_spend_txn_hashes = transaction_hashes[start_item_index - actual_start_item_index:] while actual_start_item_index < end_item_index and len(multi_sig_spend_txn_hashes) < item_per_page: actual_start_item_index += config.dev.data_per_page multi_sig_spend_txn_hashes.extend(self._chain_manager.get_multi_sig_spend_txn_hashes(address, actual_start_item_index)) return multi_sig_spend_txn_hashes[:item_per_page][-1::-1]
def get_multi_sig_address_state(self, address: bytes) -> MultiSigAddressState: if not MultiSigAddressState.address_is_valid(address): raise ValueError("Invalid Address") multi_sig_address_state = self._chain_manager.get_multi_sig_address_state(address) return multi_sig_address_state
def _validate_custom(self): for amount in self.amounts: if amount == 0: logger.warning('Amount cannot be 0 - %s', self.amounts) logger.warning('Invalid TransferTransaction') return False if self.fee < 0: logger.info('TransferTransaction [%s] Invalid Fee = %d', bin2hstr(self.txhash), self.fee) return False if len(self.addrs_to) == 0: logger.warning("[TransferTransaction] No Addrs To found") return False if len(self.addrs_to) != len(self.amounts): logger.warning('[TransferTransaction] Mismatch number of addresses to & amounts') logger.warning('>> Length of addresses_to %s', len(self.addrs_to)) logger.warning('>> Length of amounts %s', len(self.amounts)) return False if not OptimizedAddressState.address_is_valid(self.addr_from): logger.warning('[TransferTransaction] Invalid address addr_from: %s', bin2hstr(self.addr_from)) return False for addr_to in self.addrs_to: if not (OptimizedAddressState.address_is_valid(addr_to) or MultiSigAddressState.address_is_valid(addr_to)): logger.warning('[TransferTransaction] Invalid address addr_to: %s', bin2hstr(addr_to)) return False return True
def _validate_extended(self, state_container: StateContainer): if len(self.message_data) > 0: if state_container.block_number < state_container.current_dev_config.hard_fork_heights[0]: logger.warning("[TransferTransaction] Hard Fork Feature not yet activated") return False if len(self.addrs_to) > state_container.current_dev_config.transaction_multi_output_limit: logger.warning('[TransferTransaction] Number of addresses exceeds max limit') logger.warning('Number of addresses %s', len(self.addrs_to)) logger.warning('Number of amounts %s', len(self.amounts)) return False if len(self.message_data) > state_container.current_dev_config.message_max_length: logger.warning("[TransferTransaction] Message data is greater than message max length limit") logger.warning("Message data length %s", len(self.message_data)) logger.warning("Message data length limit %s", state_container.current_dev_config.message_max_length) return False tx_balance = state_container.addresses_state[self.addr_from].balance total_amount = self.total_amount for addr_to in self.addrs_to: if MultiSigAddressState.address_is_valid(addr_to): if addr_to not in state_container.addresses_state: logger.warning('[TransferTransaction] Multi Sig Address doesnt exist: %s', bin2hstr(addr_to)) return False if tx_balance < total_amount + self.fee: logger.info('State validation failed for %s because: Insufficient funds', bin2hstr(self.txhash)) logger.info('balance: %s, fee: %s, amount: %s', tx_balance, self.fee, total_amount) return False return True
def parse_qaddress(qaddress: str, check_multi_sig_address=False) -> bytes: """ Converts from a Qaddress to an Address. qaddress: 'Q' + hexstring representation of an XMSS tree's address check_multi_sig_address: Flag if multi sig address should be checked :param qaddress: :return: """ try: qaddress = parse_hexblob(qaddress[1:]) if not OptimizedAddressState.address_is_valid(qaddress): print("checking for multi_sig_address ", check_multi_sig_address) if check_multi_sig_address: print("checking for multi_sig_address") if not MultiSigAddressState.address_is_valid(qaddress): raise ValueError("Invalid Addresss ", qaddress) else: raise ValueError("Invalid Addresss ", qaddress) except Exception as e: raise ValueError("Failed To Decode Address", e) return qaddress