Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#66/ Deserializing of events from flow_proto fails with transactions with many events #67

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
19 changes: 19 additions & 0 deletions examples/transactions_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,3 +281,22 @@ async def run(self, ctx: Config):
f"transaction proposer: {transaction.proposal_key.address.hex()}"
)
self.log.info(f"transaction script: {transaction.script.decode('utf-8')}")


class DebuggingFetchTransactionByIdExample(Example):
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added example which makes a mainnet call to the failing tx ID ef6e6dcba87c5f853e0ec940dd382d609ffe11109c28ed239843d71618fa1d71, will remove this before merging changes

def __init__(self) -> None:
super().__init__(tag="T.LL.", name="DebuggingFetchTransactionByIdExample", sort_order=501)

async def run(self, ctx: Config):
# First Step : Create a client to connect to the flow blockchain
# flow_client function creates a client using the host and port
async with flow_client(
# host=ctx.access_node_host, port=ctx.access_node_port
host="access.mainnet.nodes.onflow.org", port=9000
) as client:
lealobanov marked this conversation as resolved.
Show resolved Hide resolved

tx_id = "ef6e6dcba87c5f853e0ec940dd382d609ffe11109c28ed239843d71618fa1d71"

transaction = await client.get_transaction_result(id=bytes.fromhex(tx_id))

print(f"Transaction ID: {tx_id}")
lealobanov marked this conversation as resolved.
Show resolved Hide resolved
291 changes: 291 additions & 0 deletions failed_events.json
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an output of the failing event payloads for reference, will remove before merging changes

