from users.models import * # from institutional.models import * class user_info: def __init__(self, tx_hash,service,gas_fee,script_name): self.tx_hash = tx_hash self.service= service self.gas_fee= gas_fee self.script_name= script_name def update_info(self,request): obj= BlockchainUserInfo() # if CorporateUser.objects.filter(user= request.user).exists(): associated_corporate_users = CorporateUser.objects.get(user=request.user) obj.coprate_user = associated_corporate_users obj.user = request.user obj.user_name = request.user.username obj.tx_hash= self.tx_hash obj.service= self.service obj.gas_fee= self.gas_fee obj.script_name= self.script_name obj.uploaded_by = request.user.email obj.save() def update_corporate_user(self, user, **kwargs): if CorporateUser.objects.filter(user=user).exists(): corporate_user = CorporateUser.objects.get(user=user) for key, value in kwargs.items(): setattr(corporate_user, key, value) corporate_user.save() return True, "Corporate user updated successfully." else: return False, "Corporate user not found." class get_user_info: def __init__(self): pass def get_user_tx(self,request): users = BlockchainUserInfo.objects.filter(user=request.user).order_by("-date_at") total_gas = 0 for i in users: gas_fee = i.gas_fee total_gas=total_gas+gas_fee # Conversion factor wei_in_one_ether = 10**18 # Convert Wei to Ether amount_matic = total_gas / wei_in_one_ether return users,amount_matic def get_service_tx(self,request,services): users = BlockchainUserInfo.objects.filter(user=request.user,service=services) total_gas = 0 for i in users: gas_fee = i.gas_fee total_gas=total_gas+gas_fee # Conversion factor wei_in_one_ether = 10**18 # Convert Wei to Ether amount_matic = total_gas / wei_in_one_ether return amount_matic class CorporateUserInfo: @staticmethod def get_blockchain_info_for_corporate_user(corporate_user_uuid): try: corporate_user = CorporateUser.objects.get(corporate_user_uuid=corporate_user_uuid) blockchain_info = BlockchainUserInfo.objects.filter(coprate_user=corporate_user).values( 'upload_date', 'uploaded_by', 'script_name', 'gas_fee', 'service' ) return list(blockchain_info) except CorporateUser.DoesNotExist: return None