from decimal import *

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"])
from decimal import Decimal

from btcrpc.utils.log import get_log
from rest_framework import serializers
from btcrpc.utils.chain_enum import ChainEnum

log = get_log(__file__)

class PostParameters(object):

    def __init__(self, api_key="", transfers=[]):
        self.api_key = api_key
        self.transfers = transfers


class TransfersSerializer(serializers.Serializer):
    currency = serializers.CharField(max_length=20)
    amount = serializers.FloatField()
    txFee = serializers.DecimalField(max_digits=16, decimal_places=9, coerce_to_string=False, required=False, default=0.0)
    wallet = serializers.CharField(max_length=20)
    safe_address = serializers.CharField(max_length=128)


class PostParametersSerializer(serializers.Serializer):
    transfers = TransfersSerializer(many=True)


class TransferInformationResponse(object):
    def __init__(self, currency="btc", to_address="", amount=Decimal(0), message="",
                 fee=0.0, status="", txid=""):
        self.currency = currency
Пример #3
0
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.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():
from django.test import TestCase
from btcrpc.decorator.wallet_secure_decorator import unlock_wallet
from btcrpc.utils.log import get_log

__author__ = 'sikamedia'
__Date__ = '2014-09-28'

log = get_log("send digital currency")

@unlock_wallet
def add(x, y):
    return x + y


class WalletDecoratorTestCase(TestCase):

    def setUp(self):
        pass

    def test_unlock_wallet(self):
        log.info(add.__name__)
        log.info(add.__doc__)
        log.info(add.__module__)
        log.info(str(add(1, 2)))
Пример #5
0
from decimal import Decimal
from rest_framework import status
from rest_framework.views import APIView
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

__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:
                log.info(wallet)
                btc_rpc_call = BTCRPCCall(wallet=wallet, currency=currency)
from __future__ import absolute_import
import unittest
from ddt import ddt, data, file_data, unpack
from btcrpc.utils.config_file_reader_v2 import ConfigFileReader
from btcrpc.utils.log import get_log

log = get_log("YAML configuration file reader test")
config_file_reader_v2 = ConfigFileReader("/btcrpc/test/data/test_config_v2.yml")

try:
    import yaml
except ImportError:
    have_YAML_support = False
else:
    have_YAML_support = True
    del yaml

needs_yaml = unittest.skipUnless(
    have_YAML_support, "Need YAML to run this test"
)


class MyList(list):
    pass


def annotated(a, b):
    r = MyList([a, b])
    setattr(r, "__name__", "test_%d_greater_than_%d" % (a, b))
    return r
from btcrpc.utils.config_file_reader import ConfigFileReader
from btcrpc.utils.log import get_log
from django.test import TestCase
import yaml

__author__ = 'sikamedia'
__Date__ = '2014-09-17'

log = get_log("YAML test")
config_file = './btcxblockchainapi/config.yml'
risk_low_confirmations = 6
risk_medium_confirmations = 1
risk_high_confirmations = 0


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']
Пример #8
0
from rest_framework.permissions import IsAdminUser
from rest_framework.response import Response
from rest_framework.views import APIView
#from sherlock import MCLock, LockTimeoutException, LockException
from rest_framework import status

from btcrpc.utils import constantutil
from btcrpc.utils.log import get_log
from btcrpc.vo import send_many_vo
import socket, errno
from socket import error as socket_error
from btcrpc.utils.semaphore import SemaphoreSingleton
from btcrpc.utils.rpc_calls.rpc_instance_generator import RpcGenerator
from btcrpc.utils.chain_enum import ChainEnum

log = get_log("Bitcoin Send Many:")

class BTCSendManyView(APIView):
  permission_classes = (IsAdminUser,)

  def post(self, request):
    chain = ChainEnum.UNKNOWN
    semaphore = SemaphoreSingleton()
    serializer_post = send_many_vo.SendManyPostParametersSerializer(data=request.data)

    if serializer_post.is_valid():
      log.info(serializer_post.data)
      currency = serializer_post.data["currency"]
      wallet = serializer_post.data["wallet"]
      txFee = serializer_post.data["txFee"]
Пример #9
0
from btcrpc.utils.log import get_log

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


from django.core.management.base import BaseCommand, CommandError

logger = get_log("transfer bitcoin")


class Command(BaseCommand):

    help = 'Transfer Bitcoin to a predefined address'
    args = '[address]'

    def handle(self, *args, **options):
        logger.info("This is for a trying")
        logger.info(args)
        if args.__len__() == 0:
            logger.info("Take a look at the address defined in configuration")

        elif args.__len__() == 1:
            logger.info(args)
        else:
            logger.info("Here you can not give more than one address")
from btcrpc.utils.log import get_log

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

from django.core.management.base import BaseCommand, CommandError

