Skip to content

Commit ba73642

Browse files
committed
Add anyMessage decoded MapOutputs + include protobufs
1 parent eee5786 commit ba73642

File tree

28 files changed

+2522
-32
lines changed

28 files changed

+2522
-32
lines changed

example.js

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
const { Substreams, download, unpack } = require("./");
1+
const { Substreams, download } = require("./");
22

33
// User parameters
4-
const url = "https://github.com/pinax-network/subtivity-substreams/releases/download/v0.2.0/subtivity-ethereum-v0.2.0.spkg";
5-
const outputModule = "map_block_stats";
6-
const startBlockNum = "300000";
4+
const url = "https://github.com/streamingfast/substreams-ethereum-quickstart/releases/download/1.0.0/substreams-ethereum-quickstart-v1.0.0.spkg";
5+
const outputModule = "map_block";
6+
const startBlockNum = "12292922";
77
const stopBlockNum = "+10";
88

99
(async () => {
@@ -16,33 +16,22 @@ const stopBlockNum = "+10";
1616
stopBlockNum,
1717
authorization: process.env.SUBSTREAMS_API_TOKEN
1818
});
19-
20-
// Find Protobuf message types from registry
21-
const { registry } = unpack(spkg);
22-
const BlockStats = registry.findMessage("subtivity.v1.BlockStats");
23-
if ( !BlockStats) throw new Error("Could not find BlockStats message type");
2419

2520
// first block received
2621
substreams.on("start", (cursor, clock) => {
2722
console.log({status: "start", cursor, clock});
2823
});
2924

30-
// on every map output received
31-
substreams.on("mapOutput", (output, clock) => {
32-
const decoded = BlockStats.fromBinary(output.data.value.value);
33-
console.log({decoded, clock});
25+
// stream of decoded MapOutputs
26+
substreams.on("anyMessage", (message) => {
27+
console.log({message});
3428
});
3529

3630
// end of stream
3731
substreams.on("end", (cursor, clock) => {
3832
console.log({status: "end", cursor, clock});
3933
});
4034

41-
// head block time drift
42-
substreams.on("head_block_time_drift", (seconds) => {
43-
console.log({head_block_time_drift: seconds});
44-
});
45-
4635
// start streaming Substream
4736
substreams.start();
4837
})();

