From fc08c37bec1b02bffd15fa0f8f35c6ae584ae99d Mon Sep 17 00:00:00 2001 From: YaroShkvorets Date: Thu, 23 Mar 2023 12:41:23 -0400 Subject: [PATCH] pomelo substreams --- Cargo.toml | 1 + README.md | 1 + pomelo/Cargo.toml | 23 +++++++++++++++++++++++ pomelo/Makefile | 38 ++++++++++++++++++++++++++++++++++++++ pomelo/README.md | 38 ++++++++++++++++++++++++++++++++++++++ pomelo/src/abi.rs | 20 ++++++++++++++++++++ pomelo/src/lib.rs | 4 ++++ pomelo/src/sinks.rs | 28 ++++++++++++++++++++++++++++ pomelo/src/utils.rs | 2 ++ pomelo/substreams.yaml | 23 +++++++++++++++++++++++ 10 files changed, 178 insertions(+) create mode 100644 pomelo/Cargo.toml create mode 100644 pomelo/Makefile create mode 100644 pomelo/README.md create mode 100644 pomelo/src/abi.rs create mode 100644 pomelo/src/lib.rs create mode 100644 pomelo/src/sinks.rs create mode 100644 pomelo/src/utils.rs create mode 100644 pomelo/substreams.yaml diff --git a/Cargo.toml b/Cargo.toml index 38cc65c..9bf05ff 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,6 +7,7 @@ members = [ "accounts", "params", "atomicmarket", + "pomelo", ] [workspace.dependencies] diff --git a/README.md b/README.md index 9c0b389..0400a68 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,7 @@ | [`accounts`](accounts/) | 🛠 | Antelope accounts | [`eosio.token`](eosio.token/) | 🔨 | Antelope `eosio.token` token transfers | [`atomicmarket`](atomicmarket/) | 🔨 | Metrics for [AtomicHub Market](https://eos.atomichub.io/) +| [`pomelo`](pomelo/) | 🔨 | [Pomelo Grants](https://pomelo.io/) events ### Further resources diff --git a/pomelo/Cargo.toml b/pomelo/Cargo.toml new file mode 100644 index 0000000..b937b9f --- /dev/null +++ b/pomelo/Cargo.toml @@ -0,0 +1,23 @@ +[package] +name = "pomelo" +version = "0.1.0" +authors = ["Yaro ", "Charles ", ] +description = "Antelope Pomelo substreams" +license = "MIT OR Apache-2.0" +edition = "2021" +publish = false + +[badges] +maintenance = { status = "actively-developed" } + +[lib] +crate-type = ["cdylib"] + +[dependencies] +prost = { workspace = true } +prost-types = { workspace = true } +substreams = { workspace = true } +substreams-antelope = { workspace = true } +substreams-entity-change = { workspace = true } +serde_json = "1.0.91" +serde = { version = "1.0", features = ["derive"] } \ No newline at end of file diff --git a/pomelo/Makefile b/pomelo/Makefile new file mode 100644 index 0000000..381bb6f --- /dev/null +++ b/pomelo/Makefile @@ -0,0 +1,38 @@ +.PHONY: all +all: + make build + make pack + make graph + make info + +.PHONY: build +build: + cargo build --target wasm32-unknown-unknown --release + +.PHONY: protogen +protogen: + substreams protogen --exclude-paths sf/substreams,google + +.PHONY: pack +pack: + substreams pack + +.PHONY: graph +graph: + substreams graph + +.PHONY: info +info: + substreams info + +.PHONY: run +run: + substreams run -e eos.firehose.eosnation.io:9001 entity_out -s 296787657 -t +100000 + +.PHONY: gui +gui: + substreams gui -e eos.firehose.eosnation.io:9001 entity_out -s 296787657 -t +100000 + +.PHONY: sink +sink: + substreams-sink-kv run badger3://badger_data.db eos.firehose.eosnation.io:9001 substreams.yaml kv_out \ No newline at end of file diff --git a/pomelo/README.md b/pomelo/README.md new file mode 100644 index 0000000..c6d76c1 --- /dev/null +++ b/pomelo/README.md @@ -0,0 +1,38 @@ +# Antelope Pomelo Substreams + +> Antelope Pomelo Substreams + +### [Latest Releases](https://github.com/pinax-network/substreams/releases) + +### Sinks +- Socials (stay tuned) + +### Quickstart + +```bash +$ make +$ make gui +``` + +### Graph + +```mermaid +graph TD; + entity_out[map: entity_out] + sf.antelope.type.v1.Block[source: sf.antelope.type.v1.Block] --> entity_out +``` + +### Modules + +```yaml +Package name: pomelo +Version: v0.1.0 +Doc: Antelope pomelo updates +Modules: +---- +Name: entity_out +Initial block: 0 +Kind: map +Output Type: proto:substreams.entity.v1.EntityChanges +Hash: 04d8aeae95d104cdeda26c31994ff2f2e67e7392 +``` \ No newline at end of file diff --git a/pomelo/src/abi.rs b/pomelo/src/abi.rs new file mode 100644 index 0000000..8fa00d8 --- /dev/null +++ b/pomelo/src/abi.rs @@ -0,0 +1,20 @@ +use substreams_antelope::ActionTrace; +// use antelope::Asset; +use serde::{Deserialize, Serialize}; + +#[derive(Serialize, Deserialize, Debug)] +#[serde(deny_unknown_fields)] +pub struct SetGrant { + pub author_id: String, + pub project_id: String, + pub funding_account: String, + pub accepted_tokens: Vec, +} + + +pub fn parse_setgrant(action_trace: &ActionTrace) -> Option { + let action = action_trace.action.as_ref()?; + if action.name != "setgrant" { return None; } + let data: SetGrant = serde_json::from_str(&action.json_data).unwrap(); + Some(data) +} diff --git a/pomelo/src/lib.rs b/pomelo/src/lib.rs new file mode 100644 index 0000000..72f5df0 --- /dev/null +++ b/pomelo/src/lib.rs @@ -0,0 +1,4 @@ +#[allow(dead_code)] +mod abi; +mod sinks; +mod utils; \ No newline at end of file diff --git a/pomelo/src/sinks.rs b/pomelo/src/sinks.rs new file mode 100644 index 0000000..93c010f --- /dev/null +++ b/pomelo/src/sinks.rs @@ -0,0 +1,28 @@ +use substreams::{log}; +use substreams::errors::Error; +use substreams_antelope::{Block}; +use substreams_entity_change::pb::entity::{entity_change::Operation, EntityChanges}; + +use crate::abi::SetGrant; + +#[substreams::handlers::map] +pub fn entity_out( block: Block) -> Result { + let mut entity_changes: EntityChanges = Default::default(); + + for trx in block.clone().all_transaction_traces() { + for trace in &trx.action_traces { + let action_trace = trace.action.as_ref().unwrap().clone(); + if action_trace.account != "app.pomelo" { continue; } + if action_trace.name == "setgrant" { + let data: SetGrant = serde_json::from_str(&action_trace.json_data).unwrap(); + log::info!("data={:?}", data); + entity_changes.push_change("Grant", &data.project_id, 1, Operation::Create) + .change::<&str, String>("author_id", data.author_id) + .change::<&str, String>("project_id", data.project_id) + .change::<&str, String>("funding_account", data.funding_account) + .change::<&str, String>("accepted_tokens", data.accepted_tokens.join(",")); + } + } + } + Ok( entity_changes ) +} \ No newline at end of file diff --git a/pomelo/src/utils.rs b/pomelo/src/utils.rs new file mode 100644 index 0000000..139597f --- /dev/null +++ b/pomelo/src/utils.rs @@ -0,0 +1,2 @@ + + diff --git a/pomelo/substreams.yaml b/pomelo/substreams.yaml new file mode 100644 index 0000000..819e1a3 --- /dev/null +++ b/pomelo/substreams.yaml @@ -0,0 +1,23 @@ +specVersion: v0.1.0 +package: + name: "pomelo" + version: v0.1.0 + url: https://github.com/pinax-network/substreams + doc: Antelope pomelo updates + +imports: + entities: https://github.com/streamingfast/substreams-entity-change/releases/download/v0.2.1/substreams-entity-change-v0.2.1.spkg + +binaries: + default: + type: wasm/rust-v1 + file: ../target/wasm32-unknown-unknown/release/pomelo.wasm + +modules: + + - name: entity_out + kind: map + inputs: + - source: sf.antelope.type.v1.Block + output: + type: proto:substreams.entity.v1.EntityChanges