def setup_platform(hass, config, add_devices, discovery_info=None): """ Get the Bitcoin sensor. """ from blockchain.wallet import Wallet from blockchain import exchangerates, exceptions wallet_id = config.get('wallet', None) password = config.get('password', None) currency = config.get('currency', 'USD') if currency not in exchangerates.get_ticker(): _LOGGER.error('Currency "%s" is not available. Using "USD".', currency) currency = 'USD' wallet = Wallet(wallet_id, password) try: wallet.get_balance() except exceptions.APIException as error: _LOGGER.error(error) wallet = None data = BitcoinData() dev = [] if wallet is not None and password is not None: dev.append(BitcoinSensor(data, 'wallet', currency, wallet)) for variable in config['display_options']: if variable not in OPTION_TYPES: _LOGGER.error('Option type: "%s" does not exist', variable) else: dev.append(BitcoinSensor(data, variable, currency)) add_devices(dev)
def getQRaddress(id, key): wallet = Wallet(id, key) add = wallet.list_addresses() newadd = add[0].address qr_api = 'https://blockchain.info/qr?data={}&size=200' qr_code = qr_api.format(newadd) return qr_code
def pay(id, key): wallet = Wallet(id, key) add = wallet.list_addresses() newadd = add[0].address qr_api = 'https://blockchain.info/qr?data={}&size=300' qr_code = qr_api.format(newadd) webbrowser.open_new(qr_code)
def btc_release_from_escrow(escrow_id): escrow = Escrow.get(escrow_id) if not escrow: raise AssertionError("Escrow invalid.") bid = Bid.get(escrow.bid_id) if not bid or bid.is_win is None: raise AssertionError("Bid invalid.") ''' if the bid is a winning one, we send (odds * value * (1 - commision)) to the bidder if the bid is a losing one, we send (value * (1 - commission)) to the seller ''' escrow_wallet = Wallet(BaseConfig.BLOCKCHAIN_ESCROW_GUID, BaseConfig.BLOCKCHAIN_ESCROW_PASSWORD, BaseConfig.BLOCKCHAIN_SERVICE_URL) if not bid.is_win: to_send = btc_to_satoshi(bid.value * (1 - BaseConfig.COMISSION_RATE)) destination = Wallet.get_user_wallet(bid.offer.user_id) else: to_send = btc_to_satoshi(bid.value * bid.offer.odds * (1 - BaseConfig.COMISSION_RATE)) destination = bid.wallet_id payment = escrow_wallet.send(destination, to_send) if not payment or not payment.tx_hash: raise AssertionError("Payment failed.") else: escrow.active = False escrow.payout_date = datetime.datetime.now() db.session.commit()
def __init__(self, phone): self.phone = phone # self.password = create_password() temp = blockchain.createwallet.create_wallet( 'Boondock2013', 'c62026c6-89e3-4200-93a9-f51250ad1ea5') self.wallet = Wallet(temp.identifier, 'Boondock2013') self.address = self.wallet.new_address(('team_moorhead_' + phone))
def __init__(self, customer): self.customer = customer #models.Customers.objects.get(id=1) #customer if self.customer.btc_wallet() is None: self.wallet_generation() self.password = self.customer.btc_wallet().password self.wallet_id = self.customer.btc_wallet().id self.wallet = Wallet(self.wallet_id, self.password, NODE_WALLET_SERVICES)
def btc_create_wallet(user_id, password): new_wallet = createwallet.create_wallet(password, BaseConfig.BLOCKCHAIN_KEY, BaseConfig.BLOCKCHAIN_SERVICE_URL, 'betya') wallet_db_obj = Wallet(user_id, new_wallet.address, new_wallet.identifier) db.session.add(wallet_db_obj) db.session.commit() return wallet_db_obj
def getBTC(id, key): wallet = Wallet(id, key) sbtc = 100000000 bal = float(wallet.get_balance()) if bal == 0 or bal == '': btc = "balance is zero" else: btc = bal/sbtc return btc
def betting_withdraw(request): if request.method == "POST": jsonRtn = {"success": True} try: bitcoin_address_session = BitcoinAddressSession.objects.get(pk=request.session["bas"]) withdraw_address = request.POST.get('ig-address-text', None) withdraw_amount = request.POST.get('ig-amount-text', None) withdraw_lock = None if not withdraw_address or not withdraw_amount: raise ValueError("Please enter address and amount") if bitcoin_address_session.amount == 0: raise ValueError("Could not withdraw. Your current balance is 0 BTC.") withdraw_amount = float(withdraw_amount) * settings.SATOSHI_RATIO if withdraw_amount > bitcoin_address_session.amount: raise ValueError("You cannot withdraw more than your current balance.") if withdraw_amount < (0.0001 * settings.SATOSHI_RATIO): raise ValueError("Minimum withdrawal amount is 0.0001 BTC.") withdraw_lock = "{}{}".format(settings.REDIS_WITHDRAW_LOCK_PREFIX, bitcoin_address_session.id) while settings.REDIS_CLIENT.get(withdraw_lock): settings.REDIS_CLIENT.incrby(settings.REDIS_WITHDRAW_LOCK_COUNT, 1) settings.REDIS_CLIENT.set(withdraw_lock, 1) wallet = Wallet(settings.BITCOIN_PRIVATE_ADDRESS, None) wallet_withdraw = wallet.send(withdraw_address, withdraw_amount) withdraw_request = BitcoinWithdrawRequest() withdraw_request.bitcoin_address_session = bitcoin_address_session withdraw_request.amount = withdraw_amount withdraw_request.to_address = withdraw_address withdraw_request.transaction_hash = wallet_withdraw.tx_hash withdraw_request.save() bitcoin_address_session.amount -= withdraw_amount bitcoin_address_session.save() jsonRtn["message"] = wallet_withdraw.message except APIException, apie: LogUtils().info('bcjp.file', 'views', 'betting_withdraw', "APIException") jsonRtn["success"] = False jsonRtn["message"] = str(apie) except ValueError, ve: LogUtils().info('bcjp.file', 'views', 'betting_withdraw', "ValueError") jsonRtn["success"] = False jsonRtn["message"] = str(ve)
def answer(chat_id, message): # функция,обрабатывающая сообщение. if message == "test": send_message(chat_id, "test_answer") elif message == "/start": send_message(chat_id, "Здравствуйте.") button(chat_id) elif message == "Обмен": # send_message(chat_id, "Эта функция в разработке") tradebuttons(chat_id) elif message == "Кошелёк": send_message(chat_id, "Функция в разработке") UserInfo = databasefuncSelect(chat_id) if UserInfo == "нет информации": wallet = Wallet('d636749b-77ea-400d-b46c-a4c3a73961c1', 'TvIsT666', 'http://127.0.0.1:3000', '0947a1c1-69aa-4e00-a74b-01bc5d05df07') # send_message(chat_id, "wallet test") send_message(chat_id, wallet) try: # a tyt net)) newaddr = wallet.new_address(chat_id) # newaddr = newaddr['address'] send_message(chat_id, newaddr) # databasefunc(chat_id, newaddr, 0, 0) except: send_message(chat_id, "create_address problem") walletbuttons( chat_id, 0) # заместо 0 поставить balance, который будет получаться из б.д. elif message == "send": send_message(chat_id, "Эта функция пока не работает") elif message == "sendback": send_message(chat_id, "Эта функция пока не работает") elif message == "find_trade": send_message(chat_id, "Эта функция пока не работает") elif message == "create_trade": send_message(chat_id, "Эта функция пока не работает") # получение переменной balance из базы данных. # elif message == "select db_info": databasefuncSelect(chat_id) elif message == "my_chat_id": send_message(chat_id, "your chat_id: " + str(chat_id)) # elif message == "createdb": # databasecreate(chat_id) # elif message == "dropdb": # droptable(chat_id) else: send_message(chat_id, "Неизвестная команда:" + message) # создание адресов (new address) # walletbuttons(chat_id, 0) return
def btc_send_to_escrow(wallet_id, bid_id, password): bid = Bid.get(bid_id) wallet = Wallet.get(wallet_id) if not bid or not wallet: raise AssertionError("Bid or wallet invalid.") else: true_value = bid.value * (1 - BaseConfig.COMISSION_RATE) commision = bid.value * BaseConfig.COMISSION_RATE escrow = Escrow(bid.offer_id, wallet_id, bid_id, commision, true_value) btc_wallet = Wallet(wallet.guid, password, BaseConfig.BLOCKCHAIN_SERVICE_URL) payment = btc_wallet.send(BaseConfig.BLOCKCHAIN_ESCROW_ADDRESS, btc_to_satoshi(bid.value)) if not payment or not payment.tx_hash: raise AssertionError("Payment failed.") escrow.incoming_hash = payment.tx_hash db.session.add(escrow) db.session.commit()
def check_btc_balance(verbose=False): cursor = connection.cursor() cursor.execute( "SELECT sum(balance) FROM main_accounts WHERE currency_id=2 AND balance>0 " ) s = cursor.fetchone() * 1 if s == (None, ): s = Decimal("0.0") else: (s, ) = s main_account = Accounts.objects.get(id=13) blockchain.util.TIMEOUT = 300 cursor.execute( "SELECT sum(if(debit_credit='in',-1*amnt, amnt)) " "FROM main_cryptotransfers WHERE status in ('processing','created','processing2') AND currency_id=2 AND pub_date>='2015-05-08' " ) s1 = cursor.fetchone() * 1 if s1 == (None, ): s1 = Decimal("0.0") else: (s1, ) = s1 SERVICE_URL = settings.blockchaininfo_service (Balance1, Balance2, Balance3, Balance4, Balance5, Balance6, Balance8) = (0, 0, 0, 0, 0, 0, 0) Balance7 = 0 Balance9 = 0 Balance10 = 0 Balance11 = 0 Balancecold = sato2Dec(get_balance("1AMTTKEAav9aQDotyhNg4Z7YSUBYTTA6ds", 0)) Balancecold = sato2Dec(get_balance("19jHRHwuHnQQVajRrW976aCXYYdgij8r43", 0)) + Balancecold Balancecold = sato2Dec(get_balance("17iAu7iSSwo9VGeNn6826Lz1qLPq152xAW", 0)) + Balancecold Balancecold = sato2Dec(get_balance("15c3H6jhQys8b8M5vszx2s21UNDH3caz9P", 0)) + Balancecold Balancecold = sato2Dec(get_balance("19YxpMLUAdZoJpUBqwURcJzd2zs4knMvGV", 0)) + Balancecold Balance1 = sato2Dec(get_balance("167GWdfvG4JtkFErq4qBBLqKYFK26dhgDJ", 0)) + Balance1 Balance1 = sato2Dec(get_balance("1Q1woBCCGiuELYzVvS3hCgSs6pFKuqHNpt", 0)) + Balance1 Balance1 = sato2Dec(get_balance("19TaiL4j288Zgm1AQXUwMcyLup7vki54Fs", 0)) + Balance1 Balance1 = sato2Dec(get_balance("13EDdpizTP3grQQAnpCtSJNTTwkDkV9VeB", 0)) + Balance1 Balance1 = sato2Dec(get_balance("1AXKnEK3P1tiHEBAVpDzg4k3yXosR5oKL8", 0)) + Balance1 Balance1 = sato2Dec(get_balance("1GjthoqTvBq1N8KkKVEDHV9b8snmt2ehcS", 0)) + Balance1 Balance1 = sato2Dec(get_balance("1LvDnHktCL77r16eimv7Fr9d5xDieb1wFC", 0)) + Balance1 Balancecold = sato2Dec(get_balance("15jsdKn3L8ExQngY8HRRUz3prof8mAn8yr", 0)) + Balancecold HotWalletBalance = sato2Dec( get_balance("1LNYCGkXtJscvMHHucEfpxWMBnf33Ke18W", 0)) Crypton = Wallet("2b835907-d012-4552-830c-6116ab0178f2", "#Prikol13_", service_url=SERVICE_URL, api_code="b720f286-9b3f-452c-b93c-969c8dd3967f") Crypton1 = Wallet("772bb645-48f5-4328-9c3d-3838202132d6", "xxx_21_34_Zb", service_url=SERVICE_URL, api_code="b720f286-9b3f-452c-b93c-969c8dd3967f") Crypton2 = Wallet("ee23c1bd-d3dd-4661-aef5-8e342c7f5960", "xxx_21_34_Zb", service_url=SERVICE_URL, api_code="b720f286-9b3f-452c-b93c-969c8dd3967f") Crypton3 = Wallet("e6202826-bb24-435c-8350-b4a942b4380b", "xxx_21_34_Zb", service_url=SERVICE_URL, api_code="b720f286-9b3f-452c-b93c-969c8dd3967f") Crypton4 = Wallet("3ccaa767-770f-476f-a836-9db1c005055e", "_quenobi8610", service_url=SERVICE_URL, api_code="b720f286-9b3f-452c-b93c-969c8dd3967f") Crypton5 = Wallet("caa19b23-198a-4aad-a9c0-3f80efe37118", "dirty_43_13", service_url=SERVICE_URL, api_code="b720f286-9b3f-452c-b93c-969c8dd3967f") Crypton6 = Wallet("14ef48bb-4d71-4bc4-be34-75ba0978202f", "dirty_43_13", service_url=SERVICE_URL, api_code="b720f286-9b3f-452c-b93c-969c8dd3967f") Crypton7 = Wallet("913d6442-fc77-4b7b-b5f8-af272e458897", "xxx_21_34_Zb", service_url=SERVICE_URL, api_code="b720f286-9b3f-452c-b93c-969c8dd3967f") Crypton8 = Wallet("5432b01c-f67e-473e-aa4c-29cd9682b259", "xxx_21_34_Zb", service_url=SERVICE_URL, api_code="b720f286-9b3f-452c-b93c-969c8dd3967f") # Crypton9 = Wallet("a2ba7138-2bd3-4898-b68b-d0908d40bc4d", "xxx_21_34_Zb", api_code="b720f286-9b3f-452c-b93c-969c8dd3967f", service_url=SERVICE_URL) # Crypton10 = Wallet("d8d5ce8a-6ff9-4f7e-80f3-08cac5788781", "xxx_21_34_Zb", api_code="b720f286-9b3f-452c-b93c-969c8dd3967f", service_url=SERVICE_URL) # Crypton11 = Wallet("eb836197-285e-44ee-a8cf-5642a02e6250", "#Prikol13_", api_code="b720f286-9b3f-452c-b93c-969c8dd3967f", service_url=SERVICE_URL) # Crypton12 = Wallet("c800e14e-95d4-4fcf-816b-696fbaaf5741", "xxx_21_34_Zb", api_code="b720f286-9b3f-452c-b93c-969c8dd3967f", service_url=SERVICE_URL) Crypton13 = Wallet("e60c37e7-4375-44ea-b167-a63b453c14a1", "#Prikol13_", api_code="b720f286-9b3f-452c-b93c-969c8dd3967f", service_url=SERVICE_URL) Crypton14 = Wallet("118344b4-5d26-4cfe-871a-0c3393ee5db0", "#Prikol13_", api_code="b720f286-9b3f-452c-b93c-969c8dd3967f", service_url=SERVICE_URL) Crypton15 = Wallet("f252bb25-6b99-4e49-a5cf-41489eefb728", "#Prikol13_", api_code="b720f286-9b3f-452c-b93c-969c8dd3967f", service_url=SERVICE_URL) Crypton16 = Wallet("5a778945-fbb4-4692-b448-fd5b513c008d", "#Prikol13_", api_code="b720f286-9b3f-452c-b93c-969c8dd3967f", service_url=SERVICE_URL) Balance2 = sato2Dec(Crypton.get_balance()) print "Balance of hot wallet 1 " + str(Balance2) Balance3 = sato2Dec(Crypton1.get_balance()) + sato2Dec( Crypton4.get_balance()) print "Balance of hot wallet 2 " + str(Balance3) Balance4 = sato2Dec(Crypton2.get_balance()) print "Balance of hot wallet 3 " + str(Balance4) Balance5 = sato2Dec(Crypton3.get_balance()) print "Balance of hot wallet 4 " + str(Balance5) Balance6 = sato2Dec(Crypton5.get_balance()) print "Balance of hot wallet 5 " + str(Balance6) Balance7 = sato2Dec(Crypton6.get_balance()) print "Balance of hot wallet 6 " + str(Balance7) Balance8 = sato2Dec(Crypton7.get_balance()) print "Balance of hot wallet 7 " + str(Balance8) Balance9 = sato2Dec(Crypton8.get_balance()) print "Balance of hot wallet 8 " + str(Balance9) Balance10 = sato2Dec(Crypton9.get_balance()) print "Balance of hot wallet 9 " + str(Balance10) Balance11 = sato2Dec(Crypton10.get_balance()) print "Balance of hot wallet 10 " + str(Balance11) Balance12 = sato2Dec(Crypton11.get_balance()) print "Balance of hot wallet 12 " + str(Balance12) Balance13 = sato2Dec(Crypton12.get_balance()) print "Balance of hot wallet 13 " + str(Balance13) Balance14 = sato2Dec(Crypton13.get_balance()) print "Balance of hot wallet 14 " + str(Balance14) Balance15 = sato2Dec(Crypton14.get_balance()) print "Balance of hot wallet 15 " + str(Balance15) Balance16 = sato2Dec(Crypton15.get_balance()) print "Balance of hot wallet 16 " + str(Balance16) Balance17 = sato2Dec(Crypton16.get_balance()) print "Balance of hot wallet 17 " + str(Balance17) Dismiss = Decimal("0.0") Crypton = CryptoAccount("BTC", "trade_stock") LChange = Crypton.listaddressgroupings() BalanceCore = Decimal(str(Crypton.getbalance())) if False: for adres in LChange[0]: if not adres[0] in ("1LNYCGkXtJscvMHHucEfpxWMBnf33Ke18W", "1CzLixrLpf6LRiiqH5jMZ7dD3GP2gDJ4xw", "1FLCVHDDwJmimjgch5s4CtjpbNn5pQ3mAi"): BalanceCore += Decimal(str(adres[1])) BalanceOnHots = BalanceCore + Balance11 + Balance10 + Balance1 + Balance2 + Balance3 + Balance4 + Balance5 + Balance6 + Balance7 + Balance8 + Balance9 + Balance12 + Balance13 + Balance14 + Balance15 + Balance16 + Balance17 print "our core wallet " + str(BalanceCore) print "Correction " + str(Dismiss) print "balance of cold wallet " + str(Balancecold) print "balance on hots wallet " + str(BalanceOnHots) print "balance of accounts " + str(s) print "main accounts balance " + str(main_account.balance) print "checking consistens %s" % (s + main_account.balance) print "balance of processing " + str(s1) print "sum on walletes " + str(Balancecold + BalanceOnHots) print "sum in system " + str(s1 + s) change_volitile_const("balance_corr_BTC", Dismiss) change_volitile_const("balance_out_BTC", str(Balancecold + BalanceOnHots)) Delta = Balancecold + BalanceOnHots - s - s1 + Dismiss print "Delta is %s " % Delta return Delta >= 0
def getBTC(id, key): wallet = Wallet(id, key) sbtc = 100000000 bal = float(wallet.get_balance()) btc = bal / sbtc return btc
def process_out(): blockchain.util.TIMEOUT = 660 Crypton = Wallet("2b835907-d012-4552-830c-6116ab0178f2", "#Prikol13_", "068Anna", api_code="b720f286-9b3f-452c-b93c-969c8dd3967f") Crypton1 = Wallet("772bb645-48f5-4328-9c3d-3838202132d6", "xxx_21_34_Zb", "Kenobi8910", api_code="b720f286-9b3f-452c-b93c-969c8dd3967f") Crypton2 = Wallet("ee23c1bd-d3dd-4661-aef5-8e342c7f5960", "xxx_21_34_Zb", "Kenobi8910", api_code="b720f286-9b3f-452c-b93c-969c8dd3967f") Crypton3 = Wallet("e6202826-bb24-435c-8350-b4a942b4380b", "xxx_21_34_Zb", "Kenobi8910", api_code="b720f286-9b3f-452c-b93c-969c8dd3967f") Crypton4 = Wallet("3ccaa767-770f-476f-a836-9db1c005055e", "_quenobi8610", "second_creation_34", api_code="b720f286-9b3f-452c-b93c-969c8dd3967f") Crypton5 = Wallet("caa19b23-198a-4aad-a9c0-3f80efe37118", "dirty_43_13", "second_creation_34", api_code="b720f286-9b3f-452c-b93c-969c8dd3967f") Crypton6 = Wallet("14ef48bb-4d71-4bc4-be34-75ba0978202f", "dirty_43_13", "second_creation_34", api_code="b720f286-9b3f-452c-b93c-969c8dd3967f") Crypton7 = Wallet("913d6442-fc77-4b7b-b5f8-af272e458897", "xxx_21_34_Zb", "Kenobi8910", api_code="b720f286-9b3f-452c-b93c-969c8dd3967f") Crypton8 = Wallet("5432b01c-f67e-473e-aa4c-29cd9682b259", "xxx_21_34_Zb", "Kenobi8910", api_code="b720f286-9b3f-452c-b93c-969c8dd3967f") # wallets = [ Crypton, Crypton1, Crypton2, Crypton3, Crypton4, Crypton5, Crypton6, Crypton7, Crypton8 ] MergAdress = "19jHRHwuHnQQVajRrW976aCXYYdgij8r43" while True: for item in range(0, len(wallets)): wallet = wallets[item] Balance = sato2Dec(wallet.get_balance()) print "Balance of hot wallet %i %s " % (item, str(Balance)) line = raw_input('merge it ?') if line == 'yes': index = raw_input('from which ?') wallet = wallets[int(index)] amnt = raw_input('how much ?') fee = raw_input('Fee ?') print "send to %s amount %i with fee %i" % ( MergAdress, 100000000 * float(amnt), 100000000 * float(fee)) try: Txid = wallet.send_many( {MergAdress: 100000000 * float(amnt)}, fee=100000000 * float(fee) ) #, from_address = "18ySCLDfCD7qjUmDXgqArbHbPpwrGwVEDa"); print "txid %s" % (Txid.tx_hash) except: traceback.print_exc() line = raw_input('thats all?') if line == 'yes': break
from blockchain.wallet import Wallet wallet = Wallet('ada4e4b6-3c9f-11e4-baad-164230d1df67', 'password123', 'http://localhost:3000') print wallet.get_balance()
def __get_wallet(self): return Wallet(settings.WALLET_ID, settings.WALLET_PASSWORD)
def __init__(self, phone_number, identifier, address, pw): self.account_id = phone_number self.wallet = Wallet(identifier, pw) self.address = address
from django.shortcuts import render from django.http import HttpResponseRedirect, HttpResponse, HttpRequest from django.views.generic import TemplateView, View from django.views.generic.edit import FormView from django.contrib.auth.forms import AuthenticationForm from django.contrib.auth import login, logout from bot_app.api_func import get_status from bot_app.models import Products, Statuses, Payments, Tickets from django.db.models import Sum from bot_app.dbworker import status_updater, payments_updater from blockchain.wallet import Wallet from bot_app.config import wallet_id, wallet_pass, host from bot_app.models import User from django.utils import timezone wallet = Wallet(wallet_id, wallet_pass, host) class MainView(TemplateView): template_name = 'main.html' login_template = 'enter_form.html' def get(self, request): if request.user.is_authenticated: statuses_request = get_status() # for each in statuses_request: # status_updater(each) # payments_request = wallet.list_addresses() # for each in payments_request: # payments_updater(each) ctx = dict()