Beispiel #1
0
    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()
Beispiel #2
0
    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 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))
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.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
from btcrpc.utils.rpc_calls.rpc_call import RPCCall
from btcrpc.utils.rpc_calls.rpc_instance_generator import RpcGenerator
from btcrpc.utils.chain_enum import ChainEnum

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):
        chain = ChainEnum.UNKNOWN
        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"])
Beispiel #5
0
__author__ = 'sikamedia'
__Date__ = '2015-01-19'

from btcrpc.utils.config_file_reader import ConfigFileReader

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')
 def setUp(self):
     server_config = open(config_file)
     self.server_map = yaml.safe_load(server_config)
     self.yml_config = ConfigFileReader()
class YAMLTestCase(TestCase):

    def setUp(self):
        server_config = open(config_file)
        self.server_map = yaml.safe_load(server_config)
        self.yml_config = ConfigFileReader()

    def test_read_yml(self):

        log.info(self.server_map)
        expect_url = "http://*****:*****@127.0.0.1:18332"
        btc_servers = self.server_map['btc']
        wallets = btc_servers['wallets']
        receive = btc_servers['receive']
        username = receive['username']
        key = receive['key']
        protocol = receive['protocol']
        host = receive['host']
        port = receive['port']
        url_list = list()
        url_list.append(protocol)
        url_list.append('://')
        url_list.append(username)
        url_list.append(':')
        url_list.append(key)
        url_list.append('@')
        url_list.append(host)
        url_list.append(':')
        url_list.append(str(port))

        url = ''.join(url_list)
        log.info(url)
        log.info("wallets are %s ." % wallets)
        self.assertEquals(url, expect_url)

    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 test_get_min_transfer_confirmations(self):
        min_transfer_confirmations = self.yml_config.get_min_transfer_confirmations(currency='btc')
        log.info('Minimum transfer confirmations : %d' % min_transfer_confirmations)

    def test_get_min_transfer_amount(self):
        min_transfer_amount = self.yml_config.get_min_transfer_amount(currency='btc')
        log.info('Minimum transfer amount : %f' % min_transfer_amount)

    def test_get_safe_address_to_be_transferred(self):
        safe_address_to_be_transferred = self.yml_config.get_safe_address_to_be_transferred(currency='btc')
        log.info('Safe address to be transferred : %s' % safe_address_to_be_transferred)

    def test_get_risk_confirmations_low(self):
        risk_low_confirmations_from_config = self.yml_config.get_confirmations_mapping_to_risk(currency='btc',
                                                                                               risk='low')
        self.assertEqual(risk_low_confirmations, risk_low_confirmations_from_config)

    def test_get_risk_confirmations_medium(self):
        risk_low_confirmations_from_config = self.yml_config.get_confirmations_mapping_to_risk(currency='btc',
                                                                                               risk='medium')
        self.assertEqual(risk_medium_confirmations, risk_low_confirmations_from_config)

    def test_get_risk_confirmations_high(self):
        risk_low_confirmations_from_config = self.yml_config.get_confirmations_mapping_to_risk(currency='btc',
                                                                                               risk='high')
        self.assertEqual(risk_high_confirmations, risk_low_confirmations_from_config)
from btcrpc.utils.log import get_log
from btcrpc.vo import check_multi_receives
from rest_framework.response import Response
from rest_framework import status
from decimal import *
import simplejson
from rest_framework.parsers import JSONParser
from StringIO import StringIO
from django.http import HttpResponse

__author__ = "sikamedia"
__Date__ = "2014-09-11"


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)
        btc_rpc_call = BTCRPCCall()
        is_test_net = constantutil.check_service_is_test_net(btc_rpc_call)

        response_list = []
        if post_serializers.is_valid():
            log.info(post_serializers.data["transactions"])
