Modify generateExit to return full set of signing keys

Modify generateExit to return full set of signing keys in preparation for anonymity work meaning
that owner and issuer keys are typically not the same.
This commit is contained in:
Ross Nicoll 2017-06-12 15:49:35 +01:00 committed by GitHub
parent 58c25b1115
commit a3fd54bdb0
5 changed files with 16 additions and 14 deletions

View File

@ -149,7 +149,7 @@ interface ServiceHub : ServicesForResolution {
* @throws IllegalArgumentException is thrown if any keys are unavailable locally. * @throws IllegalArgumentException is thrown if any keys are unavailable locally.
* @return Returns a [SignedTransaction] with the new node signature attached. * @return Returns a [SignedTransaction] with the new node signature attached.
*/ */
fun signInitialTransaction(builder: TransactionBuilder, signingPubKeys: List<PublicKey>): SignedTransaction { fun signInitialTransaction(builder: TransactionBuilder, signingPubKeys: Iterable<PublicKey>): SignedTransaction {
var stx: SignedTransaction? = null var stx: SignedTransaction? = null
for (pubKey in signingPubKeys) { for (pubKey in signingPubKeys) {
stx = if (stx == null) { stx = if (stx == null) {

View File

@ -455,11 +455,11 @@ class Obligation<P : Any> : Contract {
* @param amountIssued the amount to be exited, represented as a quantity of issued currency. * @param amountIssued the amount to be exited, represented as a quantity of issued currency.
* @param assetStates the asset states to take funds from. No checks are done about ownership of these states, it is * @param assetStates the asset states to take funds from. No checks are done about ownership of these states, it is
* the responsibility of the caller to check that they do not exit funds held by others. * the responsibility of the caller to check that they do not exit funds held by others.
* @return the public key of the assets issuer, who must sign the transaction for it to be valid. * @return the public keys who must sign the transaction for it to be valid.
*/ */
@Suppress("unused") @Suppress("unused")
fun generateExit(tx: TransactionBuilder, amountIssued: Amount<Issued<Terms<P>>>, fun generateExit(tx: TransactionBuilder, amountIssued: Amount<Issued<Terms<P>>>,
assetStates: List<StateAndRef<Obligation.State<P>>>): PublicKey assetStates: List<StateAndRef<Obligation.State<P>>>): Set<PublicKey>
= OnLedgerAsset.generateExit(tx, amountIssued, assetStates, = OnLedgerAsset.generateExit(tx, amountIssued, assetStates,
deriveState = { state, amount, owner -> state.copy(data = state.data.move(amount, owner)) }, deriveState = { state, amount, owner -> state.copy(data = state.data.move(amount, owner)) },
generateMoveCommand = { -> Commands.Move() }, generateMoveCommand = { -> Commands.Move() },

View File

@ -159,7 +159,7 @@ abstract class OnLedgerAsset<T : Any, C : CommandData, S : FungibleAsset<T>> : C
* @param amountIssued the amount to be exited, represented as a quantity of issued currency. * @param amountIssued the amount to be exited, represented as a quantity of issued currency.
* @param assetStates the asset states to take funds from. No checks are done about ownership of these states, it is * @param assetStates the asset states to take funds from. No checks are done about ownership of these states, it is
* the responsibility of the caller to check that they do not attempt to exit funds held by others. * the responsibility of the caller to check that they do not attempt to exit funds held by others.
* @return the public key of the assets issuer, who must sign the transaction for it to be valid. * @return the public keys which must sign the transaction for it to be valid.
*/ */
@Throws(InsufficientBalanceException::class) @Throws(InsufficientBalanceException::class)
@JvmStatic @JvmStatic
@ -167,7 +167,7 @@ abstract class OnLedgerAsset<T : Any, C : CommandData, S : FungibleAsset<T>> : C
assetStates: List<StateAndRef<S>>, assetStates: List<StateAndRef<S>>,
deriveState: (TransactionState<S>, Amount<Issued<T>>, AbstractParty) -> TransactionState<S>, deriveState: (TransactionState<S>, Amount<Issued<T>>, AbstractParty) -> TransactionState<S>,
generateMoveCommand: () -> CommandData, generateMoveCommand: () -> CommandData,
generateExitCommand: (Amount<Issued<T>>) -> CommandData): PublicKey { generateExitCommand: (Amount<Issued<T>>) -> CommandData): Set<PublicKey> {
val owner = assetStates.map { it.state.data.owner }.toSet().singleOrNull() ?: throw InsufficientBalanceException(amountIssued) val owner = assetStates.map { it.state.data.owner }.toSet().singleOrNull() ?: throw InsufficientBalanceException(amountIssued)
val currency = amountIssued.token.product val currency = amountIssued.token.product
val amount = Amount(amountIssued.quantity, currency) val amount = Amount(amountIssued.quantity, currency)
@ -193,9 +193,11 @@ abstract class OnLedgerAsset<T : Any, C : CommandData, S : FungibleAsset<T>> : C
for (state in gathered) tx.addInputState(state) for (state in gathered) tx.addInputState(state)
for (state in outputs) tx.addOutputState(state) for (state in outputs) tx.addOutputState(state)
tx.addCommand(generateMoveCommand(), gathered.map { it.state.data.owner.owningKey }) val moveKeys = gathered.map { it.state.data.owner.owningKey }
tx.addCommand(generateExitCommand(amountIssued), gathered.flatMap { it.state.data.exitKeys }) val exitKeys = gathered.flatMap { it.state.data.exitKeys }
return amountIssued.token.issuer.party.owningKey tx.addCommand(generateMoveCommand(), moveKeys)
tx.addCommand(generateExitCommand(amountIssued), exitKeys)
return (moveKeys + exitKeys).toSet()
} }
/** /**
@ -226,11 +228,11 @@ abstract class OnLedgerAsset<T : Any, C : CommandData, S : FungibleAsset<T>> : C
* necessarily owned by us. * necessarily owned by us.
* @param assetStates the asset states to take funds from. No checks are done about ownership of these states, it is * @param assetStates the asset states to take funds from. No checks are done about ownership of these states, it is
* the responsibility of the caller to check that they do not exit funds held by others. * the responsibility of the caller to check that they do not exit funds held by others.
* @return the public key of the assets issuer, who must sign the transaction for it to be valid. * @return the public keys which must sign the transaction for it to be valid.
*/ */
@Throws(InsufficientBalanceException::class) @Throws(InsufficientBalanceException::class)
fun generateExit(tx: TransactionBuilder, amountIssued: Amount<Issued<T>>, fun generateExit(tx: TransactionBuilder, amountIssued: Amount<Issued<T>>,
assetStates: List<StateAndRef<S>>): PublicKey { assetStates: List<StateAndRef<S>>): Set<PublicKey> {
return generateExit( return generateExit(
tx, tx,
amountIssued, amountIssued,

View File

@ -26,7 +26,7 @@ abstract class AbstractConserveAmount<S : FungibleAsset<T>, C : CommandData, T :
* @param amountIssued the amount to be exited, represented as a quantity of issued currency. * @param amountIssued the amount to be exited, represented as a quantity of issued currency.
* @param assetStates the asset states to take funds from. No checks are done about ownership of these states, it is * @param assetStates the asset states to take funds from. No checks are done about ownership of these states, it is
* the responsibility of the caller to check that they do not attempt to exit funds held by others. * the responsibility of the caller to check that they do not attempt to exit funds held by others.
* @return the public key of the assets issuer, who must sign the transaction for it to be valid. * @return the public keys which must sign the transaction for it to be valid.
*/ */
@Deprecated("This function will be removed in a future milestone", ReplaceWith("OnLedgerAsset.generateExit()")) @Deprecated("This function will be removed in a future milestone", ReplaceWith("OnLedgerAsset.generateExit()"))
@Throws(InsufficientBalanceException::class) @Throws(InsufficientBalanceException::class)
@ -34,7 +34,7 @@ abstract class AbstractConserveAmount<S : FungibleAsset<T>, C : CommandData, T :
assetStates: List<StateAndRef<S>>, assetStates: List<StateAndRef<S>>,
deriveState: (TransactionState<S>, Amount<Issued<T>>, AbstractParty) -> TransactionState<S>, deriveState: (TransactionState<S>, Amount<Issued<T>>, AbstractParty) -> TransactionState<S>,
generateMoveCommand: () -> CommandData, generateMoveCommand: () -> CommandData,
generateExitCommand: (Amount<Issued<T>>) -> CommandData): PublicKey generateExitCommand: (Amount<Issued<T>>) -> CommandData): Set<PublicKey>
= OnLedgerAsset.generateExit(tx, amountIssued, assetStates, deriveState, generateMoveCommand, generateExitCommand) = OnLedgerAsset.generateExit(tx, amountIssued, assetStates, deriveState, generateMoveCommand, generateExitCommand)
override fun verify(tx: TransactionForContract, override fun verify(tx: TransactionForContract,

View File

@ -36,7 +36,7 @@ class CashExitFlow(val amount: Amount<Currency>, val issueRef: OpaqueBytes, prog
val builder: TransactionBuilder = TransactionType.General.Builder(notary = null as Party?) val builder: TransactionBuilder = TransactionType.General.Builder(notary = null as Party?)
val issuer = serviceHub.myInfo.legalIdentity.ref(issueRef) val issuer = serviceHub.myInfo.legalIdentity.ref(issueRef)
val exitStates = serviceHub.vaultService.unconsumedStatesForSpending<Cash.State>(amount, setOf(issuer.party), builder.notary, builder.lockId, setOf(issuer.reference)) val exitStates = serviceHub.vaultService.unconsumedStatesForSpending<Cash.State>(amount, setOf(issuer.party), builder.notary, builder.lockId, setOf(issuer.reference))
try { val signers = try {
Cash().generateExit( Cash().generateExit(
builder, builder,
amount.issuedBy(issuer), amount.issuedBy(issuer),
@ -62,7 +62,7 @@ class CashExitFlow(val amount: Amount<Currency>, val issueRef: OpaqueBytes, prog
.toSet() .toSet()
// Sign transaction // Sign transaction
progressTracker.currentStep = SIGNING_TX progressTracker.currentStep = SIGNING_TX
val tx = serviceHub.signInitialTransaction(builder) val tx = serviceHub.signInitialTransaction(builder, signers)
// Commit the transaction // Commit the transaction
progressTracker.currentStep = FINALISING_TX progressTracker.currentStep = FINALISING_TX