logger = get_log("transfer bitcoin")


class Command(BaseCommand):

    help = 'Transfer Bitcoin to a predefined address'
    args = '[address]'

    def handle(self, *args, **options):
        logger.info("This is for a trying")
        logger.info(args)
        if args.__len__() == 0:
            logger.info("Take a look at the address defined in configuration")

        elif args.__len__() == 1:
            logger.info(args)
        else:
            logger.info("Here you can not give more than one address")
from django.contrib.auth.models import User
from rest_framework.test import APIRequestFactory
from rest_framework.test import APIClient
from btcrpc.test.test_settings import USER_NAME, PASSWORD, FROM_ACCOUNT
from btcrpc.utils.log import get_log
from django.test import TestCase

__author__ = 'sikamedia'
__Date__ = '2014-09-19'

log = get_log("web API test - Balance")


class BTCRPCTestCase(TestCase):
    def setUp(self):
        self.factory = APIRequestFactory()
        self.client = APIClient()
        log.info("login...")
        log.info(USER_NAME)
        log.info(PASSWORD)
        self.user = User.objects.create_superuser(USER_NAME,
                                                  email='*****@*****.**',
                                                  password=PASSWORD)
        self.user.save()
        self.login_client = self.client.login(username=USER_NAME,
                                              password=PASSWORD)
        log.info(self.login_client)

    def tearDown(self):
        log.info("log out...")
        #self.client.logout()
Пример #12
0
from django.contrib.auth.models import User
from rest_framework.test import APIRequestFactory
from rest_framework.test import APIClient
from btcrpc.test.test_settings import USER_NAME, PASSWORD, FROM_ACCOUNT
from btcrpc.utils.log import get_log
from django.test import TestCase

__author__ = 'sikamedia'
__Date__ = '2014-09-19'


log = get_log("web API test - Balance")


class BTCRPCTestCase(TestCase):

    def setUp(self):
        self.factory = APIRequestFactory()
        self.client = APIClient()
        log.info("login...")
        log.info(USER_NAME)
        log.info(PASSWORD)
        self.user = User.objects.create_superuser(USER_NAME, email='*****@*****.**', password=PASSWORD)
        self.user.save()
        self.login_client = self.client.login(username=USER_NAME, password=PASSWORD)
        log.info(self.login_client)

    def tearDown(self):
        log.info("log out...")
        #self.client.logout()
from decimal import Decimal

from btcrpc.utils.log import get_log
from rest_framework import serializers

log = get_log(__file__)


class PostParameters(object):
    def __init__(self, api_key="", transfers=[]):
        self.api_key = api_key
        self.transfers = transfers


class TransfersSerializer(serializers.Serializer):
    currency = serializers.CharField(max_length=20)
    amount = serializers.FloatField()
    txFee = serializers.FloatField()


class PostParametersSerializer(serializers.Serializer):
    transfers = TransfersSerializer(many=True)


class TransferInformationResponse(object):
    def __init__(self,
                 currency="btc",
                 to_address="",
                 amount=Decimal(0),
                 message="",
                 fee=0.0,
from bitcoinrpc.authproxy import JSONRPCException
from rest_framework.permissions import IsAdminUser
from rest_framework.response import Response
from rest_framework.views import APIView
from sherlock import MCLock, LockTimeoutException, LockException
from pylibmc import ConnectionError, ServerDown
from rest_framework import status

from btcrpc.utils import constantutil
from btcrpc.utils.btc_rpc_call import BTCRPCCall
from btcrpc.utils.log import get_log
from btcrpc.vo import send_many_vo
import socket, errno
from socket import error as socket_error

log = get_log("Bitcoin Send Many:")

# define a locker for send many with a tx fee
lock = MCLock(__name__)


class BTCSendManyView(APIView):
    permission_classes = (IsAdminUser, )

    def post(self, request):
        serializer_post = send_many_vo.SendManyPostParametersSerializer(
            data=request.data)

        if serializer_post.is_valid():
            log.info(serializer_post.data)
            currency = serializer_post.data["currency"]
Пример #15
0
from decimal import Decimal

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


from btcrpc.utils.log import get_log
from rest_framework import serializers

log = get_log("transfers vo")


class PostParameters(object):

    def __init__(self, api_key="", transfers=[]):
        self.api_key = api_key
        self.transfers = transfers


class TransfersSerializer(serializers.Serializer):
    currency = serializers.CharField(max_length=20)
    amount = serializers.FloatField()
    from_address = serializers.CharField(max_length=128)


class PostParametersSerializer(serializers.Serializer):
    transfers = TransfersSerializer(many=True)


class TransferInformationResponse(object):
    def __init__(self, currency="btc", from_address="", to_address="", amount=Decimal(0), status="", txid=""):
from rest_framework.views import APIView
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: