limpbrains / django-cc

Django wallet for Bitcoin and other cryptocurrencies
MIT License
121 stars 34 forks source link

How i insert this address on a view #17

Closed valentinc94 closed 4 years ago

valentinc94 commented 4 years ago

celery call -b redis:localhost:6379/0 cc.task.refill_addresses_queue

i want to create a address for user how i cant insert this celery task on view i mean call task always return a address how i insert this on view? only call without write it manually

limpbrains commented 4 years ago

Don't run this task in a view. Run it periodically in background. Once in 10 min, for example refill_addresses_queue task gets addresses from you bitcoind and put them into db. Then you create instance of cc.models.Wallet model and call wallet.get_address() method This will attach address to a wallet. Now when you send some money to address and call query_transactions money will be on a wallet balance

valentinc94 commented 4 years ago

What an incredible thank you. Another question from the library. If I put it into production, how can I change satoshis to an andress from my blockchain?

limpbrains commented 4 years ago

Sorry, I don't understand the question. django-cc works only with blockchains based on bitcon source code. So I don't know if it is compatible with your blockchain

valentinc94 commented 4 years ago

But i mean how i transf bitcoin to a this andress

El jue., 5 de mar. de 2020 1:25 a. m., Ivan notifications@github.com escribió:

Sorry, I don't understand the question. django-cc works only with blockchains based on bitcon source code. So I don't know if it is compatible with your blockchain

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/limpbrains/django-cc/issues/17?email_source=notifications&email_token=AMT2IA37OS3FEMTGUUB6U4DRF5AWLA5CNFSM4LAQH3KKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEN34DWQ#issuecomment-595050970, or unsubscribe https://github.com/notifications/unsubscribe-auth/AMT2IAZZKUVPYX4KG6FMPZ3RF5AWLANCNFSM4LAQH3KA .

valentinc94 commented 4 years ago

hello when i use wallet = Wallet.objects.get(id=usuario.my_wallet.id)

transaccion = wallet.withdraw_to_address('254d283e-9c11-4047-997f-434cc031cf77', Decimal('0.01'))

Invalid address, def withdraw_to_address(self, address, amount, description=""): if not validate(address, self.currency.magicbyte): raise ValueError('Invalid address')

why?

valentinc94 commented 4 years ago

even i call transaccion = wallet.withdraw_to_address('254d283e9c114047997f434cc031cf77', Decimal('0.01'))