Beispiel #9
0
    def post(self, request):
        post_serializer = transfers.PostParametersSerializer(data=request.DATA)

        # from_account_balance = btc_rpc_call.get_balance(account=serializer)

        yml_config = ConfigFileReader()


        if post_serializer.is_valid():

            btc_rpc_call = BTCRPCCall()
            is_test_net = constantutil.check_service_is_test_net(btc_rpc_call)

            transfer_list = post_serializer.data["transfers"]
            log.info(is_test_net)
            response_list = []


            for transfer in transfer_list:
                log.info(transfer)
                currency = transfer["currency"]
                from_address = transfer["from_address"]

                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, %s" % (currency, from_address,  to_address, send_amount))
                #log.info("%s %s" % currency, from_address)

                from_address_is_valid = (btc_rpc_call.do_validate_address(address=from_address))["isvalid"]
                to_address_is_valid = (btc_rpc_call.do_validate_address(address=to_address))["isvalid"]

                log.info("%s, %s" % (from_address_is_valid, to_address_is_valid))

                if from_address_is_valid and to_address_is_valid:
                    try:

                        send_response_tx_id = btc_rpc_call.send_from(from_account=from_address,
                                                                     to_address=to_address, amount=send_amount)

                        response = transfers.TransferInformationResponse(currency=currency,
                                                                         from_address=from_address,
                                                                         to_address=to_address,
                                                                         amount=Decimal(str(send_amount)),
                                                                         status="ok",
                                                                         txid=send_response_tx_id)

                        response_list.append(response.__dict__)
                    except JSONRPCException as ex:
                        log.info("Error: %s" % ex.error['message'])
                        response = transfers.TransferInformationResponse(currency=currency,
                                                                         from_address=from_address,
                                                                         to_address=to_address,
                                                                         amount=Decimal(str(send_amount)),
                                                                         status="fail",
                                                                         txid="")
                        response_list.append(response.__dict__)

                else:
                    log.info("do nothing")
                    response = transfers.TransferInformationResponse(currency=currency,
                                                                     from_address=from_address,
                                                                     to_address=to_address,
                                                                     amount=Decimal(str(send_amount)),
                                                                     status="fail",
                                                                     txid="")
                    response_list.append(response.__dict__)

            log.info(response_list)

            transfers_response = transfers.TransfersInformationResponse(transfers=response_list, test=is_test_net)

            response_dict = transfers_response.__dict__

        response_serializer = transfers.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_serializers.errors, status=status.HTTP_400_BAD_REQUEST)
Beispiel #10
0
  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)
    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)
    def post(self, request):
        chain = ChainEnum.UNKNOWN
        semaphore = SemaphoreSingleton()
        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:
                if semaphore.acquire_if_released():
                    for transfer in transfer_list:
                        log.info(transfer)
                        currency = transfer["currency"]
                        txFee = transfer["txFee"]
                        send_amount = transfer["amount"]
                        wallet = transfer["wallet"]
                        safe_address = transfer["safe_address"]
                        log.info(send_amount)
                        rpc_call = RpcGenerator.get_rpc_instance(wallet=wallet, currency=currency)
                        chain = constantutil.check_service_chain(rpc_call)
                        to_address = yml_config.get_safe_address_to_be_transferred(currency=currency, safe_address=safe_address)

                        log.info("%s, %s, %s" % (currency, to_address, send_amount))

                        to_address_is_valid = (rpc_call.do_validate_address(address=to_address))["isvalid"]

                        log.info("%s" % (to_address_is_valid))
                        if to_address_is_valid:
                            try:
                                rpc_call.set_tx_fee(txFee)
                                send_response_tx_id = rpc_call.send_to_address(address=to_address,
                                                                                   amount=send_amount)

                                transaction = 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:
                                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="")

                            response_list.append(response.__dict__)

                        else:
                            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)
                    semaphore.release()
                    transaction_has_failed = constantutil.check_for_failed_transactions(response_list)
                    if(transaction_has_failed):
                        transfers_response = transfers_using_sendtoaddress.TransfersInformationResponse(
                            transfers=response_list,
                            chain=chain.value,
                            error=1,
                            error_message="One or more transactions failed")
                    else:
                        transfers_response = transfers_using_sendtoaddress.TransfersInformationResponse(transfers=response_list,
                                                                                                    chain=chain.value)
                else:
                    transfers_response = transfers_using_sendtoaddress.TransfersInformationResponse(
                        transfers=response_list, chain=chain.value, error=1, error_message="Semaphore is already acquired, wait until semaphore"
                                                                        " is released.")
            except ValueError as ex:
                semaphore.release()
                log.error("Error: %s" % str(ex))
                transfers_response = transfers_using_sendtoaddress.TransfersInformationResponse(
                  transfers=response_list, chain=chain.value, error=1,
                  error_message=str(ex))
            except JSONRPCException as ex:
                semaphore.release()
                log.error("Error: %s" % ex.error['message'])
                transfers_response = transfers_using_sendtoaddress.TransfersInformationResponse(
                    transfers=response_list, chain=chain.value, 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:
                semaphore.release()
                if serr.errno != errno.ECONNREFUSED:
                    transfers_response = transfers_using_sendtoaddress.TransfersInformationResponse(
                        transfers=response_list, chain=chain.value, error=1, error_message="A general socket error was raised.")
                else:
                    transfers_response = transfers_using_sendtoaddress.TransfersInformationResponse(
                        transfers=response_list, chain=chain.value, error=1, error_message="Connection refused error, check if the wallet"
                                                                        " node is down.")
            except BaseException as ex:
                semaphore.release()
                log.error("Error: %s" % str(ex))
                error_message = "An exception was raised. Error message: " + str(ex)
                transfers_response = transfers_using_sendtoaddress.TransfersInformationResponse(
                    transfers=response_list, chain=chain.value, error=1,
                    error_message=error_message)

            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)
