Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add additional signer keys provider function for addMoveTokens #252

Open
wants to merge 1 commit into
base: 1.2
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import net.corda.core.identity.AbstractParty
import net.corda.core.node.ServiceHub
import net.corda.core.node.services.vault.QueryCriteria
import net.corda.core.transactions.TransactionBuilder
import java.security.PublicKey

/* For fungible tokens. */

Expand All @@ -29,7 +30,8 @@ import net.corda.core.transactions.TransactionBuilder
fun addMoveTokens(
transactionBuilder: TransactionBuilder,
inputs: List<StateAndRef<AbstractToken>>,
outputs: List<AbstractToken>
outputs: List<AbstractToken>,
additionalSignerKeysProvider: ((IssuedTokenType) -> List<PublicKey>)? = null
): TransactionBuilder {
val outputGroups: Map<IssuedTokenType, List<AbstractToken>> = outputs.groupBy { it.issuedTokenType }
val inputGroups: Map<IssuedTokenType, List<StateAndRef<AbstractToken>>> = inputs.groupBy {
Expand All @@ -47,7 +49,6 @@ fun addMoveTokens(
outputGroups.forEach { issuedTokenType: IssuedTokenType, outputStates: List<AbstractToken> ->
val inputGroup = inputGroups[issuedTokenType]
?: throw IllegalArgumentException("No corresponding inputs for the outputs issued token type: $issuedTokenType")
val keys = inputGroup.map { it.state.data.holder.owningKey }

var inputStartingIdx = inputStates().size
var outputStartingIdx = outputStates().size
Expand All @@ -62,6 +63,9 @@ fun addMoveTokens(
outputStartingIdx++
}

val additionalKeys = additionalSignerKeysProvider?.invoke(issuedTokenType) ?: emptyList()
val keys = inputGroup.map { it.state.data.holder.owningKey } + additionalKeys

addCommand(MoveTokenCommand(issuedTokenType, inputs = inputIdx, outputs = outputIdx), keys)
}
}
Expand All @@ -78,9 +82,15 @@ fun addMoveTokens(
fun addMoveTokens(
transactionBuilder: TransactionBuilder,
input: StateAndRef<AbstractToken>,
output: AbstractToken
output: AbstractToken,
additionalSignerKeysProvider: ((IssuedTokenType) -> List<PublicKey>)? = null
): TransactionBuilder {
return addMoveTokens(transactionBuilder = transactionBuilder, inputs = listOf(input), outputs = listOf(output))
return addMoveTokens(
transactionBuilder = transactionBuilder,
inputs = listOf(input),
outputs = listOf(output),
additionalSignerKeysProvider = additionalSignerKeysProvider
)
}

/**
Expand Down