Exemple #1
0
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
Exemple #2
0
class persons:
    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 add_withdraw(self, account):
        self.waccounts.append(account)

    def add_deposit(self, account):
        self.daccounts.append(account)

    def add_account(self, acount):
        self.accounts.append(account)
class persons:

	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 add_withdraw(self, account):
		self.waccounts.append(account)

	def add_deposit(self, account):
		self.daccounts.append(account)

	def add_account(self,acount):
		self.accounts.append(account)
 def handle(self, *args, **options):
     CurIns =  Currency.objects.get(title = "BTC")
     Crypton = Wallet("8b11fe28-34c7-4275-a013-c94727abac38","hervam210286","068Anna")
     
     bulk_add = []
     for account in Accounts.objects.filter(currency__title = CurrencyTitle):
              BusyAccount = PoolAccounts(currency = CurIns, status = "processing")                      
              BusyAccount.user =  account.user
              BusyAccount.status = "processing"
              BusyAccount.address = account.reference
              bulk_add.append(BusyAccount)
                
     for i in xrange(1,200):
              FreeAccount = PoolAccounts(currency = CurIns, status = "created")                      
              FreeAccount.pub_date = date.today() 
              d = Crypton.new_address(label = Req.user.username)          
              Addr = d.address   
              FreeAccount.address = Addr 
              bulk_add.append(FreeAccount)    
              
     PoolAccounts.objects.bulk_create(buld_add)
    def handle(self, *args, **options):
        CurIns = Currency.objects.get(title = "BTC")
        Crypton = Wallet(CryptoSettings["BTC"]["host"],
                         CryptoSettings["BTC"]["rpc_user"],
                         CryptoSettings["BTC"]["rpc_pwd"])
        
        bulk_add = []
 #       for account in Accounts.objects.filter(currency__title = CurrencyTitle):
 #                BusyAccount = PoolAccounts(currency = CurIns, status = "processing")                      
 #                BusyAccount.user =  account.user
 #                BusyAccount.status = "processing"
 #                BusyAccount.address = account.reference
 #                bulk_add.append(BusyAccount)
                   
        for i in xrange(1,50):
                 FreeAccount = PoolAccounts(currency = CurIns, status = "created")                      
                 FreeAccount.pub_date = date.today() 
                 d = Crypton.new_address(label ="pool") 
		 print d.address         
                 Addr = d.address   
                 FreeAccount.address = Addr 
                 bulk_add.append(FreeAccount)    
                 
        PoolAccounts.objects.bulk_create(bulk_add)
Exemple #6
0
class BTCProcessor:
    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 wallet_generation(self, label=None):
        label = label if label is not None else self.customer.user.get_fullname(
        ) + ' wallet'
        user_password = get_random_string(60)
        new_wallet = createwallet.create_wallet(user_password,
                                                API_CODE,
                                                NODE_WALLET_SERVICES,
                                                label=label)
        btc_wallet = BTC(id=new_wallet.identifier,
                         addr=new_wallet.address,
                         label=new_wallet.label,
                         customer=self.customer,
                         password=user_password)
        btc_wallet.save()
        return new_wallet.__dict__

    def wallet_info(self):
        wallet = self.wallet
        return wallet.__dict__

    def new_address(self, label='test_label'):
        newaddr = self.wallet.new_address(label)
        return newaddr

    def list_addresses(self):
        addresses = self.wallet.list_addresses()
        return addresses

    def get_balance(self):
        get_balance = float(self.wallet.get_balance() / 100000000)
        obj, created = models.Balance.objects.get_or_create(
            customer=self.customer, currency='BTC')
        obj.amount = get_balance
        obj.save()
        return get_balance

    def send_tx(self, target_addr, amount, from_address=None):
        amount = amount * 100000000
        payment = self.wallet.send(target_addr, amount, fee=500)  #min fee=220
        return payment.__dict__['tx_hash']

    def send_many_tx(self, recipients):
        # recipients = { '1NAF7GbdyRg3miHNrw2bGxrd63tfMEmJob' : 1428300,
        # 		'1A8JiWcwvpY7tAopUkSnGuEYHmzGYfZPiq' : 234522117 }
        payment_many = self.wallet.send_many(recipients)
        return payment_many.tx_id

    def get_address(self, addr, confirmations=2):
        addr = self.wallet.get_address(addr, confirmations=confirmations)
        return addr

    def archive_address(self, addr):
        archive_address = self.wallet.archive_address(addr)
        return archive_address

    def unarchive_address(self, addr):
        unarchive_address = self.wallet.unarchive_address(addr)
        return unarchive_address

    def push_tx(self, push_code):
        # push_code = '0100000001fd468e431cf5797b108e4d22724e1e055b3ecec59af4ef17b063afd36d3c5cf6010000008c4930460221009918eee8be186035be8ca573b7a4ef7bc672c59430785e5390cc375329a2099702210085b86387e3e15d68c847a1bdf786ed0fdbc87ab3b7c224f3c5490ac19ff4e756014104fe2cfcf0733e559cbf28d7b1489a673c0d7d6de8470d7ff3b272e7221afb051b777b5f879dd6a8908f459f950650319f0e83a5cf1d7c1dfadf6458f09a84ba80ffffffff01185d2033000000001976a9144be9a6a5f6fb75765145d9c54f1a4929e407d2ec88ac00000000'
        pushtxed = pushtx.pushtx(push_code)
        return pushtxed

    def get_price(self, currency, amount):
        btc_amount = exchangerates.to_btc(currency, amount)
        return btc_amount

    def statistics(self):
        stats = statistics.get()
        return stats

    def blockexplorer(self):
        block = blockexplorer.get_block(
            '000000000000000016f9a2c3e0f4c1245ff24856a79c34806969f5084f410680')
        tx = blockexplorer.get_tx(
            'd4af240386cdacab4ca666d178afc88280b620ae308ae8d2585e9ab8fc664a94')
        blocks = blockexplorer.get_block_height(2570)
        address = blockexplorer.get_address(
            '1HS9RLmKvJ7D1ZYgfPExJZQZA1DMU3DEVd')
        xpub = None  #blockexplorer.get_xpub('xpub6CmZamQcHw2TPtbGmJNEvRgfhLwitarvzFn3fBYEEkFTqztus7W7CNbf48Kxuj1bRRBmZPzQocB6qar9ay6buVkQk73ftKE1z4tt9cPHWRn')
        addresses = None  # blockexplorer.get_multi_address('1HS9RLmKvJ7D1ZYgfPExJZQZA1DMU3DEVd', 'xpub6CmZamQcHw2TPtbGmJNEvRgfhLwitarvzFn3fBYEEkFTqztus7W7CNbf48Kxuj1bRRBmZPzQocB6qar9ay6buVkQk73ftKE1z4tt9cPHWRn')
        outs = blockexplorer.get_unspent_outputs(
            '1HS9RLmKvJ7D1ZYgfPExJZQZA1DMU3DEVd')
        latest_block = blockexplorer.get_latest_block()
        txs = blockexplorer.get_unconfirmed_tx()
        blocks_by_name = None  #blockexplorer.get_blocks(pool_name = 'Discus Fish')

    def get_target_wallet_addr(self, customer=None, email=None):
        if customer is not None:
            return customer.btc_wallet().addr
        if email is not None:
            user = models.Users.objects.get(email=email)
            return user.customer().btc_wallet().addr
        return None