MetacoSA / QBitNinja

An Open Source and powerful blockchain API
MIT License
68 stars 42 forks source link

Connecting QBitNinja with Litecoin #85

Open TJvrDev opened 5 years ago

TJvrDev commented 5 years ago

I've successfully setup QBitNinja using Bitcoin Core. I am having trouble configuring with litecoin. The readme just specifies with Bitcoin Core. Is it safe to assume that i'll need to install litecoin core to use the altcoin capabilities with Litecoin? Would that also mean that if I used an altcoin that I would need to use a different component than Bitcoin Core?

NicolasDorier commented 5 years ago

If you want Litecoin, you need Litecoin node software; not bitcon core. Chain should be LTC, the rest should be the same. (I have not tried it though, so let me know how it goes)

TJvrDev commented 5 years ago

I have Litecoin Core [testnet] running in Azure alongside QBitNinja.Listener, but my problem in my app is using clientQBitNinja.GetBalance. The Operations.Count always return 0. The pub key it's using has 10 test coins there and its using that pub key to get the balance. but without this operations count, i'm unable to see the unspentCoins and effectively get the balance.

QBitNinja.Listener will give this output:

QBitNinja.Listener Information: 0 : Start initial indexing QBitNinja.Listener Information: 0 : Handshaking... QBitNinja.Listener Information: 0 : Handshaked QBitNinja.Listener Information: 0 : Current chain at height 864241 QBitNinja.Listener Information: 0 : Dequeuing index jobs Work remaining in the queue : 0 QBitNinja.Listener Information: 0 : Work finished, updating checkpoints QBitNinja.Listener Information: 0 : default/balances... QBitNinja.Listener Information: 0 : default/blocks... QBitNinja.Listener Information: 0 : default/transactions... QBitNinja.Listener Information: 0 : default/wallets... QBitNinja.Listener Information: 0 : default/subscriptions... QBitNinja.Listener Information: 0 : Checkpoints updated QBitNinja.Listener Information: 0 : Initial indexing terminated

If it says initial indexing terminated, will QBitNinja continue to work?

NicolasDorier commented 5 years ago

Please read the doc, after indexing you need: "QBitNinja.Listener.Console.exe --Listen"

NicolasDorier commented 5 years ago

how do you instanciate clientQBitNinja ?

TJvrDev commented 5 years ago

QBitNinjaClient clientQBitNinja = new QBitNinjaClient(NetworkAPI, m_network);

The NetworkAPI is assigned "http://tapi.qbit.ninja/" & m_network is assigned NBitcoin.Altcoins.Litecoin.Instance.Testnet

After going back through the readme I was able to get the Listener.Console.exe up and running. The problem i'm finding is not being able to find operations in the BalanceModel.

NicolasDorier commented 5 years ago

http://tapi.qbit.ninja/ only support BTC you need your to host your own server.

NicolasDorier commented 5 years ago

Follow https://github.com/MetacoSA/QBitNinja#setup-the-front

TJvrDev commented 5 years ago

Ah, ok i've updated the test network to the web address I use for my azure web application. Now when it runs the task to retrieve the balance, there is a bit of a wait. Then it returns this error:

TaskCanceledException: A task was canceled. Rethrow as AggregateException: One or more errors occurred. System.Threading.Tasks.Task.ThrowIfExceptional (System.Boolean includeTaskCanceledExceptions) (at :0) System.Threading.Tasks.Task1[TResult].GetResultCore (System.Boolean waitCompletionNotification) (at <e1a80661d61443feb3dbdaac88eeb776>:0) System.Threading.Tasks.Task1[TResult].get_Result () (at :0) YourBitcoinController.BitCoinController.GetUnspentCoins (NBitcoin.BitcoinAddress _address, System.Boolean _dispatchEvent) (at Assets/YourBitcoinController/Core/Scripts/Controller/BitCoinController.cs:866) YourBitcoinController.BitCoinController.GetBalance (System.String _privateKey, System.Boolean _dispatchEvent) (at Assets/YourBitcoinController/Core/Scripts/Controller/BitCoinController.cs:835) YourBitcoinController.BasicManager.CheckBalanceOriginReal () (at Assets/YourBitcoinController/Core/Scripts/View/BasicManager.cs:297)

I'm testing on Esteban's Unity package for bitcoin for testing then ill make the changes in my app.

Do you think the task is just timing out? I am using a single instance of QBitNinja.Listener.Console without the optional RPCConnectionString.

TJvrDev commented 5 years ago

I'm having trouble binding RPC at my address. I'm also looking into the possibility that by default my VM on Azure may be blocking RPC communication from the default networking settings.

Did you have to set up an inbound port rule to allow access to the connection?

