mirror of
https://github.com/corda/corda.git
synced 2025-05-04 09:43:05 +00:00
Reformat files in finance
This commit is contained in:
parent
b1fb321230
commit
7a372bed59
@ -8,12 +8,18 @@ import net.corda.core.contracts.PartyAndReference
|
|||||||
import java.math.BigDecimal
|
import java.math.BigDecimal
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
@JvmField val USD: Currency = Currency.getInstance("USD")
|
@JvmField
|
||||||
@JvmField val GBP: Currency = Currency.getInstance("GBP")
|
val USD: Currency = Currency.getInstance("USD")
|
||||||
@JvmField val EUR: Currency = Currency.getInstance("EUR")
|
@JvmField
|
||||||
@JvmField val CHF: Currency = Currency.getInstance("CHF")
|
val GBP: Currency = Currency.getInstance("GBP")
|
||||||
@JvmField val JPY: Currency = Currency.getInstance("JPY")
|
@JvmField
|
||||||
@JvmField val RUB: Currency = Currency.getInstance("RUB")
|
val EUR: Currency = Currency.getInstance("EUR")
|
||||||
|
@JvmField
|
||||||
|
val CHF: Currency = Currency.getInstance("CHF")
|
||||||
|
@JvmField
|
||||||
|
val JPY: Currency = Currency.getInstance("JPY")
|
||||||
|
@JvmField
|
||||||
|
val RUB: Currency = Currency.getInstance("RUB")
|
||||||
|
|
||||||
fun <T : Any> AMOUNT(amount: Int, token: T): Amount<T> = AMOUNT(amount.toLong(), token)
|
fun <T : Any> AMOUNT(amount: Int, token: T): Amount<T> = AMOUNT(amount.toLong(), token)
|
||||||
fun <T : Any> AMOUNT(amount: Long, token: T): Amount<T> = Amount.fromDecimal(BigDecimal.valueOf(amount), token)
|
fun <T : Any> AMOUNT(amount: Long, token: T): Amount<T> = Amount.fromDecimal(BigDecimal.valueOf(amount), token)
|
||||||
|
@ -49,6 +49,7 @@ class CommercialPaper : Contract {
|
|||||||
companion object {
|
companion object {
|
||||||
const val CP_PROGRAM_ID: ContractClassName = "net.corda.finance.contracts.CommercialPaper"
|
const val CP_PROGRAM_ID: ContractClassName = "net.corda.finance.contracts.CommercialPaper"
|
||||||
}
|
}
|
||||||
|
|
||||||
data class State(
|
data class State(
|
||||||
val issuance: PartyAndReference,
|
val issuance: PartyAndReference,
|
||||||
override val owner: AbstractParty,
|
override val owner: AbstractParty,
|
||||||
@ -89,7 +90,8 @@ class CommercialPaper : Contract {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @suppress */ infix fun `owned by`(owner: AbstractParty) = copy(owner = owner)
|
/** @suppress */
|
||||||
|
infix fun `owned by`(owner: AbstractParty) = copy(owner = owner)
|
||||||
}
|
}
|
||||||
|
|
||||||
interface Commands : CommandData {
|
interface Commands : CommandData {
|
||||||
|
@ -202,7 +202,7 @@ enum class Frequency(val annualCompoundCount: Int, val offset: LocalDate.(Long)
|
|||||||
* no staff are around to handle problems.
|
* no staff are around to handle problems.
|
||||||
*/
|
*/
|
||||||
@CordaSerializable
|
@CordaSerializable
|
||||||
open class BusinessCalendar (val holidayDates: List<LocalDate>) {
|
open class BusinessCalendar(val holidayDates: List<LocalDate>) {
|
||||||
@CordaSerializable
|
@CordaSerializable
|
||||||
class UnknownCalendar(name: String) : FlowException("$name not found")
|
class UnknownCalendar(name: String) : FlowException("$name not found")
|
||||||
|
|
||||||
|
@ -401,10 +401,17 @@ class Cash : OnLedgerAsset<Currency, Cash.Commands, Cash.State>() {
|
|||||||
|
|
||||||
// Small DSL extensions.
|
// Small DSL extensions.
|
||||||
|
|
||||||
/** @suppress */ infix fun Cash.State.`owned by`(owner: AbstractParty) = ownedBy(owner)
|
/** @suppress */
|
||||||
/** @suppress */ infix fun Cash.State.`issued by`(party: AbstractParty) = issuedBy(party)
|
infix fun Cash.State.`owned by`(owner: AbstractParty) = ownedBy(owner)
|
||||||
/** @suppress */ infix fun Cash.State.`issued by`(deposit: PartyAndReference) = issuedBy(deposit)
|
|
||||||
/** @suppress */ infix fun Cash.State.`with deposit`(deposit: PartyAndReference): Cash.State = withDeposit(deposit)
|
/** @suppress */
|
||||||
|
infix fun Cash.State.`issued by`(party: AbstractParty) = issuedBy(party)
|
||||||
|
|
||||||
|
/** @suppress */
|
||||||
|
infix fun Cash.State.`issued by`(deposit: PartyAndReference) = issuedBy(deposit)
|
||||||
|
|
||||||
|
/** @suppress */
|
||||||
|
infix fun Cash.State.`with deposit`(deposit: PartyAndReference): Cash.State = withDeposit(deposit)
|
||||||
|
|
||||||
// Unit testing helpers. These could go in a separate file but it's hardly worth it for just a few functions.
|
// Unit testing helpers. These could go in a separate file but it's hardly worth it for just a few functions.
|
||||||
|
|
||||||
|
@ -44,6 +44,7 @@ class CommodityContract : OnLedgerAsset<Commodity, CommodityContract.Commands, C
|
|||||||
) : FungibleAsset<Commodity> {
|
) : FungibleAsset<Commodity> {
|
||||||
constructor(deposit: PartyAndReference, amount: Amount<Commodity>, owner: AbstractParty)
|
constructor(deposit: PartyAndReference, amount: Amount<Commodity>, owner: AbstractParty)
|
||||||
: this(Amount(amount.quantity, Issued(deposit, amount.token)), owner)
|
: this(Amount(amount.quantity, Issued(deposit, amount.token)), owner)
|
||||||
|
|
||||||
override val exitKeys: Set<PublicKey> = Collections.singleton(owner.owningKey)
|
override val exitKeys: Set<PublicKey> = Collections.singleton(owner.owningKey)
|
||||||
override val participants = listOf(owner)
|
override val participants = listOf(owner)
|
||||||
|
|
||||||
@ -91,7 +92,7 @@ class CommodityContract : OnLedgerAsset<Commodity, CommodityContract.Commands, C
|
|||||||
val party = issuer.party
|
val party = issuer.party
|
||||||
|
|
||||||
requireThat {
|
requireThat {
|
||||||
"there are no zero sized outputs" using ( outputs.none { it.amount.quantity == 0L } )
|
"there are no zero sized outputs" using (outputs.none { it.amount.quantity == 0L })
|
||||||
}
|
}
|
||||||
|
|
||||||
val issueCommand = tx.commands.select<Commands.Issue>().firstOrNull()
|
val issueCommand = tx.commands.select<Commands.Issue>().firstOrNull()
|
||||||
@ -107,7 +108,7 @@ class CommodityContract : OnLedgerAsset<Commodity, CommodityContract.Commands, C
|
|||||||
val amountExitingLedger = exitCommand?.value?.amount ?: Amount(0, Issued(issuer, commodity))
|
val amountExitingLedger = exitCommand?.value?.amount ?: Amount(0, Issued(issuer, commodity))
|
||||||
|
|
||||||
requireThat {
|
requireThat {
|
||||||
"there are no zero sized inputs" using ( inputs.none { it.amount.quantity == 0L } )
|
"there are no zero sized inputs" using (inputs.none { it.amount.quantity == 0L })
|
||||||
"for reference ${issuer.reference} at issuer ${party.nameOrNull()} the amounts balance" using
|
"for reference ${issuer.reference} at issuer ${party.nameOrNull()} the amounts balance" using
|
||||||
(inputAmount == outputAmount + amountExitingLedger)
|
(inputAmount == outputAmount + amountExitingLedger)
|
||||||
}
|
}
|
||||||
|
@ -73,6 +73,7 @@ class Obligation<P : Any> : Contract {
|
|||||||
companion object {
|
companion object {
|
||||||
const val PROGRAM_ID: ContractClassName = "net.corda.finance.contracts.asset.Obligation"
|
const val PROGRAM_ID: ContractClassName = "net.corda.finance.contracts.asset.Obligation"
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents where in its lifecycle a contract state is, which in turn controls the commands that can be applied
|
* Represents where in its lifecycle a contract state is, which in turn controls the commands that can be applied
|
||||||
* to the state. Most states will not leave the [NORMAL] lifecycle. Note that settled (as an end lifecycle) is
|
* to the state. Most states will not leave the [NORMAL] lifecycle. Note that settled (as an end lifecycle) is
|
||||||
@ -191,7 +192,7 @@ class Obligation<P : Any> : Contract {
|
|||||||
*/
|
*/
|
||||||
data class Move(override val contract: Class<out Contract>? = null) : MoveCommand
|
data class Move(override val contract: Class<out Contract>? = null) : MoveCommand
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Allows new obligation states to be issued into existence.
|
* Allows new obligation states to be issued into existence.
|
||||||
*/
|
*/
|
||||||
class Issue : TypeOnlyCommandData()
|
class Issue : TypeOnlyCommandData()
|
||||||
@ -785,9 +786,11 @@ infix fun <T : Any> Obligation.State<T>.between(parties: Pair<AbstractParty, Abs
|
|||||||
infix fun <T : Any> Obligation.State<T>.`owned by`(owner: AbstractParty) = copy(beneficiary = owner)
|
infix fun <T : Any> Obligation.State<T>.`owned by`(owner: AbstractParty) = copy(beneficiary = owner)
|
||||||
infix fun <T : Any> Obligation.State<T>.`issued by`(party: AbstractParty) = copy(obligor = party)
|
infix fun <T : Any> Obligation.State<T>.`issued by`(party: AbstractParty) = copy(obligor = party)
|
||||||
// For Java users:
|
// For Java users:
|
||||||
@Suppress("unused") fun <T : Any> Obligation.State<T>.ownedBy(owner: AbstractParty) = copy(beneficiary = owner)
|
@Suppress("unused")
|
||||||
|
fun <T : Any> Obligation.State<T>.ownedBy(owner: AbstractParty) = copy(beneficiary = owner)
|
||||||
|
|
||||||
@Suppress("unused") fun <T : Any> Obligation.State<T>.issuedBy(party: AnonymousParty) = copy(obligor = party)
|
@Suppress("unused")
|
||||||
|
fun <T : Any> Obligation.State<T>.issuedBy(party: AnonymousParty) = copy(obligor = party)
|
||||||
|
|
||||||
/** A randomly generated key. */
|
/** A randomly generated key. */
|
||||||
val DUMMY_OBLIGATION_ISSUER_KEY by lazy { entropyToKeyPair(BigInteger.valueOf(10)) }
|
val DUMMY_OBLIGATION_ISSUER_KEY by lazy { entropyToKeyPair(BigInteger.valueOf(10)) }
|
||||||
|
@ -55,13 +55,13 @@ abstract class OnLedgerAsset<T : Any, C : CommandData, S : FungibleAsset<T>> : C
|
|||||||
*/
|
*/
|
||||||
@Throws(InsufficientBalanceException::class)
|
@Throws(InsufficientBalanceException::class)
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun <S : FungibleAsset<T>, T: Any> generateSpend(tx: TransactionBuilder,
|
fun <S : FungibleAsset<T>, T : Any> generateSpend(tx: TransactionBuilder,
|
||||||
amount: Amount<T>,
|
amount: Amount<T>,
|
||||||
to: AbstractParty,
|
to: AbstractParty,
|
||||||
acceptableStates: List<StateAndRef<S>>,
|
acceptableStates: List<StateAndRef<S>>,
|
||||||
payChangeTo: AbstractParty,
|
payChangeTo: AbstractParty,
|
||||||
deriveState: (TransactionState<S>, Amount<Issued<T>>, AbstractParty) -> TransactionState<S>,
|
deriveState: (TransactionState<S>, Amount<Issued<T>>, AbstractParty) -> TransactionState<S>,
|
||||||
generateMoveCommand: () -> CommandData): Pair<TransactionBuilder, List<PublicKey>> {
|
generateMoveCommand: () -> CommandData): Pair<TransactionBuilder, List<PublicKey>> {
|
||||||
return generateSpend(tx, listOf(PartyAndAmount(to, amount)), acceptableStates, payChangeTo, deriveState, generateMoveCommand)
|
return generateSpend(tx, listOf(PartyAndAmount(to, amount)), acceptableStates, payChangeTo, deriveState, generateMoveCommand)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -91,12 +91,12 @@ abstract class OnLedgerAsset<T : Any, C : CommandData, S : FungibleAsset<T>> : C
|
|||||||
*/
|
*/
|
||||||
@Throws(InsufficientBalanceException::class)
|
@Throws(InsufficientBalanceException::class)
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun <S : FungibleAsset<T>, T: Any> generateSpend(tx: TransactionBuilder,
|
fun <S : FungibleAsset<T>, T : Any> generateSpend(tx: TransactionBuilder,
|
||||||
payments: List<PartyAndAmount<T>>,
|
payments: List<PartyAndAmount<T>>,
|
||||||
acceptableStates: List<StateAndRef<S>>,
|
acceptableStates: List<StateAndRef<S>>,
|
||||||
payChangeTo: AbstractParty,
|
payChangeTo: AbstractParty,
|
||||||
deriveState: (TransactionState<S>, Amount<Issued<T>>, AbstractParty) -> TransactionState<S>,
|
deriveState: (TransactionState<S>, Amount<Issued<T>>, AbstractParty) -> TransactionState<S>,
|
||||||
generateMoveCommand: () -> CommandData): Pair<TransactionBuilder, List<PublicKey>> {
|
generateMoveCommand: () -> CommandData): Pair<TransactionBuilder, List<PublicKey>> {
|
||||||
// Discussion
|
// Discussion
|
||||||
//
|
//
|
||||||
// This code is analogous to the Wallet.send() set of methods in bitcoinj, and has the same general outline.
|
// This code is analogous to the Wallet.send() set of methods in bitcoinj, and has the same general outline.
|
||||||
@ -230,11 +230,11 @@ abstract class OnLedgerAsset<T : Any, C : CommandData, S : FungibleAsset<T>> : C
|
|||||||
*/
|
*/
|
||||||
@Throws(InsufficientBalanceException::class)
|
@Throws(InsufficientBalanceException::class)
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun <S : FungibleAsset<T>, T: Any> generateExit(tx: TransactionBuilder, amountIssued: Amount<Issued<T>>,
|
fun <S : FungibleAsset<T>, T : Any> generateExit(tx: TransactionBuilder, amountIssued: Amount<Issued<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): Set<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)
|
||||||
@ -272,9 +272,9 @@ abstract class OnLedgerAsset<T : Any, C : CommandData, S : FungibleAsset<T>> : C
|
|||||||
* wrappers around this function, which build the state for you, and those should be used in preference.
|
* wrappers around this function, which build the state for you, and those should be used in preference.
|
||||||
*/
|
*/
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun <S : FungibleAsset<T>, T: Any> generateIssue(tx: TransactionBuilder,
|
fun <S : FungibleAsset<T>, T : Any> generateIssue(tx: TransactionBuilder,
|
||||||
transactionState: TransactionState<S>,
|
transactionState: TransactionState<S>,
|
||||||
issueCommand: CommandData): Set<PublicKey> {
|
issueCommand: CommandData): Set<PublicKey> {
|
||||||
check(tx.inputStates().isEmpty())
|
check(tx.inputStates().isEmpty())
|
||||||
check(tx.outputStates().map { it.data }.filterIsInstance(transactionState.javaClass).isEmpty())
|
check(tx.outputStates().map { it.data }.filterIsInstance(transactionState.javaClass).isEmpty())
|
||||||
require(transactionState.data.amount.quantity > 0)
|
require(transactionState.data.amount.quantity > 0)
|
||||||
|
@ -54,11 +54,11 @@ class CashSelectionH2Impl : CashSelection {
|
|||||||
*/
|
*/
|
||||||
@Suspendable
|
@Suspendable
|
||||||
override fun unconsumedCashStatesForSpending(services: ServiceHub,
|
override fun unconsumedCashStatesForSpending(services: ServiceHub,
|
||||||
amount: Amount<Currency>,
|
amount: Amount<Currency>,
|
||||||
onlyFromIssuerParties: Set<AbstractParty>,
|
onlyFromIssuerParties: Set<AbstractParty>,
|
||||||
notary: Party?,
|
notary: Party?,
|
||||||
lockId: UUID,
|
lockId: UUID,
|
||||||
withIssuerRefs: Set<OpaqueBytes>): List<StateAndRef<Cash.State>> {
|
withIssuerRefs: Set<OpaqueBytes>): List<StateAndRef<Cash.State>> {
|
||||||
|
|
||||||
val issuerKeysStr = onlyFromIssuerParties.fold("") { left, right -> left + "('${right.owningKey.toBase58String()}')," }.dropLast(1)
|
val issuerKeysStr = onlyFromIssuerParties.fold("") { left, right -> left + "('${right.owningKey.toBase58String()}')," }.dropLast(1)
|
||||||
val issuerRefsStr = withIssuerRefs.fold("") { left, right -> left + "('${right.bytes.toHexString()}')," }.dropLast(1)
|
val issuerRefsStr = withIssuerRefs.fold("") { left, right -> left + "('${right.bytes.toHexString()}')," }.dropLast(1)
|
||||||
|
@ -29,4 +29,4 @@ class CashSelectionMySQLImpl : CashSelection {
|
|||||||
withIssuerRefs: Set<OpaqueBytes>): List<StateAndRef<Cash.State>> {
|
withIssuerRefs: Set<OpaqueBytes>): List<StateAndRef<Cash.State>> {
|
||||||
TODO("MySQL cash selection not implemented")
|
TODO("MySQL cash selection not implemented")
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -60,7 +60,7 @@ class CashExitFlow(private val amount: Amount<Currency>,
|
|||||||
|
|
||||||
// Work out who the owners of the burnt states were (specify page size so we don't silently drop any if > DEFAULT_PAGE_SIZE)
|
// Work out who the owners of the burnt states were (specify page size so we don't silently drop any if > DEFAULT_PAGE_SIZE)
|
||||||
val inputStates = serviceHub.vaultService.queryBy<Cash.State>(VaultQueryCriteria(stateRefs = builder.inputStates()),
|
val inputStates = serviceHub.vaultService.queryBy<Cash.State>(VaultQueryCriteria(stateRefs = builder.inputStates()),
|
||||||
PageSpecification(pageNumber = DEFAULT_PAGE_NUM, pageSize = builder.inputStates().size)).states
|
PageSpecification(pageNumber = DEFAULT_PAGE_NUM, pageSize = builder.inputStates().size)).states
|
||||||
|
|
||||||
// TODO: Is it safe to drop participants we don't know how to contact? Does not knowing how to contact them
|
// TODO: Is it safe to drop participants we don't know how to contact? Does not knowing how to contact them
|
||||||
// count as a reason to fail?
|
// count as a reason to fail?
|
||||||
|
@ -32,6 +32,7 @@ class CashIssueAndPaymentFlow(val amount: Amount<Currency>,
|
|||||||
recipient: Party,
|
recipient: Party,
|
||||||
anonymous: Boolean,
|
anonymous: Boolean,
|
||||||
notary: Party) : this(amount, issueRef, recipient, anonymous, notary, tracker())
|
notary: Party) : this(amount, issueRef, recipient, anonymous, notary, tracker())
|
||||||
|
|
||||||
constructor(request: IssueAndPaymentRequest) : this(request.amount, request.issueRef, request.recipient, request.anonymous, request.notary, tracker())
|
constructor(request: IssueAndPaymentRequest) : this(request.amount, request.issueRef, request.recipient, request.anonymous, request.notary, tracker())
|
||||||
|
|
||||||
@Suspendable
|
@Suspendable
|
||||||
|
@ -31,6 +31,7 @@ class CashIssueFlow(private val amount: Amount<Currency>,
|
|||||||
constructor(amount: Amount<Currency>,
|
constructor(amount: Amount<Currency>,
|
||||||
issuerBankPartyRef: OpaqueBytes,
|
issuerBankPartyRef: OpaqueBytes,
|
||||||
notary: Party) : this(amount, issuerBankPartyRef, notary, tracker())
|
notary: Party) : this(amount, issuerBankPartyRef, notary, tracker())
|
||||||
|
|
||||||
constructor(request: IssueRequest) : this(request.amount, request.issueRef, request.notary, tracker())
|
constructor(request: IssueRequest) : this(request.amount, request.issueRef, request.notary, tracker())
|
||||||
|
|
||||||
@Suspendable
|
@Suspendable
|
||||||
|
@ -31,8 +31,10 @@ open class CashPaymentFlow(
|
|||||||
val issuerConstraint: Set<Party> = emptySet()) : AbstractCashFlow<AbstractCashFlow.Result>(progressTracker) {
|
val issuerConstraint: Set<Party> = emptySet()) : AbstractCashFlow<AbstractCashFlow.Result>(progressTracker) {
|
||||||
/** A straightforward constructor that constructs spends using cash states of any issuer. */
|
/** A straightforward constructor that constructs spends using cash states of any issuer. */
|
||||||
constructor(amount: Amount<Currency>, recipient: Party) : this(amount, recipient, true, tracker())
|
constructor(amount: Amount<Currency>, recipient: Party) : this(amount, recipient, true, tracker())
|
||||||
|
|
||||||
/** A straightforward constructor that constructs spends using cash states of any issuer. */
|
/** A straightforward constructor that constructs spends using cash states of any issuer. */
|
||||||
constructor(amount: Amount<Currency>, recipient: Party, anonymous: Boolean) : this(amount, recipient, anonymous, tracker())
|
constructor(amount: Amount<Currency>, recipient: Party, anonymous: Boolean) : this(amount, recipient, anonymous, tracker())
|
||||||
|
|
||||||
constructor(request: PaymentRequest) : this(request.amount, request.recipient, request.anonymous, tracker(), request.issuerConstraint)
|
constructor(request: PaymentRequest) : this(request.amount, request.recipient, request.anonymous, tracker(), request.issuerConstraint)
|
||||||
|
|
||||||
@Suspendable
|
@Suspendable
|
||||||
|
@ -43,6 +43,7 @@ object TwoPartyDealFlow {
|
|||||||
companion object {
|
companion object {
|
||||||
object GENERATING_ID : ProgressTracker.Step("Generating anonymous identities")
|
object GENERATING_ID : ProgressTracker.Step("Generating anonymous identities")
|
||||||
object SENDING_PROPOSAL : ProgressTracker.Step("Handshaking and awaiting transaction proposal.")
|
object SENDING_PROPOSAL : ProgressTracker.Step("Handshaking and awaiting transaction proposal.")
|
||||||
|
|
||||||
fun tracker() = ProgressTracker(GENERATING_ID, SENDING_PROPOSAL)
|
fun tracker() = ProgressTracker(GENERATING_ID, SENDING_PROPOSAL)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -57,7 +58,7 @@ object TwoPartyDealFlow {
|
|||||||
val txIdentities = subFlow(SwapIdentitiesFlow(otherSideSession.counterparty))
|
val txIdentities = subFlow(SwapIdentitiesFlow(otherSideSession.counterparty))
|
||||||
val anonymousMe = txIdentities[ourIdentity] ?: ourIdentity.anonymise()
|
val anonymousMe = txIdentities[ourIdentity] ?: ourIdentity.anonymise()
|
||||||
val anonymousCounterparty = txIdentities[otherSideSession.counterparty] ?: otherSideSession.counterparty.anonymise()
|
val anonymousCounterparty = txIdentities[otherSideSession.counterparty] ?: otherSideSession.counterparty.anonymise()
|
||||||
// DOCEND 2
|
// DOCEND 2
|
||||||
progressTracker.currentStep = SENDING_PROPOSAL
|
progressTracker.currentStep = SENDING_PROPOSAL
|
||||||
// Make the first message we'll send to kick off the flow.
|
// Make the first message we'll send to kick off the flow.
|
||||||
val hello = Handshake(payload, anonymousMe, anonymousCounterparty)
|
val hello = Handshake(payload, anonymousMe, anonymousCounterparty)
|
||||||
@ -148,6 +149,7 @@ object TwoPartyDealFlow {
|
|||||||
|
|
||||||
@Suspendable
|
@Suspendable
|
||||||
protected abstract fun validateHandshake(handshake: Handshake<U>): Handshake<U>
|
protected abstract fun validateHandshake(handshake: Handshake<U>): Handshake<U>
|
||||||
|
|
||||||
@Suspendable
|
@Suspendable
|
||||||
protected abstract fun assembleSharedTX(handshake: Handshake<U>): Triple<TransactionBuilder, List<PublicKey>, List<TransactionSignature>>
|
protected abstract fun assembleSharedTX(handshake: Handshake<U>): Triple<TransactionBuilder, List<PublicKey>, List<TransactionSignature>>
|
||||||
}
|
}
|
||||||
|
@ -136,6 +136,7 @@ object TwoPartyTradeFlow {
|
|||||||
private val anonymous: Boolean) : FlowLogic<SignedTransaction>() {
|
private val anonymous: Boolean) : FlowLogic<SignedTransaction>() {
|
||||||
constructor(otherSideSession: FlowSession, notary: Party, acceptablePrice: Amount<Currency>, typeToBuy: Class<out OwnableState>) :
|
constructor(otherSideSession: FlowSession, notary: Party, acceptablePrice: Amount<Currency>, typeToBuy: Class<out OwnableState>) :
|
||||||
this(otherSideSession, notary, acceptablePrice, typeToBuy, true)
|
this(otherSideSession, notary, acceptablePrice, typeToBuy, true)
|
||||||
|
|
||||||
// DOCSTART 2
|
// DOCSTART 2
|
||||||
object RECEIVING : ProgressTracker.Step("Waiting for seller trading info")
|
object RECEIVING : ProgressTracker.Step("Waiting for seller trading info")
|
||||||
|
|
||||||
|
@ -22,8 +22,8 @@ object CashSchema
|
|||||||
object CashSchemaV1 : MappedSchema(schemaFamily = CashSchema.javaClass, version = 1, mappedTypes = listOf(PersistentCashState::class.java)) {
|
object CashSchemaV1 : MappedSchema(schemaFamily = CashSchema.javaClass, version = 1, mappedTypes = listOf(PersistentCashState::class.java)) {
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "contract_cash_states",
|
@Table(name = "contract_cash_states",
|
||||||
indexes = arrayOf(Index(name = "ccy_code_idx", columnList = "ccy_code"),
|
indexes = arrayOf(Index(name = "ccy_code_idx", columnList = "ccy_code"),
|
||||||
Index(name = "pennies_idx", columnList = "pennies")))
|
Index(name = "pennies_idx", columnList = "pennies")))
|
||||||
class PersistentCashState(
|
class PersistentCashState(
|
||||||
/** X500Name of owner party **/
|
/** X500Name of owner party **/
|
||||||
@Column(name = "owner_name")
|
@Column(name = "owner_name")
|
||||||
|
@ -22,9 +22,9 @@ object CommercialPaperSchema
|
|||||||
object CommercialPaperSchemaV1 : MappedSchema(schemaFamily = CommercialPaperSchema.javaClass, version = 1, mappedTypes = listOf(PersistentCommercialPaperState::class.java)) {
|
object CommercialPaperSchemaV1 : MappedSchema(schemaFamily = CommercialPaperSchema.javaClass, version = 1, mappedTypes = listOf(PersistentCommercialPaperState::class.java)) {
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "cp_states",
|
@Table(name = "cp_states",
|
||||||
indexes = arrayOf(Index(name = "ccy_code_index", columnList = "ccy_code"),
|
indexes = arrayOf(Index(name = "ccy_code_index", columnList = "ccy_code"),
|
||||||
Index(name = "maturity_index", columnList = "maturity_instant"),
|
Index(name = "maturity_index", columnList = "maturity_instant"),
|
||||||
Index(name = "face_value_index", columnList = "face_value")))
|
Index(name = "face_value_index", columnList = "face_value")))
|
||||||
class PersistentCommercialPaperState(
|
class PersistentCommercialPaperState(
|
||||||
@Column(name = "issuance_key")
|
@Column(name = "issuance_key")
|
||||||
var issuanceParty: String,
|
var issuanceParty: String,
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
@file:JvmName("StateSumming")
|
@file:JvmName("StateSumming")
|
||||||
|
|
||||||
package net.corda.finance.utils
|
package net.corda.finance.utils
|
||||||
|
|
||||||
import net.corda.core.contracts.Amount
|
import net.corda.core.contracts.Amount
|
||||||
|
@ -34,7 +34,7 @@ public class CashTestsJava {
|
|||||||
});
|
});
|
||||||
|
|
||||||
tx.tweak(tw -> {
|
tx.tweak(tw -> {
|
||||||
tw.output(Cash.PROGRAM_ID, () -> outState );
|
tw.output(Cash.PROGRAM_ID, () -> outState);
|
||||||
tw.command(getMEGA_CORP_PUBKEY(), DummyCommandData.INSTANCE);
|
tw.command(getMEGA_CORP_PUBKEY(), DummyCommandData.INSTANCE);
|
||||||
// Invalid command
|
// Invalid command
|
||||||
return tw.failsWith("required net.corda.finance.contracts.asset.Cash.Commands.Move command");
|
return tw.failsWith("required net.corda.finance.contracts.asset.Cash.Commands.Move command");
|
||||||
|
@ -80,7 +80,8 @@ class KotlinCommercialPaperLegacyTest : ICommercialPaperTestTemplate {
|
|||||||
@RunWith(Parameterized::class)
|
@RunWith(Parameterized::class)
|
||||||
class CommercialPaperTestsGeneric {
|
class CommercialPaperTestsGeneric {
|
||||||
companion object {
|
companion object {
|
||||||
@Parameterized.Parameters @JvmStatic
|
@Parameterized.Parameters
|
||||||
|
@JvmStatic
|
||||||
fun data() = listOf(JavaCommercialPaperTest(), KotlinCommercialPaperTest(), KotlinCommercialPaperLegacyTest())
|
fun data() = listOf(JavaCommercialPaperTest(), KotlinCommercialPaperTest(), KotlinCommercialPaperLegacyTest())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -227,7 +228,7 @@ class CommercialPaperTestsGeneric {
|
|||||||
|
|
||||||
private lateinit var moveTX: SignedTransaction
|
private lateinit var moveTX: SignedTransaction
|
||||||
|
|
||||||
// @Test
|
// @Test
|
||||||
@Ignore
|
@Ignore
|
||||||
fun `issue move and then redeem`() {
|
fun `issue move and then redeem`() {
|
||||||
setCordappPackages("net.corda.finance.contracts")
|
setCordappPackages("net.corda.finance.contracts")
|
||||||
|
@ -590,9 +590,9 @@ class CashTests : TestDependencyInjectionBase() {
|
|||||||
fun generateSimpleDirectSpend() {
|
fun generateSimpleDirectSpend() {
|
||||||
initialiseTestSerialization()
|
initialiseTestSerialization()
|
||||||
val wtx =
|
val wtx =
|
||||||
database.transaction {
|
database.transaction {
|
||||||
makeSpend(100.DOLLARS, THEIR_IDENTITY_1)
|
makeSpend(100.DOLLARS, THEIR_IDENTITY_1)
|
||||||
}
|
}
|
||||||
database.transaction {
|
database.transaction {
|
||||||
val vaultState = vaultStatesUnconsumed.elementAt(0)
|
val vaultState = vaultStatesUnconsumed.elementAt(0)
|
||||||
assertEquals(vaultState.ref, wtx.inputs[0])
|
assertEquals(vaultState.ref, wtx.inputs[0])
|
||||||
@ -617,9 +617,9 @@ class CashTests : TestDependencyInjectionBase() {
|
|||||||
fun generateSimpleSpendWithChange() {
|
fun generateSimpleSpendWithChange() {
|
||||||
initialiseTestSerialization()
|
initialiseTestSerialization()
|
||||||
val wtx =
|
val wtx =
|
||||||
database.transaction {
|
database.transaction {
|
||||||
makeSpend(10.DOLLARS, THEIR_IDENTITY_1)
|
makeSpend(10.DOLLARS, THEIR_IDENTITY_1)
|
||||||
}
|
}
|
||||||
database.transaction {
|
database.transaction {
|
||||||
val vaultState = vaultStatesUnconsumed.elementAt(0)
|
val vaultState = vaultStatesUnconsumed.elementAt(0)
|
||||||
val changeAmount = 90.DOLLARS `issued by` defaultIssuer
|
val changeAmount = 90.DOLLARS `issued by` defaultIssuer
|
||||||
@ -643,9 +643,9 @@ class CashTests : TestDependencyInjectionBase() {
|
|||||||
fun generateSpendWithTwoInputs() {
|
fun generateSpendWithTwoInputs() {
|
||||||
initialiseTestSerialization()
|
initialiseTestSerialization()
|
||||||
val wtx =
|
val wtx =
|
||||||
database.transaction {
|
database.transaction {
|
||||||
makeSpend(500.DOLLARS, THEIR_IDENTITY_1)
|
makeSpend(500.DOLLARS, THEIR_IDENTITY_1)
|
||||||
}
|
}
|
||||||
database.transaction {
|
database.transaction {
|
||||||
val vaultState0 = vaultStatesUnconsumed.elementAt(0)
|
val vaultState0 = vaultStatesUnconsumed.elementAt(0)
|
||||||
val vaultState1 = vaultStatesUnconsumed.elementAt(1)
|
val vaultState1 = vaultStatesUnconsumed.elementAt(1)
|
||||||
@ -660,11 +660,11 @@ class CashTests : TestDependencyInjectionBase() {
|
|||||||
fun generateSpendMixedDeposits() {
|
fun generateSpendMixedDeposits() {
|
||||||
initialiseTestSerialization()
|
initialiseTestSerialization()
|
||||||
val wtx =
|
val wtx =
|
||||||
database.transaction {
|
database.transaction {
|
||||||
val wtx = makeSpend(580.DOLLARS, THEIR_IDENTITY_1)
|
val wtx = makeSpend(580.DOLLARS, THEIR_IDENTITY_1)
|
||||||
assertEquals(3, wtx.inputs.size)
|
assertEquals(3, wtx.inputs.size)
|
||||||
wtx
|
wtx
|
||||||
}
|
}
|
||||||
database.transaction {
|
database.transaction {
|
||||||
val vaultState0: StateAndRef<Cash.State> = vaultStatesUnconsumed.elementAt(0)
|
val vaultState0: StateAndRef<Cash.State> = vaultStatesUnconsumed.elementAt(0)
|
||||||
val vaultState1: StateAndRef<Cash.State> = vaultStatesUnconsumed.elementAt(1)
|
val vaultState1: StateAndRef<Cash.State> = vaultStatesUnconsumed.elementAt(1)
|
||||||
@ -796,7 +796,7 @@ class CashTests : TestDependencyInjectionBase() {
|
|||||||
transaction {
|
transaction {
|
||||||
attachment(Cash.PROGRAM_ID)
|
attachment(Cash.PROGRAM_ID)
|
||||||
input("MEGA_CORP cash")
|
input("MEGA_CORP cash")
|
||||||
output(Cash.PROGRAM_ID, "MEGA_CORP cash 2", "MEGA_CORP cash".output<Cash.State>().copy(owner = AnonymousParty(ALICE_PUBKEY)) )
|
output(Cash.PROGRAM_ID, "MEGA_CORP cash 2", "MEGA_CORP cash".output<Cash.State>().copy(owner = AnonymousParty(ALICE_PUBKEY)))
|
||||||
command(MEGA_CORP_PUBKEY) { Cash.Commands.Move() }
|
command(MEGA_CORP_PUBKEY) { Cash.Commands.Move() }
|
||||||
this.verifies()
|
this.verifies()
|
||||||
}
|
}
|
||||||
|
@ -286,7 +286,7 @@ class ObligationTests {
|
|||||||
assertEquals(expected, actual)
|
assertEquals(expected, actual)
|
||||||
}
|
}
|
||||||
|
|
||||||
private inline fun <reified T: ContractState> getStateAndRef(state: T, contractClassName: ContractClassName): StateAndRef<T> {
|
private inline fun <reified T : ContractState> getStateAndRef(state: T, contractClassName: ContractClassName): StateAndRef<T> {
|
||||||
val txState = TransactionState(state, contractClassName, DUMMY_NOTARY)
|
val txState = TransactionState(state, contractClassName, DUMMY_NOTARY)
|
||||||
return StateAndRef(txState, StateRef(SecureHash.randomSHA256(), 0))
|
return StateAndRef(txState, StateRef(SecureHash.randomSHA256(), 0))
|
||||||
|
|
||||||
@ -418,7 +418,7 @@ class ObligationTests {
|
|||||||
@Test
|
@Test
|
||||||
fun `payment netting`() {
|
fun `payment netting`() {
|
||||||
// Try netting out two obligations
|
// Try netting out two obligations
|
||||||
ledger(mockService) {
|
ledger(mockService) {
|
||||||
cashObligationTestRoots(this)
|
cashObligationTestRoots(this)
|
||||||
transaction("Issuance") {
|
transaction("Issuance") {
|
||||||
attachments(Obligation.PROGRAM_ID)
|
attachments(Obligation.PROGRAM_ID)
|
||||||
|
@ -18,7 +18,7 @@ import kotlin.test.assertEquals
|
|||||||
import kotlin.test.assertFailsWith
|
import kotlin.test.assertFailsWith
|
||||||
|
|
||||||
class CashExitFlowTests {
|
class CashExitFlowTests {
|
||||||
private lateinit var mockNet : MockNetwork
|
private lateinit var mockNet: MockNetwork
|
||||||
private val initialBalance = 2000.DOLLARS
|
private val initialBalance = 2000.DOLLARS
|
||||||
private val ref = OpaqueBytes.of(0x01)
|
private val ref = OpaqueBytes.of(0x01)
|
||||||
private lateinit var bankOfCordaNode: StartedNode<MockNode>
|
private lateinit var bankOfCordaNode: StartedNode<MockNode>
|
||||||
|
@ -22,7 +22,7 @@ import kotlin.test.assertEquals
|
|||||||
import kotlin.test.assertFailsWith
|
import kotlin.test.assertFailsWith
|
||||||
|
|
||||||
class CashIssueFlowTests {
|
class CashIssueFlowTests {
|
||||||
private lateinit var mockNet : MockNetwork
|
private lateinit var mockNet: MockNetwork
|
||||||
private lateinit var bankOfCordaNode: StartedNode<MockNode>
|
private lateinit var bankOfCordaNode: StartedNode<MockNode>
|
||||||
private lateinit var bankOfCorda: Party
|
private lateinit var bankOfCorda: Party
|
||||||
private lateinit var notaryNode: StartedNode<MockNode>
|
private lateinit var notaryNode: StartedNode<MockNode>
|
||||||
|
@ -21,7 +21,7 @@ import kotlin.test.assertEquals
|
|||||||
import kotlin.test.assertFailsWith
|
import kotlin.test.assertFailsWith
|
||||||
|
|
||||||
class CashPaymentFlowTests {
|
class CashPaymentFlowTests {
|
||||||
private lateinit var mockNet : MockNetwork
|
private lateinit var mockNet: MockNetwork
|
||||||
private val initialBalance = 2000.DOLLARS
|
private val initialBalance = 2000.DOLLARS
|
||||||
private val ref = OpaqueBytes.of(0x01)
|
private val ref = OpaqueBytes.of(0x01)
|
||||||
private lateinit var bankOfCordaNode: StartedNode<MockNode>
|
private lateinit var bankOfCordaNode: StartedNode<MockNode>
|
||||||
|
@ -19,8 +19,8 @@ object CashSchema
|
|||||||
object SampleCashSchemaV1 : MappedSchema(schemaFamily = CashSchema.javaClass, version = 1, mappedTypes = listOf(PersistentCashState::class.java)) {
|
object SampleCashSchemaV1 : MappedSchema(schemaFamily = CashSchema.javaClass, version = 1, mappedTypes = listOf(PersistentCashState::class.java)) {
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "contract_cash_states",
|
@Table(name = "contract_cash_states",
|
||||||
indexes = arrayOf(Index(name = "ccy_code_idx", columnList = "ccy_code"),
|
indexes = arrayOf(Index(name = "ccy_code_idx", columnList = "ccy_code"),
|
||||||
Index(name = "pennies_idx", columnList = "pennies")))
|
Index(name = "pennies_idx", columnList = "pennies")))
|
||||||
class PersistentCashState(
|
class PersistentCashState(
|
||||||
@Column(name = "owner_key")
|
@Column(name = "owner_key")
|
||||||
var owner: String,
|
var owner: String,
|
||||||
|
@ -13,25 +13,25 @@ import javax.persistence.Table
|
|||||||
* [VaultFungibleState] abstract schema
|
* [VaultFungibleState] abstract schema
|
||||||
*/
|
*/
|
||||||
object SampleCashSchemaV2 : MappedSchema(schemaFamily = CashSchema.javaClass, version = 2,
|
object SampleCashSchemaV2 : MappedSchema(schemaFamily = CashSchema.javaClass, version = 2,
|
||||||
mappedTypes = listOf(PersistentCashState::class.java)) {
|
mappedTypes = listOf(PersistentCashState::class.java)) {
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "cash_states_v2",
|
@Table(name = "cash_states_v2",
|
||||||
indexes = arrayOf(Index(name = "ccy_code_idx2", columnList = "ccy_code")))
|
indexes = arrayOf(Index(name = "ccy_code_idx2", columnList = "ccy_code")))
|
||||||
class PersistentCashState (
|
class PersistentCashState(
|
||||||
/** product type */
|
/** product type */
|
||||||
@Column(name = "ccy_code", length = 3)
|
@Column(name = "ccy_code", length = 3)
|
||||||
var currency: String,
|
var currency: String,
|
||||||
|
|
||||||
/** parent attributes */
|
/** parent attributes */
|
||||||
@Transient
|
@Transient
|
||||||
val _participants: Set<AbstractParty>,
|
val _participants: Set<AbstractParty>,
|
||||||
@Transient
|
@Transient
|
||||||
val _owner: AbstractParty,
|
val _owner: AbstractParty,
|
||||||
@Transient
|
@Transient
|
||||||
val _quantity: Long,
|
val _quantity: Long,
|
||||||
@Transient
|
@Transient
|
||||||
val _issuerParty: AbstractParty,
|
val _issuerParty: AbstractParty,
|
||||||
@Transient
|
@Transient
|
||||||
val _issuerRef: ByteArray
|
val _issuerRef: ByteArray
|
||||||
) : CommonSchemaV1.FungibleState(_participants.toMutableSet(), _owner, _quantity, _issuerParty, _issuerRef)
|
) : CommonSchemaV1.FungibleState(_participants.toMutableSet(), _owner, _quantity, _issuerParty, _issuerRef)
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,7 @@ import javax.persistence.Table
|
|||||||
* at the time of writing.
|
* at the time of writing.
|
||||||
*/
|
*/
|
||||||
object SampleCashSchemaV3 : MappedSchema(schemaFamily = CashSchema.javaClass, version = 3,
|
object SampleCashSchemaV3 : MappedSchema(schemaFamily = CashSchema.javaClass, version = 3,
|
||||||
mappedTypes = listOf(PersistentCashState::class.java)) {
|
mappedTypes = listOf(PersistentCashState::class.java)) {
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "cash_states_v3")
|
@Table(name = "cash_states_v3")
|
||||||
class PersistentCashState(
|
class PersistentCashState(
|
||||||
|
@ -20,9 +20,9 @@ object CommercialPaperSchema
|
|||||||
object SampleCommercialPaperSchemaV1 : MappedSchema(schemaFamily = CommercialPaperSchema.javaClass, version = 1, mappedTypes = listOf(PersistentCommercialPaperState::class.java)) {
|
object SampleCommercialPaperSchemaV1 : MappedSchema(schemaFamily = CommercialPaperSchema.javaClass, version = 1, mappedTypes = listOf(PersistentCommercialPaperState::class.java)) {
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "cp_states",
|
@Table(name = "cp_states",
|
||||||
indexes = arrayOf(Index(name = "ccy_code_index", columnList = "ccy_code"),
|
indexes = arrayOf(Index(name = "ccy_code_index", columnList = "ccy_code"),
|
||||||
Index(name = "maturity_index", columnList = "maturity_instant"),
|
Index(name = "maturity_index", columnList = "maturity_instant"),
|
||||||
Index(name = "face_value_index", columnList = "face_value")))
|
Index(name = "face_value_index", columnList = "face_value")))
|
||||||
class PersistentCommercialPaperState(
|
class PersistentCommercialPaperState(
|
||||||
@Column(name = "issuance_key")
|
@Column(name = "issuance_key")
|
||||||
var issuanceParty: String,
|
var issuanceParty: String,
|
||||||
|
@ -14,11 +14,11 @@ import javax.persistence.Table
|
|||||||
* [VaultFungibleState] abstract schema
|
* [VaultFungibleState] abstract schema
|
||||||
*/
|
*/
|
||||||
object SampleCommercialPaperSchemaV2 : MappedSchema(schemaFamily = CommercialPaperSchema.javaClass, version = 1,
|
object SampleCommercialPaperSchemaV2 : MappedSchema(schemaFamily = CommercialPaperSchema.javaClass, version = 1,
|
||||||
mappedTypes = listOf(PersistentCommercialPaperState::class.java)) {
|
mappedTypes = listOf(PersistentCommercialPaperState::class.java)) {
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "cp_states_v2",
|
@Table(name = "cp_states_v2",
|
||||||
indexes = arrayOf(Index(name = "ccy_code_index2", columnList = "ccy_code"),
|
indexes = arrayOf(Index(name = "ccy_code_index2", columnList = "ccy_code"),
|
||||||
Index(name = "maturity_index2", columnList = "maturity_instant")))
|
Index(name = "maturity_index2", columnList = "maturity_instant")))
|
||||||
class PersistentCommercialPaperState(
|
class PersistentCommercialPaperState(
|
||||||
@Column(name = "maturity_instant")
|
@Column(name = "maturity_instant")
|
||||||
var maturity: Instant,
|
var maturity: Instant,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user