Skip to content

Commit 2e4f61c

Browse files
committed
Filtering a single previous owner of a token in nicer way
1 parent 6d67922 commit 2e4f61c

File tree

2 files changed

+7
-7
lines changed
  • Tokens/stockpaydividend

2 files changed

+7
-7
lines changed

Tokens/stockpaydividend/bridging-flows/src/main/kotlin/com/r3/corda/lib/tokens/bridging/flows/BridgeFungibleTokenFlow.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class BridgeFungibleTokenFlow(
3838

3939
@Suspendable
4040
override fun call(): SignedTransaction {
41-
val participants = listOf(holder) //TODO add confidentialIdentity
41+
val participants = listOf(holder)
4242
val observerSessions = sessionsForParties(observers)
4343
val participantSessions = sessionsForParties(participants)
4444

@@ -47,10 +47,13 @@ class BridgeFungibleTokenFlow(
4747
val cordaTokenId = (token.state.data.amount.token.tokenType as TokenPointer<*>).pointer.pointer.id
4848

4949
val owners = previousOwnersOf(token).map { serviceHub.identityService.wellKnownPartyFromAnonymous(it) ?: it }
50-
50+
val singlePreviousOwner = owners.singleOrNull { it is Party } as Party?
51+
require(singlePreviousOwner != null) {
52+
"Cannot find previous owner of the token to bridge, or multiple found: $owners"
53+
}
5154
val solanaAccountMapping = serviceHub.cordaService(SolanaAccountsMappingService::class.java)
5255
val destination =
53-
solanaAccountMapping.participants[(owners.first() as Party).name]!! //TODO handle null and ugly code
56+
solanaAccountMapping.participants[singlePreviousOwner.name]!! //TODO handle null
5457
val mint = solanaAccountMapping.mints[cordaTokenId]!! //TODO handle null
5558
val mintAuthority = solanaAccountMapping.mintAuthorities[cordaTokenId]!! //TODO handle null
5659
val additionalCommand = BridgingContract.BridgingCommand.BridgeToSolana(
@@ -80,12 +83,10 @@ class BridgeFungibleTokenFlow(
8083
val inputTokens: List<FungibleToken> =
8184
stx.toLedgerTransaction(serviceHub).inputsOfType<FungibleToken>()
8285

83-
// Usually one holder; can be many if the tx merged inputs
8486
return inputTokens.map { it.holder }.toSet()
8587
}
8688
}
8789

88-
8990
/**
9091
* Responder flow for [BridgeFungibleTokenFlow].
9192
*/
@@ -130,4 +131,3 @@ constructor(
130131
)
131132
}
132133
}
133-

Tokens/stockpaydividend/workflows/src/test/kotlin/net/corda/samples/stockpaydividend/FlowTests.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,4 +390,4 @@ class FlowTests {
390390
Assert.assertEquals(1, pointers.size)
391391
return pointers.first()
392392
}
393-
}
393+
}

0 commit comments

Comments
 (0)