Skip to content

Commit 8f286b6

Browse files
Pass merged storage to context (#8)
* Fetch operations before starting WS connection * Bigmap types WIP * Fix bigmap naming * WIP * Fix registrydao demo * Merged storage * Fix tests * Add storage test * Skip bigmap types codegen * Skip bigmap types codegen * Fix storage schema * Fix test
1 parent 0a98870 commit 8f286b6

File tree

22 files changed

+1129
-31
lines changed

22 files changed

+1129
-31
lines changed

src/demo_hic_et_nunc/dipdup.yml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,8 @@ spec_version: 0.0.1
22
package: demo_hic_et_nunc
33

44
database:
5-
kind: postgres
6-
host: db
7-
port: 5432
8-
user: dipdup
9-
database: dipdup
10-
password: ${POSTGRES_PASSWORD:-changeme}
5+
kind: sqlite
6+
path: db.sqlite3
117

128
contracts:
139
HEN_objkts:
Lines changed: 190 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,190 @@
1+
{
2+
"version": 2,
3+
"tables": [
4+
{
5+
"table": {
6+
"schema": "public",
7+
"name": "holder"
8+
},
9+
"object_relationships": [],
10+
"array_relationships": [
11+
{
12+
"name": "swaps",
13+
"using": {
14+
"foreign_key_constraint_on": {
15+
"column": "creator_id",
16+
"table": {
17+
"schema": "public",
18+
"name": "swap"
19+
}
20+
}
21+
}
22+
},
23+
{
24+
"name": "tokens",
25+
"using": {
26+
"foreign_key_constraint_on": {
27+
"column": "creator_id",
28+
"table": {
29+
"schema": "public",
30+
"name": "token"
31+
}
32+
}
33+
}
34+
},
35+
{
36+
"name": "sales",
37+
"using": {
38+
"foreign_key_constraint_on": {
39+
"column": "seller_id",
40+
"table": {
41+
"schema": "public",
42+
"name": "trade"
43+
}
44+
}
45+
}
46+
},
47+
{
48+
"name": "purchases",
49+
"using": {
50+
"foreign_key_constraint_on": {
51+
"column": "buyer_id",
52+
"table": {
53+
"schema": "public",
54+
"name": "trade"
55+
}
56+
}
57+
}
58+
}
59+
],
60+
"select_permissions": [
61+
{
62+
"role": "user",
63+
"permission": {
64+
"columns": [
65+
"address"
66+
],
67+
"filter": {},
68+
"allow_aggregations": true
69+
}
70+
}
71+
]
72+
},
73+
{
74+
"table": {
75+
"schema": "public",
76+
"name": "swap"
77+
},
78+
"object_relationships": [
79+
{
80+
"name": "holder",
81+
"using": {
82+
"foreign_key_constraint_on": "creator_id"
83+
}
84+
}
85+
],
86+
"array_relationships": [
87+
{
88+
"name": "trades",
89+
"using": {
90+
"foreign_key_constraint_on": {
91+
"column": "swap_id",
92+
"table": {
93+
"schema": "public",
94+
"name": "trade"
95+
}
96+
}
97+
}
98+
}
99+
],
100+
"select_permissions": [
101+
{
102+
"role": "user",
103+
"permission": {
104+
"columns": [
105+
"amount",
106+
"timestamp",
107+
"level",
108+
"amount_left",
109+
"id"
110+
],
111+
"filter": {},
112+
"allow_aggregations": true
113+
}
114+
}
115+
]
116+
},
117+
{
118+
"table": {
119+
"schema": "public",
120+
"name": "token"
121+
},
122+
"object_relationships": [
123+
{
124+
"name": "holder",
125+
"using": {
126+
"foreign_key_constraint_on": "creator_id"
127+
}
128+
}
129+
],
130+
"array_relationships": [],
131+
"select_permissions": [
132+
{
133+
"role": "user",
134+
"permission": {
135+
"columns": [
136+
"supply",
137+
"level",
138+
"timestamp",
139+
"id"
140+
],
141+
"filter": {},
142+
"allow_aggregations": true
143+
}
144+
}
145+
]
146+
},
147+
{
148+
"table": {
149+
"schema": "public",
150+
"name": "trade"
151+
},
152+
"object_relationships": [
153+
{
154+
"name": "swap",
155+
"using": {
156+
"foreign_key_constraint_on": "swap_id"
157+
}
158+
},
159+
{
160+
"name": "holder",
161+
"using": {
162+
"foreign_key_constraint_on": "seller_id"
163+
}
164+
},
165+
{
166+
"name": "holder",
167+
"using": {
168+
"foreign_key_constraint_on": "buyer_id"
169+
}
170+
}
171+
],
172+
"array_relationships": [],
173+
"select_permissions": [
174+
{
175+
"role": "user",
176+
"permission": {
177+
"columns": [
178+
"level",
179+
"amount",
180+
"timestamp",
181+
"id"
182+
],
183+
"filter": {},
184+
"allow_aggregations": true
185+
}
186+
}
187+
]
188+
}
189+
]
190+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# generated by datamodel-codegen:
2+
# filename: storage.json
3+
4+
from __future__ import annotations
5+
6+
from typing import Union
7+
8+
from pydantic import BaseModel, Extra
9+
10+
11+
class Metadatum(BaseModel):
12+
pass
13+
14+
class Config:
15+
extra = Extra.allow
16+
17+
18+
class Royalty(BaseModel):
19+
pass
20+
21+
class Config:
22+
extra = Extra.allow
23+
24+
25+
class Swap(BaseModel):
26+
pass
27+
28+
class Config:
29+
extra = Extra.allow
30+
31+
32+
class Storage(BaseModel):
33+
curate: str
34+
genesis: str
35+
hdao: str
36+
locked: bool
37+
manager: str
38+
metadata: Union[int, Metadatum]
39+
objkt: str
40+
objkt_id: str
41+
royalties: Union[int, Royalty]
42+
size: str
43+
swap_id: str
44+
swaps: Union[int, Swap]
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# generated by datamodel-codegen:
2+
# filename: storage.json
3+
4+
from __future__ import annotations
5+
6+
from typing import Any, List, Union
7+
8+
from pydantic import BaseModel, Extra
9+
10+
11+
class Metadatum(BaseModel):
12+
pass
13+
14+
class Config:
15+
extra = Extra.allow
16+
17+
18+
class TokenMetadatum(BaseModel):
19+
pass
20+
21+
class Config:
22+
extra = Extra.allow
23+
24+
25+
class Storage(BaseModel):
26+
administrator: str
27+
all_tokens: str
28+
ledger: Union[int, List[Any]]
29+
metadata: Union[int, Metadatum]
30+
operators: Union[int, List[Any]]
31+
paused: bool
32+
token_metadata: Union[int, TokenMetadatum]

src/demo_registrydao/__init__.py

Whitespace-only changes.

src/demo_registrydao/dipdup.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
spec_version: 0.0.1
2+
package: demo_registrydao
3+
4+
database:
5+
kind: sqlite
6+
path: db.sqlite3
7+
8+
contracts:
9+
registry:
10+
address: KT1QMdCTqzmY4QKHntV1nZEinLPU1GbxUFQu
11+
typename: registry
12+
13+
datasources:
14+
tzkt:
15+
kind: tzkt
16+
url: ${TZKT_URL:-https://staging.api.edo2net.tzkt.io}
17+
18+
templates:
19+
20+
registry_dao:
21+
kind: operation
22+
datasource: tzkt
23+
contract: <contract>
24+
handlers:
25+
- callback: on_propose
26+
pattern:
27+
- destination: <contract>
28+
entrypoint: propose
29+
30+
indexes:
31+
registry:
32+
template: registry_dao
33+
values:
34+
contract: registry

src/demo_registrydao/handlers/__init__.py

Whitespace-only changes.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from demo_registrydao.models import *
2+
from demo_registrydao.types.registry.parameter.propose import Propose
3+
from dipdup.models import HandlerContext, OperationContext
4+
5+
6+
async def on_propose(
7+
ctx: HandlerContext,
8+
propose: OperationContext[Propose],
9+
) -> None:
10+
print(propose.storage)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import logging
2+
import os
3+
import sys
4+
5+
from tortoise import Tortoise
6+
7+
_logger = logging.getLogger(__name__)
8+
9+
10+
async def on_rollback(
11+
from_level: int,
12+
to_level: int,
13+
) -> None:
14+
_logger.warning('Rollback event received, reindexing')
15+
await Tortoise._drop_databases()
16+
os.execl(sys.executable, sys.executable, *sys.argv)

0 commit comments

Comments
 (0)