Original file line number Diff line number Diff line change
@@ -0,0 +1,291 @@
[
{
"value": {
"id": "flow.AccountCapabilityControllerIssued",
"fields": [
{
"name": "id",
"value": {
"value": "3",
"type": "UInt64"
}
},
{
"name": "address",
"value": {
"value": "0x646997908e65fb70",
"type": "Address"
}
},
{
"name": "type",
"value": {
"value": {
"staticType": {
"type": {
"kind": "Account"
},
"kind": "Reference",
"authorization": {
"kind": "EntitlementConjunctionSet",
"entitlements": [
{ "kind": "Entitlement", "typeID": "Storage" },
{ "kind": "Entitlement", "typeID": "Contracts" },
{ "kind": "Entitlement", "typeID": "Keys" },
{ "kind": "Entitlement", "typeID": "Inbox" },
{ "kind": "Entitlement", "typeID": "Capabilities" }
]
}
}
},
"type": "Type"
}
}
]
},
"type": "Event"
},
{
"value": {
"id": "flow.StorageCapabilityControllerIssued",
"fields": [
{
"name": "id",
"value": {
"value": "148",
"type": "UInt64"
}
},
{
"name": "address",
"value": {
"value": "0x0342200ce19810f6",
"type": "Address"
}
},
{
"name": "type",
"value": {
"value": {
"staticType": {
"type": {
"type": "",
"kind": "Resource",
"typeID": "A.befbaccb5032a457.ContractManager.Manager",
"fields": [
{ "type": { "kind": "UInt64" }, "id": "uuid" },
{
"type": {
"type": {
"kind": "Account"
},
"kind": "Reference",
"authorization": {
"kind": "EntitlementConjunctionSet",
"entitlements": [
{ "kind": "Entitlement", "typeID": "Storage" },
{ "kind": "Entitlement", "typeID": "Contracts" },
{ "kind": "Entitlement", "typeID": "Keys" },
{ "kind": "Entitlement", "typeID": "Inbox" },
{ "kind": "Entitlement", "typeID": "Capabilities" }
]
}
},
"kind": "Capability",
"id": "acct"
},
{
"type": {
"type": {
"type": "",
"kind": "Resource",
"typeID": "A.707c0b39a8d689cb.FungibleTokenRouter.Router",
"fields": [
{ "type": { "kind": "UInt64" }, "id": "uuid" },
{ "type": { "kind": "Address" }, "id": "defaultAddress" },
{
"type": {
"key": { "kind": "String" },
"value": { "kind": "Address" },
"kind": "Dictionary"
},
"id": "addressOverrides"
}
]
},
"kind": "Reference",
"authorization": {
"kind": "EntitlementConjunctionSet",
"entitlements": [
{
"kind": "Entitlement",
"typeID": "A.707c0b39a8d689cb.FungibleTokenRouter.Owner"
}
]
}
},
"kind": "Capability",
"id": "routerCap"
},
{
"type": {
"key": { "kind": "String" },
"value": { "kind": "AnyStruct" },
"kind": "Dictionary"
},
"id": "data"
},
{
"type": {
"key": { "kind": "String" },
"value": { "kind": "AnyResource" },
"kind": "Dictionary"
},
"id": "resources"
}
]
},
"kind": "Reference",
"authorization": {
"kind": "Unauthorized",
"entitlements": null
}
}
},
"type": "Type"
}
},
{
"name": "path",
"value": {
"value": {
"domain": "storage",
"identifier": "ContractManager_0xbefbaccb5032a457"
},
"type": "Path"
}
}
]
},
"type": "Event"
},
{
"value": {
"id": "flow.CapabilityPublished",
"fields": [
{
"name": "address",
"value": {
"value": "0x0342200ce19810f6",
"type": "Address"
}
},
{
"name": "path",
"value": {
"value": {
"domain": "public",
"identifier": "ContractManager_0xbefbaccb5032a457"
},
"type": "Path"
}
},
{
"name": "capability",
"value": {
"value": {
"borrowType": {
"type": {
"type": "",
"kind": "Resource",
"typeID": "A.befbaccb5032a457.ContractManager.Manager",
"fields": [
{ "type": { "kind": "UInt64" }, "id": "uuid" },
{
"type": {
"type": {
"kind": "Account"
},
"kind": "Reference",
"authorization": {
"kind": "EntitlementConjunctionSet",
"entitlements": [
{ "kind": "Entitlement", "typeID": "Storage" },
{ "kind": "Entitlement", "typeID": "Contracts" },
{ "kind": "Entitlement", "typeID": "Keys" },
{ "kind": "Entitlement", "typeID": "Inbox" },
{ "kind": "Entitlement", "typeID": "Capabilities" }
]
}
},
"kind": "Capability",
"id": "acct"
},
{
"type": {
"type": {
"type": "",
"kind": "Resource",
"typeID": "A.707c0b39a8d689cb.FungibleTokenRouter.Router",
"fields": [
{ "type": { "kind": "UInt64" }, "id": "uuid" },
{ "type": { "kind": "Address" }, "id": "defaultAddress" },
{
"type": {
"key": { "kind": "String" },
"value": { "kind": "Address" },
"kind": "Dictionary"
},
"id": "addressOverrides"
}
]
},
"kind": "Reference",
"authorization": {
"kind": "EntitlementConjunctionSet",
"entitlements": [
{
"kind": "Entitlement",
"typeID": "A.707c0b39a8d689cb.FungibleTokenRouter.Owner"
}
]
}
},
"kind": "Capability",
"id": "routerCap"
},
{
"type": {
"key": { "kind": "String" },
"value": { "kind": "AnyStruct" },
"kind": "Dictionary"
},
"id": "data"
},
{
"type": {
"key": { "kind": "String" },
"value": { "kind": "AnyResource" },
"kind": "Dictionary"
},
"id": "resources"
}
]
},
"kind": "Reference",
"authorization": {
"kind": "Unauthorized",
"entitlements": null
}
},
"address": "0x0342200ce19810f6",
"id": "148"
},
"type": "Capability"
}
}
]
},
"type": "Event"
}
]
2 changes: 2 additions & 0 deletions flow_py_sdk/cadence/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@
inclusiveRangeTypeStr = "InclusiveRange"
capabilityTypeStr = "Capability"
functionTypeStr = "Function"
entitlementConjunctionSetStr = "EntitlementConjunctionSet"
entitlementKey = "Entitlement"
lealobanov marked this conversation as resolved.
Show resolved Hide resolved

fix64_scale = int(8)
fix64_factor = int(100_000_000)
7 changes: 7 additions & 0 deletions flow_py_sdk/cadence/decode.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ def decode(obj: [dict[Any, Any]]) -> Union[Value, Kind]:
decoder = _cadence_decoders[type_]
return decoder(obj)

# Recursively handle nested dictionaries and lists
for key, value in obj.items():
if isinstance(value, dict):
obj[key] = decode(value)
elif isinstance(value, list):
obj[key] = [decode(item) for item in value]

raise NotImplementedError()


Expand Down
16 changes: 9 additions & 7 deletions flow_py_sdk/cadence/kinds.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,13 +350,15 @@ def __init__(self, entitlements: list[EntitlementBaseKind]) -> None:

@classmethod
def decode(cls, value) -> "Kind":
entitlements_val = value[c.entitlementsKey]
entitlements = [
decode(v).as_kind(EntitlementBaseKind) for v in entitlements_val
]
return cls(
entitlements,
)
try:
entitlements_val = value[c.entitlementsKey]
entitlements = [
decode(v).as_kind(EntitlementBaseKind) for v in entitlements_val
]
return cls(entitlements)
except Exception as e:
print(f"Error decoding entitlements for {cls.kind_str()}: {value}. Error: {e}")
return None

def encode_kind(self) -> dict:
return {c.entitlementsKey: [e.encode() for e in self.entitlements]}
Expand Down
Loading
Loading