Skip to content

Tx dsl#50

Merged
lmcmz merged 4 commits intomainfrom
tx-dsl
Dec 3, 2025
Merged

Tx dsl#50
lmcmz merged 4 commits intomainfrom
tx-dsl

Conversation

@lmcmz
Copy link
Collaborator

@lmcmz lmcmz commented Dec 3, 2025

Closes: #???

Description


For contributor use:

  • Targeted PR against master branch
  • Linked to Github issue with discussion and accepted design OR link to spec that describes this work.
  • Updated relevant documentation
  • Re-reviewed Files changed in the Github PR explorer
  • Added appropriate labels

@github-actions
Copy link

github-actions bot commented Dec 3, 2025

PR Summary

Introduced a Kotlin DSL for building and sending Flow transactions, mirroring the flow-swift builder style. Added helper functions for extracting created account addresses from transaction results, new Cadence query utilities for child accounts, token balances, and staking info. Enhanced EVM manager with runEVMTransaction and callEVMContract methods. Improved contract address resolution with case-insensitive matching and normalized hex prefix handling across the codebase.

Changes

File Summary
.gitignore Added /.kotlin and /.kotlin/metadata to the gitignore list.
flow/src/androidMain/kotlin/org/onflow/flow/crypto/Crypto.kt Changed sign method signature to sign(bytes: ByteArray, transaction: Transaction?), removing the separate overload.
flow/src/androidMain/kotlin/org/onflow/flow/infrastructure/scripts/ContractAddressRegister.kt Updated importAddresses and address loading to normalize keys by removing 0x prefix and converting to uppercase. Enhanced getAddress and resolveImports with case-insensitive matching.
flow/src/androidMain/resources/scripts/common/addresses.json Added trailing newline to the JSON file.
flow/src/androidMain/resources/scripts/common/child/get_child_account_meta.cdc New Cadence script that retrieves child account metadata from a HybridCustody.Manager for a given parent address.
flow/src/androidMain/resources/scripts/common/child/get_child_addresses.cdc New Cadence script that returns the list of child addresses from a HybridCustody.Manager for a given parent address.
flow/src/androidMain/resources/scripts/common/evm/call_contract.cdc New Cadence transaction that calls an EVM contract from a COA, transferring FLOW and executing data with a specified gas limit.
flow/src/androidMain/resources/scripts/common/evm/evm_run.cdc New Cadence transaction that executes an RLP-encoded EVM transaction via EVM.run with a coinbase address.
flow/src/androidMain/resources/scripts/common/staking/get_delegator_info.cdc New Cadence script that retrieves delegator staking info from FlowStakingCollection for a given address.
flow/src/androidMain/resources/scripts/common/token/get_token_balance_storage.cdc New Cadence script that queries all FungibleToken.Vault balances in an account's storage, including available Flow balance.
flow/src/commonMain/kotlin/org/onflow/flow/AddressRegistry.kt Added HYBRID_CUSTODY constant and registered addresses for testnet and mainnet. Changed defaultChainId type from ChainId to ChainIdProvider.
flow/src/commonMain/kotlin/org/onflow/flow/CadenceTarget.kt New file defining CadenceTarget data class with CadenceTargetType enum. Added query and sendTransaction extension functions on FlowApi for executing base64-encoded Cadence scripts.
flow/src/commonMain/kotlin/org/onflow/flow/FlowApi.kt Added trailing newline to the file.
flow/src/commonMain/kotlin/org/onflow/flow/TransactionDSL.kt New file implementing TransactionDSLBuilder class with methods for setting cadence script, arguments, gas limit, payer, proposer, and authorizers. Added buildTransaction, signTransaction, and sendTransaction extension functions on FlowApi.
flow/src/commonMain/kotlin/org/onflow/flow/TransactionResultExtensions.kt New file with extension functions on TransactionResult and Event for finding events and decoding fields. Added getCreatedAddress, getCreatedAccountAddress, and waitForCreatedAccountAddress helpers.
flow/src/commonMain/kotlin/org/onflow/flow/apis/TransactionsApi.kt Updated requestTransactionResultById, requestTransactionById, getTransactionResult, getTransaction, and waitForSeal to normalize transaction IDs by removing 0x prefix.
flow/src/commonMain/kotlin/org/onflow/flow/cadence/CadenceQueries.kt New file with data classes ChildAccountThumbnail, ChildAccountMetadata, and StakingNode. Added getChildAddresses, getChildAccountMetadata, getTokenBalances, and getDelegatorInfo extension functions on FlowApi.
flow/src/commonMain/kotlin/org/onflow/flow/evm/EVMManager.kt Added runEVMTransaction and callEVMContract public methods. Refactored createCOAAccount to use the new FlowApi.sendTransaction DSL. Moved ChildAccountMetadata import from local definition to cadence package.
flow/src/commonMain/kotlin/org/onflow/flow/infrastructure/scripts/ContractAddressRegister.kt Added explicit default constructor () to the expect class ContractAddressRegister declaration.
flow/src/commonMain/kotlin/org/onflow/flow/models/Address.kt Added hex property as an alias for base16Value for more idiomatic naming.
flow/src/commonMain/kotlin/org/onflow/flow/models/Signer.kt Changed sign method signature to sign(bytes: ByteArray, transaction: Transaction?). Updated signWithDomain and signAsTransaction to pass optional transaction parameter.
flow/src/commonMain/kotlin/org/onflow/flow/websocket/FlowWebSocketClient.kt Removed unused imports JsonArray and JsonObject from the file.
flow/src/commonMain/resources/scripts/common/addresses.json Added trailing newline to the JSON file.
flow/src/commonMain/resources/scripts/common/child/get_child_account_meta.cdc New Cadence script that retrieves child account metadata from a HybridCustody.Manager for a given parent address.
flow/src/commonMain/resources/scripts/common/child/get_child_addresses.cdc New Cadence script that returns the list of child addresses from a HybridCustody.Manager for a given parent address.
flow/src/commonMain/resources/scripts/common/evm/call_contract.cdc New Cadence transaction that calls an EVM contract from a COA, transferring FLOW and executing data with a specified gas limit.
flow/src/commonMain/resources/scripts/common/evm/evm_run.cdc New Cadence transaction that executes an RLP-encoded EVM transaction via EVM.run with a coinbase address.
flow/src/commonMain/resources/scripts/common/staking/get_delegator_info.cdc New Cadence script that retrieves delegator staking info from FlowStakingCollection for a given address.
flow/src/commonMain/resources/scripts/common/token/get_token_balance_storage.cdc New Cadence script that queries all FungibleToken.Vault balances in an account's storage, including available Flow balance.
flow/src/commonTest/kotlin/org/onflow/flow/TransactionResultExtensionsTest.kt New test file with tests for getCreatedAddress returning address when event is present, returning null when event is missing, and waitForCreatedAccountAddress returning created address after seal.

