Пример #1
0
	def __init__(self, msgchan, wallet, db, cj_amount, orders, input_utxos, my_cj_addr,
		my_change_addr, my_txfee, finishcallback=None):
		'''
		if my_change is None then there wont be a change address
		thats used if you want to entirely coinjoin one utxo with no change left over
		orders is the orders you want to fill {'counterpartynick': oid, 'cp2': oid2}
		'''
		debug('starting cj to ' + my_cj_addr + ' with change at ' + str(my_change_addr))
		self.msgchan = msgchan
		self.wallet = wallet
		self.db = db
		self.cj_amount = cj_amount
		self.active_orders = dict(orders)
		self.nonrespondants = list(orders.keys())
		self.input_utxos = input_utxos
		self.utxos = {None: input_utxos.keys()} #None means they belong to me
		self.finishcallback = finishcallback
		self.my_txfee = my_txfee
		self.outputs = [{'address': my_cj_addr, 'value': self.cj_amount}]
		self.my_cj_addr = my_cj_addr
		self.my_change_addr = my_change_addr
		self.cjfee_total = 0
		self.latest_tx = None
		#create DH keypair on the fly for this Tx object
		self.kp = enc_wrapper.init_keypair()
		self.crypto_boxes = {}
		self.msgchan.fill_orders(orders, cj_amount, self.kp.hex_pk())
Пример #2
0
	def __init__(self, msgchan, wallet, db, cj_amount, orders, input_utxos, my_cj_addr,
		my_change_addr, my_txfee, finishcallback=None):
		'''
		if my_change is None then there wont be a change address
		thats used if you want to entirely coinjoin one utxo with no change left over
		orders is the orders you want to fill {'counterpartynick': oid, 'cp2': oid2}
		'''
		debug('starting cj to ' + my_cj_addr + ' with change at ' + str(my_change_addr))
		self.msgchan = msgchan
		self.wallet = wallet
		self.db = db
		self.cj_amount = cj_amount
		self.active_orders = dict(orders)
		self.nonrespondants = list(orders.keys())
		self.input_utxos = input_utxos
		self.utxos = {None: input_utxos.keys()} #None means they belong to me
		self.finishcallback = finishcallback
		self.my_txfee = my_txfee
		self.outputs = [{'address': my_cj_addr, 'value': self.cj_amount}]
		self.my_cj_addr = my_cj_addr
		self.my_change_addr = my_change_addr
		self.cjfee_total = 0
		self.latest_tx = None
		#create DH keypair on the fly for this Tx object
		self.kp = enc_wrapper.init_keypair()
		self.crypto_boxes = {}
		self.msgchan.fill_orders(orders, cj_amount, self.kp.hex_pk())
Пример #3
0
    def __init__(self,
                 msgchan,
                 wallet,
                 db,
                 cj_amount,
                 orders,
                 input_utxos,
                 my_cj_addr,
                 my_change_addr,
                 total_txfee,
                 finishcallback,
                 choose_orders_recover,
                 auth_addr=None):
        '''
		if my_change is None then there wont be a change address
		thats used if you want to entirely coinjoin one utxo with no change left over
		orders is the orders you want to fill {'counterpartynick': oid, 'cp2': oid2}
		'''
        debug('starting cj to ' + str(my_cj_addr) + ' with change at ' +
              str(my_change_addr))
        #parameters
        self.msgchan = msgchan
        self.wallet = wallet
        self.db = db
        self.cj_amount = cj_amount
        self.active_orders = dict(orders)
        self.input_utxos = input_utxos
        self.finishcallback = finishcallback
        self.total_txfee = total_txfee
        self.my_cj_addr = my_cj_addr
        self.my_change_addr = my_change_addr
        self.choose_orders_recover = choose_orders_recover
        self.auth_addr = auth_addr
        self.timeout_lock = threading.Condition()  #used to wait() and notify()
        #used to restrict access to certain variables across threads
        self.timeout_thread_lock = threading.Condition()
        self.end_timeout_thread = False
        CoinJoinTX.TimeoutThread(self).start()
        #state variables
        self.txid = None
        self.cjfee_total = 0
        self.maker_txfee_contributions = 0
        self.nonrespondants = list(self.active_orders.keys())
        self.all_responded = False
        self.latest_tx = None
        self.utxos = {
            None: self.input_utxos.keys()
        }  #None means they belong to me
        self.outputs = []
        #create DH keypair on the fly for this Tx object
        self.kp = enc_wrapper.init_keypair()
        self.crypto_boxes = {}
        self.msgchan.fill_orders(self.active_orders, self.cj_amount,
                                 self.kp.hex_pk())
