def start_encryption(self, nick, maker_pk): if nick not in self.active_orders.keys(): raise Exception("Counterparty not part of this transaction.") self.crypto_boxes[nick] = [maker_pk, enc_wrapper.as_init_encryption(\ self.kp, enc_wrapper.init_pubkey(maker_pk))] #send authorisation request my_btc_addr = self.input_utxos.itervalues().next()['address'] my_btc_priv = self.wallet.get_key_from_addr(my_btc_addr) my_btc_pub = btc.privtopub(my_btc_priv) my_btc_sig = btc.ecdsa_sign(self.kp.hex_pk(), my_btc_priv) self.msgchan.send_auth(nick, my_btc_pub, my_btc_sig)
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())
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())