├── .github ├── ISSUE_TEMPLATE │ ├── bug-report.yaml │ └── feature-request.yaml ├── pull_request_template.md ├── release.yml └── workflows │ ├── benchmark.yml │ ├── ci.yml │ ├── codeql-analysis.yml │ ├── compat.yaml │ ├── compatibility-check-template.yml │ ├── compatibility-check.yml │ ├── downstream.yml │ ├── get-contracts.yml │ └── release.yml ├── .gitignore ├── .golangci.yml ├── .mailmap ├── CHANGELOG.md ├── CODEOWNERS ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── LICENSE ├── Makefile ├── NOTICE ├── README.md ├── ROADMAP.md ├── SECURITY.md ├── activations ├── activations.go └── activations_test.go ├── ast ├── access.go ├── access_test.go ├── argument.go ├── argument_test.go ├── ast.go ├── attachment.go ├── attachment_test.go ├── block.go ├── block_test.go ├── composite.go ├── composite_test.go ├── conditionkind.go ├── conditionkind_string.go ├── conditionkind_test.go ├── declaration.go ├── elementtype.go ├── elementtype_string.go ├── entitlement_declaration.go ├── entitlement_declaration_test.go ├── expression.go ├── expression_as_type.go ├── expression_extractor.go ├── expression_extractor_test.go ├── expression_test.go ├── function_declaration.go ├── function_declaration_test.go ├── identifier.go ├── import.go ├── import_test.go ├── inspect.go ├── inspector.go ├── inspector_test.go ├── interface.go ├── interface_test.go ├── memberindices.go ├── memberindices_test.go ├── members.go ├── members_test.go ├── operation.go ├── operation_string.go ├── operation_test.go ├── parameter.go ├── parameterlist.go ├── parameterlist_test.go ├── position.go ├── pragma.go ├── pragma_test.go ├── precedence.go ├── precedence_string.go ├── prettier.go ├── primitiveaccess_string.go ├── program.go ├── program_test.go ├── programindices.go ├── programindices_test.go ├── statement.go ├── statement_test.go ├── string.go ├── string_template_test.go ├── string_test.go ├── transaction_declaration.go ├── transaction_declaration_test.go ├── transfer.go ├── transfer_test.go ├── transferoperation.go ├── transferoperation_string.go ├── transferoperation_test.go ├── type.go ├── type_test.go ├── typeparameter.go ├── typeparameterlist.go ├── variable_declaration.go ├── variable_declaration_test.go ├── variablekind.go ├── variablekind_string.go ├── variablekind_test.go ├── visitor.go └── walk.go ├── benchmarks ├── binarytrees.cdc ├── fannkuch.cdc ├── fib_dynamic.cdc ├── fib_iterative.cdc └── fib_recursive.cdc ├── bump-version.sh ├── cadence_furever.png ├── check-headers.sh ├── cmd ├── check │ └── main.go ├── cmd.go ├── decode-state-values │ └── main.go ├── execute │ ├── colors.go │ ├── debugger.go │ ├── execute.go │ └── repl.go ├── info │ ├── README.md │ └── main.go ├── json-cdc │ └── main.go ├── lex │ └── main.go ├── main │ └── main.go ├── minifier │ ├── minifier.go │ └── minifier_test.go └── parse │ ├── main.go │ └── main_wasm.go ├── codecov.yml ├── common ├── address.go ├── address_test.go ├── addresslocation.go ├── addresslocation_test.go ├── bigint.go ├── bigint_test.go ├── bimap │ ├── bimap.go │ └── bimap_test.go ├── compositekind.go ├── compositekind_string.go ├── compositekind_test.go ├── computationkind.go ├── computationkind_string.go ├── concat.go ├── controlstatement.go ├── controlstatement_string.go ├── declarationkind.go ├── declarationkind_string.go ├── declarationkind_test.go ├── deps │ ├── node.go │ ├── node_test.go │ └── set.go ├── enumerate.go ├── identifierlocation.go ├── identifierlocation_test.go ├── incomparable.go ├── integerliteralkind.go ├── integerliteralkind_string.go ├── intervalst │ ├── interval.go │ ├── intervalst.go │ ├── intervalst_test.go │ └── node.go ├── list │ └── list.go ├── location.go ├── location_test.go ├── memorykind.go ├── memorykind_string.go ├── metering.go ├── operandside.go ├── operandside_string.go ├── operationkind.go ├── operationkind_string.go ├── orderedmap │ ├── orderedmap.go │ └── orderedmap_test.go ├── pathdomain.go ├── pathdomain_string.go ├── persistent │ ├── orderedset.go │ └── orderedset_test.go ├── repllocation.go ├── repllocation_test.go ├── scriptlocation.go ├── scriptlocation_test.go ├── slice_utils.go ├── slice_utils_test.go ├── storagedomain.go ├── stringlocation.go ├── stringlocation_test.go ├── transactionlocation.go └── transactionlocation_test.go ├── compat ├── README.md ├── main.py ├── requirements.txt ├── setup.md └── suite │ ├── dapper-labs-nba-smart-contracts.yaml │ ├── dapper-labs-nfl-smart-contracts.yaml │ ├── flow-core-contracts.yaml │ ├── flow-ft.yaml │ ├── flow-nft.yaml │ └── green-goo-dao-flow-utils.yaml ├── docs ├── Cadence - Implementation, Present and Future.odp ├── Cadence - Implementation, Present and Future.pdf ├── Cadence Implementation.odp ├── Cadence Implementation.pdf ├── FAQ.md ├── README.md ├── anti-patterns.mdx ├── architecture.monopic ├── architecture.png ├── architecture.svg ├── cadence.ebnf ├── contract-upgrades.mdx ├── design-patterns.mdx ├── development.md ├── go.md ├── goland.md ├── images │ ├── compatibility_check_action_params.png │ ├── compatibility_check_action_trigger.png │ ├── create_release.png │ ├── release_action.png │ └── release_tag.png ├── index.mdx ├── json-cadence-spec.md ├── language │ ├── access-control.md │ ├── accounts.mdx │ ├── attachments.md │ ├── built-in-functions.mdx │ ├── capability-based-access-control.md │ ├── composite-types.mdx │ ├── constants-and-variables.md │ ├── contract-updatability.md │ ├── contracts.mdx │ ├── control-flow.md │ ├── core-events.md │ ├── crypto.mdx │ ├── enumerations.md │ ├── environment-information.md │ ├── events.md │ ├── functions.mdx │ ├── glossary.md │ ├── imports.mdx │ ├── index.md │ ├── interfaces.mdx │ ├── operators.md │ ├── references.mdx │ ├── resources.mdx │ ├── restricted-types.md │ ├── run-time-types.md │ ├── scope.md │ ├── syntax.md │ ├── transactions.md │ ├── type-annotations.md │ ├── type-hierarchy.md │ ├── type-hierarchy.monopic │ ├── type-hierarchy.png │ ├── type-inference.md │ ├── type-safety.md │ └── values-and-types.mdx ├── lint.js ├── measuring-time.mdx ├── package-lock.json ├── package.json ├── releasing.md ├── security-best-practices.mdx ├── solidity-to-cadence.mdx ├── syntax-highlighting.md ├── syntax │ ├── Cadence.syntax │ └── Syntax Notation.md ├── testing-framework.mdx ├── tutorial │ ├── 01-first-steps.mdx │ ├── 02-hello-world.mdx │ ├── 03-resources.mdx │ ├── 04-capabilities.mdx │ ├── 05-non-fungible-tokens-1.mdx │ ├── 05-non-fungible-tokens-2.mdx │ ├── 06-fungible-tokens.mdx │ ├── 07-marketplace-setup.mdx │ ├── 08-marketplace-compose.mdx │ ├── 09-voting.mdx │ ├── 10-resources-compose.mdx │ ├── deploybox.png │ └── txbox.png └── why.md ├── encoding ├── README.md ├── ccf │ ├── bench_test.go │ ├── ccf.go │ ├── ccf_test.go │ ├── ccf_type_id.go │ ├── ccf_type_id_test.go │ ├── consts.go │ ├── decode.go │ ├── decode_type.go │ ├── decode_typedef.go │ ├── encode.go │ ├── encode_type.go │ ├── encode_typedef.go │ ├── service_events_test.go │ ├── simpletype.go │ ├── simpletype_string.go │ ├── simpletype_test.go │ ├── sort.go │ └── traverse_value.go └── json │ ├── decode.go │ ├── encode.go │ ├── encoding_test.go │ └── json.go ├── errors ├── errors.go └── wrappanic.go ├── examples └── quicksort.cdc ├── fixedpoint ├── check.go ├── convert.go ├── fixedpoint.go ├── parse.go └── parse_test.go ├── format ├── address.go ├── array.go ├── bool.go ├── bytes.go ├── bytes_test.go ├── capability.go ├── composite.go ├── dictionary.go ├── fix.go ├── fix_test.go ├── int.go ├── nil.go ├── pad.go ├── path.go ├── reference.go ├── string.go ├── type.go └── void.go ├── fuzz.go ├── fuzz └── crashers_test.go ├── go.mod ├── go.sum ├── interpreter ├── account_storagemap.go ├── account_storagemap_test.go ├── account_test.go ├── arithmetic_test.go ├── array_test.go ├── attachments_test.go ├── bitwise_test.go ├── builtinfunctions_test.go ├── character_test.go ├── composite_value_test.go ├── condition_test.go ├── config.go ├── container_mutation_test.go ├── contract_test.go ├── conversion.go ├── conversion_test.go ├── debugger.go ├── declaration_test.go ├── decode.go ├── deepcopyremove_test.go ├── dictionary_test.go ├── div_mod_test.go ├── domain_storagemap.go ├── domain_storagemap_test.go ├── dynamic_casting_test.go ├── encode.go ├── encoding_benchmark_test.go ├── encoding_test.go ├── entitlements_test.go ├── enum_test.go ├── equality_test.go ├── errors.go ├── errors_test.go ├── fib_test.go ├── fixedpoint_test.go ├── for_test.go ├── function_test.go ├── globalvariables.go ├── hashablevalue.go ├── hashablevalue_test.go ├── if_test.go ├── import.go ├── import_test.go ├── inclusive_range_iterator.go ├── indexing_test.go ├── inspect.go ├── inspect_test.go ├── integer.go ├── integers_test.go ├── interface.go ├── interface_test.go ├── interpreter.go ├── interpreter_expression.go ├── interpreter_import.go ├── interpreter_invocation.go ├── interpreter_statement.go ├── interpreter_test.go ├── interpreter_tracing.go ├── interpreter_tracing_test.go ├── interpreter_transaction.go ├── invocation.go ├── invocation_test.go ├── location.go ├── location_test.go ├── member_test.go ├── memory_metering_test.go ├── metatype_test.go ├── metering_test.go ├── minus_test.go ├── misc_test.go ├── mul_test.go ├── negate_test.go ├── nesting_test.go ├── number.go ├── number_test.go ├── path_test.go ├── pathcapability_test.go ├── plus_test.go ├── primitivestatictype.go ├── primitivestatictype_string.go ├── primitivestatictype_test.go ├── program.go ├── range_value_test.go ├── reference_test.go ├── resources_test.go ├── runtimetype_test.go ├── sharedstate.go ├── simplecompositevalue.go ├── statementresult.go ├── statictype.go ├── statictype_test.go ├── storage.go ├── storage_test.go ├── storagemapkey.go ├── string_test.go ├── stringatreevalue.go ├── stringatreevalue_test.go ├── struct_stringer_test.go ├── switch_test.go ├── testdata │ ├── comp_v2_96d7e06eaf4b3fcf.cbor.gz │ ├── comp_v3_99dc360eee32dcec.cbor.gz │ ├── comp_v3_b52a33b7e56868f6.cbor.gz │ ├── comp_v3_d99d7e6b4dad41e1.cbor.gz │ ├── link_v3_2392f05c3b72f235.cbor.gz │ └── link_v3_3a791fe1b8243e73.cbor.gz ├── transactions_test.go ├── transfer_test.go ├── uint64atreevalue.go ├── uuid_test.go ├── value.go ├── value_account.go ├── value_account_accountcapabilities.go ├── value_account_capabilities.go ├── value_account_contracts.go ├── value_account_inbox.go ├── value_account_storage.go ├── value_account_storagecapabilities.go ├── value_accountcapabilitycontroller.go ├── value_accountkey.go ├── value_address.go ├── value_array.go ├── value_authaccount_keys.go ├── value_block.go ├── value_bool.go ├── value_capability.go ├── value_character.go ├── value_composite.go ├── value_deployedcontract.go ├── value_deployment_result.go ├── value_dictionary.go ├── value_ephemeral_reference.go ├── value_fix64.go ├── value_function.go ├── value_function_test.go ├── value_int.go ├── value_int128.go ├── value_int16.go ├── value_int256.go ├── value_int32.go ├── value_int64.go ├── value_int8.go ├── value_link.go ├── value_nil.go ├── value_number.go ├── value_optional.go ├── value_path.go ├── value_pathcapability.go ├── value_placeholder.go ├── value_publickey.go ├── value_published.go ├── value_range.go ├── value_reference.go ├── value_some.go ├── value_some_test.go ├── value_storage_reference.go ├── value_storagecapabilitycontroller.go ├── value_string.go ├── value_test.go ├── value_type.go ├── value_ufix64.go ├── value_uint.go ├── value_uint128.go ├── value_uint16.go ├── value_uint256.go ├── value_uint32.go ├── value_uint64.go ├── value_uint8.go ├── value_void.go ├── value_word128.go ├── value_word16.go ├── value_word256.go ├── value_word32.go ├── value_word64.go ├── value_word8.go ├── valuedeclaration.go ├── values_test.go ├── variable.go ├── variable_activations.go ├── visitor.go ├── walk.go └── while_test.go ├── meetings └── README.md ├── npm-packages ├── cadence-parser │ ├── .gitignore │ ├── README.md │ ├── jest.config.js │ ├── package-lock.json │ ├── package.json │ ├── src │ │ ├── go.js │ │ └── index.ts │ ├── tests │ │ ├── index.test.ts │ │ └── setup.js │ └── tsconfig.json └── monaco-languageclient-cadence │ ├── .gitignore │ ├── README.md │ ├── package-lock.json │ ├── package.json │ ├── src │ └── index.ts │ └── tsconfig.json ├── old_parser ├── benchmark_test.go ├── comment.go ├── declaration.go ├── declaration_test.go ├── docstring.go ├── docstring_test.go ├── errors.go ├── expression.go ├── expression_test.go ├── function.go ├── invalidnumberliteralkind.go ├── invalidnumberliteralkind_string.go ├── keyword.go ├── lexer │ ├── lexer.go │ ├── lexer_test.go │ ├── state.go │ ├── token.go │ ├── tokenstream.go │ └── tokentype.go ├── parser.go ├── parser_test.go ├── statement.go ├── statement_test.go ├── transaction.go ├── type.go └── type_test.go ├── parser ├── benchmark_test.go ├── comment.go ├── comment_test.go ├── declaration.go ├── declaration_test.go ├── docstring.go ├── docstring_test.go ├── errors.go ├── expression.go ├── expression_test.go ├── function.go ├── invalidnumberliteralkind.go ├── invalidnumberliteralkind_string.go ├── keyword.go ├── lexer │ ├── lexer.go │ ├── lexer_test.go │ ├── state.go │ ├── token.go │ ├── tokenstream.go │ └── tokentype.go ├── parser.go ├── parser_test.go ├── statement.go ├── statement_test.go ├── transaction.go ├── type.go └── type_test.go ├── pretty ├── print.go └── print_test.go ├── runtime ├── .gitignore ├── account_storage_v1.go ├── account_storage_v2.go ├── account_test.go ├── attachments_test.go ├── authorizer.go ├── capabilities_test.go ├── capabilitycontrollers_test.go ├── checking_environment.go ├── code.go ├── config.go ├── context.go ├── contract.go ├── contract_function_executor.go ├── contract_test.go ├── contract_update_test.go ├── contract_update_validation_test.go ├── convertTypes.go ├── convertTypes_test.go ├── convertValues.go ├── convertValues_test.go ├── coverage.go ├── coverage_test.go ├── crypto_test.go ├── debugger_test.go ├── deployedcontract_test.go ├── deployment_test.go ├── empty.go ├── entitlements_test.go ├── environment.go ├── error_test.go ├── errors.go ├── errors_test.go ├── events.go ├── executor.go ├── external.go ├── ft_test.go ├── handlers.go ├── import_test.go ├── imported_values_memory_metering_test.go ├── inbox_test.go ├── interface.go ├── literal.go ├── literal_test.go ├── location.go ├── nft_test.go ├── predeclaredvalues_test.go ├── program_params_validation_test.go ├── recover.go ├── repl.go ├── resource_duplicate_test.go ├── resourcedictionary_test.go ├── rlp_test.go ├── runtime.go ├── runtime_memory_metering_test.go ├── runtime_test.go ├── script_executor.go ├── sharedstate_test.go ├── slabindex.go ├── stackdepth.go ├── storage.go ├── storage_test.go ├── test-export-json-deterministic.json ├── transaction_executor.go ├── type_test.go ├── types.go ├── validation.go ├── validation_test.go └── value.go ├── sema ├── access.go ├── access_test.go ├── accesscheckmode.go ├── accesscheckmode_string.go ├── accesses_test.go ├── account.cdc ├── account.gen.go ├── account.go ├── account_capability_controller.cdc ├── account_capability_controller.gen.go ├── account_capability_controller.go ├── account_test.go ├── any_test.go ├── any_type.go ├── anyattachment_types.go ├── anyresource_type.go ├── anystruct_type.go ├── arrays_dictionaries_test.go ├── assert_test.go ├── assignment_test.go ├── attachments_test.go ├── before_extractor.go ├── before_extractor_test.go ├── binaryoperationkind.go ├── binaryoperationkind_string.go ├── block.cdc ├── block.gen.go ├── block.go ├── bool_type.go ├── boolean_test.go ├── builtinfunctions_test.go ├── capability_controller_test.go ├── capability_test.go ├── casting_test.go ├── character.cdc ├── character.gen.go ├── character.go ├── character_test.go ├── check_array_expression.go ├── check_assignment.go ├── check_attach_expression.go ├── check_binary_expression.go ├── check_block.go ├── check_casting_expression.go ├── check_composite_declaration.go ├── check_conditional.go ├── check_conditions.go ├── check_create_expression.go ├── check_destroy_expression.go ├── check_dictionary_expression.go ├── check_emit_statement.go ├── check_event_declaration.go ├── check_event_declaration_test.go ├── check_expression.go ├── check_for.go ├── check_force_expression.go ├── check_function.go ├── check_import_declaration.go ├── check_interface_declaration.go ├── check_invocation_expression.go ├── check_member_expression.go ├── check_path_expression.go ├── check_path_expression_test.go ├── check_pragma.go ├── check_reference_expression.go ├── check_remove_statement.go ├── check_return_statement.go ├── check_string_template_expression.go ├── check_swap.go ├── check_switch.go ├── check_transaction_declaration.go ├── check_unary_expression.go ├── check_variable_declaration.go ├── check_while.go ├── checker.go ├── checker_test.go ├── composite_test.go ├── conditional_test.go ├── conditions_test.go ├── config.go ├── conformance_test.go ├── containerkind.go ├── containerkind_string.go ├── contract_test.go ├── crypto_algorithm_types.go ├── crypto_algorithm_types_test.go ├── crypto_test.go ├── declaration_test.go ├── declarations.go ├── deployedcontract.cdc ├── deployedcontract.gen.go ├── deployedcontract.go ├── deployment_result.cdc ├── deployment_result.gen.go ├── deployment_result.go ├── dictionary_test.go ├── dynamic_casting_test.go ├── elaboration.go ├── entitlements.cdc ├── entitlements.gen.go ├── entitlements.go ├── entitlements_test.go ├── entitlementset.go ├── entitlementset_test.go ├── entrypoint.go ├── entrypoint_test.go ├── enum_test.go ├── error_handling_test.go ├── errors.go ├── errors_test.go ├── events_test.go ├── external_mutation_test.go ├── fixedpoint_test.go ├── for_test.go ├── force_test.go ├── function_activations.go ├── function_expression_test.go ├── function_invocations.go ├── function_test.go ├── gen │ ├── golden_test.go │ ├── main.go │ ├── main_test.go │ └── testdata │ │ ├── comparable │ │ ├── helper.go │ │ ├── test.cdc │ │ └── test.golden.go │ │ ├── composite_type_pragma │ │ ├── test.cdc │ │ └── test.golden.go │ │ ├── constructor │ │ ├── contract │ │ ├── test.cdc │ │ └── test.golden.go │ │ ├── docstrings │ │ ├── helper.go │ │ ├── test.cdc │ │ └── test.golden.go │ │ ├── entitlement │ │ ├── test.cdc │ │ └── test.golden.go │ │ ├── equatable │ │ ├── helper.go │ │ ├── test.cdc │ │ └── test.golden.go │ │ ├── exportable │ │ ├── helper.go │ │ ├── test.cdc │ │ └── test.golden.go │ │ ├── fields │ │ ├── helper.go │ │ ├── test.cdc │ │ └── test.golden.go │ │ ├── functions │ │ ├── helper.go │ │ ├── test.cdc │ │ └── test.golden.go │ │ ├── importable │ │ ├── helper.go │ │ ├── test.cdc │ │ └── test.golden.go │ │ ├── member_accessible │ │ ├── helper.go │ │ ├── test.cdc │ │ └── test.golden.go │ │ ├── nested │ │ ├── test.cdc │ │ └── test.golden.go │ │ ├── primitive │ │ ├── helper.go │ │ ├── test.cdc │ │ └── test.golden.go │ │ ├── simple_interface │ │ ├── test.cdc │ │ └── test.golden.go │ │ ├── simple_resource │ │ ├── helper.go │ │ ├── test.cdc │ │ └── test.golden.go │ │ ├── simple_struct │ │ ├── helper.go │ │ ├── test.cdc │ │ └── test.golden.go │ │ └── storable │ │ ├── helper.go │ │ ├── test.cdc │ │ └── test.golden.go ├── genericfunction_test.go ├── hashable_struct.cdc ├── hashable_struct.gen.go ├── hashable_struct.go ├── hashable_struct_test.go ├── hashalgorithm_string.go ├── if_test.go ├── import.go ├── import_test.go ├── indexing_test.go ├── initialization_info.go ├── initialization_test.go ├── integer_test.go ├── interface_test.go ├── interfaceset.go ├── intersection_test.go ├── invalid_test.go ├── invalid_type.go ├── invocation_test.go ├── member_accesses.go ├── member_test.go ├── meta_type.go ├── metatype_test.go ├── move_test.go ├── nesting_test.go ├── never_test.go ├── never_type.go ├── nil_coalescing_test.go ├── occurrence_matcher_test.go ├── occurrences.go ├── occurrences_test.go ├── operations_test.go ├── optional_test.go ├── orderdmaps.go ├── overloading_test.go ├── path_test.go ├── path_type.go ├── positioninfo.go ├── post_conditions_rewrite.go ├── pragma_test.go ├── predeclaredvalues_test.go ├── purity_test.go ├── range_test.go ├── range_value_test.go ├── ranges.go ├── reference_test.go ├── resolve.go ├── resource_invalidation.go ├── resource_test.go ├── resourceinfo.go ├── resourceinvalidationkind.go ├── resourceinvalidationkind_string.go ├── resources.go ├── resources_test.go ├── return_info.go ├── return_test.go ├── rlp_test.go ├── runtime_type_constructors.go ├── runtimetype_test.go ├── signaturealgorithm_string.go ├── simple_type.go ├── storable_test.go ├── storable_type.go ├── storage_capability_controller.cdc ├── storage_capability_controller.gen.go ├── storage_capability_controller.go ├── string_test.go ├── string_type.go ├── struct_stringer.cdc ├── struct_stringer.gen.go ├── struct_stringer.go ├── struct_stringer_test.go ├── swap_test.go ├── switch_test.go ├── transactions_test.go ├── type.go ├── type_inference_test.go ├── type_names.go ├── type_tags.go ├── type_test.go ├── typeannotationstate.go ├── typeannotationstate_string.go ├── typeargument_test.go ├── typecheckfunc.go ├── utils_test.go ├── variable.go ├── variable_activations.go ├── variable_activations_test.go ├── void_type.go └── while_test.go ├── semgrep.yaml ├── stdlib ├── account.go ├── account_test.go ├── assert.go ├── block.go ├── bls.cdc ├── bls.gen.go ├── bls.go ├── builtin.go ├── builtin_test.go ├── cadence_v0.42_to_v1_contract_upgrade_validation_test.go ├── cadence_v0.42_to_v1_contract_upgrade_validator.go ├── contract_update_validation.go ├── contracts │ ├── flow.json │ ├── test.cdc │ └── test.go ├── crypto.go ├── flow.go ├── flow_test.go ├── functions.go ├── hashalgorithm.go ├── log.go ├── panic.go ├── publickey.go ├── random.go ├── random_test.go ├── range.go ├── rlp.cdc ├── rlp.gen.go ├── rlp.go ├── rlp │ ├── rlp.go │ └── rlp_test.go ├── signaturealgorithm.go ├── test-framework.go ├── test.go ├── test_contract.go ├── test_emulatorbackend.go ├── test_test.go ├── type-comparator.go ├── types.go └── value.go ├── test_utils ├── common_utils │ └── utils.go ├── interpreter_utils │ ├── interpreter.go │ └── values.go ├── runtime_utils │ ├── location.go │ ├── storage.go │ ├── testinterface.go │ ├── testledger.go │ ├── testruntime.go │ └── transactions.go ├── sema_utils │ └── utils.go └── test_utils.go ├── tools ├── accounts-script │ ├── README.md │ ├── go.mod │ ├── go.sum │ ├── iterate_storage.cdc │ └── main.go ├── analysis │ ├── analysis.go │ ├── analysis_test.go │ ├── analyzer.go │ ├── config.go │ ├── diagnostic.go │ ├── error.go │ ├── inspector.go │ ├── loadmode.go │ ├── pass.go │ ├── program.go │ └── programs.go ├── ast-explorer │ ├── .eslintrc │ ├── .gitignore │ ├── README.md │ ├── main.go │ ├── package-lock.json │ ├── package.json │ ├── src │ │ ├── cadence.ts │ │ ├── index.html │ │ ├── index.tsx │ │ └── tree.tsx │ ├── tsconfig.json │ └── webpack.config.js ├── compare-parsing │ └── main.go ├── compatibility-check │ ├── cmd │ │ └── check_contracts │ │ │ └── main.go │ ├── contracts_checker.go │ ├── contracts_checker_test.go │ ├── go.mod │ └── go.sum ├── constructorcheck │ ├── Makefile │ ├── analyzer.go │ ├── analyzer_test.go │ ├── go.mod │ ├── go.sum │ ├── main.go │ └── testdata │ │ └── test.go ├── get-contracts │ ├── go.mod │ ├── go.sum │ └── main.go ├── golangci-lint │ ├── Makefile │ ├── go.mod │ ├── go.sum │ └── main.go ├── maprange │ ├── Makefile │ ├── README.md │ ├── analyzer.go │ ├── analyzer_test.go │ ├── go.mod │ ├── go.sum │ ├── main.go │ └── testdata │ │ └── src │ │ └── a │ │ └── test.go ├── pretty │ ├── README.md │ └── main.go ├── staged-contracts-report-printer │ ├── README.md │ └── main.go ├── storage-explorer │ ├── .gitignore │ ├── README.md │ ├── addresses.go │ ├── go.mod │ ├── go.sum │ ├── index.html │ ├── main.go │ ├── package-lock.json │ ├── package.json │ ├── src │ │ ├── array.tsx │ │ ├── composite.tsx │ │ ├── dictionary.tsx │ │ ├── fallback.tsx │ │ ├── index.css │ │ ├── index.ts │ │ ├── primitive.tsx │ │ ├── type.module.css │ │ ├── type.tsx │ │ ├── value.ts │ │ └── vite-env.d.ts │ ├── storagemaps.go │ ├── tsconfig.json │ ├── type.go │ └── value.go ├── unkeyed │ ├── Makefile │ ├── README.md │ ├── analyzer.go │ ├── analyzer_test.go │ ├── go.mod │ ├── go.sum │ ├── main.go │ └── testdata │ │ └── src │ │ ├── a │ │ ├── a.go │ │ └── a.go.golden │ │ └── typeparams │ │ ├── lib │ │ └── lib.go │ │ ├── typeparams.go │ │ └── typeparams.go.golden └── update │ ├── .eslintrc.cjs │ ├── README.md │ ├── config.schema.json │ ├── config.schema.ts │ ├── config.yaml │ ├── main.ts │ ├── package-lock.json │ ├── package.json │ └── tsconfig.json ├── types.go ├── types_test.go ├── utils └── version │ └── main.go ├── values.go ├── values ├── big.go ├── encode.go ├── errors.go ├── safe_math.go ├── value.go ├── value_bool.go ├── value_comparable.go ├── value_equatable.go ├── value_fixedpoint.go ├── value_int.go ├── value_integer.go ├── value_number.go └── value_ufix64.go ├── values_test.go └── version.go /.github/ISSUE_TEMPLATE/feature-request.yaml: -------------------------------------------------------------------------------- 1 | name: Requesting a Feature or Improvement 2 | description: For feature requests. Please search for existing issues first. Also see CONTRIBUTING. 3 | labels: [Feature, Feedback] 4 | assignees: onflow/cadence 5 | body: 6 | - type: markdown 7 | attributes: 8 | value: | 9 | Please fill out the template below to the best of your ability. 10 | - type: textarea 11 | attributes: 12 | label: Issue to be solved 13 | description: | 14 | Please present a concise description of the problem to be addressed by this feature request. 15 | Please be clear what parts of the problem are considered to be in-scope and out-of-scope. 16 | validations: 17 | required: true 18 | - type: textarea 19 | attributes: 20 | label: Suggested Solution 21 | description: | 22 | A concise description of your preferred solution. Things to address include: 23 | * Details of the technical implementation 24 | * Tradeoffs made in design decisions 25 | * Caveats and considerations for the future 26 | 27 | If there are multiple solutions, please present each one separately. Save comparisons for the very end. 28 | validations: 29 | required: false 30 | -------------------------------------------------------------------------------- /.github/pull_request_template.md: -------------------------------------------------------------------------------- 1 | Closes #??? 2 | 3 | ## Description 4 | 5 | 9 | 10 | ______ 11 | 12 | 13 | 14 | - [ ] Targeted PR against `master` branch 15 | - [ ] Linked to Github issue with discussion and accepted design OR link to spec that describes this work 16 | - [ ] Code follows the [standards mentioned here](https://github.com/onflow/cadence/blob/master/CONTRIBUTING.md#styleguides) 17 | - [ ] Updated relevant documentation 18 | - [ ] Re-reviewed `Files changed` in the Github PR explorer 19 | - [ ] Added appropriate labels 20 | -------------------------------------------------------------------------------- /.github/release.yml: -------------------------------------------------------------------------------- 1 | changelog: 2 | categories: 3 | - title: 💥 Language Breaking Changes 4 | labels: 5 | - Language Breaking Change 6 | - Storage Breaking Change 7 | - title: 💥 Go API Breaking Chance 8 | labels: 9 | - Go API Breaking Change 10 | - title: ⭐ Features 11 | labels: 12 | - Feature 13 | - title: 🛠 Improvements 14 | labels: 15 | - Improvement 16 | - title: 🐞 Bug Fixes 17 | labels: 18 | - Bugfix 19 | - title: 🧪 Testing 20 | labels: 21 | - Testing 22 | - title: 📖 Documentation 23 | labels: 24 | - Documentation 25 | - title: Other Changes 26 | labels: 27 | - "*" 28 | -------------------------------------------------------------------------------- /.github/workflows/codeql-analysis.yml: -------------------------------------------------------------------------------- 1 | name: "Code scanning" 2 | 3 | on: 4 | push: 5 | branches: 6 | - master 7 | - 'feature/**' 8 | - 'v**' 9 | pull_request: 10 | branches: 11 | - master 12 | - 'feature/**' 13 | - 'v**' 14 | 15 | env: 16 | GO_VERSION: '1.23' 17 | 18 | concurrency: 19 | group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.run_id }} 20 | cancel-in-progress: true 21 | 22 | jobs: 23 | CodeQL-Build: 24 | name: CodeQL 25 | runs-on: ubuntu-latest 26 | steps: 27 | - name: Checkout repository 28 | uses: actions/checkout@v3 29 | 30 | - name: Set up Go 31 | uses: actions/setup-go@v3 32 | with: 33 | go-version: ${{ env.GO_VERSION }} 34 | cache: true 35 | 36 | - name: Initialize CodeQL 37 | uses: github/codeql-action/init@v2 38 | with: 39 | languages: go 40 | 41 | - name: Build 42 | run: make build 43 | 44 | - name: Perform CodeQL Analysis 45 | uses: github/codeql-action/analyze@v2 46 | -------------------------------------------------------------------------------- /.github/workflows/compat.yaml: -------------------------------------------------------------------------------- 1 | name: Source Compatibility Suite 2 | on: 3 | schedule: 4 | - cron: '0 12 * * *' 5 | workflow_dispatch: 6 | inputs: 7 | 8 | jobs: 9 | source-compat: 10 | runs-on: ubuntu-latest 11 | steps: 12 | - name: Clone 13 | uses: actions/checkout@v4 14 | - name: Setup Python 15 | uses: actions/setup-python@v5 16 | with: 17 | python-version: '3.12' 18 | cache: 'pip' 19 | - name: Install dependencies 20 | working-directory: compat 21 | run: pip3 install -r requirements.txt 22 | - name: Run 23 | working-directory: compat 24 | run: "python3 main.py" 25 | -------------------------------------------------------------------------------- /.github/workflows/get-contracts.yml: -------------------------------------------------------------------------------- 1 | name: Get contracts 2 | 3 | on: 4 | workflow_dispatch: 5 | inputs: 6 | chain: 7 | required: true 8 | type: string 9 | secrets: 10 | FIND_API_AUTH: 11 | required: true 12 | 13 | env: 14 | GO_VERSION: '1.23' 15 | 16 | concurrency: 17 | group: ${{ github.workflow }}-${{ github.run_id }}-${{ inputs.chain }} 18 | cancel-in-progress: true 19 | 20 | jobs: 21 | check: 22 | runs-on: ubuntu-latest 23 | steps: 24 | - name: Checkout 25 | uses: actions/checkout@v4 26 | 27 | - uses: actions/setup-go@v4 28 | with: 29 | go-version: ${{ env.GO_VERSION }} 30 | cache: true 31 | 32 | - name: Make output dirs 33 | run: | 34 | mkdir tmp 35 | 36 | # Get contracts 37 | 38 | - name: Download contracts 39 | env: 40 | FIND_API_AUTH: ${{ secrets.FIND_API_AUTH }} 41 | working-directory: ./tools/get-contracts 42 | run: | 43 | go run . -chain=${{ inputs.chain }} -auth="$FIND_API_AUTH" > ../../tmp/contracts.csv 44 | 45 | # Upload 46 | 47 | - name: Upload 48 | uses: actions/upload-artifact@v4 49 | with: 50 | name: ${{ inputs.chain }}-contracts 51 | path: | 52 | ./tmp/contracts.csv 53 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Test binary, build with `go test -c` 2 | *.test 3 | 4 | # Output of the go coverage tool, specifically when used with LiteIDE 5 | *.out 6 | 7 | # Coverage artifacts 8 | /coverage.zip 9 | /cover.json 10 | /cover-summary 11 | /index.html 12 | 13 | # Since we have tooling that uses node 14 | node_modules 15 | 16 | .DS_Store 17 | 18 | # IDE related files 19 | .idea 20 | .vscode 21 | git 22 | 23 | language/tools/vscode-extension/cadence-*.vsix 24 | language/tools/vscode-extension/out/* 25 | 26 | # Go mod ignores 27 | .history 28 | go.work 29 | 30 | # go-fuzz 31 | crashers 32 | corpus 33 | suppressions 34 | 35 | coverage.txt 36 | coverage.txt-e 37 | cmd/check/check 38 | cmd/main/main 39 | cmd/parse/parse 40 | cmd/parse/parse.wasm 41 | tools/golangci-lint/golangci-lint 42 | tools/maprange/maprange 43 | tools/unkeyed/unkeyed 44 | *.so 45 | 46 | -------------------------------------------------------------------------------- /.mailmap: -------------------------------------------------------------------------------- 1 | Bastian Müller 2 | Bastian Müller 3 | -------------------------------------------------------------------------------- /CODEOWNERS: -------------------------------------------------------------------------------- 1 | * @turbolent @SupunS @RZhang05 2 | -------------------------------------------------------------------------------- /NOTICE: -------------------------------------------------------------------------------- 1 | Cadence 2 | Copyright 2019-2024 Flow Foundation 3 | 4 | This product includes software developed at the Flow Foundation (https://flow.com/flow-foundation). 5 | -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | 2 | # Responsible Disclosure Policy 3 | 4 | Flow was built from the ground up with security in mind. Our code, infrastructure, and development methodology helps us keep our users safe. 5 | 6 | We really appreciate the community's help. Responsible disclosure of vulnerabilities helps to maintain the security and privacy of everyone. 7 | 8 | If you care about making a difference, please follow the guidelines below. 9 | 10 | # **Guidelines For Responsible Disclosure** 11 | 12 | We ask that all researchers adhere to these guidelines [here](https://docs.onflow.org/bounties/responsible-disclosure/) 13 | -------------------------------------------------------------------------------- /ast/ast.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Cadence - The resource-oriented smart contract programming language 3 | * 4 | * Copyright Flow Foundation 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | // Package ast contains all AST nodes for Cadence. 20 | // All AST nodes implement the Element interface, 21 | // so have position information 22 | // and can be traversed using the Visitor interface. 23 | // Elements also implement the json.Marshaler interface 24 | // so can be serialized to a standardized/stable JSON format. 25 | package ast 26 | 27 | type TextEdit struct { 28 | Replacement string 29 | Insertion string 30 | Range 31 | } 32 | -------------------------------------------------------------------------------- /ast/conditionkind_string.go: -------------------------------------------------------------------------------- 1 | // Code generated by "stringer -type=ConditionKind"; DO NOT EDIT. 2 | 3 | package ast 4 | 5 | import "strconv" 6 | 7 | func _() { 8 | // An "invalid array index" compiler error signifies that the constant values have changed. 9 | // Re-run the stringer command to generate them again. 10 | var x [1]struct{} 11 | _ = x[ConditionKindUnknown-0] 12 | _ = x[ConditionKindPre-1] 13 | _ = x[ConditionKindPost-2] 14 | } 15 | 16 | const _ConditionKind_name = "ConditionKindUnknownConditionKindPreConditionKindPost" 17 | 18 | var _ConditionKind_index = [...]uint8{0, 20, 36, 53} 19 | 20 | func (i ConditionKind) String() string { 21 | if i >= ConditionKind(len(_ConditionKind_index)-1) { 22 | return "ConditionKind(" + strconv.FormatInt(int64(i), 10) + ")" 23 | } 24 | return _ConditionKind_name[_ConditionKind_index[i]:_ConditionKind_index[i+1]] 25 | } 26 | -------------------------------------------------------------------------------- /ast/conditionkind_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Cadence - The resource-oriented smart contract programming language 3 | * 4 | * Copyright Flow Foundation 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package ast 20 | 21 | import ( 22 | "encoding/json" 23 | "fmt" 24 | "testing" 25 | 26 | "github.com/stretchr/testify/assert" 27 | "github.com/stretchr/testify/require" 28 | ) 29 | 30 | func TestConditionKind_MarshalJSON(t *testing.T) { 31 | 32 | t.Parallel() 33 | 34 | for conditionKind := ConditionKind(0); conditionKind < ConditionKind(ConditionKindCount()); conditionKind++ { 35 | actual, err := json.Marshal(conditionKind) 36 | require.NoError(t, err) 37 | 38 | assert.JSONEq(t, fmt.Sprintf(`"%s"`, conditionKind), string(actual)) 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /ast/declaration.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Cadence - The resource-oriented smart contract programming language 3 | * 4 | * Copyright Flow Foundation 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package ast 20 | 21 | import ( 22 | "fmt" 23 | 24 | "github.com/turbolent/prettier" 25 | 26 | "github.com/onflow/cadence/common" 27 | ) 28 | 29 | type Declaration interface { 30 | Element 31 | fmt.Stringer 32 | isDeclaration() 33 | DeclarationIdentifier() *Identifier 34 | DeclarationKind() common.DeclarationKind 35 | DeclarationAccess() Access 36 | DeclarationMembers() *Members 37 | DeclarationDocString() string 38 | Doc() prettier.Doc 39 | } 40 | -------------------------------------------------------------------------------- /ast/inspect.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Cadence - The resource-oriented smart contract programming language 3 | * 4 | * Copyright Flow Foundation 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package ast 20 | 21 | type inspector func(Element) bool 22 | 23 | func (f inspector) Walk(element Element) Walker { 24 | if f(element) { 25 | return f 26 | } 27 | 28 | return nil 29 | } 30 | 31 | func Inspect(element Element, f func(Element) bool) { 32 | Walk(inspector(f), element) 33 | } 34 | -------------------------------------------------------------------------------- /ast/members_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Cadence - The resource-oriented smart contract programming language 3 | * 4 | * Copyright Flow Foundation 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package ast 20 | 21 | import ( 22 | "encoding/json" 23 | "testing" 24 | 25 | "github.com/stretchr/testify/assert" 26 | "github.com/stretchr/testify/require" 27 | ) 28 | 29 | func TestMembers_MarshalJSON(t *testing.T) { 30 | 31 | t.Parallel() 32 | 33 | members := NewUnmeteredMembers([]Declaration{}) 34 | 35 | actual, err := json.Marshal(members) 36 | require.NoError(t, err) 37 | 38 | assert.JSONEq(t, 39 | // language=json 40 | ` 41 | { 42 | "Declarations": [] 43 | } 44 | `, 45 | string(actual), 46 | ) 47 | } 48 | -------------------------------------------------------------------------------- /ast/operation_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Cadence - The resource-oriented smart contract programming language 3 | * 4 | * Copyright Flow Foundation 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package ast 20 | 21 | import ( 22 | "encoding/json" 23 | "fmt" 24 | "testing" 25 | 26 | "github.com/stretchr/testify/assert" 27 | "github.com/stretchr/testify/require" 28 | ) 29 | 30 | func TestOperation_MarshalJSON(t *testing.T) { 31 | 32 | t.Parallel() 33 | 34 | for operation := Operation(0); operation < Operation(OperationCount()); operation++ { 35 | actual, err := json.Marshal(operation) 36 | require.NoError(t, err) 37 | 38 | assert.JSONEq(t, fmt.Sprintf(`"%s"`, operation), string(actual)) 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /ast/prettier.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Cadence - The resource-oriented smart contract programming language 3 | * 4 | * Copyright Flow Foundation 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package ast 20 | 21 | import ( 22 | "strings" 23 | 24 | "github.com/turbolent/prettier" 25 | ) 26 | 27 | func Prettier(element interface{ Doc() prettier.Doc }) string { 28 | var builder strings.Builder 29 | doc := element.Doc().Flatten() 30 | prettier.Prettier(&builder, doc, 80, " ") 31 | return builder.String() 32 | } 33 | -------------------------------------------------------------------------------- /ast/primitiveaccess_string.go: -------------------------------------------------------------------------------- 1 | // Code generated by "stringer -type=PrimitiveAccess"; DO NOT EDIT. 2 | 3 | package ast 4 | 5 | import "strconv" 6 | 7 | func _() { 8 | // An "invalid array index" compiler error signifies that the constant values have changed. 9 | // Re-run the stringer command to generate them again. 10 | var x [1]struct{} 11 | _ = x[AccessNotSpecified-0] 12 | _ = x[AccessNone-1] 13 | _ = x[AccessSelf-2] 14 | _ = x[AccessContract-3] 15 | _ = x[AccessAccount-4] 16 | _ = x[AccessAll-5] 17 | _ = x[AccessPubSettableLegacy-6] 18 | } 19 | 20 | const _PrimitiveAccess_name = "AccessNotSpecifiedAccessNoneAccessSelfAccessContractAccessAccountAccessAllAccessPubSettableLegacy" 21 | 22 | var _PrimitiveAccess_index = [...]uint8{0, 18, 28, 38, 52, 65, 74, 97} 23 | 24 | func (i PrimitiveAccess) String() string { 25 | if i >= PrimitiveAccess(len(_PrimitiveAccess_index)-1) { 26 | return "PrimitiveAccess(" + strconv.FormatInt(int64(i), 10) + ")" 27 | } 28 | return _PrimitiveAccess_name[_PrimitiveAccess_index[i]:_PrimitiveAccess_index[i+1]] 29 | } 30 | -------------------------------------------------------------------------------- /ast/transferoperation_string.go: -------------------------------------------------------------------------------- 1 | // Code generated by "stringer -type=TransferOperation"; DO NOT EDIT. 2 | 3 | package ast 4 | 5 | import "strconv" 6 | 7 | func _() { 8 | // An "invalid array index" compiler error signifies that the constant values have changed. 9 | // Re-run the stringer command to generate them again. 10 | var x [1]struct{} 11 | _ = x[TransferOperationUnknown-0] 12 | _ = x[TransferOperationCopy-1] 13 | _ = x[TransferOperationMove-2] 14 | _ = x[TransferOperationMoveForced-3] 15 | } 16 | 17 | const _TransferOperation_name = "TransferOperationUnknownTransferOperationCopyTransferOperationMoveTransferOperationMoveForced" 18 | 19 | var _TransferOperation_index = [...]uint8{0, 24, 45, 66, 93} 20 | 21 | func (i TransferOperation) String() string { 22 | if i >= TransferOperation(len(_TransferOperation_index)-1) { 23 | return "TransferOperation(" + strconv.FormatInt(int64(i), 10) + ")" 24 | } 25 | return _TransferOperation_name[_TransferOperation_index[i]:_TransferOperation_index[i+1]] 26 | } 27 | -------------------------------------------------------------------------------- /ast/variablekind_string.go: -------------------------------------------------------------------------------- 1 | // Code generated by "stringer -type=VariableKind"; DO NOT EDIT. 2 | 3 | package ast 4 | 5 | import "strconv" 6 | 7 | func _() { 8 | // An "invalid array index" compiler error signifies that the constant values have changed. 9 | // Re-run the stringer command to generate them again. 10 | var x [1]struct{} 11 | _ = x[VariableKindNotSpecified-0] 12 | _ = x[VariableKindVariable-1] 13 | _ = x[VariableKindConstant-2] 14 | } 15 | 16 | const _VariableKind_name = "VariableKindNotSpecifiedVariableKindVariableVariableKindConstant" 17 | 18 | var _VariableKind_index = [...]uint8{0, 24, 44, 64} 19 | 20 | func (i VariableKind) String() string { 21 | if i >= VariableKind(len(_VariableKind_index)-1) { 22 | return "VariableKind(" + strconv.FormatInt(int64(i), 10) + ")" 23 | } 24 | return _VariableKind_name[_VariableKind_index[i]:_VariableKind_index[i+1]] 25 | } 26 | -------------------------------------------------------------------------------- /ast/variablekind_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Cadence - The resource-oriented smart contract programming language 3 | * 4 | * Copyright Flow Foundation 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package ast 20 | 21 | import ( 22 | "encoding/json" 23 | "fmt" 24 | "testing" 25 | 26 | "github.com/stretchr/testify/assert" 27 | "github.com/stretchr/testify/require" 28 | ) 29 | 30 | func TestVariableKind_MarshalJSON(t *testing.T) { 31 | 32 | t.Parallel() 33 | 34 | for variableKind := VariableKind(0); variableKind < VariableKind(VariableKindCount()); variableKind++ { 35 | actual, err := json.Marshal(variableKind) 36 | require.NoError(t, err) 37 | 38 | assert.JSONEq(t, fmt.Sprintf(`"%s"`, variableKind), string(actual)) 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /benchmarks/fib_dynamic.cdc: -------------------------------------------------------------------------------- 1 | access(all) 2 | fun fib(_ n: Int): Int { 3 | if n == 0 { 4 | return 0 5 | } 6 | 7 | let f = [0, 1] 8 | 9 | var i = 2 10 | while i <= n { 11 | f.append(f[i - 1] + f[i - 2]) 12 | i = i + 1 13 | } 14 | 15 | return f[n] 16 | } 17 | 18 | access(all) 19 | fun main() { 20 | assert(fib(23) == 28657) 21 | } 22 | -------------------------------------------------------------------------------- /benchmarks/fib_iterative.cdc: -------------------------------------------------------------------------------- 1 | access(all) 2 | fun fib(_ n: Int): Int { 3 | var fib1 = 1 4 | var fib2 = 1 5 | var fibonacci = fib1 6 | var i = 2 7 | while i < n { 8 | fibonacci = fib1 + fib2 9 | fib1 = fib2 10 | fib2 = fibonacci 11 | i = i + 1 12 | } 13 | return fibonacci 14 | } 15 | 16 | access(all) 17 | fun main() { 18 | assert(fib(23) == 28657) 19 | } 20 | -------------------------------------------------------------------------------- /benchmarks/fib_recursive.cdc: -------------------------------------------------------------------------------- 1 | access(all) 2 | fun fib(_ n: Int): Int { 3 | if n < 2 { 4 | return n 5 | } 6 | return fib(n - 1) + fib(n - 2) 7 | } 8 | 9 | access(all) 10 | fun main() { 11 | assert(fib(23) == 28657) 12 | } 13 | -------------------------------------------------------------------------------- /bump-version.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Read the version to be replaced from the `version.go` file. 4 | v=$(sed -En 's/const Version = "v(.*)"/\1/p' version.go) 5 | 6 | case "$1" in 7 | major) 8 | v2=$(echo "$v" | awk -F. '{print $1 + 1 ".0.0"}') 9 | ;; 10 | 11 | minor) 12 | v2=$(echo "$v" | awk -F. '{print $1 "." $2 + 1 ".0"}') 13 | ;; 14 | 15 | patch) 16 | v2=$(echo "$v" | awk -F. '{print $1 "." $2 "." $3 + 1}') 17 | ;; 18 | 19 | *) 20 | 21 | # Trim off preceding `v` if any. 22 | # This is to support both input version formats: `0.1.0` and `v0.1.0`. 23 | v2=$(echo "$1" | sed -Ee 's/^v//') 24 | ;; 25 | esac 26 | 27 | echo "$v => $v2" 28 | 29 | for f in $VERSIONED_FILES; do \ 30 | # Replace the version. 31 | echo "- $f"; \ 32 | if [[ "$OSTYPE" == "darwin"* ]]; then 33 | sed -i '' "s/$v/$v2/g" "$f"; \ 34 | else 35 | sed -i "s/$v/$v2/g" "$f"; \ 36 | fi 37 | 38 | # Check if the version has being properly replaced. 39 | git diff --exit-code -s "$f" 40 | if [[ $? -ne 1 ]]; then 41 | echo "failed to update version in '$f'" 42 | exit 1 43 | fi 44 | done 45 | -------------------------------------------------------------------------------- /cadence_furever.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onflow/cadence/163d49a23236d802846fddc854cf6813d85addfd/cadence_furever.png -------------------------------------------------------------------------------- /check-headers.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | files=$(find . -name \*.go -type f -print0 | xargs -0 grep -L -E '(Licensed under the Apache License)|(Code generated (from|by))|(Copyright .*\. All rights reserved)') 4 | if [ -n "$files" ]; then 5 | echo "Missing license header in:" 6 | echo "$files" 7 | exit 1 8 | fi 9 | -------------------------------------------------------------------------------- /codecov.yml: -------------------------------------------------------------------------------- 1 | coverage: 2 | status: 3 | project: 4 | default: 5 | target: auto 6 | threshold: 5% 7 | informational: false 8 | patch: 9 | default: 10 | target: 100% 11 | threshold: 5% 12 | informational: false 13 | -------------------------------------------------------------------------------- /common/compositekind_string.go: -------------------------------------------------------------------------------- 1 | // Code generated by "stringer -type=CompositeKind"; DO NOT EDIT. 2 | 3 | package common 4 | 5 | import "strconv" 6 | 7 | func _() { 8 | // An "invalid array index" compiler error signifies that the constant values have changed. 9 | // Re-run the stringer command to generate them again. 10 | var x [1]struct{} 11 | _ = x[CompositeKindUnknown-0] 12 | _ = x[CompositeKindStructure-1] 13 | _ = x[CompositeKindResource-2] 14 | _ = x[CompositeKindContract-3] 15 | _ = x[CompositeKindEvent-4] 16 | _ = x[CompositeKindEnum-5] 17 | _ = x[CompositeKindAttachment-6] 18 | } 19 | 20 | const _CompositeKind_name = "CompositeKindUnknownCompositeKindStructureCompositeKindResourceCompositeKindContractCompositeKindEventCompositeKindEnumCompositeKindAttachment" 21 | 22 | var _CompositeKind_index = [...]uint8{0, 20, 42, 63, 84, 102, 119, 142} 23 | 24 | func (i CompositeKind) String() string { 25 | if i >= CompositeKind(len(_CompositeKind_index)-1) { 26 | return "CompositeKind(" + strconv.FormatInt(int64(i), 10) + ")" 27 | } 28 | return _CompositeKind_name[_CompositeKind_index[i]:_CompositeKind_index[i+1]] 29 | } 30 | -------------------------------------------------------------------------------- /common/compositekind_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Cadence - The resource-oriented smart contract programming language 3 | * 4 | * Copyright Flow Foundation 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package common 20 | 21 | import ( 22 | "encoding/json" 23 | "fmt" 24 | "testing" 25 | 26 | "github.com/stretchr/testify/assert" 27 | "github.com/stretchr/testify/require" 28 | ) 29 | 30 | func TestCompositeKind_MarshalJSON(t *testing.T) { 31 | 32 | t.Parallel() 33 | 34 | for compositeKind := CompositeKind(0); compositeKind < CompositeKind(CompositeKindCount()); compositeKind++ { 35 | actual, err := json.Marshal(compositeKind) 36 | require.NoError(t, err) 37 | 38 | assert.JSONEq(t, fmt.Sprintf(`"%s"`, compositeKind), string(actual)) 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /common/concat.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Cadence - The resource-oriented smart contract programming language 3 | * 4 | * Copyright Flow Foundation 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package common 20 | 21 | func Concat[T any](slices ...[]T) []T { 22 | var length int 23 | 24 | for _, slice := range slices { 25 | length += len(slice) 26 | } 27 | 28 | result := make([]T, length) 29 | 30 | var offset int 31 | for _, slice := range slices { 32 | offset += copy(result[offset:], slice) 33 | } 34 | 35 | return result 36 | } 37 | -------------------------------------------------------------------------------- /common/controlstatement.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Cadence - The resource-oriented smart contract programming language 3 | * 4 | * Copyright Flow Foundation 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package common 20 | 21 | import ( 22 | "github.com/onflow/cadence/errors" 23 | ) 24 | 25 | //go:generate stringer -type=ControlStatement 26 | 27 | type ControlStatement uint 28 | 29 | const ( 30 | ControlStatementUnknown ControlStatement = iota 31 | ControlStatementBreak 32 | ControlStatementContinue 33 | ) 34 | 35 | func (s ControlStatement) Symbol() string { 36 | switch s { 37 | case ControlStatementBreak: 38 | return "break" 39 | case ControlStatementContinue: 40 | return "continue" 41 | } 42 | 43 | panic(errors.NewUnreachableError()) 44 | } 45 | -------------------------------------------------------------------------------- /common/controlstatement_string.go: -------------------------------------------------------------------------------- 1 | // Code generated by "stringer -type=ControlStatement"; DO NOT EDIT. 2 | 3 | package common 4 | 5 | import "strconv" 6 | 7 | func _() { 8 | // An "invalid array index" compiler error signifies that the constant values have changed. 9 | // Re-run the stringer command to generate them again. 10 | var x [1]struct{} 11 | _ = x[ControlStatementUnknown-0] 12 | _ = x[ControlStatementBreak-1] 13 | _ = x[ControlStatementContinue-2] 14 | } 15 | 16 | const _ControlStatement_name = "ControlStatementUnknownControlStatementBreakControlStatementContinue" 17 | 18 | var _ControlStatement_index = [...]uint8{0, 23, 44, 68} 19 | 20 | func (i ControlStatement) String() string { 21 | if i >= ControlStatement(len(_ControlStatement_index)-1) { 22 | return "ControlStatement(" + strconv.FormatInt(int64(i), 10) + ")" 23 | } 24 | return _ControlStatement_name[_ControlStatement_index[i]:_ControlStatement_index[i+1]] 25 | } 26 | -------------------------------------------------------------------------------- /common/incomparable.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Cadence - The resource-oriented smart contract programming language 3 | * 4 | * Copyright Flow Foundation 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package common 20 | 21 | // Incomparable (the zero-sized type [0]func()) makes the surrounding incomparable. 22 | // It is crucial to ensure its placed at the beginning or middle of the surrounding struct, 23 | // and NOT at the end of the struct, as otherwise the compiler will add padding bytes. 24 | // See https://i.hsfzxjy.site/zst-at-the-rear-of-go-struct/ for more details 25 | type Incomparable [0]func() 26 | -------------------------------------------------------------------------------- /common/integerliteralkind_string.go: -------------------------------------------------------------------------------- 1 | // Code generated by "stringer -type=IntegerLiteralKind"; DO NOT EDIT. 2 | 3 | package common 4 | 5 | import "strconv" 6 | 7 | func _() { 8 | // An "invalid array index" compiler error signifies that the constant values have changed. 9 | // Re-run the stringer command to generate them again. 10 | var x [1]struct{} 11 | _ = x[IntegerLiteralKindUnknown-0] 12 | _ = x[IntegerLiteralKindBinary-1] 13 | _ = x[IntegerLiteralKindOctal-2] 14 | _ = x[IntegerLiteralKindDecimal-3] 15 | _ = x[IntegerLiteralKindHexadecimal-4] 16 | } 17 | 18 | const _IntegerLiteralKind_name = "IntegerLiteralKindUnknownIntegerLiteralKindBinaryIntegerLiteralKindOctalIntegerLiteralKindDecimalIntegerLiteralKindHexadecimal" 19 | 20 | var _IntegerLiteralKind_index = [...]uint8{0, 25, 49, 72, 97, 126} 21 | 22 | func (i IntegerLiteralKind) String() string { 23 | if i >= IntegerLiteralKind(len(_IntegerLiteralKind_index)-1) { 24 | return "IntegerLiteralKind(" + strconv.FormatInt(int64(i), 10) + ")" 25 | } 26 | return _IntegerLiteralKind_name[_IntegerLiteralKind_index[i]:_IntegerLiteralKind_index[i+1]] 27 | } 28 | -------------------------------------------------------------------------------- /common/operandside.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Cadence - The resource-oriented smart contract programming language 3 | * 4 | * Copyright Flow Foundation 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package common 20 | 21 | import ( 22 | "github.com/onflow/cadence/errors" 23 | ) 24 | 25 | //go:generate stringer -type=OperandSide 26 | 27 | type OperandSide uint 28 | 29 | const ( 30 | OperandSideUnknown OperandSide = iota 31 | OperandSideLeft 32 | OperandSideRight 33 | ) 34 | 35 | func (s OperandSide) Name() string { 36 | switch s { 37 | case OperandSideLeft: 38 | return "left" 39 | case OperandSideRight: 40 | return "right" 41 | } 42 | 43 | panic(errors.NewUnreachableError()) 44 | } 45 | -------------------------------------------------------------------------------- /common/operandside_string.go: -------------------------------------------------------------------------------- 1 | // Code generated by "stringer -type=OperandSide"; DO NOT EDIT. 2 | 3 | package common 4 | 5 | import "strconv" 6 | 7 | func _() { 8 | // An "invalid array index" compiler error signifies that the constant values have changed. 9 | // Re-run the stringer command to generate them again. 10 | var x [1]struct{} 11 | _ = x[OperandSideUnknown-0] 12 | _ = x[OperandSideLeft-1] 13 | _ = x[OperandSideRight-2] 14 | } 15 | 16 | const _OperandSide_name = "OperandSideUnknownOperandSideLeftOperandSideRight" 17 | 18 | var _OperandSide_index = [...]uint8{0, 18, 33, 49} 19 | 20 | func (i OperandSide) String() string { 21 | if i >= OperandSide(len(_OperandSide_index)-1) { 22 | return "OperandSide(" + strconv.FormatInt(int64(i), 10) + ")" 23 | } 24 | return _OperandSide_name[_OperandSide_index[i]:_OperandSide_index[i+1]] 25 | } 26 | -------------------------------------------------------------------------------- /common/operationkind_string.go: -------------------------------------------------------------------------------- 1 | // Code generated by "stringer -type=OperationKind"; DO NOT EDIT. 2 | 3 | package common 4 | 5 | import "strconv" 6 | 7 | func _() { 8 | // An "invalid array index" compiler error signifies that the constant values have changed. 9 | // Re-run the stringer command to generate them again. 10 | var x [1]struct{} 11 | _ = x[OperationKindUnknown-0] 12 | _ = x[OperationKindUnary-1] 13 | _ = x[OperationKindBinary-2] 14 | _ = x[OperationKindTernary-3] 15 | } 16 | 17 | const _OperationKind_name = "OperationKindUnknownOperationKindUnaryOperationKindBinaryOperationKindTernary" 18 | 19 | var _OperationKind_index = [...]uint8{0, 20, 38, 57, 77} 20 | 21 | func (i OperationKind) String() string { 22 | if i >= OperationKind(len(_OperationKind_index)-1) { 23 | return "OperationKind(" + strconv.FormatInt(int64(i), 10) + ")" 24 | } 25 | return _OperationKind_name[_OperationKind_index[i]:_OperationKind_index[i+1]] 26 | } 27 | -------------------------------------------------------------------------------- /common/pathdomain_string.go: -------------------------------------------------------------------------------- 1 | // Code generated by "stringer -type=PathDomain"; DO NOT EDIT. 2 | 3 | package common 4 | 5 | import "strconv" 6 | 7 | func _() { 8 | // An "invalid array index" compiler error signifies that the constant values have changed. 9 | // Re-run the stringer command to generate them again. 10 | var x [1]struct{} 11 | _ = x[PathDomainUnknown-0] 12 | _ = x[PathDomainStorage-1] 13 | _ = x[PathDomainPrivate-2] 14 | _ = x[PathDomainPublic-3] 15 | } 16 | 17 | const _PathDomain_name = "PathDomainUnknownPathDomainStoragePathDomainPrivatePathDomainPublic" 18 | 19 | var _PathDomain_index = [...]uint8{0, 17, 34, 51, 67} 20 | 21 | func (i PathDomain) String() string { 22 | if i >= PathDomain(len(_PathDomain_index)-1) { 23 | return "PathDomain(" + strconv.FormatInt(int64(i), 10) + ")" 24 | } 25 | return _PathDomain_name[_PathDomain_index[i]:_PathDomain_index[i+1]] 26 | } 27 | -------------------------------------------------------------------------------- /compat/README.md: -------------------------------------------------------------------------------- 1 | # Source Compatibility Suite 2 | 3 | The source compatibility suite prevents regressions and helps understand what impact changes in the language and implementation have on real-world Cadence projects. 4 | 5 | The suite contains a [set of repository descriptions](https://github.com/onflow/cadence/tree/master/compat/suite). When the suite is run, the repositories get cloned and checked. The runner can optionally run benchmarks and compare against another commit / branch, producing output in the terminal (pretty), as JSON, or Markdown. 6 | 7 | In the future we can integrate this as part of CI, maybe as a periodic job. 8 | 9 | ## Running 10 | 11 | - Install the dependencies: 12 | 13 | ```sh 14 | pip3 install -r requirements.txt 15 | ``` 16 | 17 | - Run the suite: 18 | 19 | ```sh 20 | python3 main.py 21 | ``` 22 | -------------------------------------------------------------------------------- /compat/requirements.txt: -------------------------------------------------------------------------------- 1 | click==7.1.2 2 | coloredlogs==14.0 3 | dacite==1.5.1 4 | PyYAML>=6.0.1 5 | typing-extensions==3.7.4.3 6 | -------------------------------------------------------------------------------- /compat/suite/dapper-labs-nba-smart-contracts.yaml: -------------------------------------------------------------------------------- 1 | description: Dapper Labs NBA Top Shot 2 | maintainers: 3 | url: https://github.com/dapperlabs/nba-smart-contracts.git 4 | branch: master 5 | go_tests: 6 | - path: lib/go/test 7 | command: make test 8 | -------------------------------------------------------------------------------- /compat/suite/dapper-labs-nfl-smart-contracts.yaml: -------------------------------------------------------------------------------- 1 | description: Dapper Labs NFL Smart Contracts 2 | maintainers: 3 | url: https://github.com/dapperlabs/nfl-smart-contracts.git 4 | branch: main 5 | go_tests: 6 | - path: lib/go/test 7 | command: make test 8 | -------------------------------------------------------------------------------- /compat/suite/flow-core-contracts.yaml: -------------------------------------------------------------------------------- 1 | description: Flow Core Contracts 2 | maintainers: 3 | url: https://github.com/onflow/flow-core-contracts.git 4 | branch: master 5 | go_tests: 6 | - path: lib/go/test 7 | command: make test 8 | cadence_tests: 9 | - path: . 10 | command: flow test tests/*.cdc 11 | -------------------------------------------------------------------------------- /compat/suite/flow-ft.yaml: -------------------------------------------------------------------------------- 1 | description: Flow Fungible Token 2 | maintainers: 3 | url: https://github.com/onflow/flow-ft.git 4 | branch: master 5 | go_tests: 6 | - path: lib/go/test 7 | command: make test 8 | -------------------------------------------------------------------------------- /compat/suite/flow-nft.yaml: -------------------------------------------------------------------------------- 1 | description: Flow Non-Fungible Token 2 | maintainers: 3 | url: https://github.com/onflow/flow-nft.git 4 | branch: master 5 | go_tests: 6 | - path: lib/go/test 7 | command: make test 8 | -------------------------------------------------------------------------------- /compat/suite/green-goo-dao-flow-utils.yaml: -------------------------------------------------------------------------------- 1 | description: Green Goo Dao flow-utils 2 | maintainers: 3 | url: https://github.com/green-goo-dao/flow-utils.git 4 | branch: main 5 | cadence_tests: 6 | - path: . 7 | command: npm i && ./run-tests.sh 8 | -------------------------------------------------------------------------------- /docs/Cadence - Implementation, Present and Future.odp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onflow/cadence/163d49a23236d802846fddc854cf6813d85addfd/docs/Cadence - Implementation, Present and Future.odp -------------------------------------------------------------------------------- /docs/Cadence - Implementation, Present and Future.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onflow/cadence/163d49a23236d802846fddc854cf6813d85addfd/docs/Cadence - Implementation, Present and Future.pdf -------------------------------------------------------------------------------- /docs/Cadence Implementation.odp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onflow/cadence/163d49a23236d802846fddc854cf6813d85addfd/docs/Cadence Implementation.odp -------------------------------------------------------------------------------- /docs/Cadence Implementation.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onflow/cadence/163d49a23236d802846fddc854cf6813d85addfd/docs/Cadence Implementation.pdf -------------------------------------------------------------------------------- /docs/README.md: -------------------------------------------------------------------------------- 1 | # Documentation 2 | 3 | This directory contains documentation for contributors to/developers of Cadence. 4 | 5 | If you are looking for documentation for using Cadence, it can be found at https://cadence-lang.org/. 6 | 7 | The source for the user documentation is at https://github.com/onflow/cadence-lang.org, not in this repository. 8 | -------------------------------------------------------------------------------- /docs/anti-patterns.mdx: -------------------------------------------------------------------------------- 1 | # This document has been moved to a new location: 2 | 3 | https://github.com/onflow/cadence-lang.org/tree/main/docs/anti-patterns.mdx 4 | -------------------------------------------------------------------------------- /docs/architecture.monopic: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onflow/cadence/163d49a23236d802846fddc854cf6813d85addfd/docs/architecture.monopic -------------------------------------------------------------------------------- /docs/architecture.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onflow/cadence/163d49a23236d802846fddc854cf6813d85addfd/docs/architecture.png -------------------------------------------------------------------------------- /docs/contract-upgrades.mdx: -------------------------------------------------------------------------------- 1 | # This document has been moved to a new location: 2 | 3 | https://github.com/onflow/cadence-lang.org/tree/main/docs/contract-upgrades.mdx 4 | -------------------------------------------------------------------------------- /docs/design-patterns.mdx: -------------------------------------------------------------------------------- 1 | # This document has been moved to a new location: 2 | 3 | https://github.com/onflow/cadence-lang.org/tree/main/docs/design-patterns.mdx 4 | -------------------------------------------------------------------------------- /docs/go.md: -------------------------------------------------------------------------------- 1 | # Go 2 | 3 | ## Patterns 4 | 5 | - To ensure interface cannot be implemented in other packages, 6 | add a private function (first character must be lower-case) named "is" + type name, 7 | which takes no arguments, returns nothing, and has an empty body. 8 | 9 | For example: 10 | 11 | ```go 12 | type I interface { 13 | isI() 14 | } 15 | ``` 16 | 17 | See https://go.dev/doc/faq#guarantee_satisfies_interface 18 | 19 | - To ensure a type implements an interface at compile-time, 20 | use the "interface guard" pattern: 21 | Introduce a global variable named `_`, type it as the interface, 22 | and assign an empty value of the concrete type to it. 23 | 24 | For example: 25 | 26 | ```go 27 | type T struct { 28 | //... 29 | } 30 | 31 | var _ io.ReadWriter = (*T)(nil) 32 | 33 | func (t *T) Read(p []byte) (n int, err error) { 34 | // ... 35 | ``` 36 | 37 | See 38 | - https://go.dev/doc/faq#guarantee_satisfies_interface 39 | - https://rednafi.com/go/interface_guards/ 40 | - https://github.com/uber-go/guide/blob/master/style.md#verify-interface-compliance 41 | - https://medium.com/@matryer/golang-tip-compile-time-checks-to-ensure-your-type-satisfies-an-interface-c167afed3aae 42 | 43 | -------------------------------------------------------------------------------- /docs/goland.md: -------------------------------------------------------------------------------- 1 | # GoLand 2 | 3 | ## Linter Integration 4 | 5 | - Build golangci-lint and the custom analyzers: Run `make build-linter` 6 | - In GoLand go to `Preferences` -> `Tools` -> `File Watchers` -> Add `golangci-lint` 7 | - File Type: Go files 8 | - Scope: Project files 9 | - Program: `/path/to/cadence/tools/golangci-lint/golangci-lint` (NOTE: NOT `~/go/bin/golangci-lint`) 10 | - Arguments: `run $FileDir$` 11 | - Advanced Options: 12 | - Create output file from stdout 13 | - Show console: Never 14 | - Output filters: `$FILE_PATH$:$LINE$:$COLUMN$: $MESSAGE$` 15 | 16 | -------------------------------------------------------------------------------- /docs/images/compatibility_check_action_params.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onflow/cadence/163d49a23236d802846fddc854cf6813d85addfd/docs/images/compatibility_check_action_params.png -------------------------------------------------------------------------------- /docs/images/compatibility_check_action_trigger.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onflow/cadence/163d49a23236d802846fddc854cf6813d85addfd/docs/images/compatibility_check_action_trigger.png -------------------------------------------------------------------------------- /docs/images/create_release.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onflow/cadence/163d49a23236d802846fddc854cf6813d85addfd/docs/images/create_release.png -------------------------------------------------------------------------------- /docs/images/release_action.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onflow/cadence/163d49a23236d802846fddc854cf6813d85addfd/docs/images/release_action.png -------------------------------------------------------------------------------- /docs/images/release_tag.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onflow/cadence/163d49a23236d802846fddc854cf6813d85addfd/docs/images/release_tag.png -------------------------------------------------------------------------------- /docs/index.mdx: -------------------------------------------------------------------------------- 1 | # This document has been moved to a new location: 2 | 3 | https://github.com/onflow/cadence-lang.org/tree/main/docs/intro.md 4 | -------------------------------------------------------------------------------- /docs/json-cadence-spec.md: -------------------------------------------------------------------------------- 1 | # This document has been moved to a new location: 2 | 3 | https://github.com/onflow/cadence-lang.org/tree/main/docs/json-cadence-spec.md 4 | -------------------------------------------------------------------------------- /docs/language/access-control.md: -------------------------------------------------------------------------------- 1 | # This document has been moved to a new location: 2 | 3 | https://github.com/onflow/cadence-lang.org/tree/main/docs/language/access-control.md 4 | -------------------------------------------------------------------------------- /docs/language/accounts.mdx: -------------------------------------------------------------------------------- 1 | # This document has been moved to a new location: 2 | 3 | https://github.com/onflow/cadence-lang.org/tree/main/docs/language/accounts.mdx 4 | -------------------------------------------------------------------------------- /docs/language/attachments.md: -------------------------------------------------------------------------------- 1 | # This document has been moved to a new location: 2 | 3 | https://github.com/onflow/cadence-lang.org/tree/main/docs/language/attachments.mdx 4 | -------------------------------------------------------------------------------- /docs/language/built-in-functions.mdx: -------------------------------------------------------------------------------- 1 | # This document has been moved to a new location: 2 | 3 | https://github.com/onflow/cadence-lang.org/tree/main/docs/language/built-in-functions.mdx 4 | -------------------------------------------------------------------------------- /docs/language/capability-based-access-control.md: -------------------------------------------------------------------------------- 1 | # This document has been moved to a new location: 2 | 3 | https://github.com/onflow/cadence-lang.org/tree/main/docs/language/capabilities.md 4 | -------------------------------------------------------------------------------- /docs/language/composite-types.mdx: -------------------------------------------------------------------------------- 1 | # This document has been moved to a new location: 2 | 3 | https://github.com/onflow/cadence-lang.org/tree/main/docs/language/composite-types.mdx 4 | -------------------------------------------------------------------------------- /docs/language/constants-and-variables.md: -------------------------------------------------------------------------------- 1 | # This document has been moved to a new location: 2 | 3 | https://github.com/onflow/cadence-lang.org/tree/main/docs/language/constants-and-variables.md 4 | -------------------------------------------------------------------------------- /docs/language/contract-updatability.md: -------------------------------------------------------------------------------- 1 | # This document has been moved to a new location: 2 | 3 | https://github.com/onflow/cadence-lang.org/tree/main/docs/language/contract-updatability.md 4 | -------------------------------------------------------------------------------- /docs/language/contracts.mdx: -------------------------------------------------------------------------------- 1 | # This document has been moved to a new location: 2 | 3 | https://github.com/onflow/cadence-lang.org/tree/main/docs/language/contracts.mdx 4 | -------------------------------------------------------------------------------- /docs/language/control-flow.md: -------------------------------------------------------------------------------- 1 | # This document has been moved to a new location: 2 | 3 | https://github.com/onflow/cadence-lang.org/tree/main/docs/language/control-flow.md 4 | -------------------------------------------------------------------------------- /docs/language/core-events.md: -------------------------------------------------------------------------------- 1 | # This document has been moved to a new location: 2 | 3 | https://github.com/onflow/cadence-lang.org/tree/main/docs/language/core-events.md 4 | -------------------------------------------------------------------------------- /docs/language/crypto.mdx: -------------------------------------------------------------------------------- 1 | # This document has been moved to a new location: 2 | 3 | https://github.com/onflow/cadence-lang.org/tree/main/docs/language/crypto.mdx 4 | -------------------------------------------------------------------------------- /docs/language/enumerations.md: -------------------------------------------------------------------------------- 1 | # This document has been moved to a new location: 2 | 3 | https://github.com/onflow/cadence-lang.org/tree/main/docs/language/enumerations.md 4 | -------------------------------------------------------------------------------- /docs/language/environment-information.md: -------------------------------------------------------------------------------- 1 | # This document has been moved to a new location: 2 | 3 | https://github.com/onflow/cadence-lang.org/tree/main/docs/language/environment-information.md 4 | -------------------------------------------------------------------------------- /docs/language/events.md: -------------------------------------------------------------------------------- 1 | # This document has been moved to a new location: 2 | 3 | https://github.com/onflow/cadence-lang.org/tree/main/docs/language/events.md 4 | -------------------------------------------------------------------------------- /docs/language/functions.mdx: -------------------------------------------------------------------------------- 1 | # This document has been moved to a new location: 2 | 3 | https://github.com/onflow/cadence-lang.org/tree/main/docs/language/functions.mdx 4 | -------------------------------------------------------------------------------- /docs/language/glossary.md: -------------------------------------------------------------------------------- 1 | # This document has been moved to a new location: 2 | 3 | https://github.com/onflow/cadence-lang.org/tree/main/docs/language/glossary.mdx 4 | -------------------------------------------------------------------------------- /docs/language/imports.mdx: -------------------------------------------------------------------------------- 1 | # This document has been moved to a new location: 2 | 3 | https://github.com/onflow/cadence-lang.org/tree/main/docs/language/imports.mdx 4 | -------------------------------------------------------------------------------- /docs/language/index.md: -------------------------------------------------------------------------------- 1 | # This document has been moved to a new location: 2 | 3 | https://github.com/onflow/cadence-lang.org/tree/main/docs/language/index.md 4 | -------------------------------------------------------------------------------- /docs/language/interfaces.mdx: -------------------------------------------------------------------------------- 1 | # This document has been moved to a new location: 2 | 3 | https://github.com/onflow/cadence-lang.org/tree/main/docs/language/interfaces.mdx 4 | -------------------------------------------------------------------------------- /docs/language/operators.md: -------------------------------------------------------------------------------- 1 | # This document has been moved to a new location: 2 | 3 | https://github.com/onflow/cadence-lang.org/tree/main/docs/language/operators.md 4 | -------------------------------------------------------------------------------- /docs/language/references.mdx: -------------------------------------------------------------------------------- 1 | # This document has been moved to a new location: 2 | 3 | https://github.com/onflow/cadence-lang.org/tree/main/docs/language/references.md 4 | -------------------------------------------------------------------------------- /docs/language/resources.mdx: -------------------------------------------------------------------------------- 1 | # This document has been moved to a new location: 2 | 3 | https://github.com/onflow/cadence-lang.org/tree/main/docs/language/resources.mdx 4 | -------------------------------------------------------------------------------- /docs/language/restricted-types.md: -------------------------------------------------------------------------------- 1 | # This document has been moved to a new location: 2 | 3 | https://github.com/onflow/cadence-lang.org/tree/main/docs/language/restricted-types.md 4 | -------------------------------------------------------------------------------- /docs/language/run-time-types.md: -------------------------------------------------------------------------------- 1 | # This document has been moved to a new location: 2 | 3 | https://github.com/onflow/cadence-lang.org/tree/main/docs/language/run-time-types.md 4 | -------------------------------------------------------------------------------- /docs/language/scope.md: -------------------------------------------------------------------------------- 1 | # This document has been moved to a new location: 2 | 3 | https://github.com/onflow/cadence-lang.org/tree/main/docs/language/scope.md 4 | -------------------------------------------------------------------------------- /docs/language/syntax.md: -------------------------------------------------------------------------------- 1 | # This document has been moved to a new location: 2 | 3 | https://github.com/onflow/cadence-lang.org/tree/main/docs/language/syntax.md 4 | -------------------------------------------------------------------------------- /docs/language/transactions.md: -------------------------------------------------------------------------------- 1 | # This document has been moved to a new location: 2 | 3 | https://github.com/onflow/cadence-lang.org/tree/main/docs/language/transactions.md 4 | -------------------------------------------------------------------------------- /docs/language/type-annotations.md: -------------------------------------------------------------------------------- 1 | # This document has been moved to a new location: 2 | 3 | https://github.com/onflow/cadence-lang.org/tree/main/docs/language/type-annotations.md 4 | -------------------------------------------------------------------------------- /docs/language/type-hierarchy.md: -------------------------------------------------------------------------------- 1 | # This document has been moved to a new location: 2 | 3 | https://github.com/onflow/cadence-lang.org/tree/main/docs/language/type-hierarchy.md 4 | -------------------------------------------------------------------------------- /docs/language/type-hierarchy.monopic: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onflow/cadence/163d49a23236d802846fddc854cf6813d85addfd/docs/language/type-hierarchy.monopic -------------------------------------------------------------------------------- /docs/language/type-hierarchy.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onflow/cadence/163d49a23236d802846fddc854cf6813d85addfd/docs/language/type-hierarchy.png -------------------------------------------------------------------------------- /docs/language/type-inference.md: -------------------------------------------------------------------------------- 1 | # This document has been moved to a new location: 2 | 3 | https://github.com/onflow/cadence-lang.org/tree/main/docs/language/type-inference.md 4 | -------------------------------------------------------------------------------- /docs/language/type-safety.md: -------------------------------------------------------------------------------- 1 | # This document has been moved to a new location: 2 | 3 | https://github.com/onflow/cadence-lang.org/tree/main/docs/language/type-safety.md 4 | -------------------------------------------------------------------------------- /docs/language/values-and-types.mdx: -------------------------------------------------------------------------------- 1 | # This document has been moved to a new location: 2 | 3 | https://github.com/onflow/cadence-lang.org/tree/main/docs/language/values-and-types.mdx 4 | -------------------------------------------------------------------------------- /docs/measuring-time.mdx: -------------------------------------------------------------------------------- 1 | # This document has been moved to a new location: 2 | 3 | https://github.com/onflow/cadence-lang.org/tree/main/docs/measuring-time.mdx 4 | -------------------------------------------------------------------------------- /docs/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "private": true, 3 | "type": "module", 4 | "dependencies": { 5 | "fastest-levenshtein": "^1.0.12", 6 | "github-slugger": "^1.4.0", 7 | "hast-util-to-string": "^2.0.0", 8 | "remark-mdx": "^2.1.2", 9 | "remark-parse": "^10.0.1", 10 | "remark-rehype": "^10.1.0", 11 | "unified": "^10.1.2", 12 | "unist-util-visit": "^4.1.0", 13 | "walk-sync": "^3.0.0" 14 | }, 15 | "scripts": { 16 | "lint": "node lint.js" 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /docs/security-best-practices.mdx: -------------------------------------------------------------------------------- 1 | # This document has been moved to a new location: 2 | 3 | https://github.com/onflow/cadence-lang.org/tree/main/docs/security-best-practices.mdx 4 | -------------------------------------------------------------------------------- /docs/solidity-to-cadence.mdx: -------------------------------------------------------------------------------- 1 | # This document has been moved to a new location: 2 | 3 | https://github.com/onflow/cadence-lang.org/tree/main/docs/solidity-to-cadence.mdx 4 | -------------------------------------------------------------------------------- /docs/testing-framework.mdx: -------------------------------------------------------------------------------- 1 | # This document has been moved to a new location: 2 | 3 | https://github.com/onflow/cadence-lang.org/tree/main/docs/testing-framework.mdx 4 | -------------------------------------------------------------------------------- /docs/tutorial/01-first-steps.mdx: -------------------------------------------------------------------------------- 1 | # This document has been moved to a new location: 2 | 3 | https://github.com/onflow/cadence-lang.org/tree/main/docs/tutorial/01-first-steps.mdx 4 | -------------------------------------------------------------------------------- /docs/tutorial/02-hello-world.mdx: -------------------------------------------------------------------------------- 1 | # This document has been moved to a new location: 2 | 3 | https://github.com/onflow/cadence-lang.org/tree/main/docs/tutorial/02-hello-world.mdx 4 | -------------------------------------------------------------------------------- /docs/tutorial/03-resources.mdx: -------------------------------------------------------------------------------- 1 | # This document has been moved to a new location: 2 | 3 | https://github.com/onflow/cadence-lang.org/tree/main/docs/tutorial/03-resources.mdx 4 | -------------------------------------------------------------------------------- /docs/tutorial/04-capabilities.mdx: -------------------------------------------------------------------------------- 1 | # This document has been moved to a new location: 2 | 3 | https://github.com/onflow/cadence-lang.org/tree/main/docs/tutorial/04-capabilities.mdx 4 | -------------------------------------------------------------------------------- /docs/tutorial/05-non-fungible-tokens-1.mdx: -------------------------------------------------------------------------------- 1 | # This document has been moved to a new location: 2 | 3 | https://github.com/onflow/cadence-lang.org/tree/main/docs/tutorial/05-non-fungible-tokens-1.mdx 4 | -------------------------------------------------------------------------------- /docs/tutorial/05-non-fungible-tokens-2.mdx: -------------------------------------------------------------------------------- 1 | # This document has been moved to a new location: 2 | 3 | https://github.com/onflow/cadence-lang.org/tree/main/docs/tutorial/05-non-fungible-tokens-2.mdx 4 | -------------------------------------------------------------------------------- /docs/tutorial/06-fungible-tokens.mdx: -------------------------------------------------------------------------------- 1 | # This document has been moved to a new location: 2 | 3 | https://github.com/onflow/cadence-lang.org/tree/main/docs/tutorial/06-fungible-tokens.mdx 4 | -------------------------------------------------------------------------------- /docs/tutorial/07-marketplace-setup.mdx: -------------------------------------------------------------------------------- 1 | # This document has been moved to a new location: 2 | 3 | https://github.com/onflow/cadence-lang.org/tree/main/docs/tutorial/07-marketplace-setup.mdx 4 | -------------------------------------------------------------------------------- /docs/tutorial/08-marketplace-compose.mdx: -------------------------------------------------------------------------------- 1 | # This document has been moved to a new location: 2 | 3 | https://github.com/onflow/cadence-lang.org/tree/main/docs/tutorial/08-marketplace-compose.mdx 4 | -------------------------------------------------------------------------------- /docs/tutorial/09-voting.mdx: -------------------------------------------------------------------------------- 1 | # This document has been moved to a new location: 2 | 3 | https://github.com/onflow/cadence-lang.org/tree/main/docs/tutorial/09-voting.mdx 4 | -------------------------------------------------------------------------------- /docs/tutorial/10-resources-compose.mdx: -------------------------------------------------------------------------------- 1 | # This document has been moved to a new location: 2 | 3 | https://github.com/onflow/cadence-lang.org/tree/main/docs/tutorial/10-resources-compose.mdx 4 | -------------------------------------------------------------------------------- /docs/tutorial/deploybox.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onflow/cadence/163d49a23236d802846fddc854cf6813d85addfd/docs/tutorial/deploybox.png -------------------------------------------------------------------------------- /docs/tutorial/txbox.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onflow/cadence/163d49a23236d802846fddc854cf6813d85addfd/docs/tutorial/txbox.png -------------------------------------------------------------------------------- /docs/why.md: -------------------------------------------------------------------------------- 1 | # This document has been moved to a new location: 2 | 3 | https://github.com/onflow/cadence-lang.org/tree/main/docs/why.md 4 | -------------------------------------------------------------------------------- /encoding/README.md: -------------------------------------------------------------------------------- 1 | # `encoding` 2 | 3 | The `encoding` packages contain functions to encode and decode Cadence values to other formats. 4 | 5 | Currently, only the [JSON-Cadence](https://docs.onflow.org/cadence/json-cadence-spec/) format is supported. 6 | 7 | In the future other formats may be added. 8 | -------------------------------------------------------------------------------- /encoding/ccf/ccf.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Cadence - The resource-oriented smart contract programming language 3 | * 4 | * Copyright Flow Foundation 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | // Package ccf implements CCF specification 20 | package ccf 21 | -------------------------------------------------------------------------------- /encoding/json/json.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Cadence - The resource-oriented smart contract programming language 3 | * 4 | * Copyright Flow Foundation 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | // Package json implements the JSON-Cadence specification: 20 | // https://github.com/onflow/flow/blob/master/docs/json-cadence-spec.md 21 | package json 22 | -------------------------------------------------------------------------------- /errors/wrappanic.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Cadence - The resource-oriented smart contract programming language 3 | * 4 | * Copyright Flow Foundation 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package errors 20 | 21 | import ( 22 | goRuntime "runtime" 23 | ) 24 | 25 | func WrapPanic(f func()) { 26 | defer func() { 27 | if r := recover(); r != nil { 28 | // don't wrap Go errors and internal errors 29 | switch r := r.(type) { 30 | case goRuntime.Error, InternalError: 31 | panic(r) 32 | case error: 33 | panic(ExternalError{ 34 | Recovered: r, 35 | }) 36 | default: 37 | panic(ExternalNonError{ 38 | Recovered: r, 39 | }) 40 | } 41 | } 42 | }() 43 | f() 44 | } 45 | -------------------------------------------------------------------------------- /fixedpoint/fixedpoint.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Cadence - The resource-oriented smart contract programming language 3 | * 4 | * Copyright Flow Foundation 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | // Package fixedpoint provides constants, as well as formatting, conversion, 20 | // and checking functionality for Cadence fixed-point number types 21 | package fixedpoint 22 | -------------------------------------------------------------------------------- /format/address.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Cadence - The resource-oriented smart contract programming language 3 | * 4 | * Copyright Flow Foundation 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package format 20 | 21 | import ( 22 | "github.com/onflow/cadence/common" 23 | ) 24 | 25 | func Address(address common.Address) string { 26 | return address.HexWithPrefix() 27 | } 28 | -------------------------------------------------------------------------------- /format/array.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Cadence - The resource-oriented smart contract programming language 3 | * 4 | * Copyright Flow Foundation 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package format 20 | 21 | import ( 22 | "strings" 23 | ) 24 | 25 | func Array(values []string) string { 26 | var builder strings.Builder 27 | builder.WriteByte('[') 28 | for i, value := range values { 29 | if i > 0 { 30 | builder.WriteString(", ") 31 | } 32 | builder.WriteString(value) 33 | } 34 | builder.WriteByte(']') 35 | return builder.String() 36 | } 37 | -------------------------------------------------------------------------------- /format/bool.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Cadence - The resource-oriented smart contract programming language 3 | * 4 | * Copyright Flow Foundation 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package format 20 | 21 | func Bool(b bool) string { 22 | if b { 23 | return "true" 24 | } 25 | return "false" 26 | } 27 | -------------------------------------------------------------------------------- /format/bytes.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Cadence - The resource-oriented smart contract programming language 3 | * 4 | * Copyright Flow Foundation 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package format 20 | 21 | import ( 22 | "fmt" 23 | ) 24 | 25 | func Bytes(bytes []byte) string { 26 | values := make([]string, len(bytes)) 27 | for i, b := range bytes { 28 | values[i] = fmt.Sprintf("0x%x", b) 29 | } 30 | return Array(values) 31 | } 32 | -------------------------------------------------------------------------------- /format/bytes_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Cadence - The resource-oriented smart contract programming language 3 | * 4 | * Copyright Flow Foundation 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package format 20 | 21 | import ( 22 | "testing" 23 | 24 | "github.com/stretchr/testify/require" 25 | ) 26 | 27 | func TestBytes(t *testing.T) { 28 | t.Parallel() 29 | 30 | t.Run("empty", func(t *testing.T) { 31 | require.Equal(t, "[]", Bytes([]byte{})) 32 | }) 33 | 34 | t.Run("one", func(t *testing.T) { 35 | require.Equal(t, "[0x1]", Bytes([]byte{0x1})) 36 | }) 37 | 38 | t.Run("two", func(t *testing.T) { 39 | require.Equal(t, "[0x1, 0x2]", Bytes([]byte{0x1, 0x2})) 40 | }) 41 | } 42 | -------------------------------------------------------------------------------- /format/composite.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Cadence - The resource-oriented smart contract programming language 3 | * 4 | * Copyright Flow Foundation 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package format 20 | 21 | import ( 22 | "strings" 23 | ) 24 | 25 | func Composite(typeID string, fields []struct { 26 | Name string 27 | Value string 28 | }) string { 29 | var builder strings.Builder 30 | builder.WriteString(typeID) 31 | builder.WriteByte('(') 32 | for i, nameValuePair := range fields { 33 | if i > 0 { 34 | builder.WriteString(", ") 35 | } 36 | builder.WriteString(nameValuePair.Name) 37 | builder.WriteString(": ") 38 | builder.WriteString(nameValuePair.Value) 39 | } 40 | builder.WriteByte(')') 41 | return builder.String() 42 | } 43 | -------------------------------------------------------------------------------- /format/dictionary.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Cadence - The resource-oriented smart contract programming language 3 | * 4 | * Copyright Flow Foundation 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package format 20 | 21 | import ( 22 | "strings" 23 | ) 24 | 25 | func Dictionary(pairs []struct { 26 | Key string 27 | Value string 28 | }) string { 29 | var builder strings.Builder 30 | builder.WriteByte('{') 31 | for i, p := range pairs { 32 | if i > 0 { 33 | builder.WriteString(", ") 34 | } 35 | builder.WriteString(p.Key) 36 | builder.WriteString(": ") 37 | builder.WriteString(p.Value) 38 | } 39 | builder.WriteByte('}') 40 | return builder.String() 41 | } 42 | -------------------------------------------------------------------------------- /format/fix_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Cadence - The resource-oriented smart contract programming language 3 | * 4 | * Copyright Flow Foundation 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package format 20 | 21 | import ( 22 | "testing" 23 | 24 | "github.com/stretchr/testify/require" 25 | ) 26 | 27 | func TestUFix64(t *testing.T) { 28 | 29 | t.Parallel() 30 | 31 | require.Equal(t, "99999999999.70000000", UFix64(9999999999970000000)) 32 | } 33 | -------------------------------------------------------------------------------- /format/int.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Cadence - The resource-oriented smart contract programming language 3 | * 4 | * Copyright Flow Foundation 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package format 20 | 21 | import ( 22 | "math/big" 23 | "strconv" 24 | ) 25 | 26 | func BigInt(int *big.Int) string { 27 | return int.Text(10) 28 | } 29 | 30 | func Int(int int64) string { 31 | return strconv.FormatInt(int, 10) 32 | } 33 | 34 | func Uint(uint uint64) string { 35 | return strconv.FormatUint(uint, 10) 36 | } 37 | -------------------------------------------------------------------------------- /format/nil.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Cadence - The resource-oriented smart contract programming language 3 | * 4 | * Copyright Flow Foundation 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package format 20 | 21 | const Nil = "nil" 22 | -------------------------------------------------------------------------------- /format/pad.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Cadence - The resource-oriented smart contract programming language 3 | * 4 | * Copyright Flow Foundation 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package format 20 | 21 | import ( 22 | "strings" 23 | ) 24 | 25 | func PadLeft(value string, separator rune, minLength uint) string { 26 | length := uint(len(value)) 27 | if length >= minLength { 28 | return value 29 | } 30 | n := int(minLength - length) 31 | 32 | var builder strings.Builder 33 | builder.Grow(n) 34 | for i := 0; i < n; i++ { 35 | builder.WriteRune(separator) 36 | } 37 | builder.WriteString(value) 38 | return builder.String() 39 | } 40 | -------------------------------------------------------------------------------- /format/path.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Cadence - The resource-oriented smart contract programming language 3 | * 4 | * Copyright Flow Foundation 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package format 20 | 21 | import ( 22 | "fmt" 23 | ) 24 | 25 | func Path(domain string, identifier string) string { 26 | return fmt.Sprintf( 27 | "/%s/%s", 28 | domain, 29 | identifier, 30 | ) 31 | } 32 | -------------------------------------------------------------------------------- /format/reference.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Cadence - The resource-oriented smart contract programming language 3 | * 4 | * Copyright Flow Foundation 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package format 20 | 21 | const StorageReference = "StorageReference()" 22 | const AccountReference = "AccountReference()" 23 | -------------------------------------------------------------------------------- /format/type.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Cadence - The resource-oriented smart contract programming language 3 | * 4 | * Copyright Flow Foundation 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package format 20 | 21 | import ( 22 | "fmt" 23 | ) 24 | 25 | func TypeValue(ty string) string { 26 | if ty == "" { 27 | return "Type()" 28 | } 29 | return fmt.Sprintf("Type<%s>()", ty) 30 | } 31 | -------------------------------------------------------------------------------- /format/void.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Cadence - The resource-oriented smart contract programming language 3 | * 4 | * Copyright Flow Foundation 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package format 20 | 21 | const Void = "()" 22 | -------------------------------------------------------------------------------- /interpreter/hashablevalue_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Cadence - The resource-oriented smart contract programming language 3 | * 4 | * Copyright Flow Foundation 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package interpreter 20 | 21 | import ( 22 | "testing" 23 | 24 | "github.com/stretchr/testify/require" 25 | ) 26 | 27 | func TestHashableValue(t *testing.T) { 28 | t.Parallel() 29 | 30 | t.Run("No new types added in between", func(t *testing.T) { 31 | require.Equal(t, byte(50), byte(HashInputType_Count)) 32 | }) 33 | } 34 | -------------------------------------------------------------------------------- /interpreter/inspect.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Cadence - The resource-oriented smart contract programming language 3 | * 4 | * Copyright Flow Foundation 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package interpreter 20 | 21 | type valueInspector func(Value) bool 22 | 23 | func (f valueInspector) WalkValue(_ ValueWalkContext, value Value) ValueWalker { 24 | if f(value) { 25 | return f 26 | } 27 | 28 | return nil 29 | } 30 | 31 | func InspectValue(context ValueWalkContext, value Value, f func(Value) bool, locationRange LocationRange) { 32 | WalkValue( 33 | context, 34 | valueInspector(f), 35 | value, 36 | locationRange, 37 | ) 38 | } 39 | -------------------------------------------------------------------------------- /interpreter/program.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Cadence - The resource-oriented smart contract programming language 3 | * 4 | * Copyright Flow Foundation 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package interpreter 20 | 21 | import ( 22 | "github.com/onflow/cadence/ast" 23 | "github.com/onflow/cadence/sema" 24 | ) 25 | 26 | type Program struct { 27 | Program *ast.Program 28 | Elaboration *sema.Elaboration 29 | } 30 | 31 | func ProgramFromChecker(checker *sema.Checker) *Program { 32 | return &Program{ 33 | Program: checker.Program, 34 | Elaboration: checker.Elaboration, 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /interpreter/testdata/comp_v2_96d7e06eaf4b3fcf.cbor.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onflow/cadence/163d49a23236d802846fddc854cf6813d85addfd/interpreter/testdata/comp_v2_96d7e06eaf4b3fcf.cbor.gz -------------------------------------------------------------------------------- /interpreter/testdata/comp_v3_99dc360eee32dcec.cbor.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onflow/cadence/163d49a23236d802846fddc854cf6813d85addfd/interpreter/testdata/comp_v3_99dc360eee32dcec.cbor.gz -------------------------------------------------------------------------------- /interpreter/testdata/comp_v3_b52a33b7e56868f6.cbor.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onflow/cadence/163d49a23236d802846fddc854cf6813d85addfd/interpreter/testdata/comp_v3_b52a33b7e56868f6.cbor.gz -------------------------------------------------------------------------------- /interpreter/testdata/comp_v3_d99d7e6b4dad41e1.cbor.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onflow/cadence/163d49a23236d802846fddc854cf6813d85addfd/interpreter/testdata/comp_v3_d99d7e6b4dad41e1.cbor.gz -------------------------------------------------------------------------------- /interpreter/testdata/link_v3_2392f05c3b72f235.cbor.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onflow/cadence/163d49a23236d802846fddc854cf6813d85addfd/interpreter/testdata/link_v3_2392f05c3b72f235.cbor.gz -------------------------------------------------------------------------------- /interpreter/testdata/link_v3_3a791fe1b8243e73.cbor.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onflow/cadence/163d49a23236d802846fddc854cf6813d85addfd/interpreter/testdata/link_v3_3a791fe1b8243e73.cbor.gz -------------------------------------------------------------------------------- /interpreter/value_optional.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Cadence - The resource-oriented smart contract programming language 3 | * 4 | * Copyright Flow Foundation 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package interpreter 20 | 21 | import ( 22 | "github.com/onflow/cadence/common" 23 | "github.com/onflow/cadence/sema" 24 | ) 25 | 26 | // OptionalValue 27 | 28 | type OptionalValue interface { 29 | Value 30 | isOptionalValue() 31 | forEach(f func(Value)) 32 | fmap(memoryGauge common.MemoryGauge, f func(Value) Value) OptionalValue 33 | InnerValueType(context ValueStaticTypeContext) sema.Type 34 | } 35 | -------------------------------------------------------------------------------- /interpreter/valuedeclaration.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Cadence - The resource-oriented smart contract programming language 3 | * 4 | * Copyright Flow Foundation 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package interpreter 20 | 21 | type ValueDeclaration interface { 22 | ValueDeclarationName() string 23 | ValueDeclarationValue() Value 24 | } 25 | -------------------------------------------------------------------------------- /interpreter/variable_activations.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Cadence - The resource-oriented smart contract programming language 3 | * 4 | * Copyright Flow Foundation 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package interpreter 20 | 21 | import "github.com/onflow/cadence/activations" 22 | 23 | type VariableActivations = activations.Activations[Variable] 24 | 25 | type VariableActivation = activations.Activation[Variable] 26 | 27 | func Declare(a *VariableActivation, declaration ValueDeclaration) { 28 | 29 | value := declaration.ValueDeclarationValue() 30 | variable := NewVariableWithValue(a.MemoryGauge, value) 31 | 32 | a.Set( 33 | declaration.ValueDeclarationName(), 34 | variable, 35 | ) 36 | } 37 | -------------------------------------------------------------------------------- /meetings/README.md: -------------------------------------------------------------------------------- 1 | # Cadence Language and Execution Working Group 2 | 3 | Meeting notes moved to https://github.com/onflow/Flow-Working-Groups/tree/main/cadence_language_and_execution_working_group 4 | -------------------------------------------------------------------------------- /npm-packages/cadence-parser/.gitignore: -------------------------------------------------------------------------------- 1 | dist 2 | -------------------------------------------------------------------------------- /npm-packages/cadence-parser/README.md: -------------------------------------------------------------------------------- 1 | # Cadence Parser 2 | 3 | The [Cadence](https://github.com/onflow/cadence) parser compiled to WebAssembly and bundled as an NPM package, 4 | so it can be used in tools written in JavaScript. 5 | 6 | ## Usage 7 | 8 | ```js 9 | import {CadenceParser} from "@onflow/cadence-parser" 10 | 11 | const parser = await CadenceParser.create("cadence-parser.wasm") 12 | 13 | const ast = parser.parse(` 14 | access(all) contract HelloWorld { 15 | access(all) fun hello() { 16 | log("Hello, world!") 17 | } 18 | } 19 | `) 20 | ``` 21 | -------------------------------------------------------------------------------- /npm-packages/cadence-parser/jest.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | testEnvironment: 'node', 3 | "transform": { 4 | "^.+\\.[tj]s$": "ts-jest" 5 | }, 6 | setupFilesAfterEnv: [ './tests/setup.js' ], 7 | testPathIgnorePatterns: ["/node_modules/", "/dist/"] 8 | }; 9 | -------------------------------------------------------------------------------- /npm-packages/cadence-parser/tests/setup.js: -------------------------------------------------------------------------------- 1 | Object.defineProperty(global, 'performance', { 2 | writable: true, 3 | }); 4 | 5 | Object.defineProperty(global, 'fetch', { 6 | writable: true, 7 | }); 8 | 9 | global.performance = require("perf_hooks").performance; 10 | global.fetch = require("node-fetch"); 11 | -------------------------------------------------------------------------------- /npm-packages/cadence-parser/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compileOnSave": false, 3 | "compilerOptions": { 4 | "target": "es6", 5 | "module": "esnext", 6 | "allowJs": true, 7 | "moduleResolution": "node", 8 | "strict": true, 9 | "noUnusedLocals": true, 10 | "noUnusedParameters": true, 11 | "removeComments": false, 12 | "preserveConstEnums": true, 13 | "sourceMap": true, 14 | "skipLibCheck": true, 15 | "baseUrl": ".", 16 | "esModuleInterop": true, 17 | "lib": [ 18 | "dom", 19 | "es6", 20 | "es7" 21 | ], 22 | "declaration": true, 23 | "noImplicitAny": false, 24 | "outDir": "./dist" 25 | }, 26 | "exclude": [ 27 | "node_modules", 28 | "dist", 29 | "tests", 30 | "*.js" 31 | ] 32 | } -------------------------------------------------------------------------------- /npm-packages/monaco-languageclient-cadence/.gitignore: -------------------------------------------------------------------------------- 1 | dist 2 | -------------------------------------------------------------------------------- /npm-packages/monaco-languageclient-cadence/README.md: -------------------------------------------------------------------------------- 1 | # monaco-languageclient-cadence 2 | 3 | An integration of the Cadence Language Server into the Monaco editor 4 | 5 | -------------------------------------------------------------------------------- /npm-packages/monaco-languageclient-cadence/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@onflow/monaco-languageclient-cadence", 3 | "version": "0.3.0", 4 | "description": "An integration of the Cadence Language Server into the Monaco editor", 5 | "homepage": "https://github.com/onflow/cadence", 6 | "repository": { 7 | "type": "git", 8 | "url": "https://github.com/onflow/cadence.git" 9 | }, 10 | "main": "dist/index.js", 11 | "scripts": { 12 | "build": "tsc" 13 | }, 14 | "license": "Apache-2.0", 15 | "devDependencies": { 16 | "typescript": "^4.0.2" 17 | }, 18 | "dependencies": { 19 | "@onflow/cadence-language-server": "^0.14.0", 20 | "monaco-languageclient": "^0.13.0", 21 | "vscode-jsonrpc": "^5.0.1" 22 | }, 23 | "files": [ 24 | "dist/**/*" 25 | ] 26 | } 27 | -------------------------------------------------------------------------------- /npm-packages/monaco-languageclient-cadence/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compileOnSave": false, 3 | "compilerOptions": { 4 | "target": "es6", 5 | "module": "esnext", 6 | "allowJs": true, 7 | "moduleResolution": "node", 8 | "strict": true, 9 | "noUnusedLocals": true, 10 | "noUnusedParameters": true, 11 | "removeComments": false, 12 | "preserveConstEnums": true, 13 | "sourceMap": true, 14 | "skipLibCheck": true, 15 | "baseUrl": ".", 16 | "lib": ["dom", "es2015", "es2016"], 17 | "declaration": true, 18 | "outDir": "./dist" 19 | }, 20 | "exclude": ["node_modules", "dist"] 21 | } 22 | -------------------------------------------------------------------------------- /old_parser/invalidnumberliteralkind_string.go: -------------------------------------------------------------------------------- 1 | // Code generated by "stringer -type=InvalidNumberLiteralKind"; DO NOT EDIT. 2 | 3 | package old_parser 4 | 5 | import "strconv" 6 | 7 | func _() { 8 | // An "invalid array index" compiler error signifies that the constant values have changed. 9 | // Re-run the stringer command to generate them again. 10 | var x [1]struct{} 11 | _ = x[InvalidNumberLiteralKindUnknown-0] 12 | _ = x[InvalidNumberLiteralKindLeadingUnderscore-1] 13 | _ = x[InvalidNumberLiteralKindTrailingUnderscore-2] 14 | _ = x[InvalidNumberLiteralKindUnknownPrefix-3] 15 | _ = x[InvalidNumberLiteralKindMissingDigits-4] 16 | } 17 | 18 | const _InvalidNumberLiteralKind_name = "InvalidNumberLiteralKindUnknownInvalidNumberLiteralKindLeadingUnderscoreInvalidNumberLiteralKindTrailingUnderscoreInvalidNumberLiteralKindUnknownPrefixInvalidNumberLiteralKindMissingDigits" 19 | 20 | var _InvalidNumberLiteralKind_index = [...]uint8{0, 31, 72, 114, 151, 188} 21 | 22 | func (i InvalidNumberLiteralKind) String() string { 23 | if i >= InvalidNumberLiteralKind(len(_InvalidNumberLiteralKind_index)-1) { 24 | return "InvalidNumberLiteralKind(" + strconv.FormatInt(int64(i), 10) + ")" 25 | } 26 | return _InvalidNumberLiteralKind_name[_InvalidNumberLiteralKind_index[i]:_InvalidNumberLiteralKind_index[i+1]] 27 | } 28 | -------------------------------------------------------------------------------- /old_parser/lexer/token.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Cadence - The resource-oriented smart contract programming language 3 | * 4 | * Copyright Flow Foundation 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package lexer 20 | 21 | import ( 22 | "github.com/onflow/cadence/ast" 23 | ) 24 | 25 | type Token struct { 26 | SpaceOrError any 27 | ast.Range 28 | Type TokenType 29 | } 30 | 31 | func (t Token) Is(ty TokenType) bool { 32 | return t.Type == ty 33 | } 34 | 35 | func (t Token) Source(input []byte) []byte { 36 | startOffset := t.StartPos.Offset 37 | endOffset := t.EndPos.Offset + 1 38 | return input[startOffset:endOffset] 39 | } 40 | -------------------------------------------------------------------------------- /old_parser/lexer/tokenstream.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Cadence - The resource-oriented smart contract programming language 3 | * 4 | * Copyright Flow Foundation 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package lexer 20 | 21 | type TokenStream interface { 22 | // Next consumes and returns one Token. If there are no tokens remaining, it returns Token{TokenEOF} 23 | Next() Token 24 | Cursor() int 25 | Revert(cursor int) 26 | // Input returns the whole input as source code 27 | Input() []byte 28 | Reclaim() 29 | } 30 | -------------------------------------------------------------------------------- /parser/comment_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Cadence - The resource-oriented smart contract programming language 3 | * 4 | * Copyright Flow Foundation 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package parser 20 | 21 | import ( 22 | "testing" 23 | 24 | "github.com/stretchr/testify/require" 25 | ) 26 | 27 | func TestParseBlockCommentEmpty(t *testing.T) { 28 | 29 | t.Parallel() 30 | 31 | _, err := testParseProgram(`/**/`) 32 | require.NoError(t, err) 33 | } 34 | -------------------------------------------------------------------------------- /parser/invalidnumberliteralkind_string.go: -------------------------------------------------------------------------------- 1 | // Code generated by "stringer -type=InvalidNumberLiteralKind"; DO NOT EDIT. 2 | 3 | package parser 4 | 5 | import "strconv" 6 | 7 | func _() { 8 | // An "invalid array index" compiler error signifies that the constant values have changed. 9 | // Re-run the stringer command to generate them again. 10 | var x [1]struct{} 11 | _ = x[InvalidNumberLiteralKindUnknown-0] 12 | _ = x[InvalidNumberLiteralKindLeadingUnderscore-1] 13 | _ = x[InvalidNumberLiteralKindTrailingUnderscore-2] 14 | _ = x[InvalidNumberLiteralKindUnknownPrefix-3] 15 | _ = x[InvalidNumberLiteralKindMissingDigits-4] 16 | } 17 | 18 | const _InvalidNumberLiteralKind_name = "InvalidNumberLiteralKindUnknownInvalidNumberLiteralKindLeadingUnderscoreInvalidNumberLiteralKindTrailingUnderscoreInvalidNumberLiteralKindUnknownPrefixInvalidNumberLiteralKindMissingDigits" 19 | 20 | var _InvalidNumberLiteralKind_index = [...]uint8{0, 31, 72, 114, 151, 188} 21 | 22 | func (i InvalidNumberLiteralKind) String() string { 23 | if i >= InvalidNumberLiteralKind(len(_InvalidNumberLiteralKind_index)-1) { 24 | return "InvalidNumberLiteralKind(" + strconv.FormatInt(int64(i), 10) + ")" 25 | } 26 | return _InvalidNumberLiteralKind_name[_InvalidNumberLiteralKind_index[i]:_InvalidNumberLiteralKind_index[i+1]] 27 | } 28 | -------------------------------------------------------------------------------- /parser/lexer/token.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Cadence - The resource-oriented smart contract programming language 3 | * 4 | * Copyright Flow Foundation 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package lexer 20 | 21 | import ( 22 | "github.com/onflow/cadence/ast" 23 | ) 24 | 25 | type Token struct { 26 | SpaceOrError any 27 | ast.Range 28 | Type TokenType 29 | } 30 | 31 | func (t Token) Is(ty TokenType) bool { 32 | return t.Type == ty 33 | } 34 | 35 | func (t Token) Source(input []byte) []byte { 36 | startOffset := t.StartPos.Offset 37 | endOffset := t.EndPos.Offset + 1 38 | return input[startOffset:endOffset] 39 | } 40 | -------------------------------------------------------------------------------- /parser/lexer/tokenstream.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Cadence - The resource-oriented smart contract programming language 3 | * 4 | * Copyright Flow Foundation 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package lexer 20 | 21 | type TokenStream interface { 22 | // Next consumes and returns one Token. If there are no tokens remaining, it returns Token{TokenEOF} 23 | Next() Token 24 | Cursor() int 25 | Revert(cursor int) 26 | // Input returns the whole input as source code 27 | Input() []byte 28 | Reclaim() 29 | } 30 | -------------------------------------------------------------------------------- /runtime/.gitignore: -------------------------------------------------------------------------------- 1 | /.idea 2 | /flow-runtime 3 | -------------------------------------------------------------------------------- /runtime/code.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Cadence - The resource-oriented smart contract programming language 3 | * 4 | * Copyright Flow Foundation 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package runtime 20 | 21 | import ( 22 | "github.com/onflow/cadence/common" 23 | ) 24 | 25 | func getLocationCodeFromInterface( 26 | i Interface, 27 | location common.Location, 28 | ) ( 29 | code []byte, 30 | err error, 31 | ) { 32 | if addressLocation, ok := location.(common.AddressLocation); ok { 33 | code, err = i.GetAccountContractCode(addressLocation) 34 | } else { 35 | code, err = i.GetCode(location) 36 | } 37 | return 38 | } 39 | -------------------------------------------------------------------------------- /runtime/location.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Cadence - The resource-oriented smart contract programming language 3 | * 4 | * Copyright Flow Foundation 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package runtime 20 | 21 | func ResolveLocationWithInterface( 22 | i Interface, 23 | identifiers []Identifier, 24 | location Location, 25 | ) ( 26 | res []ResolvedLocation, 27 | err error, 28 | ) { 29 | return i.ResolveLocation(identifiers, location) 30 | } 31 | -------------------------------------------------------------------------------- /runtime/test-export-json-deterministic.json: -------------------------------------------------------------------------------- 1 | {"value":{"id":"s.0000000000000000000000000000000000000000000000000000000000000000.Foo","fields":[{"value":{"value":"2","type":"Int"},"name":"bar"},{"value":{"value":[{"key":{"value":"0","type":"Int"},"value":{"value":[{"key":{"value":"0","type":"Int"},"value":{"value":"a","type":"String"}},{"key":{"value":"1","type":"Int"},"value":{"value":"a","type":"String"}},{"key":{"value":"3","type":"Int"},"value":{"value":"c","type":"String"}},{"key":{"value":"2","type":"Int"},"value":{"value":"c","type":"String"}}],"type":"Dictionary"}},{"key":{"value":"2","type":"Int"},"value":{"value":[{"key":{"value":"1","type":"Int"},"value":{"value":"c","type":"String"}},{"key":{"value":"7","type":"Int"},"value":{"value":"d","type":"String"}},{"key":{"value":"3","type":"Int"},"value":{"value":"b","type":"String"}}],"type":"Dictionary"}},{"key":{"value":"1","type":"Int"},"value":{"value":[{"key":{"value":"7","type":"Int"},"value":{"value":"b","type":"String"}},{"key":{"value":"1","type":"Int"},"value":{"value":"","type":"String"}},{"key":{"value":"2","type":"Int"},"value":{"value":"a","type":"String"}},{"key":{"value":"3","type":"Int"},"value":{"value":"a","type":"String"}}],"type":"Dictionary"}}],"type":"Dictionary"},"name":"aaa"}]},"type":"Event"} 2 | -------------------------------------------------------------------------------- /runtime/value.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Cadence - The resource-oriented smart contract programming language 3 | * 4 | * Copyright Flow Foundation 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package runtime 20 | 21 | import ( 22 | "github.com/onflow/cadence/common" 23 | "github.com/onflow/cadence/interpreter" 24 | "github.com/onflow/cadence/sema" 25 | ) 26 | 27 | type exportableEvent struct { 28 | Type sema.Type 29 | Fields []interpreter.Value 30 | } 31 | 32 | type Address = common.Address 33 | -------------------------------------------------------------------------------- /sema/accesscheckmode_string.go: -------------------------------------------------------------------------------- 1 | // Code generated by "stringer -type=AccessCheckMode"; DO NOT EDIT. 2 | 3 | package sema 4 | 5 | import "strconv" 6 | 7 | func _() { 8 | // An "invalid array index" compiler error signifies that the constant values have changed. 9 | // Re-run the stringer command to generate them again. 10 | var x [1]struct{} 11 | _ = x[AccessCheckModeDefault-0] 12 | _ = x[AccessCheckModeStrict-1] 13 | _ = x[AccessCheckModeNotSpecifiedRestricted-2] 14 | _ = x[AccessCheckModeNotSpecifiedUnrestricted-3] 15 | _ = x[AccessCheckModeNone-4] 16 | } 17 | 18 | const _AccessCheckMode_name = "AccessCheckModeDefaultAccessCheckModeStrictAccessCheckModeNotSpecifiedRestrictedAccessCheckModeNotSpecifiedUnrestrictedAccessCheckModeNone" 19 | 20 | var _AccessCheckMode_index = [...]uint8{0, 22, 43, 80, 119, 138} 21 | 22 | func (i AccessCheckMode) String() string { 23 | if i >= AccessCheckMode(len(_AccessCheckMode_index)-1) { 24 | return "AccessCheckMode(" + strconv.FormatInt(int64(i), 10) + ")" 25 | } 26 | return _AccessCheckMode_name[_AccessCheckMode_index[i]:_AccessCheckMode_index[i+1]] 27 | } 28 | -------------------------------------------------------------------------------- /sema/account_capability_controller.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Cadence - The resource-oriented smart contract programming language 3 | * 4 | * Copyright Flow Foundation 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package sema 20 | 21 | //go:generate go run ./gen/main.go account_capability_controller.cdc account_capability_controller.gen.go 22 | 23 | var AccountCapabilityControllerTypeAnnotation = NewTypeAnnotation(AccountCapabilityControllerType) 24 | -------------------------------------------------------------------------------- /sema/binaryoperationkind_string.go: -------------------------------------------------------------------------------- 1 | // Code generated by "stringer -type=BinaryOperationKind"; DO NOT EDIT. 2 | 3 | package sema 4 | 5 | import "strconv" 6 | 7 | func _() { 8 | // An "invalid array index" compiler error signifies that the constant values have changed. 9 | // Re-run the stringer command to generate them again. 10 | var x [1]struct{} 11 | _ = x[BinaryOperationKindUnknown-0] 12 | _ = x[BinaryOperationKindArithmetic-1] 13 | _ = x[BinaryOperationKindNonEqualityComparison-2] 14 | _ = x[BinaryOperationKindBooleanLogic-3] 15 | _ = x[BinaryOperationKindEquality-4] 16 | _ = x[BinaryOperationKindNilCoalescing-5] 17 | _ = x[BinaryOperationKindBitwise-6] 18 | } 19 | 20 | const _BinaryOperationKind_name = "BinaryOperationKindUnknownBinaryOperationKindArithmeticBinaryOperationKindNonEqualityComparisonBinaryOperationKindBooleanLogicBinaryOperationKindEqualityBinaryOperationKindNilCoalescingBinaryOperationKindBitwise" 21 | 22 | var _BinaryOperationKind_index = [...]uint8{0, 26, 55, 95, 126, 153, 185, 211} 23 | 24 | func (i BinaryOperationKind) String() string { 25 | if i >= BinaryOperationKind(len(_BinaryOperationKind_index)-1) { 26 | return "BinaryOperationKind(" + strconv.FormatInt(int64(i), 10) + ")" 27 | } 28 | return _BinaryOperationKind_name[_BinaryOperationKind_index[i]:_BinaryOperationKind_index[i+1]] 29 | } 30 | -------------------------------------------------------------------------------- /sema/block.cdc: -------------------------------------------------------------------------------- 1 | 2 | access(all) struct Block: ContainFields { 3 | 4 | /// The height of the block. 5 | /// 6 | /// If the blockchain is viewed as a tree with the genesis block at the root, 7 | /// the height of a node is the number of edges between the node and the genesis block 8 | /// 9 | access(all) let height: UInt64 10 | 11 | /// The view of the block. 12 | /// 13 | /// It is a detail of the consensus algorithm. It is a monotonically increasing integer and counts rounds in the consensus algorithm. 14 | /// Since not all rounds result in a finalized block, the view number is strictly greater than or equal to the block height 15 | /// 16 | access(all) let view: UInt64 17 | 18 | /// The timestamp of the block. 19 | /// 20 | /// Unix timestamp of when the proposer claims it constructed the block. 21 | /// 22 | /// NOTE: It is included by the proposer, there are no guarantees on how much the time stamp can deviate 23 | // from the true time the block was published. 24 | /// Consider observing blocks' status changes off-chain yourself to get a more reliable value. 25 | /// 26 | access(all) let timestamp: UFix64 27 | 28 | /// The ID of the block. 29 | /// It is essentially the hash of the block 30 | access(all) let id: [UInt8; 32] 31 | } 32 | -------------------------------------------------------------------------------- /sema/block.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Cadence - The resource-oriented smart contract programming language 3 | * 4 | * Copyright Flow Foundation 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package sema 20 | 21 | //go:generate go run ./gen block.cdc block.gen.go 22 | 23 | var BlockTypeAnnotation = NewTypeAnnotation(BlockType) 24 | -------------------------------------------------------------------------------- /sema/bool_type.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Cadence - The resource-oriented smart contract programming language 3 | * 4 | * Copyright Flow Foundation 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package sema 20 | 21 | // BoolType represents the boolean type 22 | var BoolType = &SimpleType{ 23 | Name: "Bool", 24 | QualifiedName: "Bool", 25 | TypeID: "Bool", 26 | TypeTag: BoolTypeTag, 27 | IsResource: false, 28 | Storable: true, 29 | Primitive: true, 30 | Equatable: true, 31 | Comparable: true, 32 | Exportable: true, 33 | Importable: true, 34 | conformances: []*InterfaceType{ 35 | StructStringerType, 36 | }, 37 | } 38 | 39 | var BoolTypeAnnotation = NewTypeAnnotation(BoolType) 40 | -------------------------------------------------------------------------------- /sema/character.cdc: -------------------------------------------------------------------------------- 1 | 2 | access(all) 3 | struct Character: Storable, Primitive, Equatable, Comparable, Exportable, Importable, StructStringer { 4 | 5 | /// The byte array of the UTF-8 encoding. 6 | access(all) 7 | let utf8: [UInt8] 8 | 9 | /// Returns this character as a String. 10 | access(all) 11 | view fun toString(): String 12 | } 13 | -------------------------------------------------------------------------------- /sema/character.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Cadence - The resource-oriented smart contract programming language 3 | * 4 | * Copyright Flow Foundation 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package sema 20 | 21 | //go:generate go run ./gen character.cdc character.gen.go 22 | 23 | import "github.com/rivo/uniseg" 24 | 25 | func IsValidCharacter(s string) bool { 26 | graphemes := uniseg.NewGraphemes(s) 27 | // a valid character must have exactly one grapheme cluster 28 | return graphemes.Next() && !graphemes.Next() 29 | } 30 | -------------------------------------------------------------------------------- /sema/containerkind.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Cadence - The resource-oriented smart contract programming language 3 | * 4 | * Copyright Flow Foundation 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package sema 20 | 21 | //go:generate stringer -type=ContainerKind 22 | 23 | type ContainerKind uint 24 | 25 | const ( 26 | ContainerKindUnknown ContainerKind = iota 27 | ContainerKindInterface 28 | ContainerKindComposite 29 | ) 30 | -------------------------------------------------------------------------------- /sema/containerkind_string.go: -------------------------------------------------------------------------------- 1 | // Code generated by "stringer -type=ContainerKind"; DO NOT EDIT. 2 | 3 | package sema 4 | 5 | import "strconv" 6 | 7 | func _() { 8 | // An "invalid array index" compiler error signifies that the constant values have changed. 9 | // Re-run the stringer command to generate them again. 10 | var x [1]struct{} 11 | _ = x[ContainerKindUnknown-0] 12 | _ = x[ContainerKindInterface-1] 13 | _ = x[ContainerKindComposite-2] 14 | } 15 | 16 | const _ContainerKind_name = "ContainerKindUnknownContainerKindInterfaceContainerKindComposite" 17 | 18 | var _ContainerKind_index = [...]uint8{0, 20, 42, 64} 19 | 20 | func (i ContainerKind) String() string { 21 | if i >= ContainerKind(len(_ContainerKind_index)-1) { 22 | return "ContainerKind(" + strconv.FormatInt(int64(i), 10) + ")" 23 | } 24 | return _ContainerKind_name[_ContainerKind_index[i]:_ContainerKind_index[i+1]] 25 | } 26 | -------------------------------------------------------------------------------- /sema/crypto_algorithm_types_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Cadence - The resource-oriented smart contract programming language 3 | * 4 | * Copyright Flow Foundation 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package sema 20 | 21 | import ( 22 | "testing" 23 | 24 | "github.com/stretchr/testify/require" 25 | ) 26 | 27 | func TestHashAlgorithm_IsValid(t *testing.T) { 28 | for _, algorithm := range HashAlgorithms { 29 | require.True(t, algorithm.IsValid()) 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /sema/deployedcontract.cdc: -------------------------------------------------------------------------------- 1 | 2 | access(all) struct DeployedContract: ContainFields { 3 | /// The address of the account where the contract is deployed at. 4 | access(all) 5 | let address: Address 6 | 7 | /// The name of the contract. 8 | access(all) 9 | let name: String 10 | 11 | /// The code of the contract. 12 | access(all) 13 | let code: [UInt8] 14 | 15 | /// Returns an array of `Type` objects representing all the public type declarations in this contract 16 | /// (e.g. structs, resources, enums). 17 | /// 18 | /// For example, given a contract 19 | /// ``` 20 | /// contract Foo { 21 | /// access(all) struct Bar {...} 22 | /// access(all) resource Qux {...} 23 | /// } 24 | /// ``` 25 | /// then `.publicTypes()` will return an array equivalent to the expression `[Type(), Type()]` 26 | access(all) 27 | view fun publicTypes(): [Type] 28 | } 29 | -------------------------------------------------------------------------------- /sema/deployedcontract.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Cadence - The resource-oriented smart contract programming language 3 | * 4 | * Copyright Flow Foundation 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package sema 20 | 21 | //go:generate go run ./gen deployedcontract.cdc deployedcontract.gen.go 22 | -------------------------------------------------------------------------------- /sema/deployment_result.cdc: -------------------------------------------------------------------------------- 1 | #compositeType 2 | access(all) 3 | struct DeploymentResult { 4 | 5 | /// The deployed contract. 6 | /// 7 | /// If the the deployment was unsuccessfull, this will be nil. 8 | /// 9 | access(all) 10 | let deployedContract: DeployedContract? 11 | } 12 | -------------------------------------------------------------------------------- /sema/deployment_result.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Cadence - The resource-oriented smart contract programming language 3 | * 4 | * Copyright Flow Foundation 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package sema 20 | 21 | //go:generate go run ./gen deployment_result.cdc deployment_result.gen.go 22 | -------------------------------------------------------------------------------- /sema/entitlements.cdc: -------------------------------------------------------------------------------- 1 | 2 | entitlement Mutate 3 | 4 | entitlement Insert 5 | 6 | entitlement Remove 7 | -------------------------------------------------------------------------------- /sema/entitlements.gen.go: -------------------------------------------------------------------------------- 1 | // Code generated from entitlements.cdc. DO NOT EDIT. 2 | /* 3 | * Cadence - The resource-oriented smart contract programming language 4 | * 5 | * Copyright Flow Foundation 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | 20 | package sema 21 | 22 | var MutateType = &EntitlementType{ 23 | Identifier: "Mutate", 24 | } 25 | 26 | var InsertType = &EntitlementType{ 27 | Identifier: "Insert", 28 | } 29 | 30 | var RemoveType = &EntitlementType{ 31 | Identifier: "Remove", 32 | } 33 | 34 | func init() { 35 | BuiltinEntitlements[MutateType.Identifier] = MutateType 36 | BuiltinEntitlements[InsertType.Identifier] = InsertType 37 | BuiltinEntitlements[RemoveType.Identifier] = RemoveType 38 | } 39 | -------------------------------------------------------------------------------- /sema/entitlements.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Cadence - The resource-oriented smart contract programming language 3 | * 4 | * Copyright Flow Foundation 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package sema 20 | 21 | //go:generate go run ./gen entitlements.cdc entitlements.gen.go 22 | 23 | func init() { 24 | addToBaseActivation(MutateType) 25 | addToBaseActivation(InsertType) 26 | addToBaseActivation(RemoveType) 27 | } 28 | -------------------------------------------------------------------------------- /sema/gen/testdata/comparable/helper.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Cadence - The resource-oriented smart contract programming language 3 | * 4 | * Copyright Flow Foundation 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package comparable 20 | 21 | import "github.com/onflow/cadence/sema" 22 | 23 | var TestTypeTag sema.TypeTag 24 | -------------------------------------------------------------------------------- /sema/gen/testdata/comparable/test.cdc: -------------------------------------------------------------------------------- 1 | access(all) struct Test: Comparable {} 2 | -------------------------------------------------------------------------------- /sema/gen/testdata/composite_type_pragma/test.cdc: -------------------------------------------------------------------------------- 1 | #compositeType 2 | access(all) struct Test {} 3 | -------------------------------------------------------------------------------- /sema/gen/testdata/composite_type_pragma/test.golden.go: -------------------------------------------------------------------------------- 1 | // Code generated from testdata/composite_type_pragma/test.cdc. DO NOT EDIT. 2 | /* 3 | * Cadence - The resource-oriented smart contract programming language 4 | * 5 | * Copyright Flow Foundation 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | 20 | package composite_type_pragma 21 | 22 | import ( 23 | "github.com/onflow/cadence/common" 24 | "github.com/onflow/cadence/sema" 25 | ) 26 | 27 | const TestTypeName = "Test" 28 | 29 | var TestType = func() *sema.CompositeType { 30 | var t = &sema.CompositeType{ 31 | Identifier: TestTypeName, 32 | Kind: common.CompositeKindStructure, 33 | ImportableBuiltin: false, 34 | HasComputedMembers: true, 35 | } 36 | 37 | return t 38 | }() 39 | -------------------------------------------------------------------------------- /sema/gen/testdata/constructor/test.cdc: -------------------------------------------------------------------------------- 1 | /// The Foo type 2 | struct Foo { 3 | 4 | /// Constructs a new Foo 5 | init(bar: Int) 6 | } 7 | -------------------------------------------------------------------------------- /sema/gen/testdata/contract/test.cdc: -------------------------------------------------------------------------------- 1 | access(all) 2 | contract Test { 3 | 4 | /// The Foo type 5 | struct Foo { 6 | 7 | /// Constructs a new Foo 8 | init(bar: Int) 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /sema/gen/testdata/docstrings/helper.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Cadence - The resource-oriented smart contract programming language 3 | * 4 | * Copyright Flow Foundation 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package docstrings 20 | 21 | import "github.com/onflow/cadence/sema" 22 | 23 | var DocstringsTypeTag sema.TypeTag 24 | -------------------------------------------------------------------------------- /sema/gen/testdata/docstrings/test.cdc: -------------------------------------------------------------------------------- 1 | access(all) struct Docstrings { 2 | /// This is a 1-line docstring. 3 | access(all) let owo: Int 4 | 5 | /// This is a 2-line docstring. 6 | /// This is the second line. 7 | access(all) let uwu: [Int] 8 | 9 | /// This is a 3-line docstring for a function. 10 | /// This is the second line. 11 | /// And the third line! 12 | access(all) fun nwn(x: Int): String? 13 | 14 | /// This is a multiline docstring. 15 | /// 16 | /// There should be two newlines before this line! 17 | access(all) let withBlanks: Int 18 | 19 | /// The function `isSmolBean` has docstrings with backticks. 20 | /// These should be handled accordingly. 21 | access(all) fun isSmolBean(): Bool 22 | 23 | /// A function with a docstring. 24 | /// This docstring is `cool` because it has inline backticked expressions. 25 | /// Look, I did it `again`, wowie!! 26 | access(all) fun runningOutOfIdeas(): UInt64? 27 | 28 | } -------------------------------------------------------------------------------- /sema/gen/testdata/entitlement/test.cdc: -------------------------------------------------------------------------------- 1 | entitlement Foo 2 | 3 | entitlement Bar 4 | 5 | entitlement mapping Baz { 6 | Foo -> Bar 7 | } 8 | 9 | entitlement mapping Qux { 10 | include Identity 11 | Foo -> Bar 12 | } -------------------------------------------------------------------------------- /sema/gen/testdata/equatable/helper.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Cadence - The resource-oriented smart contract programming language 3 | * 4 | * Copyright Flow Foundation 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package equatable 20 | 21 | import "github.com/onflow/cadence/sema" 22 | 23 | var TestTypeTag sema.TypeTag 24 | -------------------------------------------------------------------------------- /sema/gen/testdata/equatable/test.cdc: -------------------------------------------------------------------------------- 1 | access(all) struct Test: Equatable {} 2 | -------------------------------------------------------------------------------- /sema/gen/testdata/exportable/helper.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Cadence - The resource-oriented smart contract programming language 3 | * 4 | * Copyright Flow Foundation 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package exportable 20 | 21 | import "github.com/onflow/cadence/sema" 22 | 23 | var TestTypeTag sema.TypeTag 24 | -------------------------------------------------------------------------------- /sema/gen/testdata/exportable/test.cdc: -------------------------------------------------------------------------------- 1 | access(all) struct Test: Exportable {} 2 | -------------------------------------------------------------------------------- /sema/gen/testdata/fields/helper.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Cadence - The resource-oriented smart contract programming language 3 | * 4 | * Copyright Flow Foundation 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package fields 20 | 21 | import "github.com/onflow/cadence/sema" 22 | 23 | var TestTypeTag sema.TypeTag 24 | var FooType = &sema.CapabilityType{} 25 | var BarType *sema.InterfaceType 26 | var BazType *sema.InterfaceType 27 | -------------------------------------------------------------------------------- /sema/gen/testdata/fields/test.cdc: -------------------------------------------------------------------------------- 1 | 2 | access(all) struct Test { 3 | /// This is a test integer. 4 | access(all) let testInt: UInt64 5 | 6 | /// This is a test optional integer. 7 | access(all) let testOptInt: UInt64? 8 | 9 | /// This is a test integer reference. 10 | access(all) let testRefInt: &UInt64 11 | 12 | /// This is a test variable-sized integer array. 13 | access(all) let testVarInts: [UInt64] 14 | 15 | /// This is a test constant-sized integer array. 16 | access(all) let testConstInts: [UInt64; 2] 17 | 18 | /// This is a test integer dictionary. 19 | access(all) let testIntDict: {UInt64: Bool} 20 | 21 | /// This is a test parameterized-type field. 22 | access(all) let testParam: Foo 23 | 24 | /// This is a test address field. 25 | access(all) let testAddress: Address 26 | 27 | /// This is a test type field. 28 | access(all) let testType: Type 29 | 30 | /// This is a test unparameterized capability field. 31 | access(all) let testCap: Capability 32 | 33 | /// This is a test parameterized capability field. 34 | access(all) let testCapInt: Capability 35 | 36 | /// This is a test intersection type (without type) field. 37 | access(all) let testIntersectionWithoutType: {Bar, Baz} 38 | } 39 | -------------------------------------------------------------------------------- /sema/gen/testdata/functions/helper.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Cadence - The resource-oriented smart contract programming language 3 | * 4 | * Copyright Flow Foundation 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package functions 20 | 21 | import "github.com/onflow/cadence/sema" 22 | 23 | var TestTypeTag sema.TypeTag 24 | -------------------------------------------------------------------------------- /sema/gen/testdata/functions/test.cdc: -------------------------------------------------------------------------------- 1 | access(all) struct Test { 2 | /// This is a test function. 3 | access(all) fun nothing() {} 4 | 5 | /// This is a test function with parameters. 6 | access(all) fun params(a: Int, _ b: String) {} 7 | 8 | /// This is a test function with a return type. 9 | access(all) fun returnBool(): Bool {} 10 | 11 | /// This is a test function with parameters and a return type. 12 | access(all) fun paramsAndReturn(a: Int, _ b: String): Bool {} 13 | 14 | /// This is a test function with a type parameter. 15 | access(all) fun typeParam() {} 16 | 17 | /// This is a test function with a type parameter and a type bound. 18 | access(all) fun typeParamWithBound() {} 19 | 20 | /// This is a test function with a type parameter and a parameter using it. 21 | access(all) fun typeParamWithBoundAndParam(t: T) {} 22 | 23 | /// This is a function with 'view' modifier 24 | access(all) view fun viewFunction() {} 25 | } 26 | -------------------------------------------------------------------------------- /sema/gen/testdata/importable/helper.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Cadence - The resource-oriented smart contract programming language 3 | * 4 | * Copyright Flow Foundation 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package importable 20 | 21 | import "github.com/onflow/cadence/sema" 22 | 23 | var TestTypeTag sema.TypeTag 24 | -------------------------------------------------------------------------------- /sema/gen/testdata/importable/test.cdc: -------------------------------------------------------------------------------- 1 | access(all) struct Test: Importable {} 2 | -------------------------------------------------------------------------------- /sema/gen/testdata/member_accessible/helper.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Cadence - The resource-oriented smart contract programming language 3 | * 4 | * Copyright Flow Foundation 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package member_accessible 20 | 21 | import "github.com/onflow/cadence/sema" 22 | 23 | var TestTypeTag sema.TypeTag 24 | -------------------------------------------------------------------------------- /sema/gen/testdata/member_accessible/test.cdc: -------------------------------------------------------------------------------- 1 | access(all) struct Test: ContainFields {} 2 | -------------------------------------------------------------------------------- /sema/gen/testdata/nested/test.cdc: -------------------------------------------------------------------------------- 1 | struct Foo { 2 | /// foo 3 | access(all) fun foo() 4 | 5 | /// Bar 6 | access(all) let bar: Foo.Bar 7 | 8 | struct Bar { 9 | /// bar 10 | access(all) fun bar() 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /sema/gen/testdata/primitive/helper.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Cadence - The resource-oriented smart contract programming language 3 | * 4 | * Copyright Flow Foundation 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package primitive 20 | 21 | import "github.com/onflow/cadence/sema" 22 | 23 | var TestTypeTag sema.TypeTag 24 | -------------------------------------------------------------------------------- /sema/gen/testdata/primitive/test.cdc: -------------------------------------------------------------------------------- 1 | access(all) struct Test: Primitive {} 2 | -------------------------------------------------------------------------------- /sema/gen/testdata/simple_interface/test.cdc: -------------------------------------------------------------------------------- 1 | access(all) struct interface Test {} 2 | -------------------------------------------------------------------------------- /sema/gen/testdata/simple_interface/test.golden.go: -------------------------------------------------------------------------------- 1 | // Code generated from testdata/simple_interface/test.cdc. DO NOT EDIT. 2 | /* 3 | * Cadence - The resource-oriented smart contract programming language 4 | * 5 | * Copyright Flow Foundation 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | 20 | package simple_interface 21 | 22 | import ( 23 | "github.com/onflow/cadence/common" 24 | "github.com/onflow/cadence/sema" 25 | ) 26 | 27 | const TestTypeName = "Test" 28 | 29 | var TestType = func() *sema.InterfaceType { 30 | var t = &sema.InterfaceType{ 31 | Identifier: TestTypeName, 32 | CompositeKind: common.CompositeKindStructure, 33 | } 34 | 35 | return t 36 | }() 37 | -------------------------------------------------------------------------------- /sema/gen/testdata/simple_resource/helper.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Cadence - The resource-oriented smart contract programming language 3 | * 4 | * Copyright Flow Foundation 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package simple_resource 20 | 21 | import "github.com/onflow/cadence/sema" 22 | 23 | var TestTypeTag sema.TypeTag 24 | -------------------------------------------------------------------------------- /sema/gen/testdata/simple_resource/test.cdc: -------------------------------------------------------------------------------- 1 | access(all) resource Test {} 2 | -------------------------------------------------------------------------------- /sema/gen/testdata/simple_struct/helper.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Cadence - The resource-oriented smart contract programming language 3 | * 4 | * Copyright Flow Foundation 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package simple_struct 20 | 21 | import "github.com/onflow/cadence/sema" 22 | 23 | var TestTypeTag sema.TypeTag 24 | -------------------------------------------------------------------------------- /sema/gen/testdata/simple_struct/test.cdc: -------------------------------------------------------------------------------- 1 | access(all) struct Test {} 2 | -------------------------------------------------------------------------------- /sema/gen/testdata/storable/helper.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Cadence - The resource-oriented smart contract programming language 3 | * 4 | * Copyright Flow Foundation 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package storable 20 | 21 | import "github.com/onflow/cadence/sema" 22 | 23 | var TestTypeTag sema.TypeTag 24 | -------------------------------------------------------------------------------- /sema/gen/testdata/storable/test.cdc: -------------------------------------------------------------------------------- 1 | access(all) struct Test: Storable {} 2 | -------------------------------------------------------------------------------- /sema/hashable_struct.cdc: -------------------------------------------------------------------------------- 1 | 2 | /// HashableStructType represents the type that can be used as a Dictionary key type. 3 | access(all) struct HashableStruct: Storable, Exportable, Importable { 4 | } 5 | -------------------------------------------------------------------------------- /sema/hashable_struct.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Cadence - The resource-oriented smart contract programming language 3 | * 4 | * Copyright Flow Foundation 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package sema 20 | 21 | //go:generate go run ./gen hashable_struct.cdc hashable_struct.gen.go 22 | -------------------------------------------------------------------------------- /sema/hashalgorithm_string.go: -------------------------------------------------------------------------------- 1 | // Code generated by "stringer -type=HashAlgorithm"; DO NOT EDIT. 2 | 3 | package sema 4 | 5 | import "strconv" 6 | 7 | func _() { 8 | // An "invalid array index" compiler error signifies that the constant values have changed. 9 | // Re-run the stringer command to generate them again. 10 | var x [1]struct{} 11 | _ = x[HashAlgorithmUnknown-0] 12 | _ = x[HashAlgorithmSHA2_256-1] 13 | _ = x[HashAlgorithmSHA2_384-2] 14 | _ = x[HashAlgorithmSHA3_256-3] 15 | _ = x[HashAlgorithmSHA3_384-4] 16 | _ = x[HashAlgorithmKMAC128_BLS_BLS12_381-5] 17 | _ = x[HashAlgorithmKECCAK_256-6] 18 | } 19 | 20 | const _HashAlgorithm_name = "HashAlgorithmUnknownHashAlgorithmSHA2_256HashAlgorithmSHA2_384HashAlgorithmSHA3_256HashAlgorithmSHA3_384HashAlgorithmKMAC128_BLS_BLS12_381HashAlgorithmKECCAK_256" 21 | 22 | var _HashAlgorithm_index = [...]uint8{0, 20, 41, 62, 83, 104, 138, 161} 23 | 24 | func (i HashAlgorithm) String() string { 25 | if i >= HashAlgorithm(len(_HashAlgorithm_index)-1) { 26 | return "HashAlgorithm(" + strconv.FormatInt(int64(i), 10) + ")" 27 | } 28 | return _HashAlgorithm_name[_HashAlgorithm_index[i]:_HashAlgorithm_index[i+1]] 29 | } 30 | -------------------------------------------------------------------------------- /sema/invalid_type.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Cadence - The resource-oriented smart contract programming language 3 | * 4 | * Copyright Flow Foundation 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package sema 20 | 21 | // InvalidType represents a type that is invalid. 22 | // It is the result of type checking failing and 23 | // can't be expressed in programs. 24 | var InvalidType = &SimpleType{ 25 | Name: "<>", 26 | QualifiedName: "<>", 27 | TypeID: "<>", 28 | TypeTag: InvalidTypeTag, 29 | IsResource: false, 30 | Storable: false, 31 | Primitive: false, 32 | Equatable: false, 33 | Comparable: false, 34 | Exportable: false, 35 | Importable: false, 36 | } 37 | -------------------------------------------------------------------------------- /sema/never_type.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Cadence - The resource-oriented smart contract programming language 3 | * 4 | * Copyright Flow Foundation 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package sema 20 | 21 | // NeverType represents the bottom type 22 | var NeverType = &SimpleType{ 23 | Name: "Never", 24 | QualifiedName: "Never", 25 | TypeID: "Never", 26 | TypeTag: NeverTypeTag, 27 | IsResource: false, 28 | Storable: false, 29 | Primitive: false, 30 | Equatable: false, 31 | Comparable: false, 32 | Exportable: false, 33 | Importable: false, 34 | } 35 | 36 | var NeverTypeAnnotation = NewTypeAnnotation(NeverType) 37 | -------------------------------------------------------------------------------- /sema/post_conditions_rewrite.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Cadence - The resource-oriented smart contract programming language 3 | * 4 | * Copyright Flow Foundation 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package sema 20 | 21 | import ( 22 | "github.com/onflow/cadence/ast" 23 | ) 24 | 25 | type PostConditionsRewrite struct { 26 | BeforeStatements []ast.Statement 27 | RewrittenPostConditions []ast.Condition 28 | } 29 | -------------------------------------------------------------------------------- /sema/resource_invalidation.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Cadence - The resource-oriented smart contract programming language 3 | * 4 | * Copyright Flow Foundation 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package sema 20 | 21 | import ( 22 | "github.com/onflow/cadence/ast" 23 | ) 24 | 25 | type ResourceInvalidation struct { 26 | Kind ResourceInvalidationKind 27 | StartPos ast.Position 28 | EndPos ast.Position 29 | } 30 | -------------------------------------------------------------------------------- /sema/signaturealgorithm_string.go: -------------------------------------------------------------------------------- 1 | // Code generated by "stringer -type=SignatureAlgorithm"; DO NOT EDIT. 2 | 3 | package sema 4 | 5 | import "strconv" 6 | 7 | func _() { 8 | // An "invalid array index" compiler error signifies that the constant values have changed. 9 | // Re-run the stringer command to generate them again. 10 | var x [1]struct{} 11 | _ = x[SignatureAlgorithmUnknown-0] 12 | _ = x[SignatureAlgorithmECDSA_P256-1] 13 | _ = x[SignatureAlgorithmECDSA_secp256k1-2] 14 | _ = x[SignatureAlgorithmBLS_BLS12_381-3] 15 | } 16 | 17 | const _SignatureAlgorithm_name = "SignatureAlgorithmUnknownSignatureAlgorithmECDSA_P256SignatureAlgorithmECDSA_secp256k1SignatureAlgorithmBLS_BLS12_381" 18 | 19 | var _SignatureAlgorithm_index = [...]uint8{0, 25, 53, 86, 117} 20 | 21 | func (i SignatureAlgorithm) String() string { 22 | if i >= SignatureAlgorithm(len(_SignatureAlgorithm_index)-1) { 23 | return "SignatureAlgorithm(" + strconv.FormatInt(int64(i), 10) + ")" 24 | } 25 | return _SignatureAlgorithm_name[_SignatureAlgorithm_index[i]:_SignatureAlgorithm_index[i+1]] 26 | } 27 | -------------------------------------------------------------------------------- /sema/storage_capability_controller.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Cadence - The resource-oriented smart contract programming language 3 | * 4 | * Copyright Flow Foundation 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package sema 20 | 21 | //go:generate go run ./gen/main.go storage_capability_controller.cdc storage_capability_controller.gen.go 22 | 23 | var StorageCapabilityControllerTypeAnnotation = NewTypeAnnotation(StorageCapabilityControllerType) 24 | -------------------------------------------------------------------------------- /sema/struct_stringer.cdc: -------------------------------------------------------------------------------- 1 | /// StructStringer is an interface implemented by all the string convertible structs. 2 | access(all) 3 | struct interface StructStringer { 4 | /// Returns the string representation of this object. 5 | access(all) 6 | view fun toString(): String 7 | } 8 | -------------------------------------------------------------------------------- /sema/struct_stringer.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Cadence - The resource-oriented smart contract programming language 3 | * 4 | * Copyright Flow Foundation 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package sema 20 | 21 | //go:generate go run ./gen struct_stringer.cdc struct_stringer.gen.go 22 | -------------------------------------------------------------------------------- /sema/typecheckfunc.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Cadence - The resource-oriented smart contract programming language 3 | * 4 | * Copyright Flow Foundation 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package sema 20 | 21 | type TypeCheckFunc = func() Type 22 | 23 | func wrapTypeCheck(check TypeCheckFunc, outerChecks ...func(TypeCheckFunc) Type) TypeCheckFunc { 24 | for _, outerCheck := range outerChecks { 25 | innerCheck := check 26 | currentOuterCheck := outerCheck 27 | check = func() Type { 28 | return currentOuterCheck(innerCheck) 29 | } 30 | } 31 | 32 | return check 33 | } 34 | -------------------------------------------------------------------------------- /sema/void_type.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Cadence - The resource-oriented smart contract programming language 3 | * 4 | * Copyright Flow Foundation 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package sema 20 | 21 | // VoidType represents the void type 22 | var VoidType = &SimpleType{ 23 | Name: "Void", 24 | QualifiedName: "Void", 25 | TypeID: "Void", 26 | TypeTag: VoidTypeTag, 27 | IsResource: false, 28 | Storable: false, 29 | Primitive: true, 30 | Equatable: true, 31 | Comparable: false, 32 | Exportable: true, 33 | Importable: false, 34 | } 35 | 36 | var VoidTypeAnnotation = NewTypeAnnotation(VoidType) 37 | -------------------------------------------------------------------------------- /semgrep.yaml: -------------------------------------------------------------------------------- 1 | rules: 2 | - id: host-function-value-without-type 3 | languages: 4 | - go 5 | message: Host function values must have a static type 6 | pattern-either: 7 | - pattern: NewHostFunctionValue($GAUGE, nil, $HOST_FUNC) 8 | - pattern: interpreter.NewHostFunctionValue($GAUGE, nil, $HOST_FUNC) 9 | - pattern: NewUnmeteredHostFunctionValue(nil, $HOST_FUNC) 10 | - pattern: interpreter.NewUnmeteredHostFunctionValue(nil, $HOST_FUNC) 11 | severity: ERROR 12 | -------------------------------------------------------------------------------- /stdlib/bls.cdc: -------------------------------------------------------------------------------- 1 | access(all) 2 | contract BLS { 3 | /// Aggregates multiple BLS signatures into one, 4 | /// considering the proof of possession as a defense against rogue attacks. 5 | /// 6 | /// Signatures could be generated from the same or distinct messages, 7 | /// they could also be the aggregation of other signatures. 8 | /// The order of the signatures in the slice does not matter since the aggregation is commutative. 9 | /// No subgroup membership check is performed on the input signatures. 10 | /// The function returns nil if the array is empty or if decoding one of the signature fails. 11 | access(all) 12 | view fun aggregateSignatures(_ signatures: [[UInt8]]): [UInt8]? 13 | 14 | 15 | /// Aggregates multiple BLS public keys into one. 16 | /// 17 | /// The order of the public keys in the slice does not matter since the aggregation is commutative. 18 | /// No subgroup membership check is performed on the input keys. 19 | /// The function returns nil if the array is empty or any of the input keys is not a BLS key. 20 | access(all) 21 | view fun aggregatePublicKeys(_ keys: [PublicKey]): PublicKey? 22 | } 23 | -------------------------------------------------------------------------------- /stdlib/contracts/flow.json: -------------------------------------------------------------------------------- 1 | { 2 | "networks": { 3 | "emulator": "127.0.0.1:3569", 4 | "testing": "127.0.0.1:3569", 5 | "mainnet": "access.mainnet.nodes.onflow.org:9000", 6 | "sandboxnet": "access.sandboxnet.nodes.onflow.org:9000", 7 | "testnet": "access.devnet.nodes.onflow.org:9000" 8 | }, 9 | "contracts": { 10 | "Crypto": { 11 | "source": "crypto.cdc", 12 | "aliases": { 13 | "testing": "0x0000000000000007" 14 | } 15 | } 16 | }, 17 | "deployments": { 18 | "emulator": { 19 | "emulator-account": [ 20 | "Crypto" 21 | ] 22 | } 23 | }, 24 | "accounts": { 25 | "emulator-account": { 26 | "address": "f8d6e0586b0a20c7", 27 | "key": "b775d6da04a0b4819903d89a25395bfd90eb8559182255690c7c141edaeae923" 28 | } 29 | } 30 | } -------------------------------------------------------------------------------- /stdlib/contracts/test.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Cadence - The resource-oriented smart contract programming language 3 | * 4 | * Copyright Flow Foundation 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package contracts 20 | 21 | import ( 22 | _ "embed" 23 | ) 24 | 25 | //go:embed test.cdc 26 | var TestContract []byte 27 | -------------------------------------------------------------------------------- /stdlib/rlp.cdc: -------------------------------------------------------------------------------- 1 | access(all) 2 | contract RLP { 3 | /// Decodes an RLP-encoded byte array (called string in the context of RLP). 4 | /// The byte array should only contain of a single encoded value for a string; 5 | /// if the encoded value type does not match, or it has trailing unnecessary bytes, the program aborts. 6 | /// If any error is encountered while decoding, the program aborts. 7 | access(all) 8 | view fun decodeString(_ input: [UInt8]): [UInt8] 9 | 10 | 11 | /// Decodes an RLP-encoded list into an array of RLP-encoded items. 12 | /// Note that this function does not recursively decode, so each element of the resulting array is RLP-encoded data. 13 | /// The byte array should only contain of a single encoded value for a list; 14 | /// if the encoded value type does not match, or it has trailing unnecessary bytes, the program aborts. 15 | /// If any error is encountered while decoding, the program aborts. 16 | access(all) 17 | view fun decodeList(_ input: [UInt8]): [[UInt8]] 18 | } 19 | -------------------------------------------------------------------------------- /tools/accounts-script/iterate_storage.cdc: -------------------------------------------------------------------------------- 1 | access(all) 2 | fun main(addresses: [Address]): String { 3 | for address in addresses { 4 | let account = getAccount(address) 5 | // iterate over all storage 6 | account.storage.forEachStored(fun (path: StoragePath, type: Type): Bool { 7 | return true 8 | }) 9 | account.storage.forEachPublic(fun (path: PublicPath, type: Type): Bool { 10 | return true 11 | }) 12 | } 13 | 14 | return "success" 15 | } -------------------------------------------------------------------------------- /tools/analysis/analysis.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Cadence - The resource-oriented smart contract programming language 3 | * 4 | * Copyright Flow Foundation 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package analysis 20 | 21 | import ( 22 | "github.com/onflow/cadence/common" 23 | ) 24 | 25 | func Load(config *Config, locations ...common.Location) (*Programs, error) { 26 | programs := &Programs{ 27 | Programs: make(map[common.Location]*Program, len(locations)), 28 | CryptoContractElaboration: config.CryptoContractElaboration, 29 | } 30 | for _, location := range locations { 31 | err := programs.Load(config, location) 32 | if err != nil { 33 | return nil, err 34 | } 35 | } 36 | 37 | return programs, nil 38 | } 39 | -------------------------------------------------------------------------------- /tools/analysis/analyzer.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Cadence - The resource-oriented smart contract programming language 3 | * 4 | * Copyright Flow Foundation 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package analysis 20 | 21 | // Analyzer describes an analysis function and its options 22 | type Analyzer struct { 23 | Description string 24 | 25 | Run func(*Pass) interface{} 26 | 27 | // Requires is a set of analyzers that must run before this one. 28 | // This analyzer may inspect the outputs produced by each analyzer in Requires. 29 | // The graph over analyzers implied by Requires edges must be acyclic 30 | Requires []*Analyzer 31 | } 32 | -------------------------------------------------------------------------------- /tools/analysis/inspector.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Cadence - The resource-oriented smart contract programming language 3 | * 4 | * Copyright Flow Foundation 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package analysis 20 | 21 | import ( 22 | "github.com/onflow/cadence/ast" 23 | ) 24 | 25 | var InspectorAnalyzer = &Analyzer{ 26 | Run: func(pass *Pass) interface{} { 27 | return ast.NewInspector(pass.Program.Program) 28 | }, 29 | } 30 | -------------------------------------------------------------------------------- /tools/ast-explorer/.eslintrc: -------------------------------------------------------------------------------- 1 | 2 | { 3 | "parser": "@typescript-eslint/parser", 4 | "plugins": ["@typescript-eslint"], 5 | "extends": [ 6 | "eslint:recommended", 7 | "plugin:@typescript-eslint/eslint-recommended", 8 | "plugin:@typescript-eslint/recommended", 9 | "plugin:react/recommended" 10 | ], 11 | "settings": { 12 | "react": { 13 | "version": "detect" 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /tools/ast-explorer/.gitignore: -------------------------------------------------------------------------------- 1 | dist 2 | -------------------------------------------------------------------------------- /tools/ast-explorer/README.md: -------------------------------------------------------------------------------- 1 | # Cadence AST Explorer 2 | 3 | Install the dependencies: 4 | 5 | ```sh 6 | npm install 7 | ``` 8 | 9 | Start the UI: 10 | 11 | ```sh 12 | npm run start 13 | ``` 14 | 15 | In a separate shell, run the API: 16 | 17 | ```sh 18 | go run . 19 | ``` 20 | -------------------------------------------------------------------------------- /tools/ast-explorer/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "cadence-ast-explorer", 3 | "version": "0.1.0", 4 | "private": true, 5 | "scripts": { 6 | "watch": "webpack --watch", 7 | "start": "webpack-dev-server --open", 8 | "build": "webpack --mode=production" 9 | }, 10 | "devDependencies": { 11 | "@types/react": "^18.0.24", 12 | "@types/react-dom": "^18.0.8", 13 | "@typescript-eslint/eslint-plugin": "^5.42.0", 14 | "@typescript-eslint/parser": "^5.42.0", 15 | "css-loader": "5.2.7", 16 | "eslint": "^8.26.0", 17 | "eslint-config-prettier": "^8.5.0", 18 | "eslint-plugin-react": "^7.31.10", 19 | "file-loader": "^6.2.0", 20 | "html-webpack-plugin": "^5.5.0", 21 | "monaco-editor-webpack-plugin": "^7.0.1", 22 | "prettier": "2.7.1", 23 | "style-loader": "^3.3.1", 24 | "ts-loader": "^9.4.1", 25 | "typescript": "^4.8.4", 26 | "webpack": "^5.74.0", 27 | "webpack-cli": "^4.10.0", 28 | "webpack-dev-server": "^4.11.1" 29 | }, 30 | "dependencies": { 31 | "monaco-editor": "^0.34.1", 32 | "react": "^18.2.0", 33 | "react-dom": "^18.2.0" 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /tools/ast-explorer/tsconfig.json: -------------------------------------------------------------------------------- 1 | 2 | { 3 | "compilerOptions": { 4 | "jsx": "react", 5 | "skipLibCheck": true, 6 | "noImplicitAny": true, 7 | "noUnusedLocals": true, 8 | "noUnusedParameters": true, 9 | "target": "es5", 10 | "module": "es2015", 11 | "moduleResolution": "node", 12 | "lib": [ 13 | "dom", 14 | "es5", 15 | "es6" 16 | ] 17 | }, 18 | "include": [ 19 | "src/**/*" 20 | ] 21 | } 22 | -------------------------------------------------------------------------------- /tools/ast-explorer/webpack.config.js: -------------------------------------------------------------------------------- 1 | const MonacoWebpackPlugin = require('monaco-editor-webpack-plugin') 2 | const HtmlWebpackPlugin = require("html-webpack-plugin"); 3 | 4 | module.exports = { 5 | entry: [ "./src/index.tsx"], 6 | output: { 7 | filename: "bundle.js" 8 | }, 9 | resolve: { 10 | extensions: [".ts", ".tsx", ".js"] 11 | }, 12 | module: { 13 | rules: [ 14 | { 15 | test: /\.tsx?$/, 16 | loader: "ts-loader" 17 | }, 18 | { 19 | test: /\.css$/, 20 | use: ['style-loader', 'css-loader'] 21 | }, 22 | { 23 | test: /\.ttf$/, 24 | use: ['file-loader'] 25 | }, 26 | ] 27 | }, 28 | plugins: [ 29 | new MonacoWebpackPlugin({ 30 | languages: [] 31 | }), 32 | new HtmlWebpackPlugin({ 33 | template: "./src/index.html", 34 | }), 35 | ], 36 | mode: 'development', 37 | devServer: { 38 | port: 8000, 39 | devMiddleware: { 40 | writeToDisk: true, 41 | }, 42 | proxy: { 43 | '/api': 'http://127.0.0.1:3000', 44 | }, 45 | }, 46 | } 47 | -------------------------------------------------------------------------------- /tools/constructorcheck/Makefile: -------------------------------------------------------------------------------- 1 | constructorcheck.so: go.mod *.go 2 | go build -buildmode=plugin . 3 | -------------------------------------------------------------------------------- /tools/constructorcheck/analyzer_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Cadence - The resource-oriented smart contract programming language 3 | * 4 | * Copyright Flow Foundation 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package main 20 | 21 | import ( 22 | "testing" 23 | 24 | "golang.org/x/tools/go/analysis/analysistest" 25 | ) 26 | 27 | func TestAll(t *testing.T) { 28 | analysistest.Run(t, analysistest.TestData(), Analyzer) 29 | } 30 | -------------------------------------------------------------------------------- /tools/constructorcheck/go.mod: -------------------------------------------------------------------------------- 1 | module github.com/onflow/cadence/tools/constructorcheck 2 | 3 | go 1.23.0 4 | 5 | toolchain go1.24.2 6 | 7 | require golang.org/x/tools v0.32.0 8 | 9 | require ( 10 | golang.org/x/mod v0.24.0 // indirect 11 | golang.org/x/sync v0.13.0 // indirect 12 | ) 13 | -------------------------------------------------------------------------------- /tools/constructorcheck/go.sum: -------------------------------------------------------------------------------- 1 | github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= 2 | github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= 3 | golang.org/x/mod v0.24.0 h1:ZfthKaKaT4NrhGVZHO1/WDTwGES4De8KtWO0SIbNJMU= 4 | golang.org/x/mod v0.24.0/go.mod h1:IXM97Txy2VM4PJ3gI61r1YEk/gAj6zAHN3AdZt6S9Ww= 5 | golang.org/x/sync v0.13.0 h1:AauUjRAJ9OSnvULf/ARrrVywoJDy0YS2AwQ98I37610= 6 | golang.org/x/sync v0.13.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA= 7 | golang.org/x/tools v0.32.0 h1:Q7N1vhpkQv7ybVzLFtTjvQya2ewbwNDZzUgfXGqtMWU= 8 | golang.org/x/tools v0.32.0/go.mod h1:ZxrU41P/wAbZD8EDa6dDCa6XfpkhJ7HFMjHJXfBDu8s= 9 | -------------------------------------------------------------------------------- /tools/constructorcheck/main.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Cadence - The resource-oriented smart contract programming language 3 | * 4 | * Copyright Flow Foundation 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package main 20 | 21 | import ( 22 | "golang.org/x/tools/go/analysis" 23 | "golang.org/x/tools/go/analysis/singlechecker" 24 | ) 25 | 26 | func main() { 27 | singlechecker.Main(Analyzer) 28 | } 29 | 30 | // This must be defined and named 'New' for golangci-lint, 31 | // see https://golangci-lint.run/plugins/go-plugins/#create-a-plugin 32 | func New(_ any) ([]*analysis.Analyzer, error) { 33 | return []*analysis.Analyzer{ 34 | Analyzer, 35 | }, nil 36 | } 37 | -------------------------------------------------------------------------------- /tools/constructorcheck/testdata/test.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Cadence - The resource-oriented smart contract programming language 3 | * 4 | * Copyright Flow Foundation 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package testdata 20 | 21 | type Value interface { 22 | isValue() 23 | } 24 | 25 | type XValue struct{} 26 | 27 | var _ Value = XValue{} 28 | 29 | func (XValue) isValue() {} 30 | 31 | func testValue() { 32 | v := XValue{} // want "value composite literal should be constructor function call" 33 | _ = v 34 | } 35 | -------------------------------------------------------------------------------- /tools/get-contracts/go.mod: -------------------------------------------------------------------------------- 1 | module github.com/onflow/cadence/tools/get-contracts 2 | 3 | go 1.23 4 | 5 | require github.com/hasura/go-graphql-client v0.10.2 6 | 7 | require ( 8 | github.com/google/uuid v1.5.0 // indirect 9 | nhooyr.io/websocket v1.8.10 // indirect 10 | ) 11 | -------------------------------------------------------------------------------- /tools/get-contracts/go.sum: -------------------------------------------------------------------------------- 1 | github.com/google/uuid v1.5.0 h1:1p67kYwdtXjb0gL0BPiP1Av9wiZPo5A8z2cWkTZ+eyU= 2 | github.com/google/uuid v1.5.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= 3 | github.com/gorilla/websocket v1.5.1 h1:gmztn0JnHVt9JZquRuzLw3g4wouNVzKL15iLr/zn/QY= 4 | github.com/graph-gophers/graphql-go v1.5.0 h1:fDqblo50TEpD0LY7RXk/LFVYEVqo3+tXMNMPSVXA1yc= 5 | github.com/graph-gophers/graphql-transport-ws v0.0.2 h1:DbmSkbIGzj8SvHei6n8Mh9eLQin8PtA8xY9eCzjRpvo= 6 | github.com/hasura/go-graphql-client v0.10.2 h1:+/v5/gWYgWr0cpd0aCi4GNtiy8uAIxnkADHTKDM+boY= 7 | github.com/hasura/go-graphql-client v0.10.2/go.mod h1:eNNnmHAp6NgwKZ4xRbZEfywxr07qk34Y0QhbPsYIfhw= 8 | golang.org/x/net v0.19.0 h1:zTwKpTd2XuCqf8huc7Fo2iSy+4RHPd10s4KzeTnVr1c= 9 | nhooyr.io/websocket v1.8.10 h1:mv4p+MnGrLDcPlBoWsvPP7XCzTYMXP9F9eIGoKbgx7Q= 10 | nhooyr.io/websocket v1.8.10/go.mod h1:rN9OFWIUwuxg4fR5tELlYC04bXYowCP9GX47ivo2l+c= 11 | -------------------------------------------------------------------------------- /tools/golangci-lint/Makefile: -------------------------------------------------------------------------------- 1 | golangci-lint: go.mod 2 | go build -o golangci-lint github.com/golangci/golangci-lint/v2/cmd/golangci-lint 3 | -------------------------------------------------------------------------------- /tools/golangci-lint/main.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Cadence - The resource-oriented smart contract programming language 3 | * 4 | * Copyright Flow Foundation 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package lint 20 | 21 | import ( 22 | _ "github.com/golangci/golangci-lint/v2/pkg/commands" 23 | _ "github.com/golangci/golangci-lint/v2/pkg/lint" 24 | ) 25 | -------------------------------------------------------------------------------- /tools/maprange/Makefile: -------------------------------------------------------------------------------- 1 | maprange.so: go.mod *.go 2 | go build -buildmode=plugin . 3 | -------------------------------------------------------------------------------- /tools/maprange/README.md: -------------------------------------------------------------------------------- 1 | # maprange 2 | 3 | A Go analyzer which detects uses of for-range statements over maps. 4 | For such statements, iteration order is undefined / nondeterministic. 5 | -------------------------------------------------------------------------------- /tools/maprange/analyzer_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Cadence - The resource-oriented smart contract programming language 3 | * 4 | * Copyright Flow Foundation 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package main 20 | 21 | import ( 22 | "testing" 23 | 24 | "golang.org/x/tools/go/analysis/analysistest" 25 | ) 26 | 27 | func TestAll(t *testing.T) { 28 | analysistest.Run(t, analysistest.TestData(), Analyzer, "a") 29 | } 30 | -------------------------------------------------------------------------------- /tools/maprange/go.mod: -------------------------------------------------------------------------------- 1 | module github.com/onflow/cadence/tools/maprange 2 | 3 | go 1.23.0 4 | 5 | toolchain go1.24.2 6 | 7 | require golang.org/x/tools v0.32.0 8 | 9 | require ( 10 | golang.org/x/mod v0.24.0 // indirect 11 | golang.org/x/sync v0.13.0 // indirect 12 | ) 13 | -------------------------------------------------------------------------------- /tools/maprange/go.sum: -------------------------------------------------------------------------------- 1 | github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= 2 | github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= 3 | golang.org/x/mod v0.24.0 h1:ZfthKaKaT4NrhGVZHO1/WDTwGES4De8KtWO0SIbNJMU= 4 | golang.org/x/mod v0.24.0/go.mod h1:IXM97Txy2VM4PJ3gI61r1YEk/gAj6zAHN3AdZt6S9Ww= 5 | golang.org/x/sync v0.13.0 h1:AauUjRAJ9OSnvULf/ARrrVywoJDy0YS2AwQ98I37610= 6 | golang.org/x/sync v0.13.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA= 7 | golang.org/x/tools v0.32.0 h1:Q7N1vhpkQv7ybVzLFtTjvQya2ewbwNDZzUgfXGqtMWU= 8 | golang.org/x/tools v0.32.0/go.mod h1:ZxrU41P/wAbZD8EDa6dDCa6XfpkhJ7HFMjHJXfBDu8s= 9 | -------------------------------------------------------------------------------- /tools/maprange/main.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Cadence - The resource-oriented smart contract programming language 3 | * 4 | * Copyright Flow Foundation 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package main 20 | 21 | import ( 22 | "golang.org/x/tools/go/analysis" 23 | "golang.org/x/tools/go/analysis/singlechecker" 24 | ) 25 | 26 | func main() { 27 | singlechecker.Main(Analyzer) 28 | } 29 | 30 | // This must be defined and named 'New' for golangci-lint, 31 | // see https://golangci-lint.run/plugins/go-plugins/#create-a-plugin 32 | func New(_ any) ([]*analysis.Analyzer, error) { 33 | return []*analysis.Analyzer{ 34 | Analyzer, 35 | }, nil 36 | } 37 | -------------------------------------------------------------------------------- /tools/pretty/README.md: -------------------------------------------------------------------------------- 1 | # Pretty 2 | 3 | A tool that helps with the development of the pretty-printing of the AST. 4 | 5 | ```sh 6 | go run . 7 | ``` -------------------------------------------------------------------------------- /tools/staged-contracts-report-printer/README.md: -------------------------------------------------------------------------------- 1 | # Readme 2 | 3 | A tool that takes in a JSON report produced from staged contract migration, and outputs a more 4 | human-readable report in Markdown format. 5 | 6 | ```sh 7 | go run . --report /path/to/staged-contracts-migrator_report.json 8 | ``` 9 | 10 | This will produce a Markdown format report with the same name, but with the makdown extension. 11 | e.g: `/path/to/staged-contracts-migrator_report.md` -------------------------------------------------------------------------------- /tools/storage-explorer/.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | pnpm-debug.log* 8 | lerna-debug.log* 9 | 10 | node_modules 11 | dist 12 | dist-ssr 13 | *.local 14 | 15 | # Editor directories and files 16 | .vscode/* 17 | !.vscode/extensions.json 18 | .idea 19 | .DS_Store 20 | *.suo 21 | *.ntvs* 22 | *.njsproj 23 | *.sln 24 | *.sw? 25 | -------------------------------------------------------------------------------- /tools/storage-explorer/README.md: -------------------------------------------------------------------------------- 1 | # storage-explorer 2 | 3 | Load a payloads file and browse its accounts, their storage maps, and their stored values. 4 | 5 | ## Usage 6 | 7 | ```shell 8 | npm i 9 | npm run build 10 | go run . -port 4000 -payloads payloads-file 11 | ``` 12 | 13 | ## Development 14 | 15 | ```shell 16 | gow -e go,gohtml run . -port 4000 -payloads payloads-file 17 | ``` 18 | 19 | and 20 | 21 | ```shell 22 | npx vite build --watch 23 | ``` 24 | -------------------------------------------------------------------------------- /tools/storage-explorer/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Storage Explorer 10 | 11 | 12 |
13 |
14 |
15 |