Beispiel #13
0
class BTCCurrencyTransfer(AbstractDigitalCurrencyTransfer):
    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 __get_total_amount_in_wallet(self):

        if self.coin_to_be_send_dict.values():
            return reduce(lambda (coin_value), y: coin_value + y,
                          self.coin_to_be_send_dict.values())
        else:
            return 0

    def __init_dict_of_accounts(self):

        lists_received_by_account = self.btc_rpc_call.list_accounts(
            self.confirms)

        dict_coin_to_be_send = {}

        for received_account, amount in lists_received_by_account.iteritems():

            amount_balance = self.btc_rpc_call.get_balance(
                received_account, self.confirms)

            if amount_balance > 0:
                dict_coin_to_be_send[received_account] = amount_balance

            if amount_balance < 0:
                logger_file.error("Minus value is in the account %s ",
                                  received_account)
                raise SystemExit("Minus value is in an account!!")

        return dict_coin_to_be_send

    def __create_an_address_with_account_assigned(self):

        new_address = self.btc_rpc_call.do_get_new_address()
        self.btc_rpc_call.do_set_account(new_address, new_address)
        return new_address

    def main(self):

        min_transfer = self.yml_config.get_min_transfer_amount(currency='btc')

        total_amount = self.__get_total_amount_in_wallet()
        balance_amount = (self.btc_rpc_call.do_getinfo())['balance']

        amount_thresh = abs(balance_amount - total_amount)

        if amount_thresh > 0.0001:
            logger_file.error(
                "%d confirmed amount %s  != the total receiving balance %s, need more confirms",
                int(self.confirms), total_amount, balance_amount)

        logger_file.info("Total amount of coins to be transfer: %f" %
                         total_amount)

        if total_amount >= min_transfer:
            logger_file.info("Init transferring...")
            logger_file.info(
                "Creating a temporary address for moving coins...")
            btc_account = self.__create_an_address_with_account_assigned()
            logger_file.info("Starting to move coins to %s", btc_account)

            for received_account, amount in self.coin_to_be_send_dict.iteritems(
            ):
                """
                logger_file.info("%s, %s, %f", received_account,
                                 self.btc_rpc_call.get_addresses_by_account(received_account), amount)
                """
                if self.btc_rpc_call.move(received_account, btc_account,
                                          float(amount)):
                    pass
                else:
                    logger_file.error("Fail to move coins to from %s to %s!",
                                      received_account, btc_account)

            send_to_address = self.yml_config.get_safe_address_to_be_transferred(
                currency='btc')

            amount_to_transfer = float(total_amount) - float(self.fee)

            logger_file.info(
                "Starting transferring %f coins to address: %s from account: %s",
                amount_to_transfer, send_to_address, btc_account)

            self.btc_rpc_call.send_from(btc_account, send_to_address,
                                        amount_to_transfer)
            logger_file.info("Transfer is done")
        else:
            logger_file.info("It is not ready to do the coin transferring!")

    def main_test(self):

        total_amount = self.__get_total_amount_in_wallet()
        logger_file.info(total_amount)

        balance_amount = (self.btc_rpc_call.do_getinfo())['balance']
        logger_file.info(balance_amount)

        logger_file.info(len(self.coin_to_be_send_dict))

        for received_account, amount in self.coin_to_be_send_dict.iteritems():
            logger_file.info("account: %s, amount: %f", received_account,
                             amount)
