Skip to content

Commit 9a4400a

Browse files
Backport: Fix operation matching when contract code hash specified as a string (#833)
1 parent 1eeb1ff commit 9a4400a

File tree

60 files changed

+578
-514
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+578
-514
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ The format is based on [Keep a Changelog], and this project adheres to [Semantic
99
### Fixed
1010

1111
- tzkt: Fixed issue with processing rollbacks while sync is in progress.
12+
- tzkt: Fixed operation matching when contract code hash specified as a string.
1213

1314
## [6.5.11] - 2023-09-02
1415

demos/demo-factories/dipdup.yml

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,52 @@
11
spec_version: 1.2
22
package: demo_factories
33

4-
database:
5-
kind: sqlite
6-
path: demo-factories.sqlite3
7-
84
contracts:
9-
registry:
10-
address: KT19CF3KKrvdW77ttFomCuin2k4uAVkryYqh
11-
typename: registry
5+
factory:
6+
address: KT1PvEyN1xCFCgorN92QCfYjw3axS6jawCiJ
7+
typename: factory
8+
token:
9+
address: KT1UsSfaXyqcjSVPeiD7U1bWgKy3taYN7NWY
10+
typename: token
1211

1312
datasources:
1413
tzkt:
1514
kind: tzkt
1615
url: ${TZKT_URL:-https://api.tzkt.io}
1716

1817
templates:
19-
registry_dao:
18+
dex:
2019
kind: operation
2120
datasource: tzkt
2221
types:
2322
- transaction
24-
- origination
2523
contracts:
26-
- <contract>
24+
- <dex>
25+
- <token>
2726
handlers:
28-
- callback: on_origination
29-
pattern:
30-
- type: origination
31-
originated_contract: <contract>
32-
- callback: on_propose
27+
- callback: on_transfer
3328
pattern:
3429
- type: transaction
35-
destination: <contract>
36-
entrypoint: propose
30+
destination: <token>
31+
entrypoint: transfer
32+
first_level: 2393103
33+
last_level: 2393103
3734

3835
indexes:
3936
factory:
4037
kind: operation
4138
datasource: tzkt
39+
contracts:
40+
- factory
4241
types:
4342
- origination
43+
- transaction
4444
handlers:
45-
- callback: on_factory_origination
46-
pattern:
47-
- type: origination
48-
similar_to: registry
45+
- callback: on_factory_origination
46+
pattern:
47+
- type: transaction
48+
entrypoint: launchExchange
49+
- type: origination
50+
source: factory
51+
first_level: 2428590
52+
last_level: 2428590
Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,36 @@
1+
from contextlib import suppress
12
from typing import cast
23

3-
from demo_factories.types.registry.storage import RegistryStorage
44
from dipdup.context import HandlerContext
5-
from dipdup.models import Origination
5+
from dipdup.exceptions import ContractAlreadyExistsError
6+
from dipdup.models import OperationData
67

78

89
async def on_factory_origination(
910
ctx: HandlerContext,
10-
registry_origination: Origination[RegistryStorage],
11+
transaction_0: OperationData,
12+
origination_1: OperationData,
1113
) -> None:
12-
originated_contract = cast(str, registry_origination.data.originated_contract_address)
13-
name = f'registry_dao_{originated_contract}'
14+
assert transaction_0.parameter_json
15+
dex_contract = cast(str, origination_1.originated_contract_address)
16+
token_contract = cast(str, transaction_0.parameter_json['token']['address'])
17+
1418
await ctx.add_contract(
15-
name=originated_contract,
16-
address=originated_contract,
17-
typename='registry',
19+
name=dex_contract,
20+
address=dex_contract,
21+
typename='dex',
1822
)
23+
with suppress(ContractAlreadyExistsError):
24+
await ctx.add_contract(
25+
name=token_contract,
26+
address=token_contract,
27+
typename='token',
28+
)
1929
await ctx.add_index(
20-
name=name,
21-
template='registry_dao',
22-
values={'contract': originated_contract},
30+
name=dex_contract,
31+
template='dex',
32+
values={
33+
'dex': dex_contract,
34+
'token': token_contract,
35+
},
2336
)

demos/demo-factories/src/demo_factories/handlers/on_origination.py

Lines changed: 0 additions & 11 deletions
This file was deleted.

demos/demo-factories/src/demo_factories/handlers/on_propose.py

Lines changed: 0 additions & 13 deletions
This file was deleted.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import demo_factories.models as models
2+
from demo_factories.types.token.parameter.transfer import TransferParameter
3+
from demo_factories.types.token.storage import TokenStorage
4+
from dipdup.context import HandlerContext
5+
from dipdup.models import Transaction
6+
7+
8+
async def on_transfer(
9+
ctx: HandlerContext,
10+
transfer: Transaction[TransferParameter, TokenStorage],
11+
) -> None:
12+
for transfer_item in transfer.parameter.__root__:
13+
for tx in transfer_item.txs:
14+
await models.Transfer.create(
15+
from_=transfer_item.from_,
16+
to=tx.to_,
17+
amount=tx.amount,
18+
)
Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,10 @@
11
from tortoise import fields
2-
from tortoise.fields.relational import ForeignKeyFieldInstance
32

43
from dipdup.models import Model
54

65

7-
class DAO(Model):
8-
address = fields.CharField(36, pk=True)
9-
10-
11-
class User(Model):
12-
address = fields.CharField(36, pk=True)
13-
balance = fields.IntField()
14-
15-
16-
class Proposal(Model):
17-
id = fields.IntField(pk=True)
18-
dao: ForeignKeyFieldInstance[DAO] = fields.ForeignKeyField('models.DAO', 'proposals')
19-
# upvotes = fields.IntField(default=0)
20-
# downvotes = fields.IntField(default=0)
21-
# start_date = fields.DatetimeField()
22-
# metadata = fields.JSONField()
23-
# proposer = fields.ForeignKeyField('models.Address', 'proposals')
24-
25-
26-
class Vote(Model):
6+
class Transfer(Model):
277
id = fields.IntField(pk=True)
28-
proposal: ForeignKeyFieldInstance[Proposal] = fields.ForeignKeyField('models.Proposal', 'votes')
29-
amount = fields.IntField()
8+
from_ = fields.TextField()
9+
to = fields.TextField()
10+
amount = fields.TextField()
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# generated by datamodel-codegen:
2+
# filename: storage.json
3+
4+
from __future__ import annotations
5+
6+
from typing import Dict
7+
from typing import List
8+
from typing import Optional
9+
10+
from pydantic import BaseModel
11+
from pydantic import Extra
12+
13+
14+
class Ledger(BaseModel):
15+
class Config:
16+
extra = Extra.forbid
17+
18+
allowances: List[str]
19+
balance: str
20+
frozen_balance: str
21+
22+
23+
class TokenList(BaseModel):
24+
class Config:
25+
extra = Extra.forbid
26+
27+
address: str
28+
nat: str
29+
30+
31+
class Key(BaseModel):
32+
class Config:
33+
extra = Extra.forbid
34+
35+
address: str
36+
nat: str
37+
38+
39+
class TokenToExchangeItem(BaseModel):
40+
class Config:
41+
extra = Extra.forbid
42+
43+
key: Key
44+
value: str
45+
46+
47+
class UserRewards(BaseModel):
48+
class Config:
49+
extra = Extra.forbid
50+
51+
reward: str
52+
reward_paid: str
53+
54+
55+
class Voters(BaseModel):
56+
class Config:
57+
extra = Extra.forbid
58+
59+
candidate: Optional[str]
60+
last_veto: str
61+
veto: str
62+
vote: str
63+
64+
65+
class FactoryStorage(BaseModel):
66+
class Config:
67+
extra = Extra.forbid
68+
69+
baker_validator: str
70+
counter: str
71+
dex_lambdas: Dict[str, str]
72+
ledger: Dict[str, Ledger]
73+
metadata: Dict[str, str]
74+
token_lambdas: Dict[str, str]
75+
token_list: Dict[str, TokenList]
76+
token_to_exchange: List[TokenToExchangeItem]
77+
user_rewards: Dict[str, UserRewards]
78+
vetos: Dict[str, str]
79+
voters: Dict[str, Voters]
80+
votes: Dict[str, str]

demos/demo-factories/src/demo_factories/types/registry/parameter/propose.py

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)