Accounts

16 | 18 |
19 | 20 |
21 |

Storage Maps

22 | 24 |
25 |
26 | 27 |
28 |

29 | 31 |
32 | 33 |
34 |
35 | 36 | 37 | -------------------------------------------------------------------------------- /tools/storage-explorer/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "storage-explorer", 3 | "private": true, 4 | "version": "0.0.0", 5 | "type": "module", 6 | "scripts": { 7 | "dev": "vite", 8 | "build": "tsc && vite build", 9 | "preview": "vite preview" 10 | }, 11 | "devDependencies": { 12 | "typescript": "^5.2.2", 13 | "vite": "^5.1.4" 14 | }, 15 | "dependencies": { 16 | "@types/react": "^18.2.61", 17 | "@types/react-dom": "^18.2.19", 18 | "react": "^18.2.0", 19 | "react-dom": "^18.2.0" 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /tools/storage-explorer/src/composite.tsx: -------------------------------------------------------------------------------- 1 | import React from "react" 2 | import { CompositeValue } from "./value.ts" 3 | import Type from "./type.tsx" 4 | 5 | interface Props { 6 | value: CompositeValue 7 | onChange?: (field: string) => void, 8 | onKeyDown?: (event: React.KeyboardEvent) => void 9 | } 10 | 11 | export default function CompositeValue({ 12 | value, 13 | onChange, 14 | onKeyDown 15 | }: Props) { 16 | 17 | function _onChange(event: React.ChangeEvent) { 18 | const field = event.target.value 19 | onChange?.(field) 20 | } 21 | 22 | const options = value.fields.map(field => 23 | 24 | ) 25 | 26 | return ( 27 | <> 28 | 33 | 41 | 42 | ) 43 | } 44 | -------------------------------------------------------------------------------- /tools/storage-explorer/src/fallback.tsx: -------------------------------------------------------------------------------- 1 | import React from "react" 2 | import { FallbackValue } from "./value.ts" 3 | import Type from "./type.tsx" 4 | 5 | interface Props { 6 | value: FallbackValue, 7 | } 8 | 9 | export default function FallbackValue({ 10 | value, 11 | }: Props) { 12 | return ( 13 | <> 14 | 19 |
{value.description}
20 | 21 | ) 22 | } 23 | -------------------------------------------------------------------------------- /tools/storage-explorer/src/primitive.tsx: -------------------------------------------------------------------------------- 1 | import React from "react" 2 | import { PrimitiveValue } from "./value.ts" 3 | import Type from "./type.tsx" 4 | 5 | interface Props { 6 | value: PrimitiveValue, 7 | } 8 | 9 | export default function PrimitiveValue({ 10 | value, 11 | }: Props) { 12 | return ( 13 | <> 14 | 19 |
{value.description}
20 | 21 | ) 22 | } 23 | -------------------------------------------------------------------------------- /tools/storage-explorer/src/type.module.css: -------------------------------------------------------------------------------- 1 | .type { 2 | font-size: .875rem; 3 | line-height: 1.25rem; 4 | padding: .1rem .6rem; 5 | border-radius: 6px; 6 | } 7 | 8 | .type-container { 9 | border: 1px solid rgba(59, 130, 246, .5); 10 | background-color: rgb(239, 246, 255); 11 | color: rgb(29, 78, 216); 12 | } 13 | 14 | .type-leaf { 15 | border: 1px solid rgb(16, 185, 129, .2); 16 | background-color: rgba(16, 185, 129, 0.1); 17 | color: rgb(5 150 105); 18 | } 19 | -------------------------------------------------------------------------------- /tools/storage-explorer/src/type.tsx: -------------------------------------------------------------------------------- 1 | import React from "react" 2 | import styles from "./type.module.css" 3 | import { Type } from "./value.ts" 4 | 5 | type Kind = "dictionary" | "composite" | "array" | "primitive" | "fallback" 6 | 7 | type Category = "container" | "leaf" 8 | 9 | interface Props { 10 | kind: Kind 11 | type: Type 12 | description: string 13 | } 14 | 15 | function category(kind: Kind): Category { 16 | switch (kind) { 17 | case "dictionary": 18 | case "composite": 19 | case "array": 20 | return "container" 21 | case "primitive": 22 | case "fallback": 23 | return "leaf" 24 | } 25 | } 26 | 27 | export default function Type({ 28 | kind, 29 | description 30 | }: Props) { 31 | return ( 32 |
33 | {description} 34 |
35 | ) 36 | } 37 | -------------------------------------------------------------------------------- /tools/storage-explorer/src/value.ts: -------------------------------------------------------------------------------- 1 | import CompositeValue from "./composite.tsx" 2 | 3 | export type Type = string | any 4 | 5 | export interface CompositeValue { 6 | kind: "composite" 7 | type: Type 8 | typeString: string 9 | fields: string[] 10 | } 11 | 12 | export interface DictionaryValue { 13 | kind: "dictionary" 14 | type: Type 15 | typeString: string 16 | keys: DictionaryKey[] 17 | } 18 | 19 | interface DictionaryKey { 20 | description: string 21 | value: Value 22 | } 23 | 24 | export interface ArrayValue { 25 | kind: "array" 26 | type: Type 27 | typeString: string 28 | count: number 29 | } 30 | 31 | export interface PrimitiveValue { 32 | kind: "primitive" 33 | type: Type 34 | typeString: string 35 | value: any 36 | description: string 37 | } 38 | 39 | export interface FallbackValue { 40 | kind: "fallback" 41 | type: Type 42 | typeString: string 43 | description: string 44 | } 45 | 46 | export type Value = CompositeValue | DictionaryValue | ArrayValue | PrimitiveValue | FallbackValue 47 | -------------------------------------------------------------------------------- /tools/storage-explorer/src/vite-env.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | -------------------------------------------------------------------------------- /tools/storage-explorer/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "ES2020", 4 | "useDefineForClassFields": true, 5 | "module": "ESNext", 6 | "lib": ["ES2020", "DOM", "DOM.Iterable"], 7 | "skipLibCheck": true, 8 | 9 | /* Bundler mode */ 10 | "moduleResolution": "bundler", 11 | "allowImportingTsExtensions": true, 12 | "resolveJsonModule": true, 13 | "isolatedModules": true, 14 | "noEmit": true, 15 | 16 | /* Linting */ 17 | "strict": true, 18 | "noUnusedLocals": true, 19 | "noUnusedParameters": true, 20 | "noFallthroughCasesInSwitch": true, 21 | "jsx": "react" 22 | }, 23 | "include": [ 24 | "src" 25 | ] 26 | } 27 | -------------------------------------------------------------------------------- /tools/unkeyed/Makefile: -------------------------------------------------------------------------------- 1 | unkeyed.so: go.mod *.go 2 | go build -buildmode=plugin . 3 | -------------------------------------------------------------------------------- /tools/unkeyed/README.md: -------------------------------------------------------------------------------- 1 | # unkeyed 2 | 3 | A fork of https://pkg.go.dev/golang.org/x/tools/go/analysis/passes/composite. 4 | Reports unkeyed composite literals. 5 | 6 | ## Usage 7 | 8 | The linter is integrated into the golangci-lint configuration. 9 | 10 | If you want to run the linter separately or fix reported issues, 11 | first compile the binary: 12 | 13 | ```sh 14 | go build . 15 | ``` 16 | 17 | To automatically fix reported issues, invoke the tool with the `-fix` flag and pass the package specifier: 18 | 19 | ```sh 20 | unkeyed -fix ./... 21 | ``` 22 | 23 | -------------------------------------------------------------------------------- /tools/unkeyed/analyzer_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Cadence - The resource-oriented smart contract programming language 3 | * 4 | * Copyright Flow Foundation 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package main 20 | 21 | import ( 22 | "testing" 23 | 24 | "golang.org/x/exp/typeparams" 25 | "golang.org/x/tools/go/analysis/analysistest" 26 | ) 27 | 28 | func TestAll(t *testing.T) { 29 | testdata := analysistest.TestData() 30 | pkgs := []string{"a"} 31 | if typeparams.Enabled() { 32 | pkgs = append(pkgs, "typeparams") 33 | } 34 | analysistest.RunWithSuggestedFixes(t, testdata, Analyzer, pkgs...) 35 | } 36 | -------------------------------------------------------------------------------- /tools/unkeyed/go.mod: -------------------------------------------------------------------------------- 1 | module github.com/onflow/cadence/tools/unkeyed 2 | 3 | go 1.23.0 4 | 5 | toolchain go1.24.2 6 | 7 | require ( 8 | golang.org/x/exp/typeparams v0.0.0-20250210185358-939b2ce775ac 9 | golang.org/x/tools v0.32.0 10 | ) 11 | 12 | require ( 13 | golang.org/x/mod v0.24.0 // indirect 14 | golang.org/x/sync v0.13.0 // indirect 15 | ) 16 | -------------------------------------------------------------------------------- /tools/unkeyed/go.sum: -------------------------------------------------------------------------------- 1 | github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= 2 | github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= 3 | golang.org/x/exp/typeparams v0.0.0-20250210185358-939b2ce775ac h1:TSSpLIG4v+p0rPv1pNOQtl1I8knsO4S9trOxNMOLVP4= 4 | golang.org/x/exp/typeparams v0.0.0-20250210185358-939b2ce775ac/go.mod h1:AbB0pIl9nAr9wVwH+Z2ZpaocVmF5I4GyWCDIsVjR0bk= 5 | golang.org/x/mod v0.24.0 h1:ZfthKaKaT4NrhGVZHO1/WDTwGES4De8KtWO0SIbNJMU= 6 | golang.org/x/mod v0.24.0/go.mod h1:IXM97Txy2VM4PJ3gI61r1YEk/gAj6zAHN3AdZt6S9Ww= 7 | golang.org/x/sync v0.13.0 h1:AauUjRAJ9OSnvULf/ARrrVywoJDy0YS2AwQ98I37610= 8 | golang.org/x/sync v0.13.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA= 9 | golang.org/x/tools v0.32.0 h1:Q7N1vhpkQv7ybVzLFtTjvQya2ewbwNDZzUgfXGqtMWU= 10 | golang.org/x/tools v0.32.0/go.mod h1:ZxrU41P/wAbZD8EDa6dDCa6XfpkhJ7HFMjHJXfBDu8s= 11 | -------------------------------------------------------------------------------- /tools/unkeyed/main.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Cadence - The resource-oriented smart contract programming language 3 | * 4 | * Copyright Flow Foundation 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package main 20 | 21 | import ( 22 | "golang.org/x/tools/go/analysis" 23 | "golang.org/x/tools/go/analysis/singlechecker" 24 | ) 25 | 26 | func main() { 27 | singlechecker.Main(Analyzer) 28 | } 29 | 30 | // This must be defined and named 'New' for golangci-lint, 31 | // see https://golangci-lint.run/plugins/go-plugins/#create-a-plugin 32 | func New(_ any) ([]*analysis.Analyzer, error) { 33 | return []*analysis.Analyzer{ 34 | Analyzer, 35 | }, nil 36 | } 37 | -------------------------------------------------------------------------------- /tools/unkeyed/testdata/src/typeparams/lib/lib.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package lib 6 | 7 | type Struct struct{ F int } 8 | type Slice []int 9 | type Map map[int]int 10 | -------------------------------------------------------------------------------- /tools/unkeyed/testdata/src/typeparams/typeparams.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package typeparams 6 | 7 | import "typeparams/lib" 8 | 9 | type localStruct struct{ F int } 10 | 11 | func F[ 12 | T1 ~struct{ f int }, 13 | T2a localStruct, 14 | T2b lib.Struct, 15 | T3 ~[]int, 16 | T4 lib.Slice, 17 | T5 ~map[int]int, 18 | T6 lib.Map, 19 | ]() { 20 | _ = T1{2} // want "unkeyed fields" 21 | _ = T2a{2} // want "unkeyed fields" 22 | _ = T2b{2} // want "unkeyed fields" 23 | _ = T3{1, 2} 24 | _ = T4{1, 2} 25 | _ = T5{1: 2} 26 | _ = T6{1: 2} 27 | } 28 | -------------------------------------------------------------------------------- /tools/unkeyed/testdata/src/typeparams/typeparams.go.golden: -------------------------------------------------------------------------------- 1 | // Copyright 2021 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package typeparams 6 | 7 | import "typeparams/lib" 8 | 9 | type localStruct struct{ F int } 10 | 11 | func F[ 12 | T1 ~struct{ f int }, 13 | T2a localStruct, 14 | T2b lib.Struct, 15 | T3 ~[]int, 16 | T4 lib.Slice, 17 | T5 ~map[int]int, 18 | T6 lib.Map, 19 | ]() { 20 | _ = T1{2} // want "unkeyed fields" 21 | _ = T2a{F: 2} // want "unkeyed fields" 22 | _ = T2b{F: 2} // want "unkeyed fields" 23 | _ = T3{1, 2} 24 | _ = T4{1, 2} 25 | _ = T5{1: 2} 26 | _ = T6{1: 2} 27 | } 28 | -------------------------------------------------------------------------------- /tools/update/.eslintrc.cjs: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended'], 3 | parser: '@typescript-eslint/parser', 4 | plugins: ['@typescript-eslint'], 5 | root: true, 6 | }; 7 | 8 | -------------------------------------------------------------------------------- /tools/update/config.schema.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable */ 2 | /** 3 | * This file was automatically generated by json-schema-to-typescript. 4 | * DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file, 5 | * and run json-schema-to-typescript to regenerate this file. 6 | */ 7 | 8 | export interface CadenceUpdateToolConfigSchema { 9 | /** 10 | * The repository name 11 | */ 12 | repo: string; 13 | repos: Repo[]; 14 | } 15 | export interface Repo { 16 | /** 17 | * The repository name 18 | */ 19 | repo: string; 20 | /** 21 | * The branch name 22 | */ 23 | branch?: string; 24 | /** 25 | * The modules of the repository 26 | */ 27 | mods: Mod[]; 28 | /** 29 | * Indicates if a released version of this repo should be used, or if the latest commit should be used instead 30 | */ 31 | needsRelease: boolean; 32 | updateLabels?: string[]; 33 | /** 34 | * Prefix the PR title with the mod(s) 35 | */ 36 | prefixPRTitle?: boolean; 37 | } 38 | export interface Mod { 39 | /** 40 | * The path of the module 41 | */ 42 | path: string; 43 | /** 44 | * The dependencies that should be updated 45 | */ 46 | deps: string[]; 47 | } 48 | -------------------------------------------------------------------------------- /tools/update/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": { 3 | "axios": "^1.1.0", 4 | "executive": "^1.6.3", 5 | "js-yaml": "^4.1.0", 6 | "octokit": "^2.0.7", 7 | "prompts": "^2.4.2", 8 | "semver": "^7.3.8", 9 | "yargs": "^17.6.0" 10 | }, 11 | "devDependencies": { 12 | "@tsconfig/node16": "^1.0.3", 13 | "@types/inquirer": "^9.0.2", 14 | "@types/js-yaml": "^4.0.5", 15 | "@types/node-fetch": "^2.6.2", 16 | "@types/semver": "^7.3.12", 17 | "@types/yargs": "^17.0.13", 18 | "@typescript-eslint/eslint-plugin": "^5.39.0", 19 | "@typescript-eslint/parser": "^5.39.0", 20 | "eslint": "^8.24.0", 21 | "json-schema-to-typescript": "^11.0.2", 22 | "typescript": "^4.8.4" 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /tools/update/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "@tsconfig/node16/tsconfig.json" 3 | } -------------------------------------------------------------------------------- /values/safe_math.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Cadence - The resource-oriented smart contract programming language 3 | * 4 | * Copyright Flow Foundation 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package values 20 | 21 | func SafeAddUint64(a, b uint64) (uint64, error) { 22 | sum := a + b 23 | // INT30-C 24 | if sum < a { 25 | return 0, OverflowError{} 26 | } 27 | return sum, nil 28 | } 29 | -------------------------------------------------------------------------------- /values/value.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Cadence - The resource-oriented smart contract programming language 3 | * 4 | * Copyright Flow Foundation 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package values 20 | 21 | import "fmt" 22 | 23 | type Value interface { 24 | IsValue() 25 | fmt.Stringer 26 | } 27 | -------------------------------------------------------------------------------- /values/value_comparable.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Cadence - The resource-oriented smart contract programming language 3 | * 4 | * Copyright Flow Foundation 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package values 20 | 21 | type ComparableValue[T Value] interface { 22 | EquatableValue 23 | Less(other T) bool 24 | LessEqual(other T) bool 25 | Greater(other T) bool 26 | GreaterEqual(other T) bool 27 | } 28 | -------------------------------------------------------------------------------- /values/value_equatable.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Cadence - The resource-oriented smart contract programming language 3 | * 4 | * Copyright Flow Foundation 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package values 20 | 21 | type EquatableValue interface { 22 | Value 23 | Equal(other Value) bool 24 | } 25 | -------------------------------------------------------------------------------- /values/value_fixedpoint.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Cadence - The resource-oriented smart contract programming language 3 | * 4 | * Copyright Flow Foundation 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package values 20 | 21 | // FixedPointValue is a fixed-point number value 22 | type FixedPointValue[T Value, U uint64 | int64] interface { 23 | NumberValue[T] 24 | IntegerPart() U 25 | Scale() int 26 | } 27 | -------------------------------------------------------------------------------- /values/value_integer.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Cadence - The resource-oriented smart contract programming language 3 | * 4 | * Copyright Flow Foundation 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package values 20 | 21 | import "github.com/onflow/cadence/common" 22 | 23 | type IntegerValue[T Value] interface { 24 | NumberValue[T] 25 | BitwiseOr(gauge common.MemoryGauge, other T) (T, error) 26 | BitwiseXor(gauge common.MemoryGauge, other T) (T, error) 27 | BitwiseAnd(gauge common.MemoryGauge, other T) (T, error) 28 | BitwiseLeftShift(gauge common.MemoryGauge, other T) (T, error) 29 | BitwiseRightShift(gauge common.MemoryGauge, other T) (T, error) 30 | } 31 | -------------------------------------------------------------------------------- /version.go: -------------------------------------------------------------------------------- 1 | // Code generated by utils/version. DO NOT EDIT. 2 | /* 3 | * Cadence - The resource-oriented smart contract programming language 4 | * 5 | * Copyright Flow Foundation 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | 20 | //go:generate go run ./utils/version/main.go 21 | 22 | package cadence 23 | 24 | const Version = "v1.6.0" 25 | --------------------------------------------------------------------------------