forked from witoff/blockparser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
callback.h
75 lines (66 loc) · 5.6 KB
/
callback.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#ifndef __CALLBACK_H__
#define __CALLBACK_H__
struct Block;
#include <vector>
#include <common.h>
#include <option.h>
// Derive from this if you want to add a new command
struct Callback
{
// Housekeeping
Callback();
typedef optparse::OptionParser Parser;
static void showAllHelps(bool longHelp);
static Callback *find(const char *name, bool printList=false);
// Naming, option parsing, construction, etc ...
virtual const char *name( ) const = 0; // Main name for callback
virtual const Parser *optionParser( ) const = 0; // Option parser object for callback
virtual void aliases(std::vector<const char *> &v) const { } // Alternate names for callback
virtual int init(int argc, const char *argv[]) { return 0; } // Called after callback construction, with command line arguments
virtual bool needTXHash( ) const { return false; } // Overload if you need parser to compute TX hashes
// Callback for first, shallow parse -- all blocks are seen, including orphaned ones but aren't parsed
virtual void startMap(const uint8_t *p ) { } // Called when a blockchain file is mapped into memory
virtual void endMap(const uint8_t *p ) { } // Called when a blockchain file is unmapped from memory
virtual void startBlock(const uint8_t *p ) { } // Called when a block is encountered during first pass
virtual void endBlock(const uint8_t *p ) { } // Called when an end of block is encountered during first pass
// Callback for second, deep parse -- only valid blocks are seen, and are parsed in details
virtual void start( const Block *s, const Block *e ) { } // Called when the second parse of the full chain starts
virtual void startTX(const uint8_t *p, const uint8_t *hash) { } // Called when a new TX is encountered
virtual void endTX(const uint8_t *p ) { } // Called when an end of TX is encountered
virtual void startInputs(const uint8_t *p ) { } // Called when the start of a TX's input array is encountered
virtual void endInputs(const uint8_t *p ) { } // Called when the end of a TX's input array is encountered
virtual void startInput(const uint8_t *p ) { } // Called when a TX input is encountered
virtual void endInput(const uint8_t *p ) { } // Called when at the end of a TX input
virtual void startOutputs(const uint8_t *p ) { } // Called when the start of a TX's output array is encountered
virtual void endOutputs(const uint8_t *p ) { } // Called when the end of a TX's output array is encountered
virtual void startOutput(const uint8_t *p ) { } // Called when a TX output is encountered
virtual void startBlock( const Block *b, uint64_t chainSize ) { } // Called when a new block is encountered
virtual void endBlock( const Block *b ) { } // Called when an end of block is encountered
virtual void wrapup( ) { } // Called when the whole chain has been parsed
// Called when an output has been fully parsed
virtual void endOutput(
const uint8_t *p, // Pointer to TX output raw data
uint64_t value, // Number of satoshis on this output
const uint8_t *txHash, // sha256 of the current transaction
uint64_t outputIndex, // Index of this output in the current transaction
const uint8_t *outputScript, // Raw script (challenge to would-be spender) carried by this output
uint64_t outputScriptSize // Byte size of raw script
)
{
}
// Called exactly like startInput, but with a much richer context
virtual void edge(
uint64_t value, // Number of satoshis coming in on this input from upstream transaction
const uint8_t *upTXHash, // sha256 of upstream transaction
uint64_t outputIndex, // Index of output in upstream transaction
const uint8_t *outputScript, // Raw script (challenge to spender) carried by output in upstream transaction
uint64_t outputScriptSize, // Byte size of script carried by output in upstream transaction
const uint8_t *downTXHash, // sha256 of current (downstream) transaction
uint64_t inputIndex, // Index of input in downstream transaction
const uint8_t *inputScript, // Raw script (answer to challenge) carried by input in downstream transaction
uint64_t inputScriptSize // Byte size of script carried by input in downstream transaction
)
{
}
};
#endif // __CALLBACK_H__