examples/subtivity.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ const authorization = process.env.SUBSTREAMS_API_TOKEN;
2020
substreams.on("start", (cursor, clock) => {
2121
console.log({status: "start", cursor, clock});
2222
});
23-
substreams.on("mapOutput", (mapOutput, clock) => {
24-
console.log({mapOutput, clock});
23+
substreams.on("anyMessage", (message, clock) => {
24+
console.log({message, clock});
2525
});
2626
substreams.start();
2727
})();

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "substreams",
33
"description": "Substreams Javascript consumer",
4-
"version": "0.4.2",
4+
"version": "0.5.0",
55
"homepage": "https://github.com/pinax-network/substreams-js",
66
"main": "dist/index.js",
77
"types": "dist/index.d.ts",
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
syntax = "proto3";
2+
3+
package pinax.substreams.sink.prometheus.v1;
4+
5+
// Vector of Prometheus metrics
6+
message PrometheusOperations {
7+
repeated PrometheusOperation operations = 1;
8+
}
9+
10+
message PrometheusOperation {
11+
string name = 1; // Name of the Prometheus metric
12+
map<string, string> labels = 2; // Labels represents a collection of label name -> value mappings.
13+
oneof operation {
14+
GaugeOp gauge = 3;
15+
CounterOp counter = 4;
16+
HistogramOp histogram = 5;
17+
SummaryOp summary = 6;
18+
}
19+
}
20+
21+
message GaugeOp {
22+
enum Operation {
23+
// Protobuf default should not be used, this is used so that the consume can ensure that the value was actually specified
24+
OPERATION_UNSPECIFIED = 0;
25+
// Inc increments the Gauge by 1. Use Add to increment it by arbitrary values.
26+
OPERATION_INC = 1;
27+
// Add adds the given value to the Gauge. (The value can be negative, resulting in a decrease of the Gauge.)
28+
OPERATION_ADD = 2; // float
29+
// Set sets the Gauge to an arbitrary value.
30+
OPERATION_SET = 3; // float
31+
// Dec decrements the Gauge by 1. Use Sub to decrement it by arbitrary values.
32+
OPERATION_DEC = 4;
33+
// Sub subtracts the given value from the Gauge. (The value can be negative, resulting in an increase of the Gauge.)
34+
OPERATION_SUB = 5; // float
35+
// SetToCurrentTime sets the Gauge to the current Unix time in seconds.
36+
OPERATION_SET_TO_CURRENT_TIME = 6;
37+
// Remove metrics for the given label values
38+
OPERATION_REMOVE = 7;
39+
// Reset gauge values
40+
OPERATION_RESET = 8;
41+
}
42+
Operation operation = 1;
43+
double value = 2; // Value (Float) to be used in the operation
44+
}
45+
46+
message CounterOp {
47+
enum Operation {
48+
// Protobuf default should not be used, this is used so that the consume can ensure that the value was actually specified
49+
OPERATION_UNSPECIFIED = 0;
50+
// Increments the Counter by 1.
51+
OPERATION_INC = 1;
52+
// Adds an arbitrary value to a Counter. (Returns an error if the value is < 0.)
53+
OPERATION_ADD = 2; // float
54+
// Remove metrics for the given label values
55+
OPERATION_REMOVE = 7;
56+
// Reset counter values
57+
OPERATION_RESET = 8;
58+
}
59+
Operation operation = 1;
60+
double value = 2; // Value (Float) to be used in the operation
61+
}
62+
63+
message SummaryOp {
64+
enum Operation {
65+
// Protobuf default should not be used, this is used so that the consume can ensure that the value was actually specified
66+
OPERATION_UNSPECIFIED = 0;
67+
// Observe adds a single observation to the summary.
68+
// Observations are usually positive or zero.
69+
// Negative observations are accepted but prevent current versions of Prometheus from properly detecting counter resets in the sum of observations
70+
OPERATION_OBSERVE = 1;
71+
// Start a timer. Calling the returned function will observe the duration in seconds in the summary.
72+
OPERATION_START_TIMER = 2;
73+
// Remove metrics for the given label values
74+
OPERATION_REMOVE = 7;
75+
// Reset counter values
76+
OPERATION_RESET = 8;
77+
}
78+
Operation operation = 1;
79+
double value = 2; // Value (Float) to be used in the operation
80+
}
81+
82+
message HistogramOp {
83+
enum Operation {
84+
// Protobuf default should not be used, this is used so that the consume can ensure that the value was actually specified
85+
OPERATION_UNSPECIFIED = 0;
86+
// Observe adds a single observation to the histogram.
87+
// Observations are usually positive or zero.
88+
// Negative observations are accepted but prevent current versions of Prometheus from properly detecting counter resets in the sum of observations.
89+
OPERATION_OBSERVE = 1;
90+
// Start a timer. Calling the returned function will observe the duration in seconds in the summary.
91+
OPERATION_START_TIMER = 2;
92+
// Initialize the metrics for the given combination of labels to zero
93+
OPERATION_ZERO = 3;
94+
// Remove metrics for the given label values
95+
OPERATION_REMOVE = 7;
96+
// Reset counter values
97+
OPERATION_RESET = 8;
98+
}
99+
Operation operation = 1;
100+
double value = 2; // Value (Float) to be used in the operation
101+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
syntax = "proto3";
2+
3+
package pinax.substreams.sink.winston.v1;
4+
5+
option go_package = "github.com/pinax-network/substreams-sink-winston/pb;pbkv";
6+
7+
// Vector of Winston Logging messages
8+
message LoggerOperations {
9+
repeated LoggerOperation operations = 1;
10+
}
11+
12+
message LoggerOperation {
13+
string service = 1;
14+
LoggingLevels level = 2;
15+
string message = 3;
16+
map<string, string> meta = 4;
17+
}
18+
19+
// Each level is given a specific integer priority.
20+
// The higher the priority the more important the message is considered to be,
21+
// and the lower the corresponding integer priority.
22+
// For example, as specified exactly in RFC5424 the syslog levels are prioritized from 0 to 7 (highest to lowest).
23+
enum LoggingLevels {
24+
// UNSPECIFIED = 0; // Unspecified: default value
25+
EMERG = 0; // Emergency: system is unusable
26+
ALERT = 1; // Alert: action must be taken immediately
27+
CRIT = 2; // Critical: critical conditions
28+
ERROR = 3; // Error: error conditions
29+
WARNING = 4; // Warning: warning conditions
30+
NOTICE = 5; // Notice: normal but significant condition
31+
INFO = 6; // Informational: informational messages
32+
DEBUG = 7; // Debug: debug-level messages
33+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
syntax = "proto3";
2+
3+
package sf.substreams.sink.database.v1;
4+
5+
option go_package = "github.com/streamingfast/substreams-database-change/pb;pbdatabase";
6+
7+
message DatabaseChanges {
8+
repeated TableChange table_changes = 1;
9+
}
10+
11+
message TableChange {
12+
string table = 1;
13+
string pk = 2;
14+
uint64 ordinal = 3;
15+
enum Operation {
16+
UNSET = 0; // Protobuf default should not be used, this is used so that the consume can ensure that the value was actually specified
17+
CREATE = 1;
18+
UPDATE = 2;
19+
DELETE = 3;
20+
}
21+
Operation operation = 4;
22+
repeated Field fields = 5;
23+
}
24+
25+
message Field {
26+
string name = 1;
27+
string new_value = 2;
28+
string old_value = 3;
29+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
syntax = "proto3";
2+
3+
package sf.substreams.entity.v1;
4+
5+
message EntityChanges {
6+
repeated EntityChange entity_changes = 5;
7+
}
8+
9+
message EntityChange {
10+
string entity = 1;
11+
string id = 2;
12+
uint64 ordinal = 3;
13+
enum Operation {
14+
UNSET = 0; // Protobuf default should not be used, this is used so that the consume can ensure that the value was actually specified
15+
CREATE = 1;
16+
UPDATE = 2;
17+
DELETE = 3;
18+
}
19+
Operation operation = 4;
20+
repeated Field fields = 5;
21+
}
22+
23+
message Value {
24+
oneof typed {
25+
int32 int32 = 1;
26+
string bigdecimal = 2;
27+
string bigint = 3;
28+
string string = 4;
29+
string bytes = 5;
30+
bool bool = 6;
31+
32+
//reserved 7 to 9; // For future types
33+
34+
Array array = 10;
35+
}
36+
}
37+
38+
message Array {
39+
repeated Value value = 1;
40+
}
41+
42+
message Field {
43+
string name = 1;
44+
optional Value new_value = 3;
45+
optional Value old_value = 5;
46+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
syntax = "proto3";
2+
3+
package sf.substreams.sink.kv.v1;
4+
5+
option go_package = "github.com/streamingfast/substreams-sink-kv/pb;pbkv";
6+
7+
message KVOperations {
8+
repeated KVOperation operations = 1;
9+
}
10+
11+
message KVOperation {
12+
string key = 1;
13+
bytes value = 2;
14+
uint64 ordinal = 3;
15+
enum Type {
16+
UNSET = 0; // Protobuf default should not be used, this is used so that the consume can ensure that the value was actually specified
17+
SET = 1;
18+
DELETE = 2;
19+
}
20+
Type type = 4;
21+
}

0 commit comments

Comments
 (0)