def inits_new_portal(dd): return db.to_phone.drop() resp = "" # для всех криптовалют создадим главные аккоунты в кошельках for xcurr in db(db.xcurrs).select(): try: aa = crypto_client.conn(xcurr) except Exception as e: print e msg = xcurr.name + " no connection to wallet" print msg resp = resp + msg + '<br>' continue try: x = crypto_client.get_xaddress_by_label(xcurr,'.main.',aa) except Exception as e: print e msg = xcurr.name + " no made .main. account" print msg resp = resp + msg + '<br>' continue return resp
def get_deal_acc_addr_for_xcurr(db, deal_acc_id, curr, xcurr, x_acc_label): # найдем адрес крипты для данногоо аккаунта дела или создадим deal_acc_addr = db( (db.deal_acc_addrs.deal_acc_id == deal_acc_id) & (db.deal_acc_addrs.xcurr_id == xcurr.id)).select().first() if deal_acc_addr: return deal_acc_addr conn = crypto_client.conn(curr, xcurr) if not conn: return # http://docs.python.org/2/library/codecs.html?highlight=decoding x_acc_label = x_acc_label.decode('utf8') #x_acc_label = x_acc_label.encode('koi8_r') # 'iso8859_5') # 'cp866') # 'cp1251') #'cp855') #x_acc_label = x_acc_label.decode('cp855') #print 'GET new addr for',x_acc_label try: addr = crypto_client.get_xaddress_by_label(conn, x_acc_label) except: return if not addr: return else: id = db.deal_acc_addrs.insert(deal_acc_id=deal_acc_id, xcurr_id=xcurr.id, addr=addr) deal_acc_addr = db.deal_acc_addrs[id] return deal_acc_addr
def get_shop_order_addr_for_xcurr(db, shop_order_id, curr, xcurr, order_id_label): # найдем адрес крипты для данногоо аккаунта дела или создадим shop_order_addr = db((db.shop_order_addrs.shop_order_id==shop_order_id) & (db.shop_order_addrs.xcurr_id==xcurr.id) ).select().first() if not shop_order_addr: conn = crypto_client.conn(curr, xcurr) if not conn: return # http://docs.python.org/2/library/codecs.html?highlight=decoding ### после trans - не надо! x_acc_label = order_id_label.decode('utf8') #x_acc_label = x_acc_label.encode('koi8_r') # 'iso8859_5') # 'cp866') # 'cp1251') #'cp855') #x_acc_label = x_acc_label.decode('cp855') x_acc_label = order_id_label print 'GET new addr for',x_acc_label ## тут нельзя по метке брать адрес - так как метка может быть от старого счета для заказа с тем же номером ## addr = crypto_client.get_xaddress_by_label(conn, x_acc_label) ## делаем по номеру счета адрес # TODO - надо сделать проверку в кошельке - может там такого адреса нет который есть в ДБ # может новый кошель создан а база у нас старая с адресами - надо новый адрес сгенерить!!! addr = crypto_client.get_xaddress_by_label(conn, '%s' % shop_order_id) if not addr: return else: id = db.shop_order_addrs.insert( shop_order_id = shop_order_id, xcurr_id=xcurr.id, addr = addr) shop_order_addr = db.shop_order_addrs[id] return shop_order_addr
def get_deal_acc_addr_for_xcurr(db, deal_acc_id, curr, xcurr, x_acc_label): # найдем адрес крипты для данного аккаунта дела или создадим deal_acc_addr = db( (db.deal_acc_addrs.deal_acc_id == deal_acc_id) & (db.deal_acc_addrs.xcurr_id == xcurr.id)).select().first() if deal_acc_addr: ##print 'get_deal_acc_addr_for_xcurr found:', 'deal_acc_id:', deal_acc_id, 'xcurr_id:', xcurr.id, '>>', deal_acc_addr.id, deal_acc_addr.addr return deal_acc_addr # Erachain tokens? token_system = None token_key = xcurr.as_token if token_key: token = db.tokens[token_key] token_system = db.systems[token.system_id] addr = token_system.account else: try: conn = crypto_client.conn(curr, xcurr) except: conn = None if not conn: return if xcurr.protocol == 'zen': ## in Horizen Account is removed addr = conn.getnewaddress() else: # http://docs.python.org/2/library/codecs.html?highlight=decoding x_acc_label = x_acc_label.decode('utf8') #x_acc_label = x_acc_label.encode('koi8_r') # 'iso8859_5') # 'cp866') # 'cp1251') #'cp855') #x_acc_label = x_acc_label.decode('cp855') ##print 'GET new addr for x_acc_label:', x_acc_label try: addr = crypto_client.get_xaddress_by_label(conn, x_acc_label) except: return if not addr: return id = db.deal_acc_addrs.insert(deal_acc_id=deal_acc_id, xcurr_id=xcurr.id, addr=addr) deal_acc_addr = db.deal_acc_addrs[id] ##print 'GETed new addr :', addr return deal_acc_addr
def send_to_main(conn, acc_from, amo): main_addr = crypto_client.get_xaddress_by_label(conn,'.main.') mess = "to send %s from acc:"% amo +acc_from +" to " + main_addr print 'try', mess try: conn.sendfrom( acc_from, main_addr,amo) except Exception as e: if e.error['code']==-4: # если не хватает на комисиию то уменишим сумму и повторим print 'tax -0.01' send_to_main(conn, acc_from, amo-0.01) return print e.error return e.error