Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
[package]
edition = "2021"
name = "dojo-c"
version = "1.7.0-alpha.5"
version = "1.7.0-alpha.6"

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

[dependencies]
dojo-world = { git = "https://github.com/dojoengine/dojo", branch = "primitive-from-sql" }
dojo-types = { git = "https://github.com/dojoengine/dojo", branch = "primitive-from-sql" }
torii-proto = { git = "https://github.com/dojoengine/torii", tag = "v1.7.0-alpha.5" }
torii-client = { git = "https://github.com/dojoengine/torii", tag = "v1.7.0-alpha.5" }
torii-grpc-client = { git = "https://github.com/dojoengine/torii", tag = "v1.7.0-alpha.5" }
torii-proto = { git = "https://github.com/dojoengine/torii", rev = "77710f7" }
torii-client = { git = "https://github.com/dojoengine/torii", rev = "77710f7" }
torii-grpc-client = { git = "https://github.com/dojoengine/torii", rev = "77710f7" }

starknet = "0.17.0-rc.2"
starknet-crypto = "0.7.4"
Expand Down
106 changes: 83 additions & 23 deletions dojo.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ struct Struct;
struct Token;
struct TokenBalance;
struct TokenCollection;
struct Contract;
enum ContractType;
struct Provider;
struct Account;
struct Ty;
Expand Down Expand Up @@ -56,6 +58,15 @@ typedef enum ComparisonOperator {
ArrayLengthLt,
} ComparisonOperator;

typedef enum ContractType {
WORLD,
ERC20,
ERC721,
ERC1155,
UDC,
OTHER,
} ContractType;

typedef enum LogicalOperator {
And,
Or,
Expand Down Expand Up @@ -737,12 +748,62 @@ typedef struct ResultPageTokenCollection {
};
} ResultPageTokenCollection;

typedef struct IndexerUpdate {
int64_t head;
int64_t tps;
int64_t last_block_timestamp;
typedef struct CArrayContract {
struct Contract *data;
uintptr_t data_len;
} CArrayContract;

typedef enum ResultCArrayContract_Tag {
OkCArrayContract,
ErrCArrayContract,
} ResultCArrayContract_Tag;

typedef struct ResultCArrayContract {
ResultCArrayContract_Tag tag;
union {
struct {
struct CArrayContract ok;
};
struct {
struct Error err;
};
};
} ResultCArrayContract;

typedef struct CArrayContractType {
enum ContractType *data;
uintptr_t data_len;
} CArrayContractType;

typedef struct ContractQuery {
struct CArrayFieldElement contract_addresses;
struct CArrayContractType contract_types;
} ContractQuery;

typedef enum COptionFieldElement_Tag {
SomeFieldElement,
NoneFieldElement,
} COptionFieldElement_Tag;

typedef struct COptionFieldElement {
COptionFieldElement_Tag tag;
union {
struct {
struct FieldElement some;
};
};
} COptionFieldElement;

typedef struct Contract {
struct FieldElement contract_address;
} IndexerUpdate;
enum ContractType contract_type;
struct COptionu64 head;
struct COptionu64 tps;
struct COptionu64 last_block_timestamp;
struct COptionFieldElement last_pending_block_tx;
uint64_t updated_at;
uint64_t created_at;
} Contract;

