Skip to content

Commit

Permalink
Update to cadence api v0.3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
janezpodhostnik committed Feb 20, 2023
1 parent 6c9f1da commit 467bf87
Show file tree
Hide file tree
Showing 17 changed files with 1,650 additions and 1,104 deletions.
4 changes: 1 addition & 3 deletions examples/common/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,7 @@ async def random_account_with_weights(

result = await client.execute_transaction(tx)
new_addresses = [
e.value.address
for e in result.events
if isinstance(e.value, cadence.AccountCreatedEvent)
e.value.address for e in result.events if e.value.id == "flow.AccountCreated"
]

return (
Expand Down
2 changes: 1 addition & 1 deletion examples/events_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ async def run(self, ctx: Config):
e.value for e in result.events if isinstance(e.value, cadence.Event)
][0]

assert add_event.fields[2].as_type(cadence.Int).value == 7
assert add_event.sum.as_type(cadence.Int).value == 7

self.log.info(f"event type: {result.events[0].type}")
self.log.info(f"event value: {result.events[0].value}")
Expand Down
6 changes: 3 additions & 3 deletions examples/scripts_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,11 @@ async def run(self, ctx: Config):
script_result: cadence.Value = complex_script

self.log.info(
f"Name: {script_result.as_type(cadence.Struct).fields[2].as_type(cadence.String).value}"
f"Name: {script_result.as_type(cadence.Struct).name.as_type(cadence.String).value}"
)
self.log.info(
f"Address: {script_result.as_type(cadence.Struct).fields[1].as_type(cadence.Address).bytes.hex()}"
f"Address: {script_result.as_type(cadence.Struct).address.as_type(cadence.Address).bytes.hex()}"
)
self.log.info(
f"Balance: {script_result.as_type(cadence.Struct).fields[0].as_type(cadence.UFix64).value}"
f"Balance: {script_result.as_type(cadence.Struct).balance.as_type(cadence.UFix64).value}"
)
8 changes: 2 additions & 6 deletions examples/user_message_examples.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
from examples.common import Example, Config
from examples.common.utils import random_account_with_weights
from flow_py_sdk import (
SignAlgo,
HashAlgo,
InMemorySigner,
InMemoryVerifier,
flow_client,
AccountKey,
utils,
)
from examples.common.utils import random_account, random_account_with_weights
from examples.common import Example, Config


# -------------------------------------------------------------------------
Expand Down
99 changes: 79 additions & 20 deletions flow_py_sdk/cadence/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
from .decode import cadence_object_hook
from .encode import CadenceJsonEncoder, encode_arguments
from .events import (
Event,
BaseEvent,
EventTypeRegistry,
EventType,
)
from .types import (
Value,
Void,
Expand Down Expand Up @@ -35,28 +29,93 @@
UFix64,
Array,
Dictionary,
Link,
Path,
Capability,
Function,
KeyValuePair,
TypeValue,
)
from .composite import (
Type,
CompositeType,
Struct,
StructType,
Resource,
ResourceType,
ContractType,
Contract,
Field,
Event,
Enum,
Composite,
)
from .kind import (
Kind,
)
from .simple_kinds import (
AnyKind,
AnyStructKind,
AnyResourceKind,
TypeKind,
VoidKind,
NeverKind,
BoolKind,
StringKind,
CharacterKind,
BytesKind,
AddressKind,
NumberKind,
SignedNumberKind,
IntegerKind,
SignedIntegerKind,
FixedPointKind,
SignedFixedPointKind,
IntKind,
Int8Kind,
Int16Kind,
Int32Kind,
Int64Kind,
Int128Kind,
Int256Kind,
UIntKind,
UInt8Kind,
UInt16Kind,
UInt32Kind,
UInt64Kind,
UInt128Kind,
UInt256Kind,
Word8Kind,
Word16Kind,
Word32Kind,
Word64Kind,
Fix64Kind,
UFix64Kind,
PathKind,
CapabilityPathKind,
StoragePathKind,
PublicPathKind,
PrivatePathKind,
AuthAccountKind,
PublicAccountKind,
AuthAccountKeysKind,
PublicAccountKeysKind,
AuthAccountContractsKind,
PublicAccountContractsKind,
DeployedContractKind,
AccountKeyKind,
BlockKind,
)
from .events import AccountCreatedEvent
from .location import (
StringLocation,
FlowLocation,
AddressLocation,
Location,
ScriptLocation,
from .kinds import (
OptionalKind,
VariableSizedArrayKind,
ConstantSizedArrayKind,
DictionaryKind,
ParameterKind,
FieldKind,
StructKind,
ResourceKind,
EventKind,
ContractKind,
StructInterfaceKind,
ResourceInterfaceKind,
ContractInterfaceKind,
FunctionKind,
ReferenceKind,
RestrictedKind,
CapabilityKind,
EnumKind,
)
Loading

0 comments on commit 467bf87

Please sign in to comment.