Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: coder0x15 on November 09, 2016, 10:35:15 AM



Title: Block parsing and getting values.
Post by: coder0x15 on November 09, 2016, 10:35:15 AM
Being still very novice in the subject, there was a question about parsing blocks.
I understand that the block contains the transaction, each containing the inputs and outputs.
Outputs include the Value is Satoshi (8 bytes) and Address (20 bytes or 32 bytes ripemd160 publicKey).
Question. How to get a list of the form [Address1, Value1], [Address2, Value2] ... and so on, after parsing few blk00*.dat files?
It is clear how to add ballance for each address. But how to subtract?
It is also clear that value of the the transaction outputs is equal to the sum of the inputs. But this is only an indirect indication.
Prompt where to dig. How do I get this information?


Title: Re: Block parsing and getting values.
Post by: shorena on November 09, 2016, 10:41:49 AM
Being still very novice in the subject, there was a question about parsing blocks.
I understand that the block contains the transaction, each containing the inputs and outputs.
Outputs include the Value is Satoshi (8 bytes) and Address (20 bytes or 32 bytes ripemd160 publicKey).
Question. How to get a list of the form [Address1, Value1], [Address2, Value2] ... and so on, after parsing few blk00*.dat files?
It is clear how to add ballance for each address. But how to subtract?
It is also clear that value of the the transaction outputs is equal to the sum of the inputs. But this is only an indirect indication.
Prompt where to dig. How do I get this information?


Have you tried asking bitcoin core instead of the files directly?


Title: Re: Block parsing and getting values.
Post by: sophia martin on November 09, 2016, 11:00:29 AM
Looks Like
var lastReading = 0
is defined inside a class (better add context code to know where it is defined). If that is the case, you're probably executing your block / closure in a different thread. So:

you set lastReading = 0
you launch some time-consuming task in another thread. The main thread (or the thread running that code) continues executing immediately. At the end of the block, you assign lastReading.
if you check lastReading just after the block, nothing changes (https://mystyleportal.blogspot.com/). Still == 0. That's because Main thread executes immediately and lastReading hasn't changed.
I'd better call a method to update lastReading at the end of the block:
var lastReading = 0

Query.getFirstObjectInBackgroundWithBlock(

    {(data:PFObject?,error:NSError?) -> Void in

    var dataEntry = data!

    var Reading: AnyObject! = dataEntry["reading"]!

    self.updatelastReading(Reading.integerValue)
})