Skip to content

Commit

Permalink
pomelo substreams
Browse files Browse the repository at this point in the history
  • Loading branch information
YaroShkvorets committed Mar 23, 2023
1 parent 02da68a commit fc08c37
Show file tree
Hide file tree
Showing 10 changed files with 178 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ members = [
"accounts",
"params",
"atomicmarket",
"pomelo",
]

[workspace.dependencies]
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
23 changes: 23 additions & 0 deletions pomelo/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[package]
name = "pomelo"
version = "0.1.0"
authors = ["Yaro <[email protected]>", "Charles <[email protected]>", ]
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"] }
38 changes: 38 additions & 0 deletions pomelo/Makefile
Original file line number Diff line number Diff line change
@@ -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
38 changes: 38 additions & 0 deletions pomelo/README.md
Original file line number Diff line number Diff line change
@@ -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
```
20 changes: 20 additions & 0 deletions pomelo/src/abi.rs
Original file line number Diff line number Diff line change
@@ -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<String>,
}


pub fn parse_setgrant(action_trace: &ActionTrace) -> Option<SetGrant> {
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)
}
4 changes: 4 additions & 0 deletions pomelo/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#[allow(dead_code)]
mod abi;
mod sinks;
mod utils;
28 changes: 28 additions & 0 deletions pomelo/src/sinks.rs
Original file line number Diff line number Diff line change
@@ -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<EntityChanges, Error> {
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 )
}
2 changes: 2 additions & 0 deletions pomelo/src/utils.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@


23 changes: 23 additions & 0 deletions pomelo/substreams.yaml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit fc08c37

Please sign in to comment.