Пример #4
0
    def __init__(self, maker, nick, oid, amount, taker_pk):
        self.maker = maker
        self.oid = oid
        self.cj_amount = amount
        if self.cj_amount <= common.DUST_THRESHOLD:
            self.maker.msgchan.send_error(nick, 'amount below dust threshold')
        #the btc pubkey of the utxo that the taker plans to use as input
        self.taker_pk = taker_pk
        #create DH keypair on the fly for this Order object
        self.kp = enc_wrapper.init_keypair()
        #the encryption channel crypto box for this Order object
        self.crypto_box = enc_wrapper.as_init_encryption(self.kp, \
                                enc_wrapper.init_pubkey(taker_pk))

        order_s = [o for o in maker.orderlist if o['oid'] == oid]
        if len(order_s) == 0:
            self.maker.msgchan.send_error(nick, 'oid not found')
        order = order_s[0]
        if amount < order['minsize'] or amount > order['maxsize']:
            self.maker.msgchan.send_error(nick, 'amount out of range')
        self.ordertype = order['ordertype']
        self.txfee = order['txfee']
        self.cjfee = order['cjfee']
        debug('new cjorder nick=%s oid=%d amount=%d' % (nick, oid, amount))
        self.utxos, self.cj_addr, self.change_addr = maker.oid_to_order(
            self, oid, amount)
        self.maker.wallet.update_cache_index()
        if not self.utxos:
            self.maker.msgchan.send_error(
                nick, 'unable to fill order constrained by dust avoidance')
            #TODO make up orders offers in a way that this error cant appear
        #check nothing has messed up with the wallet code, remove this code after a while
        import pprint
        debug('maker utxos = ' + pprint.pformat(self.utxos))
        utxo_list = self.utxos.keys()
        utxo_data = common.bc_interface.query_utxo_set(utxo_list)
        if None in utxo_data:
            debug('wrongly using an already spent utxo. utxo_data = ' +
                  pprint.pformat(utxo_data))
            sys.exit(0)
        for utxo, data in zip(utxo_list, utxo_data):
            if self.utxos[utxo]['value'] != data['value']:
                debug('wrongly labeled utxo, expected value ' +
                      str(self.utxos[utxo]['value']) + ' got ' +
                      str(data['value']))
                sys.exit(0)

        #always a new address even if the order ends up never being
        # furfilled, you dont want someone pretending to fill all your
        # orders to find out which addresses you use
        self.maker.msgchan.send_pubkey(nick, self.kp.hex_pk())
Пример #5
0
	def __init__(self, maker, nick, oid, amount, taker_pk):
		self.maker = maker
		self.oid = oid
		self.cj_amount = amount
		if self.cj_amount <= common.DUST_THRESHOLD:
			self.maker.msgchan.send_error(nick, 'amount below dust threshold')
		#the btc pubkey of the utxo that the taker plans to use as input
		self.taker_pk = taker_pk
		#create DH keypair on the fly for this Order object
		self.kp = enc_wrapper.init_keypair()
		#the encryption channel crypto box for this Order object
		self.crypto_box = enc_wrapper.as_init_encryption(self.kp, \
		                        enc_wrapper.init_pubkey(taker_pk))
		
		order_s = [o for o in maker.orderlist if o['oid'] == oid]
		if len(order_s) == 0:
			self.maker.msgchan.send_error(nick, 'oid not found')
		order = order_s[0]
		if amount < order['minsize'] or amount > order['maxsize']:
			self.maker.msgchan.send_error(nick, 'amount out of range')
		self.ordertype = order['ordertype']
		self.txfee = order['txfee']
		self.cjfee = order['cjfee']
		debug('new cjorder nick=%s oid=%d amount=%d' % (nick, oid, amount))
		self.utxos, self.cj_addr, self.change_addr = maker.oid_to_order(self, oid, amount)
		self.maker.wallet.update_cache_index()
		if not self.utxos:
			self.maker.msgchan.send_error(nick, 'unable to fill order constrained by dust avoidance')
			#TODO make up orders offers in a way that this error cant appear
		#check nothing has messed up with the wallet code, remove this code after a while
		import pprint
		debug('maker utxos = ' + pprint.pformat(self.utxos))
		utxo_list = self.utxos.keys()
		utxo_data = common.bc_interface.query_utxo_set(utxo_list)
		if None in utxo_data:
			debug('wrongly using an already spent utxo. utxo_data = ' + pprint.pformat(utxo_data))
			sys.exit(0)
		for utxo, data in zip(utxo_list, utxo_data):
			if self.utxos[utxo]['value'] != data['value']:
				debug('wrongly labeled utxo, expected value ' +
					str(self.utxos[utxo]['value']) + ' got ' + str(data['value']))
				sys.exit(0)

		#always a new address even if the order ends up never being
		# furfilled, you dont want someone pretending to fill all your
		# orders to find out which addresses you use
		self.maker.msgchan.send_pubkey(nick, self.kp.hex_pk())
Пример #6
0
	def __init__(self, msgchan, wallet, db, cj_amount, orders, input_utxos, my_cj_addr,
		my_change_addr, total_txfee, finishcallback, choose_orders_recover, auth_addr=None):
		'''
		if my_change is None then there wont be a change address
		thats used if you want to entirely coinjoin one utxo with no change left over
		orders is the orders you want to fill {'counterpartynick': oid, 'cp2': oid2}
		'''
		debug('starting cj to ' + str(my_cj_addr) + ' with change at ' + str(my_change_addr))
		#parameters
		self.msgchan = msgchan
		self.wallet = wallet
		self.db = db
		self.cj_amount = cj_amount
		self.active_orders = dict(orders)
		self.input_utxos = input_utxos
		self.finishcallback = finishcallback
		self.total_txfee = total_txfee
		self.my_cj_addr = my_cj_addr
		self.my_change_addr = my_change_addr
		self.choose_orders_recover = choose_orders_recover
		self.auth_addr = auth_addr
		self.timeout_lock = threading.Condition() #used to wait() and notify()
		#used to restrict access to certain variables across threads
		self.timeout_thread_lock = threading.Condition()
		self.end_timeout_thread = False
		CoinJoinTX.TimeoutThread(self).start()
		#state variables
		self.txid = None
		self.cjfee_total = 0
		self.maker_txfee_contributions = 0
		self.nonrespondants = list(self.active_orders.keys())
		self.all_responded = False
		self.latest_tx = None
		self.utxos = {None: self.input_utxos.keys()} #None means they belong to me
		self.outputs = []
		#create DH keypair on the fly for this Tx object
		self.kp = enc_wrapper.init_keypair()
		self.crypto_boxes = {}
		self.msgchan.fill_orders(self.active_orders, self.cj_amount, self.kp.hex_pk())