If that isnt the problem then it may be how I have litecoin.conf set up. Is there anything you would recommend changing in this?

I do get a message in the debug log: Binding RPC on address 127.0.0.1 port 19335 failed.

//## //## litecoin.conf configuration file. Lines beginning with # are comments. //##

//# IMPORTANT: do not use the daemon's wallet disablewallet=1

datadir=/ltc

//# Network-related settings:

//# Run on the test network instead of the real lite network. testnet=1

//# Listening mode, enabled by default except when 'connect' is being used. Port 19335 (TestNet4) listen=1

//# //# JSON-RPC options (for controlling a running Litecoin/litecoind process) //#

//# server=1 tells litecoind to accept JSON-RPC commands server=1 //# Accept public REST requests (default: 0) rest=0 //# RPC username or password is not specified, so a cookie is written to the /ltc/testnet4 directory for the CLI to use for auth

NicolasDorier commented 5 years ago

The timeout has nothing to do with this. The front does not connect to RPC. I don't really know how to troubleshoot this. If you can manage to get azure logs for the front it would be good.

TJvrDev commented 5 years ago

It's strange but when I enabled "Application Logging" for the webapp in Azure, it started working. Even after disabling "Application Logging". My app goes through the flow and I get a Transaction Success result from

BroadcastResponse broadcastResponse = _clientQBitNinja.Broadcast(_customerTransaction).Result;

But the wallets and testnet do not reflect the transaction. I did retrieve the web server logs from Azure, ill email them to you.

NicolasDorier commented 5 years ago

please do not email, just copy paste here. What is your server url?

TJvrDev commented 5 years ago

https://alarisbattles.azurewebsites.net

NicolasDorier commented 5 years ago

OK, let's try to solve it, can you try to run the front under visual studio with the same config as the website?

TJvrDev commented 5 years ago

I started running QBitNinja in Visual Studio with the same config as the website.

NicolasDorier commented 5 years ago

Any exception or anything you can notice? You have the same timeout?

TJvrDev commented 5 years ago

When reviewing the logs there were a few exceptions, this was one of them:

System.TimeoutException, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089The client could not finish the operation within specified timeout. at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at NBitcoin.Indexer.IndexerClient.&lt;GetChainChangesUntilFork&gt;d22.MoveNext() at NBitcoin.Indexer.ChainChangeEntryExtensions.UpdateChain(IEnumerable`1 entries, ChainBase chain) at QBitNinja.QBitNinjaDependencyResolver.UpdateChain() at QBitNinja.UpdateChainListener.&lt;Listen&gt;b100(Object ) at System.Threading.TimerQueueTimer.CallCallbackInContext(Object state) at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.TimerQueueTimer.CallCallback() at System.Threading.TimerQueueTimer.Fire() at System.Threading.TimerQueue.FireQueuedTimerCompletion(Object state) at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem() at System.Threading.ThreadPoolWorkQueue.Dispatch() at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback() System.TimeoutException: The client could not finish the operation within specified timeout.

NicolasDorier commented 5 years ago

I should be able to fix that, can you send me your account storage creds by mail?

TJvrDev commented 5 years ago

Sent

NicolasDorier commented 5 years ago

@TJvrDev can you verify that your storage account and your front website reside in the same datacenter ? (region)

TJvrDev commented 5 years ago

It looks like the storage account resides in East US & West US. The website resides in Central. Ill get them in the same region.

TJvrDev commented 5 years ago

Alright I have Web App residing in East US now. I did have to create a new web app but I applied to updated PublishSettings for QBitNinja and republished it.

TJvrDev commented 5 years ago

The new server url is: http://alarisbattlesapp.azurewebsites.net/

NicolasDorier commented 5 years ago

storage account resides in East US & West US a storage account can't live in two different place. It does not seem to have resolved the issue.

I will try something.

NicolasDorier commented 5 years ago

Actually it solved, it. It is not timing out now.

NicolasDorier commented 5 years ago

It is quite slow though... Querying on an address take a while.

NicolasDorier commented 5 years ago

Actually timing out. It does not make sense. What is your machine specification for the front? I am wondering if the server does not get restarted because it uses too much memory or something like this. One sec, I check on my servers.

NicolasDorier commented 5 years ago

Ok so this is my tier for the service plan Basic: 1 Large

TJvrDev commented 5 years ago

My service plan for the web app shows Standard: 1 small. I'll try to change it to match yours.

TJvrDev commented 5 years ago

Before it had: 100 total ACU 1.75 GB memory

Now has: 400 total ACU 7GB memory

NicolasDorier commented 5 years ago

It is still timing out it seems. That is super strange. Trying to replicate it as much as I can.

NicolasDorier commented 5 years ago

Can you get the applications logs on your server at all? Is it still this timeout?