invalid address :(

limpbrains commented 4 years ago

wallet.withdraw_to_address creates WithdrawTransaction, which sends funds into bitcoin blockchain when you call cc.tasks.process_withdraw_transactions

It is not intended to transfer funds inside the service. Address here should be a a valid bitcoin address

valentinc94 commented 4 years ago

Does that mean that I transfer a bitcoin from here?

How do I want to transfer bitcoin here or within the platform transfer to another user within the platform for example Captura de Pantalla 2020-03-05 a la(s) 3 14 25 p  m

valentinc94 commented 4 years ago

On the other hand I mean internally within the platform with django-cc how could I change another user?

transaccion = wallet.withdraw_to_address('1HkazAUyRjzqpBgZdErEryHaBho3tqu3eH', Decimal('0.00022'))

suposse that is the addres of the user 04cdbb58-5a63-47d4-b038-94d344960794

limpbrains commented 4 years ago

To transfer funds internally, use wallet.transfer wallet1.transfer(1, wallet2, None, 'bla bla bla') Take a look at the source code https://github.com/limpbrains/django-cc/blob/master/cc/models.py It is quite simple and you can find something useful there

valentinc94 commented 4 years ago

If it worked, thank you very much, but I mean let's say how I connect this wallet with the blockchain? I say to be able to validate the transfers with the blockchain

limpbrains commented 4 years ago

wallet.get_address() will give you a bitcoin address. Send bitcoins to it, then cc.tasks.query_transactions that's it

valentinc94 commented 4 years ago

but this address is not valid according of bitcoin :( and how i can use testnet? and bitcoint address looks like i show you in the picture

limpbrains commented 4 years ago

I've remembered. wallet.get_address() returns Wallet model which has address field. So it is wallet.get_address().address

valentinc94 commented 4 years ago

wallet.get_address().address return this 04cdbb58-5a63-47d4-b038-94d344960794 and tell me this addres is invalid

limpbrains commented 4 years ago

I don't know how it is possible that you have address like 04cdbb58-5a63-47d4-b038-94d344960794 Sure it is not a valid address. You didn't tell me, are you using bitcoin ? Have you setup Currency model in django admin ? Does refill_addresses_queue runs without errors ? What's in celery logs during run of refill_addresses_queue ? Try purge database and setup it again.

valentinc94 commented 4 years ago

from cc.models import Currency

currency = Currency.objects.create( label = 'Bitcoin', ticker = 'BTC', api_url = 'http://root:toor@localhost:8332' )

use this for create a new currency? i need yo work with bitcoin

valentinc94 commented 4 years ago

celery call -b redis://localhost:6379/0 wallet.tasks.refill_addresses_queue

got me

[2020-03-09 09:24:15,806: INFO/MainProcess] Received task: wallet.tasks.refill_addresses_queue[48181908-f93c-48c1-a687-0db6253b74c0]
[2020-03-09 09:24:15,817: INFO/ForkPoolWorker-2] Task wallet.tasks.refill_addresses_queue[48181908-f93c-48c1-a687-0db6253b74c0] succeeded in 0.01044358900000475s: None

valentinc94 commented 4 years ago

[2020-03-09 09:49:41,107: ERROR/ForkPoolWorker-2] Task wallet.tasks.refill_addresses_queue[4c1cfbf4-6dc1-4b02-9d8c-6bab67b47b23] raised unexpected: TypeError("unsupported operand type(s) for +: 'NoneType' and 'bytes'") Traceback (most recent call last): File "/Users/administrador/Desktop/Nebula-project/nebula-env/lib/python3.8/site-packages/celery/app/trace.py", line 385, in trace_task R = retval = fun(*args, *kwargs) File "/Users/administrador/Desktop/Nebula-project/nebula-env/lib/python3.8/site-packages/celery/app/trace.py", line 650, in __protected_call__ return self.run(args, **kwargs) File "/Users/administrador/Desktop/nebula/wallet/tasks.py", line 138, in refill_addresses_queue coin = AuthServiceProxy(currency.api_url) File "/Users/administrador/Desktop/Nebula-project/nebula-env/lib/python3.8/site-packages/bitcoinrpc/authproxy.py", line 100, in init authpair = user + b':' + passwd TypeError: unsupported operand type(s) for +: 'NoneType' and 'bytes'

valentinc94 commented 4 years ago

Captura de Pantalla 2020-03-09 a la(s) 9 57 58 a  m

if i use your example with currency got me a invalid address and this got me a error

valentinc94 commented 4 years ago

http://administrador:password@localhost:8080 on api hostname give me

File "/Users/administrador/Desktop/Nebula-project/nebula-env/lib/python3.8/site-packages/bitcoinrpc/authproxy.py", line 186, in _get_response raise JSONRPCException({ bitcoinrpc.authproxy.JSONRPCException: -342: non-JSON HTTP response with '403 Forbidden' from server

limpbrains commented 4 years ago

Do you have bitcoind running on localhost with API accessible at http://root:toor@localhost:8332 ?

valentinc94 commented 4 years ago

nop what is bitcoind ._. can you help me?

valentinc94 commented 4 years ago

Captura de Pantalla 2020-03-10 a la(s) 2 09 20 p  m

valentinc94 commented 4 years ago

Task wallet.tasks.refill_addresses_queue[871c0395-ac05-4c0d-ae98-9131e7431b5e] raised unexpected: <JSONRPCException '-342: non-JSON HTTP response with '401 Unauthorized' from server'> Traceback (most recent call last):

valentinc94 commented 4 years ago

Users/username/Library/Application Support/Bitcoin/bitcoin.conf

y meti los siguientes datos

server=1 testnet=1 rpcuser='username' rpcpassword='my_password'

entre comillas pero sigue dandome el mismo error :(

valentinc94 commented 4 years ago

my currency api url is

http://user:password@localhost:18332/

valentinc94 commented 4 years ago

JSONRPC server handles only POST requests return but celery call -b redis://localhost:6379/0 wallet.tasks.refill_addresses_queue return none when i call this task

limpbrains commented 4 years ago

celery call -b redis://localhost:6379/0 wallet.tasks.refill_addresses_queue return none when i call this task

You need celery server running when you call refill_addresses_queue.

limpbrains commented 4 years ago

If you are running testnet you need to change your Currency model instance. Magic bytes should be "111,196"

valentinc94 commented 4 years ago

Can you give me an email to ask for help in this project and if you like, can you participate?

valentinc94 commented 4 years ago

I have indeed running the server but it keeps returning none

valentinc94 commented 4 years ago

is it valid to use the bitcoin library and do this? my_private_key = random_key()

my_public_key = privtopub(my_private_key)

my_bitcoin_address = pubtoaddr(my_public_key)

address = Address.objects.create(address=my_bitcoin_address, currency=usuario.my_wallet.currency, wallet=usuario.my_wallet)

do you want to participate in this project? it is very important and would help me a lot

limpbrains commented 4 years ago

is it valid to use the bitcoin library and do this? No it is not

Your bitcoin instance keeps the private keys in local wallet.dat django-cc just tracks pairs wallet <-> public address What do you have in celery log when you call wallet.tasks.refill_addresses_queue ?

valentinc94 commented 4 years ago

1) python manage.py runsver 8080 2) redis-server 3) celery worker -A nebula.celery --loglevel=info 4) celery call -b redis:localhost:6379/0 wallet.tasks.refill_addresses_queue

valentinc94 commented 4 years ago

my email es valentincc94m@gmail.com Do you have time to participate in this project? It's very important

limpbrains commented 4 years ago

Add -B to the celery command celery worker -B -A nebula.celery --loglevel=info You need to run not just celery worker, but also celery broker