autogenerated by presubmit.ai

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

🚨 Pull request needs attention.

Review Summary

Commits Considered (4)
  • a1d831d: fix: unit test and ignore the wws test
  • 0d20757: fix: unit test
  • 3bc8ee9: feat: add helper func for getCreatedAccountAddress
  • 58bd773: feat: add tx dsl
Files Processed (30)
  • .gitignore (1 hunk)
  • flow/src/androidMain/kotlin/org/onflow/flow/crypto/Crypto.kt (2 hunks)
  • flow/src/androidMain/kotlin/org/onflow/flow/infrastructure/scripts/ContractAddressRegister.kt (4 hunks)
  • flow/src/androidMain/resources/scripts/common/addresses.json (1 hunk)
  • flow/src/androidMain/resources/scripts/common/child/get_child_account_meta.cdc (1 hunk)
  • flow/src/androidMain/resources/scripts/common/child/get_child_addresses.cdc (1 hunk)
  • flow/src/androidMain/resources/scripts/common/evm/call_contract.cdc (1 hunk)
  • flow/src/androidMain/resources/scripts/common/evm/evm_run.cdc (1 hunk)
  • flow/src/androidMain/resources/scripts/common/staking/get_delegator_info.cdc (1 hunk)
  • flow/src/androidMain/resources/scripts/common/token/get_token_balance_storage.cdc (1 hunk)
  • flow/src/commonMain/kotlin/org/onflow/flow/AddressRegistry.kt (3 hunks)
  • flow/src/commonMain/kotlin/org/onflow/flow/CadenceTarget.kt (1 hunk)
  • flow/src/commonMain/kotlin/org/onflow/flow/FlowApi.kt (1 hunk)
  • flow/src/commonMain/kotlin/org/onflow/flow/TransactionDSL.kt (1 hunk)
  • flow/src/commonMain/kotlin/org/onflow/flow/TransactionResultExtensions.kt (1 hunk)
  • flow/src/commonMain/kotlin/org/onflow/flow/apis/TransactionsApi.kt (4 hunks)
  • flow/src/commonMain/kotlin/org/onflow/flow/cadence/CadenceQueries.kt (1 hunk)
  • flow/src/commonMain/kotlin/org/onflow/flow/evm/EVMManager.kt (6 hunks)
  • flow/src/commonMain/kotlin/org/onflow/flow/infrastructure/scripts/ContractAddressRegister.kt (2 hunks)
  • flow/src/commonMain/kotlin/org/onflow/flow/models/Address.kt (1 hunk)
  • flow/src/commonMain/kotlin/org/onflow/flow/models/Signer.kt (1 hunk)
  • flow/src/commonMain/kotlin/org/onflow/flow/websocket/FlowWebSocketClient.kt (1 hunk)
  • flow/src/commonMain/resources/scripts/common/addresses.json (1 hunk)
  • flow/src/commonMain/resources/scripts/common/child/get_child_account_meta.cdc (1 hunk)
  • flow/src/commonMain/resources/scripts/common/child/get_child_addresses.cdc (1 hunk)
  • flow/src/commonMain/resources/scripts/common/evm/call_contract.cdc (1 hunk)
  • flow/src/commonMain/resources/scripts/common/evm/evm_run.cdc (1 hunk)
  • flow/src/commonMain/resources/scripts/common/staking/get_delegator_info.cdc (1 hunk)
  • flow/src/commonMain/resources/scripts/common/token/get_token_balance_storage.cdc (1 hunk)
  • flow/src/commonTest/kotlin/org/onflow/flow/TransactionResultExtensionsTest.kt (1 hunk)
