def save(self): super(Cryptocurrency, self).save() users = User.objects.all() for user in users: wallet = UserWallet(user=user, account_balance=0, cryptocurrency=self) wallet.save()
def deposit(self, wallet, wallet_address, amount): """ @param UserWallet : wallet @param String : wallet_address @param String : amount """ amount=Decimal(str(amount)) wallet.deposit(wallet_address=wallet_address,amount=amount) wallet.save() return 0
def withdraw(self, wallet, wallet_address, amount): """ @param UserWallet : wallet @param String : wallet_address @param String : amount pobiera kwotę amount z konta i wysyłą ją na adres wallet_address """ amount=Decimal(str(amount)) wallet.withdrawRequest(wallet_address=wallet_address,amount=amount) wallet.save() return 0
def confirm(user, code, wallet_address, amount): hashs = hashlib.md5() hashs.update(code) code = hashs.hexdigest() if WithdrawCodes.objects.filter(code=code).exists(): code = WithdrawCodes.objects.filter(code=code)[0] if(code.wallet.user.id is not user.id): raise Exception("Użytkownik %s nie jest zalogowany." % (code.user)) wallet = UserWallet.objects.get(id = code.wallet.id) if(wallet.account_balance-Decimal(amount) < 0): raise Exception("Brakuje środków na portfelu %s. Na portfelu posiadasz jedynie %s, a chcesz wypłacić %s" % (wallet.cryptocurrency, wallet.account_balance, amount)) wallet.account_balance = wallet.account_balance-Decimal(amount) wallet.save() code.delete() now = datetime.datetime.utcnow().replace(tzinfo=utc) deposit_history = DepositHistory(user=wallet.user, wallet_address=wallet_address, cryptocurrency=wallet.cryptocurrency, amount=amount, executed_time=now, deposit=False) deposit_history.save() return True else: return False return 0
def create_keys(n=100): keys = {} try: with open('keys.pkl', 'rb') as f: keys = pickle.load(f) except Exception as e: print(e) for i in range(n): key_pair = eosapi.create_key() # print(key_pair) keys[key_pair.public] = key_pair.private with open('keys.pkl', 'wb') as f: pickle.dump(keys, f) exist_keys = wallet.list_keys() for pub in keys: if pub in exist_keys: continue priv_key = keys[pub] print(priv_key) wallet.import_key('mywallet', priv_key, False) wallet.save('mywallet')
def save(self): super(UserProxy, self).save() cryptocurrency = Cryptocurrency.objects.all() for c in cryptocurrency: wallet = UserWallet(user=self,account_balance=0,cryptocurrency=c) wallet.save()
def save(self): super(Cryptocurrency, self).save() users = User.objects.all() for user in users: wallet = UserWallet(user=user,account_balance=0,cryptocurrency=self) wallet.save()
def save(self): super(UserProxy, self).save() cryptocurrency = Cryptocurrency.objects.all() for c in cryptocurrency: wallet = UserWallet(user=self, account_balance=0, cryptocurrency=c) wallet.save()
def import_keys(): keys = wallet.list_keys('mywallet', initeos.psw) for a in accounts: if not a['pub'] in keys: wallet.import_key('mywallet', a['pvt'], False) wallet.save('mywallet')