MetacoSA / QBitNinja

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

GetBalance is broken #110

Open ChristianOConnor opened 4 years ago

ChristianOConnor commented 4 years ago

When I run

var client = new QBitNinjaClient(network); var balance = await client.GetBalance(address, true); Console.WriteLine(balance.Operations.Count());

It always outputs 0 even though I have sent coins to this testnet address. I kept trying it with multiple testnet address addresses that I filled with bitcoin and it can't find any coins or activity on these addresses. This problem has persisted for about a week now. Before last week the code worked perfectly. Any solutions?

littleAnarchy commented 4 years ago

The system stopped processing new blocks.

NicolasDorier commented 4 years ago

yeah testnet is fucked. I will put it back when I have time,I don't know why.

ChristianOConnor commented 4 years ago

Hey, just checking on the status of the testnet. It appears that the GetBalance function is still broken on the testnet. Is there another testnet API server that we can connect to in the meantime to run QBitNinja functions? Like is there any other public APIs besides "http://tapi.qbit.ninja/?"

NicolasDorier commented 4 years ago

https://smartbit.com.au/

NicolasDorier commented 4 years ago

I want to fix it but I don't have time these days

ChristianOConnor commented 4 years ago

Oh okay cool, can you give a code example. I can't find any documentation on how to get smartbit API to function with QBitNinja. For example when I just put the url into the QBitNinjaClient method it throws an error.

Ex. var client = new QBitNinjaClient("https://smartbit.com.au/", network); var balance = await client.GetBalance(address, true);

It crashes and throws the following error: JsonReaderException: Unexpected character encountered while parsing value:

If possible a code example of how to get new QBitNinjaClient() to work with https://smartbit.com.au/ API would be super helpful.

BTW sidenote I love this project! I'm a big fan of both QBitNinja and NBitcoin. I was really struggling to find a good C# implementation of Bitcoin functionality and QBitNinja and NBitcoin are really intuitive and great! So sorry to be asking a lot in this thread lol.

NicolasDorier commented 4 years ago

Smartbit API has a different API than qbit ninja so this will not work of course.

If you are doing it for learning, what you can do as well is to try NBxplorer (https://programmingblockchain.gitbook.io/programmingblockchain/wallet/web-api)

I did this book relying on qbitninja because it was convenient but for real prod code, I don't advise a full block explorer. Once you understand the concepts of the book, NBXplorer is a breeze to use (easier than QBitnInja) but require you learn the bitcoin concepts of the book.

NicolasDorier commented 4 years ago

I restarted the indexer on testnet, I am not sure if it will fix the situation or not

ChristianOConnor commented 4 years ago

Okay... so after like a 12+ hour day of trying to build a work-around I am almost finished! I query a web API to get uspent transaction outputs and then I can use those transactions as new UTXOs. It took a LOOOONNNG time but I am almost done. I just have one missing piece.

I only have a little bit of code in my app that still uses QBitNinja:

var client = new QBitNinjaClient(network); GetTransactionResponse transactionResponse = await client.GetTransaction(txid); transactionsReceived = transactionResponse.ReceivedCoins

I figured out that all that this call is doing is querying the QBitNinja API (the one that's down right now) at an address like this "http://tapi.qbit.ninja/transactions/470b364cf484bd2b98909b9089e6c9a638c08b413db0f51afe774b07a62da8f3" and getting back JSON data and then adding ".ReceivedCoins" just takes the JSON key ["receivedCoins"] and returns its value like the JSON data here:

[ { "transactionId": "470b364cf484bd2b98909b9089e6c9a638c08b413db0f51afe774b07a62da8f3", "index": 0, "value": 90000, "scriptPubKey": "0014c8a6c3cbc819e1136603a5db926944ea758aea1d", "redeemScript": null }, { "transactionId": "470b364cf484bd2b98909b9089e6c9a638c08b413db0f51afe774b07a62da8f3", "index": 1, "value": 0, "scriptPubKey": "6a40cad96cb1104eb41ce99e40a9203203c792124d02d8cfbe0667679a87bdbc03c091cf3255a27e525be1d969e665e0c11051d1f421565a07be3141692f45ec2398", "redeemScript": null } ]

The only problem I have is that I can't figure out how to turn this data into a List object if I use a third party API to get it. It is EXACTLY the same data as the result of transactionResponse.ReceivedCoins but for some reason I can only get the data to convert to a "string," "List," "JToken," "JObject," or "JArray."

So finally my question is, How do I convert this JSON data that I am able to build with third party APIs into a List object? Is there some function in NBitcoin that I'm not seeing like "transactionResponse.ReceivedCoins.Parse(>>RawJSONDataHere<<)" or something like that?

ChristianOConnor commented 4 years ago

Can you guys please just show me how to convert raw JSON data to an "ICoin." That's all I need to know. I can get the exact same JSON data as from "tapi.qbit.ninja." I just need to know how to Convert the JSON data to an "ICoin," object. Please show me how to do that. Is it like a JsonConvert.DeserializeObject() type of thing?

muteddisk commented 4 years ago

you know. it would have been a lot better if you didn't use azure to store your data. Most people using qbitninja don't realize how slow this is and on top of that when you broadcast transactions, qbitninja returns error 11 unknown or something stupid like this but the transaction actually executed.

Now for running your own qbitninja server you have to get a stupid azure account. Why the hell did you pick this stupid bullshit that limits everyone using your code.

NicolasDorier commented 4 years ago

@muteddisk and @ChristianOConnor I would really advise you to use https://github.com/dgarage/NBXplorer if you can instead of QBitNinja, most project don't need a full block explorer.

muteddisk commented 4 years ago

@muteddisk and @ChristianOConnor I would really advise you to use https://github.com/dgarage/NBXplorer if you can instead of QBitNinja, most project don't need a full block explorer.

Thanks. I'll take a look at it. I decided to go ahead with coding my won stuff to use the API on bitcoin core node. With the time I spent looking for a good solution....I would have been done coding it!

NicolasDorier commented 4 years ago

Depending on what you want to do, relying to bitcoin core node is the best way to go. However, it is quite difficult to use, if you have issues, use NBXplorer.