Actionable Comments (2)
  • flow/src/commonMain/resources/scripts/common/token/get_token_balance_storage.cdc [19-26]

    possible bug: "The seen array is never populated, causing duplicate type handling to fail."

  • flow/src/androidMain/resources/scripts/common/token/get_token_balance_storage.cdc [19-26]

    possible bug: "The seen array is never populated, causing duplicate type handling to fail."

Skipped Comments (5)
  • flow/src/commonMain/kotlin/org/onflow/flow/TransactionDSL.kt [77-78]

    possible issue: "Inconsistent default values for keyIndex between proposer overloads."

  • flow/src/commonMain/kotlin/org/onflow/flow/TransactionDSL.kt [112-117]

    enhancement: "Error message could be misleading when key auto-detection fails."

  • flow/src/commonMain/kotlin/org/onflow/flow/evm/EVMManager.kt [91-92]

    readability: "Byte to UByte conversion may be unclear for negative byte values."

  • flow/src/commonTest/kotlin/org/onflow/flow/TransactionResultExtensionsTest.kt [45-46]

    maintainability: "Unused test variables should be removed."

  • flow/src/commonTest/kotlin/org/onflow/flow/TransactionResultExtensionsTest.kt [65-71]

    best practice: "Test relies on external network call and hardcoded transaction ID."

Comment on lines +19 to +26
// Insert a new values if it's the first time we've seen the type
if !seen.contains(type.identifier) {
balances.insert(key: type.identifier, vaultRef.balance)
} else {
// Otherwise just update the balance of the vault (unlikely we'll see the same type twice in
// the same account, but we want to cover the case)
balances[type.identifier] = balances[type.identifier]! + vaultRef.balance
}
Copy link

Choose a reason for hiding this comment

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

The seen array is checked with !seen.contains(type.identifier) but is never updated after inserting a new type. This means the else branch (updating existing balance) will never execute, and duplicate vault types in the same account will overwrite rather than accumulate. Add seen.append(type.identifier) after the first insert.

Comment on lines +19 to +26
// Insert a new values if it's the first time we've seen the type
if !seen.contains(type.identifier) {
balances.insert(key: type.identifier, vaultRef.balance)
} else {
// Otherwise just update the balance of the vault (unlikely we'll see the same type twice in
// the same account, but we want to cover the case)
balances[type.identifier] = balances[type.identifier]! + vaultRef.balance
}
Copy link

Choose a reason for hiding this comment

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

Same issue as the commonMain version: the seen array is never populated after inserting a new type identifier. Add seen.append(type.identifier) after the insert to properly track seen types.

@github-actions
Copy link

github-actions bot commented Dec 3, 2025

Unit Test Results

  24 files    24 suites   2m 5s ⏱️
117 tests 109 ✔️   8 💤 0 ❌
234 runs  218 ✔️ 16 💤 0 ❌

Results for commit a1d831d.

@lmcmz lmcmz merged commit 6cf478d into main Dec 3, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant