Skip to content

Commit 8743ce5

Browse files
authored
feat: activities & aggregations (#149)
1 parent 98943fa commit 8743ce5

File tree

9 files changed

+1487
-23
lines changed

9 files changed

+1487
-23
lines changed

Cargo.lock

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
[package]
22
edition = "2021"
33
name = "dojo-c"
4-
version = "1.7.2"
4+
version = "1.7.5"
55

66
[lib]
77
crate-type = ["cdylib", "rlib", "staticlib"]
88

99
[dependencies]
1010
dojo-world = { git = "https://github.com/dojoengine/dojo", rev = "6daa3d0" }
1111
dojo-types = { git = "https://github.com/dojoengine/dojo", rev = "6daa3d0" }
12-
torii-proto = { git = "https://github.com/dojoengine/torii", tag = "v1.7.2" }
13-
torii-client = { git = "https://github.com/dojoengine/torii", tag = "v1.7.2" }
14-
torii-grpc-client = { git = "https://github.com/dojoengine/torii", tag = "v1.7.2" }
12+
torii-proto = { git = "https://github.com/dojoengine/torii", rev = "23d0da6" }
13+
torii-client = { git = "https://github.com/dojoengine/torii", rev = "23d0da6" }
14+
torii-grpc-client = { git = "https://github.com/dojoengine/torii", rev = "23d0da6" }
1515

1616
starknet = "0.17.0"
1717
starknet-crypto = "0.8"

dojo.h

Lines changed: 224 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ struct Transaction;
2020
struct Subscription;
2121
struct TransactionCall;
2222
struct Struct;
23+
struct AggregationEntry;
24+
struct Activity;
25+
struct ActionCount;
2326
struct Token;
2427
struct AttributeFilter;
2528
struct TokenBalance;
@@ -620,6 +623,104 @@ typedef struct Entity {
620623
uint64_t executed_at;
621624
} Entity;
622625

626+
typedef struct CArrayAggregationEntry {
627+
struct AggregationEntry *data;
628+
uintptr_t data_len;
629+
} CArrayAggregationEntry;
630+
631+
typedef struct PageAggregationEntry {
632+
struct CArrayAggregationEntry items;
633+
struct COptionc_char next_cursor;
634+
} PageAggregationEntry;
635+
636+
typedef enum ResultPageAggregationEntry_Tag {
637+
OkPageAggregationEntry,
638+
ErrPageAggregationEntry,
639+
} ResultPageAggregationEntry_Tag;
640+
641+
typedef struct ResultPageAggregationEntry {
642+
ResultPageAggregationEntry_Tag tag;
643+
union {
644+
struct {
645+
struct PageAggregationEntry ok;
646+
};
647+
struct {
648+
struct Error err;
649+
};
650+
};
651+
} ResultPageAggregationEntry;
652+
653+
typedef struct AggregationQuery {
654+
struct CArrayc_char aggregator_ids;
655+
struct CArrayc_char entity_ids;
656+
struct Pagination pagination;
657+
} AggregationQuery;
658+
659+
typedef struct AggregationEntry {
660+
const char *id;
661+
const char *aggregator_id;
662+
const char *entity_id;
663+
struct U256 value;
664+
const char *display_value;
665+
uint64_t position;
666+
struct FieldElement model_id;
667+
uint64_t created_at;
668+
uint64_t updated_at;
669+
} AggregationEntry;
670+
671+
typedef struct CArrayActivity {
672+
struct Activity *data;
673+
uintptr_t data_len;
674+
} CArrayActivity;
675+
676+
typedef struct PageActivity {
677+
struct CArrayActivity items;
678+
struct COptionc_char next_cursor;
679+
} PageActivity;
680+
681+
typedef enum ResultPageActivity_Tag {
682+
OkPageActivity,
683+
ErrPageActivity,
684+
} ResultPageActivity_Tag;
685+
686+
typedef struct ResultPageActivity {
687+
ResultPageActivity_Tag tag;
688+
union {
689+
struct {
690+
struct PageActivity ok;
691+
};
692+
struct {
693+
struct Error err;
694+
};
695+
};
696+
} ResultPageActivity;
697+
698+
typedef struct ActivityQuery {
699+
struct CArrayFieldElement world_addresses;
700+
struct CArrayc_char namespaces;
701+
struct CArrayFieldElement caller_addresses;
702+
struct COptionu64 from_time;
703+
struct COptionu64 to_time;
704+
struct Pagination pagination;
705+
} ActivityQuery;
706+
707+
typedef struct CArrayActionCount {
708+
struct ActionCount *data;
709+
uintptr_t data_len;
710+
} CArrayActionCount;
711+
712+
typedef struct Activity {
713+
const char *id;
714+
struct FieldElement world_address;
715+
const char *namespace_;
716+
struct FieldElement caller_address;
717+
uint64_t session_start;
718+
uint64_t session_end;
719+
uint32_t action_count;
720+
struct CArrayActionCount actions;
721+
uint64_t updated_at;
722+
} Activity;
723+
623724
typedef struct Event {
624725
struct CArrayFieldElement keys;
625726
struct CArrayFieldElement data;
@@ -1085,6 +1186,11 @@ typedef struct TransactionCall {
10851186
struct FieldElement caller_address;
10861187
} TransactionCall;
10871188

1189+
typedef struct ActionCount {
1190+
const char *action_name;
1191+
uint32_t count;
1192+
} ActionCount;
1193+
10881194
typedef struct AttributeFilter {
10891195
const char *trait_name;
10901196
const char *trait_value;
@@ -1423,6 +1529,124 @@ struct Resultbool client_update_entity_subscription(struct ToriiClient *client,
14231529
struct Subscription *subscription,
14241530
struct COptionClause clause);
14251531

1532+
/**
1533+
* Retrieves aggregations (leaderboards, stats, rankings) matching query parameter
1534+
*
1535+
* # Parameters
1536+
* * `client` - Pointer to ToriiClient instance
1537+
* * `query` - AggregationQuery containing aggregator_ids, entity_ids, and pagination
1538+
*
1539+
* # Returns
1540+
* Result containing Page of AggregationEntry or error
1541+
*/
1542+
struct ResultPageAggregationEntry client_aggregations(struct ToriiClient *client,
1543+
struct AggregationQuery query);
1544+
1545+
/**
1546+
* Subscribes to aggregation updates (leaderboards, stats, rankings)
1547+
*
1548+
* # Parameters
1549+
* * `client` - Pointer to ToriiClient instance
1550+
* * `aggregator_ids` - Array of aggregator IDs to subscribe to
1551+
* * `aggregator_ids_len` - Length of aggregator_ids array
1552+
* * `entity_ids` - Array of entity IDs to subscribe to
1553+
* * `entity_ids_len` - Length of entity_ids array
1554+
* * `callback` - Function called when updates occur
1555+
*
1556+
* # Returns
1557+
* Result containing pointer to Subscription or error
1558+
*/
1559+
struct ResultSubscription client_on_aggregation_update(struct ToriiClient *client,
1560+
const char *const *aggregator_ids,
1561+
uintptr_t aggregator_ids_len,
1562+
const char *const *entity_ids,
1563+
uintptr_t entity_ids_len,
1564+
void (*callback)(struct AggregationEntry));
1565+
1566+
/**
1567+
* Updates an existing aggregation subscription with new parameters
1568+
*
1569+
* # Parameters
1570+
* * `client` - Pointer to ToriiClient instance
1571+
* * `subscription` - Pointer to existing Subscription
1572+
* * `aggregator_ids` - Array of aggregator IDs to subscribe to
1573+
* * `aggregator_ids_len` - Length of aggregator_ids array
1574+
* * `entity_ids` - Array of entity IDs to subscribe to
1575+
* * `entity_ids_len` - Length of entity_ids array
1576+
*
1577+
* # Returns
1578+
* Result containing success boolean or error
1579+
*/
1580+
struct Resultbool client_update_aggregation_subscription(struct ToriiClient *client,
1581+
struct Subscription *subscription,
1582+
const char *const *aggregator_ids,
1583+
uintptr_t aggregator_ids_len,
1584+
const char *const *entity_ids,
1585+
uintptr_t entity_ids_len);
1586+
1587+
/**
1588+
* Retrieves activities (user session tracking) matching query parameter
1589+
*
1590+
* # Parameters
1591+
* * `client` - Pointer to ToriiClient instance
1592+
* * `query` - ActivityQuery containing world_addresses, namespaces, caller_addresses, and pagination
1593+
*
1594+
* # Returns
1595+
* Result containing Page of Activity or error
1596+
*/
1597+
struct ResultPageActivity client_activities(struct ToriiClient *client,
1598+
struct ActivityQuery query);
1599+
1600+
/**
1601+
* Subscribes to activity updates (user session tracking)
1602+
*
1603+
* # Parameters
1604+
* * `client` - Pointer to ToriiClient instance
1605+
* * `world_addresses` - Array of world addresses to subscribe to
1606+
* * `world_addresses_len` - Length of world_addresses array
1607+
* * `namespaces` - Array of namespaces to subscribe to
1608+
* * `namespaces_len` - Length of namespaces array
1609+
* * `caller_addresses` - Array of caller addresses to subscribe to
1610+
* * `caller_addresses_len` - Length of caller_addresses array
1611+
* * `callback` - Function called when updates occur
1612+
*
1613+
* # Returns
1614+
* Result containing pointer to Subscription or error
1615+
*/
1616+
struct ResultSubscription client_on_activity_update(struct ToriiClient *client,
1617+
const struct FieldElement *world_addresses,
1618+
uintptr_t world_addresses_len,
1619+
const char *const *namespaces,
1620+
uintptr_t namespaces_len,
1621+
const struct FieldElement *caller_addresses,
1622+
uintptr_t caller_addresses_len,
1623+
void (*callback)(struct Activity));
1624+
1625+
/**
1626+
* Updates an existing activity subscription with new parameters
1627+
*
1628+
* # Parameters
1629+
* * `client` - Pointer to ToriiClient instance
1630+
* * `subscription` - Pointer to existing Subscription
1631+
* * `world_addresses` - Array of world addresses to subscribe to
1632+
* * `world_addresses_len` - Length of world_addresses array
1633+
* * `namespaces` - Array of namespaces to subscribe to
1634+
* * `namespaces_len` - Length of namespaces array
1635+
* * `caller_addresses` - Array of caller addresses to subscribe to
1636+
* * `caller_addresses_len` - Length of caller_addresses array
1637+
*
1638+
* # Returns
1639+
* Result containing success boolean or error
1640+
*/
1641+
struct Resultbool client_update_activity_subscription(struct ToriiClient *client,
1642+
struct Subscription *subscription,
1643+
const struct FieldElement *world_addresses,
1644+
uintptr_t world_addresses_len,
1645+
const char *const *namespaces,
1646+
uintptr_t namespaces_len,
1647+
const struct FieldElement *caller_addresses,
1648+
uintptr_t caller_addresses_len);
1649+
14261650
/**
14271651
* Subscribes to event message updates
14281652
*

0 commit comments

Comments
 (0)