def test_singleton_yml_reader(self): yml_reader_send = ConfigFileReader() send_url = yml_reader_send.get_rpc_server(currency='btc', wallet='send') log.info(send_url) yml_reader_receive = ConfigFileReader() receive_url = yml_reader_receive.get_rpc_server(currency='btc', wallet='receive') log.info(receive_url) self.assertEqual(id(yml_reader_send), id(yml_reader_receive))
def __init__(self): self.yml_config = ConfigFileReader() self.fee = self.yml_config.get_reserved_fee_for_transferring( currency='btc') self.confirms = self.yml_config.get_min_transfer_confirmations( currency='btc') self.btc_rpc_call = BTCRPCCall(wallet='receive', currency='btc') self.coin_to_be_send_dict = self.__init_dict_of_accounts()
def __init__(self, wallet="receive", currency="btc"): yml_config_reader = ConfigFileReader() url = yml_config_reader.get_rpc_server(currency=currency, wallet=wallet) self.access = AuthServiceProxy(url)
from rest_framework import status from rest_framework.response import Response from rest_framework.views import APIView from bitcoinrpc.authproxy import JSONRPCException from btcrpc.utils import constantutil from btcrpc.utils.btc_rpc_call import BTCRPCCall from btcrpc.utils.config_file_reader import ConfigFileReader from btcrpc.utils.log import get_log from btcrpc.vo import check_multi_receives import errno from socket import error as socket_error log = get_log("CheckMultiAddressesReceive view") yml_config = ConfigFileReader() RISK_LOW_CONFIRMATIONS = yml_config.get_confirmations_mapping_to_risk(currency='btc', risk='low') RISK_MEDIUM_CONFIRMATIONS = yml_config.get_confirmations_mapping_to_risk(currency='btc', risk='medium') RISK_HIGH_CONFIRMATIONS = yml_config.get_confirmations_mapping_to_risk(currency='btc', risk='high') class CheckMultiAddressesReceive(APIView): def post(self, request): log.info(request.data) post_serializers = check_multi_receives.PostParametersSerializer(data=request.data) response_list = [] if post_serializers.is_valid(): log.info(post_serializers.data["transactions"]) transactions = post_serializers.data["transactions"]
def setUp(self): server_config = open(config_file) self.server_map = yaml.safe_load(server_config) self.yml_config = ConfigFileReader()
def post(self, request): global response_serializer post_serializer = transfers_using_sendtoaddress.PostParametersSerializer( data=request.data) yml_config = ConfigFileReader() if post_serializer.is_valid(): transfer_list = post_serializer.data["transfers"] response_list = [] try: btc_rpc_call = BTCRPCCall() is_test_net = constantutil.check_service_is_test_net( btc_rpc_call) for transfer in transfer_list: log.info(transfer) currency = transfer["currency"] txFee = transfer["txFee"] send_amount = transfer["amount"] log.info(send_amount) to_address = yml_config.get_safe_address_to_be_transferred( currency=currency) log.info("%s, %s, %s" % (currency, to_address, send_amount)) to_address_is_valid = (btc_rpc_call.do_validate_address( address=to_address))["isvalid"] log.info("%s" % (to_address_is_valid)) if to_address_is_valid: try: if lock.locked() is False: lock.acquire() btc_rpc_call.set_tx_fee(txFee) send_response_tx_id = btc_rpc_call.send_to_address( address=to_address, amount=send_amount) lock.release() transaction = btc_rpc_call.do_get_transaction( send_response_tx_id) response = \ transfers_using_sendtoaddress.TransferInformationResponse(currency=currency, to_address=to_address, amount=Decimal(str(send_amount)), fee=abs(transaction["fee"]), message="Transfer is done", status="ok", txid=send_response_tx_id) except JSONRPCException as ex: if lock.locked() is True: lock.release() log.error("Error: %s" % ex.error['message']) response = transfers_using_sendtoaddress.TransferInformationResponse( currency=currency, to_address=to_address, amount=Decimal(str(send_amount)), message=ex.error['message'], status="fail", txid="") except (LockTimeoutException, LockException): log.error("Error: %s" % "LockTimeoutException or LockException") response = transfers_using_sendtoaddress.TransferInformationResponse( currency=currency, to_address=to_address, amount=Decimal(str(send_amount)), message="LockTimeoutException or LockException", status="fail", txid="") except (ConnectionError, ServerDown): log.error( "Error: ConnectionError or ServerDown exception" ) response = transfers_using_sendtoaddress.TransferInformationResponse( currency=currency, to_address=to_address, amount=Decimal(str(send_amount)), message= "Error: ConnectionError or ServerDown exception", status="fail", txid="") response_list.append(response.__dict__) else: log.info("do nothing") response = transfers_using_sendtoaddress.TransferInformationResponse( currency=currency, to_address=to_address, amount=Decimal(str(send_amount)), message="to_address is not valid", status="fail", txid="") response_list.append(response.__dict__) log.info(response_list) transfers_response = transfers_using_sendtoaddress.TransfersInformationResponse( transfers=response_list, test=is_test_net) except JSONRPCException as ex: if lock.locked() is True: lock.release() log.error("Error: %s" % ex.error['message']) transfers_response = transfers_using_sendtoaddress.TransfersInformationResponse( transfers=[], test=True, error=1, error_message= "Bitcoin RPC error, check if username and password " "for node is correct. Message from python-bitcoinrpc: " + ex.message) except socket_error as serr: if lock.locked() is True: lock.release() if serr.errno != errno.ECONNREFUSED: transfers_response = transfers_using_sendtoaddress.TransfersInformationResponse( transfers=[], test=True, error=1, error_message="A general socket error was raised.") else: transfers_response = transfers_using_sendtoaddress.TransfersInformationResponse( transfers=[], test=True, error=1, error_message= "Connection refused error, check if the wallet" " node is down.") response_dict = transfers_response.__dict__ response_serializer = transfers_using_sendtoaddress.TransfersInformationResponseSerializer( data=response_dict) if response_serializer.is_valid(): return Response(response_serializer.data, status=status.HTTP_200_OK) else: return Response(response_serializer.errors, status=status.HTTP_406_NOT_ACCEPTABLE) return Response(post_serializer.errors, status=status.HTTP_400_BAD_REQUEST)