CashExitFlow now uses coin selection with soft locking. ()

This commit is contained in:
josecoll 2017-03-31 11:47:59 +01:00 committed by GitHub
parent 79e9c3f5c7
commit 73c0fdc118
3 changed files with 10 additions and 4 deletions
core/src/main/kotlin/net/corda/core/node/services
finance/src/main/kotlin/net/corda/flows
node/src/main/kotlin/net/corda/node/services/vault

@ -247,6 +247,13 @@ interface VaultService {
fun <T : ContractState> softLockedStates(lockId: UUID? = null): List<StateAndRef<T>>
// DOCEND SoftLockAPI
/**
* TODO: this function should be private to the vault, but currently Cash Exit functionality
* is implemented in a separate module (finance) and requires access to it.
*/
@Suspendable
fun <T : ContractState> unconsumedStatesForSpending(amount: Amount<Currency>, onlyFromIssuerParties: Set<AbstractParty>? = null, notary: Party? = null, lockId: UUID): List<StateAndRef<T>>
}
inline fun <reified T: ContractState> VaultService.unconsumedStates(includeSoftLockedStates: Boolean = true): Iterable<StateAndRef<T>> =

@ -7,8 +7,6 @@ import net.corda.core.contracts.InsufficientBalanceException
import net.corda.core.contracts.TransactionType
import net.corda.core.contracts.issuedBy
import net.corda.core.crypto.Party
import net.corda.core.node.services.Vault
import net.corda.core.node.services.unconsumedStates
import net.corda.core.serialization.OpaqueBytes
import net.corda.core.transactions.SignedTransaction
import net.corda.core.transactions.TransactionBuilder
@ -35,11 +33,12 @@ class CashExitFlow(val amount: Amount<Currency>, val issueRef: OpaqueBytes, prog
progressTracker.currentStep = GENERATING_TX
val builder: TransactionBuilder = TransactionType.General.Builder(null)
val issuer = serviceHub.myInfo.legalIdentity.ref(issueRef)
val exitStates = serviceHub.vaultService.unconsumedStatesForSpending<Cash.State>(amount, setOf(issuer.party), builder.notary, builder.lockId)
try {
Cash().generateExit(
builder,
amount.issuedBy(issuer),
serviceHub.vaultService.unconsumedStates<Cash.State>().filter { it.state.data.owner == issuer.party.owningKey })
exitStates)
} catch (e: InsufficientBalanceException) {
throw CashException("Exiting more cash than exists", e)
}

@ -326,7 +326,7 @@ class NodeVaultService(private val services: ServiceHub, dataSourceProperties: P
val spendLock: ReentrantLock = ReentrantLock()
@Suspendable
internal fun <T : ContractState> unconsumedStatesForSpending(amount: Amount<Currency>, onlyFromIssuerParties: Set<AbstractParty>? = null, notary: Party? = null, lockId: UUID): List<StateAndRef<T>> {
override fun <T : ContractState> unconsumedStatesForSpending(amount: Amount<Currency>, onlyFromIssuerParties: Set<AbstractParty>?, notary: Party?, lockId: UUID): List<StateAndRef<T>> {
val issuerKeysStr = onlyFromIssuerParties?.fold("") { left, right -> left + "('${right.owningKey.toBase58String()}')," }?.dropLast(1)
var stateAndRefs = mutableListOf<StateAndRef<T>>()