typedef struct TokenBalance {
struct U256 balance;
Expand Down Expand Up @@ -877,20 +938,6 @@ typedef struct OrderBy {
enum OrderDirection direction;
} OrderBy;

typedef enum COptionFieldElement_Tag {
SomeFieldElement,
NoneFieldElement,
} COptionFieldElement_Tag;

typedef struct COptionFieldElement {
COptionFieldElement_Tag tag;
union {
struct {
struct FieldElement some;
};
};
} COptionFieldElement;

typedef struct CArrayMember {
struct Member *data;
uintptr_t data_len;
Expand Down Expand Up @@ -1437,7 +1484,20 @@ struct ResultPageTokenCollection client_token_collections(struct ToriiClient *cl
struct TokenBalanceQuery query);

/**
* Subscribes to indexer updates
* Gets contracts matching the given query
*
* # Parameters
* * `client` - Pointer to ToriiClient instance
* * `query` - ContractQuery parameters
*
* # Returns
* Result containing array of Contract information or error
*/
struct ResultCArrayContract client_contracts(struct ToriiClient *client,
struct ContractQuery query);

/**
* Subscribes to contract updates
*
* # Parameters
* * `client` - Pointer to ToriiClient instance
Expand All @@ -1447,9 +1507,9 @@ struct ResultPageTokenCollection client_token_collections(struct ToriiClient *cl
* # Returns
* Result containing pointer to Subscription or error
*/
struct ResultSubscription on_indexer_update(struct ToriiClient *client,
const struct FieldElement *contract_address,
void (*callback)(struct IndexerUpdate));
struct ResultSubscription on_contract_update(struct ToriiClient *client,
const struct FieldElement *contract_address,
void (*callback)(struct Contract));

/**
* Subscribes to token balance updates
Expand Down
44 changes: 36 additions & 8 deletions dojo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,15 @@ enum class ComparisonOperator {
ArrayLengthLt,
};

enum class ContractType {
WORLD,
ERC20,
ERC721,
ERC1155,
UDC,
OTHER,
};

enum class LogicalOperator {
And,
Or,
Expand Down Expand Up @@ -908,11 +917,20 @@ struct TokenCollection {
const char *metadata;
};

struct IndexerUpdate {
int64_t head;
int64_t tps;
int64_t last_block_timestamp;
struct Contract {
FieldElement contract_address;
ContractType contract_type;
COption<uint64_t> head;
COption<uint64_t> tps;
COption<uint64_t> last_block_timestamp;
COption<FieldElement> last_pending_block_tx;
uint64_t updated_at;
uint64_t created_at;
};

struct ContractQuery {
CArray<FieldElement> contract_addresses;
CArray<ContractType> contract_types;
};

struct Signature {
Expand Down Expand Up @@ -1369,7 +1387,17 @@ Result<Page<TokenBalance>> client_token_balances(ToriiClient *client, TokenBalan
Result<Page<TokenCollection>> client_token_collections(ToriiClient *client,
TokenBalanceQuery query);

/// Subscribes to indexer updates
/// Gets contracts matching the given query
///
/// # Parameters
/// * `client` - Pointer to ToriiClient instance
/// * `query` - ContractQuery parameters
///
/// # Returns
/// Result containing array of Contract information or error
Result<CArray<Contract>> client_contracts(ToriiClient *client, ContractQuery query);

/// Subscribes to contract updates
///
/// # Parameters
/// * `client` - Pointer to ToriiClient instance
Expand All @@ -1378,9 +1406,9 @@ Result<Page<TokenCollection>> client_token_collections(ToriiClient *client,
///
/// # Returns
/// Result containing pointer to Subscription or error
Result<Subscription*> on_indexer_update(ToriiClient *client,
const FieldElement *contract_address,
void (*callback)(IndexerUpdate));
Result<Subscription*> on_contract_update(ToriiClient *client,
const FieldElement *contract_address,
void (*callback)(Contract));

/// Subscribes to token balance updates
///
Expand Down
75 changes: 59 additions & 16 deletions dojo.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ cdef extern from *:
ArrayLengthGt,
ArrayLengthLt,

cdef enum ContractType:
WORLD,
ERC20,
ERC721,
ERC1155,
UDC,
OTHER,

cdef enum LogicalOperator:
And,
Or,
Expand Down Expand Up @@ -483,11 +491,44 @@ cdef extern from *:
PageTokenCollection ok;
Error err;

cdef struct IndexerUpdate:
int64_t head;
int64_t tps;
int64_t last_block_timestamp;
cdef struct CArrayContract:
Contract *data;
uintptr_t data_len;

cdef enum ResultCArrayContract_Tag:
OkCArrayContract,
ErrCArrayContract,

cdef struct ResultCArrayContract:
ResultCArrayContract_Tag tag;
CArrayContract ok;
Error err;

cdef struct CArrayContractType:
ContractType *data;
uintptr_t data_len;

cdef struct ContractQuery:
CArrayFieldElement contract_addresses;
CArrayContractType contract_types;

cdef enum COptionFieldElement_Tag:
SomeFieldElement,
NoneFieldElement,

cdef struct COptionFieldElement:
COptionFieldElement_Tag tag;
FieldElement some;

cdef struct Contract:
FieldElement contract_address;
ContractType contract_type;
COptionu64 head;
COptionu64 tps;
COptionu64 last_block_timestamp;
COptionFieldElement last_pending_block_tx;
uint64_t updated_at;
uint64_t created_at;

cdef struct TokenBalance:
U256 balance;
Expand Down Expand Up @@ -568,14 +609,6 @@ cdef extern from *:
const char *field;
OrderDirection direction;

cdef enum COptionFieldElement_Tag:
SomeFieldElement,
NoneFieldElement,

cdef struct COptionFieldElement:
COptionFieldElement_Tag tag;
FieldElement some;

cdef struct CArrayMember:
Member *data;
uintptr_t data_len;
Expand Down Expand Up @@ -1027,7 +1060,17 @@ cdef extern from *:
# Result containing array of TokenBalance information or error
ResultPageTokenCollection client_token_collections(ToriiClient *client, TokenBalanceQuery query);

# Subscribes to indexer updates
# Gets contracts matching the given query
#
# # Parameters
# * `client` - Pointer to ToriiClient instance
# * `query` - ContractQuery parameters
#
# # Returns
# Result containing array of Contract information or error
ResultCArrayContract client_contracts(ToriiClient *client, ContractQuery query);

# Subscribes to contract updates
#
# # Parameters
# * `client` - Pointer to ToriiClient instance
Expand All @@ -1036,9 +1079,9 @@ cdef extern from *:
#
# # Returns
# Result containing pointer to Subscription or error
ResultSubscription on_indexer_update(ToriiClient *client,
const FieldElement *contract_address,
void (*callback)(IndexerUpdate));
ResultSubscription on_contract_update(ToriiClient *client,
const FieldElement *contract_address,
void (*callback)(Contract));

# Subscribes to token balance updates
#
Expand Down
Loading
Loading