Obligation Cordapp转移功能问题:linearId被识别为External id而非id
Hey, I get it—you’ve got the Issue flow up and running, but the transfer flow is misinterpreting the LinearId you’re passing, treating it as an externalId instead of the actual UUID (the id field in UniqueIdentifier). Let’s break down how to fix this:
1. Double-Check How You’re Passing the LinearId
First, confirm the value you’re feeding into the transfer flow. When you run the Issue flow, the generated LinearId has two distinct parts:
id: The auto-generated UUID that Corda relies on to uniquely identify LinearStates (this is what the vault uses to look up states)externalId: An optional user-defined string (only if you explicitly set it in the Issue flow)
Make sure the value you’re passing to the transfer flow is the UUID string from the id field, not your custom externalId. For example, use something like "3fa85f64-5717-4562-b3fc-2c963f66afa6" instead of your external label.
2. Fix LinearId Parsing in Your Transfer Flow
Chances are, your transfer flow is incorrectly constructing the UniqueIdentifier object. Let’s compare common mistakes with the correct approach:
Wrong Approach (Treats Input as ExternalId)
// This tells Corda to look for a state where externalId matches your input val linearId = UniqueIdentifier(externalId = inputLinearIdString)
Correct Approach (Uses Input as the UUID id Field)
// Parses your input string into a UUID and assigns it to the `id` field val targetUuid = UUID.fromString(inputLinearIdString) val linearId = UniqueIdentifier(id = targetUuid)
If you’re using the Corda RPC client to trigger the flow, ensure you’re creating the UniqueIdentifier with the id parameter set, not just externalId.
3. Verify the Issue Flow’s LinearId Output
To confirm you’re grabbing the right value, add a log statement at the end of your Issue flow to print the full LinearId details:
logger.info("Created Obligation - LinearId UUID: ${obligation.linearId.id}, ExternalId: ${obligation.linearId.externalId}")
Use the LinearId UUID value from this log when calling your transfer flow.
4. Fix the Vault Query in the Transfer Flow
If your transfer flow includes a vault query to fetch the Obligation state, ensure the query criteria targets the id field of UniqueIdentifier:
Wrong Query (Filters by ExternalId)
val queryCriteria = QueryCriteria.LinearStateQueryCriteria( linearId = listOf(UniqueIdentifier(externalId = inputId)) )
Correct Query (Filters by UUID id)
val queryCriteria = QueryCriteria.LinearStateQueryCriteria( linearId = listOf(UniqueIdentifier(id = UUID.fromString(inputId))) )
The key takeaway here is that Corda uses the id field of UniqueIdentifier as the primary identifier for LinearStates. The externalId is just an optional secondary label—so your transfer flow needs to target the id to find the right Obligation.
内容的提问来源于stack exchange,提问作者Teja

