bitcoind_log_parser/log_line/log_message/mod.rs
1mod message;
2mod new_outbound_peer_connected_message;
3mod new_pow_valid_block_message;
4mod parse_error;
5mod parse_result;
6mod transaction_added_to_mempool_message;
7use message::Message;
8use new_outbound_peer_connected_message::NewOutboundPeerConnectedMessage;
9use new_pow_valid_block_message::NewPoWValidBlockMessage;
10use parse_error::ParseError;
11use transaction_added_to_mempool_message::TransactionAddedToMempoolMessage;
12
13#[derive(Debug)]
14pub enum LogMessage {
15 Unknown { raw: String },
16 NewOutboundPeerConnected(NewOutboundPeerConnectedMessage), // https://github.com/bitcoin/bitcoin/blob/87d012324afa285221073540781295f1b7381a15/src/net_processing.cpp#L2992
17 UpdateTip, // https://github.com/bitcoin/bitcoin/blob/a7f3479ba3fda4c9fb29bd7080165744c02ee921/src/validation.cpp#L2504
18 FlushStateToDisk, // https://github.com/bitcoin/bitcoin/blob/a7f3479ba3fda4c9fb29bd7080165744c02ee921/src/validation.cpp#L2426
19 AssumingAncestorOfBlockHasValidSignatures, // https://github.com/bitcoin/bitcoin/blob/a7f3479ba3fda4c9fb29bd7080165744c02ee921/src/init.cpp#L917
20 P2pPeersAvailableSkippedDnsSeeding, // https://github.com/bitcoin/bitcoin/blob/d571cf2d2421c6f8efb2b61ca844034eaf230945/src/net.cpp#L1445
21 ThreadStart, // https://github.com/bitcoin/bitcoin/blob/2e30e328a7a46e0405664fd0cb31d971171f71d1/src/util/thread.cpp#L17
22 ThreadExit, // https://github.com/bitcoin/bitcoin/blob/2e30e328a7a46e0405664fd0cb31d971171f71d1/src/util/thread.cpp#L19
23 ImportedMempoolTransactionsFromDisk, // https://github.com/bitcoin/bitcoin/blob/a7f3479ba3fda4c9fb29bd7080165744c02ee921/src/validation.cpp#L4723
24 InitMessage, // https://github.com/bitcoin/bitcoin/blob/38c63e3683746774d3ddc60e32aa33af20573473/src/noui.cpp#L56
25 WaitingBeforeQueryingDnsSeeds, // https://github.com/bitcoin/bitcoin/blob/d571cf2d2421c6f8efb2b61ca844034eaf230945/src/net.cpp#L1423
26 BlockRelayOnlyAnchorsWillBeTriedForConnections, // https://github.com/bitcoin/bitcoin/blob/d571cf2d2421c6f8efb2b61ca844034eaf230945/src/net.cpp#L2284
27 TransactionAddedToMempool(TransactionAddedToMempoolMessage), // https://github.com/bitcoin/bitcoin/blob/66e3b16b8b1033414f843058f360e22b725d89c5/src/validationinterface.cpp#L209
28 NewPoWValidBlock(NewPoWValidBlockMessage), // https://github.com/bitcoin/bitcoin/blob/66e3b16b8b1033414f843058f360e22b725d89c5/src/validationinterface.cpp#L257
29 // DOCS about inv: https://developer.bitcoin.org/reference/p2p_networking.html#inv
30 GotInvTx, // https://github.com/bitcoin/bitcoin/blob/948f5ba6363fcc64f95fed3f04dbda3d50d61827/src/net_processing.cpp#L3237 OR https://github.com/bitcoin/bitcoin/blob/948f5ba6363fcc64f95fed3f04dbda3d50d61827/src/net_processing.cpp#L3256
31 GotInvWtx,
32}
33
34impl LogMessage {
35 pub fn parse(raw_log_message: String) -> Result<Self, ParseError> {
36 if NewOutboundPeerConnectedMessage::is_valid(&raw_log_message) {
37 // TODO: Switch this to return a Result, instead of an Option.
38 let nopcm = NewOutboundPeerConnectedMessage::parse(&raw_log_message);
39 match nopcm {
40 Ok(n) => Ok(Self::NewOutboundPeerConnected(n)),
41 Err(err) => Err(err),
42 }
43 } else if TransactionAddedToMempoolMessage::is_valid(&raw_log_message) {
44 let tatmp = TransactionAddedToMempoolMessage::parse(&raw_log_message);
45 match tatmp {
46 Ok(t) => Ok(Self::TransactionAddedToMempool(t)),
47 Err(err) => Err(err),
48 }
49 } else if NewPoWValidBlockMessage::is_valid(&raw_log_message) {
50 let npowvbm = NewPoWValidBlockMessage::parse(&raw_log_message);
51 match npowvbm {
52 Ok(t) => Ok(Self::NewPoWValidBlock(t)),
53 Err(err) => Err(err),
54 }
55 } else {
56 Ok(Self::Unknown {
57 raw: raw_log_message,
58 })
59 }
60 }
61}