Beispiel #14
0
class BTCCurrencyTransfer(AbstractDigitalCurrencyTransfer):

    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 __get_total_amount_in_wallet(self):

        if self.coin_to_be_send_dict.values():
            return reduce(lambda (coin_value), y: coin_value + y, self.coin_to_be_send_dict.values())
        else:
            return 0

    def __init_dict_of_accounts(self):

        lists_received_by_account = self.btc_rpc_call.list_accounts(self.confirms)

        dict_coin_to_be_send = {}

        for received_account, amount in lists_received_by_account.iteritems():

            amount_balance = self.btc_rpc_call.get_balance(received_account, self.confirms)

            if amount_balance > 0:
                dict_coin_to_be_send[received_account] = amount_balance

            if amount_balance < 0:
                logger_file.error("Minus value is in the account %s ", received_account)
                raise SystemExit("Minus value is in an account!!")

        return dict_coin_to_be_send

    def __create_an_address_with_account_assigned(self):

        new_address = self.btc_rpc_call.do_get_new_address()
        self.btc_rpc_call.do_set_account(new_address, new_address)
        return new_address

    def main(self):

        min_transfer = self.yml_config.get_min_transfer_amount(currency='btc')

        total_amount = self.__get_total_amount_in_wallet()
        balance_amount = (self.btc_rpc_call.do_getinfo())['balance']

        amount_thresh = abs(balance_amount - total_amount)

        if amount_thresh > 0.0001:
            logger_file.error("%d confirmed amount %s  != the total receiving balance %s, need more confirms",
                              int(self.confirms), total_amount, balance_amount)

        logger_file.info("Total amount of coins to be transfer: %f" % total_amount)

        if total_amount >= min_transfer:
            logger_file.info("Init transferring...")
            logger_file.info("Creating a temporary address for moving coins...")
            btc_account = self.__create_an_address_with_account_assigned()
            logger_file.info("Starting to move coins to %s", btc_account)

            for received_account, amount in self.coin_to_be_send_dict.iteritems():
                """
                logger_file.info("%s, %s, %f", received_account,
                                 self.btc_rpc_call.get_addresses_by_account(received_account), amount)
                """
                if self.btc_rpc_call.move(received_account, btc_account, float(amount)):
                    pass
                else:
                    logger_file.error("Fail to move coins to from %s to %s!", received_account, btc_account)

            send_to_address = self.yml_config.get_safe_address_to_be_transferred(currency='btc')

            amount_to_transfer = float(total_amount) - float(self.fee)

            logger_file.info("Starting transferring %f coins to address: %s from account: %s", amount_to_transfer,
                             send_to_address, btc_account)

            self.btc_rpc_call.send_from(btc_account, send_to_address, amount_to_transfer)
            logger_file.info("Transfer is done")
        else:
            logger_file.info("It is not ready to do the coin transferring!")

    def main_test(self):

        total_amount = self.__get_total_amount_in_wallet()
        logger_file.info(total_amount)

        balance_amount = (self.btc_rpc_call.do_getinfo())['balance']
        logger_file.info(balance_amount)

        logger_file.info(len(self.coin_to_be_send_dict))

        for received_account, amount in self.coin_to_be_send_dict.iteritems():
            logger_file.info("account: %s, amount: %f", received_account, amount)
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"]
__author__ = 'sikamedia'
__Date__ = '2015-01-19'

from btcrpc.utils.config_file_reader import ConfigFileReader


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')
Beispiel #17
0
    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.response import Response
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 wallet_balance
from pylibmc import ConnectionError, ServerDown
import errno
from bitcoinrpc.authproxy import JSONRPCException
from socket import error as socket_error

__author__ = 'sikamedia'
__Date__ = '2015-01-18'

log = get_log("CheckWalletsBalance view")
yml_config = ConfigFileReader()


class CheckWalletsBalance(APIView):
    def post(self, request):
        post_serializers = wallet_balance.GetWalletBalancePostParameterSerializer(
            data=request.data)

        wallet_balance_response_list = []
        if post_serializers.is_valid():
            currency = post_serializers.data["currency"]
            wallet_list = yml_config.get_wallet_list(currency)
            log.info(wallet_list)
            for wallet in wallet_list:
                try:
                    log.info(wallet)