def send_to_address(self, ticker, address, amount, multisig={}): if self.testnet: network = "XTN" else: network = "BTC" if is_address_valid(address) != network: raise INVALID_ADDRESS contract = util.get_contract(self.session, ticker) if not multisig: withdrawal_amount = float(util.quantity_from_wire(contract, amount)) try: result = yield self.bitcoinrpc[ticker].getbalance() except Exception as e: log.err("Unable to get wallet balance: %s" % str(e)) raise e balance = result['result'] if balance >= withdrawal_amount: try: result = yield self.bitcoinrpc[ticker].sendtoaddress(address, withdrawal_amount) txid = result['result'] tx = yield self.bitcoinrpc[ticker].gettransaction(txid) # The fee shows up from gettransaction as a negative number, # but we want a positive number fee = abs(long(round(tx['result']['fee'] * contract.denominator))) except Exception as e: log.err("Unable to send to address: %s" % str(e)) raise e else: raise INSUFFICIENT_FUNDS else: self.bitgo.token = multisig['token'].encode('utf-8') try: yield self.bitgo.unlock(multisig['otp']) except Exception as e: log.err("Unable to unlock multisig") raise OTP_INVALID wallet_id = contract.multisig_wallet_address try: wallet = yield self.bitgo.wallets.get(wallet_id) except Exception as e: log.err("Unable to get wallet details") log.err(e) raise e balance = wallet.balance if balance < amount: raise INSUFFICIENT_FUNDS if not os.path.exists(self.bitgo_private_key_file): raise NO_KEY_FILE else: with open(self.bitgo_private_key_file, "rb") as f: key_data = json.load(f) passphrase = key_data['passphrase'] try: result = yield wallet.sendCoins(address=address, amount=amount, passphrase=passphrase) txid = result['tx'] fee = result['fee'] except Exception as e: log.err("Unable to sendCoins") log.err(e) raise e returnValue({'txid': txid, 'fee': fee})
def quantity_left_ui(self): return util.quantity_from_wire(self.contract, self.quantity_left)
def send_to_address(self, ticker, address, amount, multisig={}): if self.testnet: network = "XTN" else: network = "BTC" if is_address_valid(address) != network: raise INVALID_ADDRESS contract = util.get_contract(self.session, ticker) if not multisig: withdrawal_amount = float(util.quantity_from_wire( contract, amount)) try: result = yield self.bitcoinrpc[ticker].getbalance() except Exception as e: log.err("Unable to get wallet balance: %s" % str(e)) raise e balance = result['result'] if balance >= withdrawal_amount: try: result = yield self.bitcoinrpc[ticker].sendtoaddress( address, withdrawal_amount) txid = result['result'] tx = yield self.bitcoinrpc[ticker].gettransaction(txid) # The fee shows up from gettransaction as a negative number, # but we want a positive number fee = abs( long(round(tx['result']['fee'] * contract.denominator))) except Exception as e: log.err("Unable to send to address: %s" % str(e)) raise e else: raise INSUFFICIENT_FUNDS else: self.bitgo.token = multisig['token'].encode('utf-8') try: yield self.bitgo.unlock(multisig['otp']) except Exception as e: log.err("Unable to unlock multisig") raise OTP_INVALID wallet_id = contract.multisig_wallet_address try: wallet = yield self.bitgo.wallets.get(wallet_id) except Exception as e: log.err("Unable to get wallet details") log.err(e) raise e balance = wallet.balance if balance < amount: raise INSUFFICIENT_FUNDS if not os.path.exists(self.bitgo_private_key_file): raise NO_KEY_FILE else: with open(self.bitgo_private_key_file, "rb") as f: key_data = json.load(f) passphrase = key_data['passphrase'] try: result = yield wallet.sendCoins(address=address, amount=amount, passphrase=passphrase) txid = result['tx'] fee = result['fee'] except Exception as e: log.err("Unable to sendCoins") log.err(e) raise e returnValue({'txid': txid, 'fee': fee})