Skip to content

Commit

Permalink
Merge branch 'bug-66-test' of https://github.com/janezpodhostnik/flow…
Browse files Browse the repository at this point in the history
…-py-sdk into bug-66
  • Loading branch information
lealobanov committed Nov 1, 2024
2 parents cdfb195 + a68d9cb commit 35d1697
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 38 deletions.
40 changes: 20 additions & 20 deletions examples/transactions_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,23 +283,23 @@ async def run(self, ctx: Config):
self.log.info(f"transaction script: {transaction.script.decode('utf-8')}")


class DebuggingFetchTransactionByIdExample(Example):
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:

tx_id = "ef6e6dcba87c5f853e0ec940dd382d609ffe11109c28ed239843d71618fa1d71"

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

print(f"Transaction ID: {tx_id}")
# class DebuggingFetchTransactionByIdExample(Example):
# 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:
#
# tx_id = "ef6e6dcba87c5f853e0ec940dd382d609ffe11109c28ed239843d71618fa1d71"
#
# transaction = await client.get_transaction_result(id=bytes.fromhex(tx_id))
#
# print(f"Transaction ID: {tx_id}")
2 changes: 1 addition & 1 deletion flow_py_sdk/cadence/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
StoragePathKind,
PublicPathKind,
PrivatePathKind,
AuthAccountKind,
AccountKind,
PublicAccountKind,
AuthAccountKeysKind,
PublicAccountKeysKind,
Expand Down
28 changes: 14 additions & 14 deletions flow_py_sdk/cadence/decode.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,20 @@ def decode(obj: dict[Any, Any]) -> Union[Value, Kind, dict]:
decoder = _cadence_decoders[type_]
return decoder(obj)

# Recursively handle nested structures
if isinstance(obj, dict):
for key, value in obj.items():
if isinstance(value, dict):
obj[key] = decode(value) # Recursive call for nested dict
elif isinstance(value, list):
obj[key] = [
decode(item) for item in value
] # Recursive list handling

elif isinstance(obj, list):
obj = [
decode(item) for item in obj
] # Handle obj itself as a list if list type
# # Recursively handle nested structures
# if isinstance(obj, dict):
# for key, value in obj.items():
# if isinstance(value, dict):
# obj[key] = decode(value) # Recursive call for nested dict
# elif isinstance(value, list):
# obj[key] = [
# decode(item) for item in value
# ] # Recursive list handling
#
# elif isinstance(obj, list):
# obj = [
# decode(item) for item in obj
# ] # Handle obj itself as a list if list type

return obj # Return the object if no decoder applies

Expand Down
6 changes: 3 additions & 3 deletions flow_py_sdk/cadence/simple_kinds.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,10 +275,10 @@ def kind_str(cls) -> str:
return "PrivatePath"


class AuthAccountKind(SimpleKind):
class AccountKind(SimpleKind):
@classmethod
def kind_str(cls) -> str:
return "AuthAccount"
return "Account"


class PublicAccountKind(SimpleKind):
Expand Down Expand Up @@ -372,7 +372,7 @@ def kind_str(cls) -> str:
StoragePathKind,
PublicPathKind,
PrivatePathKind,
AuthAccountKind,
AccountKind,
PublicAccountKind,
AuthAccountKeysKind,
PublicAccountKeysKind,
Expand Down
62 changes: 62 additions & 0 deletions tests/cadence/encode_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1400,6 +1400,68 @@ def testInclusiveRangeKind(self):
)
self._encodeAndDecodeAll([kind])

def testAccountCapabilityControllerIssued(self):
kind = _EncodeTestParams(
"AccountCapabilityControllerIssued event",
cadence.Event(
"flow.AccountCapabilityControllerIssued",
[
(
"type",
cadence.TypeValue(
cadence.ReferenceKind(
cadence.EntitlementConjunctionSetKind(
[
cadence.EntitlementKind("Storage"),
cadence.EntitlementKind("Contracts"),
cadence.EntitlementKind("Keys"),
cadence.EntitlementKind("Inbox"),
cadence.EntitlementKind("Capabilities"),
]
),
cadence.AccountKind()
),
),
)
]
),
"""
{
"value": {
"id": "flow.AccountCapabilityControllerIssued",
"fields": [
{
"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"
}
""",
)
self._encodeAndDecodeAll([kind])

def testStorefrontEvent(self):
self.maxDiff = None
event = _EncodeTestParams(
Expand Down

0 comments on commit 35d1697

Please sign in to comment.