corda / net.corda.core.contracts / AmountTransfer

AmountTransfer

class AmountTransfer<T : Any, P : Any>

This class represents a possibly negative transfer of tokens from one vault state to another, possibly at a future date.

Constructors

<init>

This class represents a possibly negative transfer of tokens from one vault state to another, possibly at a future date.

AmountTransfer(quantityDelta: Long, token: T, source: P, destination: P)

Properties

destination

is the Party, CompositeKey, or other identifier of the token sink if quantityDelta is positive, or the token source if quantityDelta is negative. The type P should support value equality.

val destination: P

quantityDelta

is a signed Long value representing the exchanged number of tokens. If positive then it represents the movement of Math.abs(quantityDelta) tokens away from source and receipt of Math.abs(quantityDelta) at the destination. If the quantityDelta is negative then the source will receive Math.abs(quantityDelta) tokens and the destination will lose Math.abs(quantityDelta) tokens. Where possible the source and destination should be coded to ensure a positive quantityDelta, but in various scenarios it may be more consistent to allow positive and negative values. For example it is common for a bank to code asset flows as gains and losses from its perspective i.e. always the destination.

val quantityDelta: Long

source

is the Party, CompositeKey, or other identifier of the token source if quantityDelta is positive, or the token sink if quantityDelta is negative. The type P should support value equality.

val source: P

token

represents the type of asset token as would be used to construct Amount objects.

val token: T

Functions

apply

Applies this AmountTransfer to a list of SourceAndAmount objects representing balances. The list can be heterogeneous in terms of token types and parties, so long as there is sufficient balance of the correct token type held with the party paying for the transfer.

fun apply(balances: List<SourceAndAmount<T, P>>, newRef: Any? = null): List<SourceAndAmount<T, P>>

equals

Checks value equality of AmountTransfer objects, but also matches the reversed source and destination equivalent.

fun equals(other: Any?): Boolean

hashCode

This hash code function ensures that reversed source and destination equivalents will hash to the same value.

fun hashCode(): Int

novate

Returns a list of two new AmountTransfers each between one of the original parties and the centralParty. The net total exchange is the same as in the original input. Novation is a common financial operation in which a bilateral exchange is modified so that the same relative asset exchange happens, but with each party exchanging versus a central counterparty, or clearing house.

fun novate(centralParty: P): List<AmountTransfer<T, P>>

plus

Add together two AmountTransfer objects to produce the single equivalent net flow. The addition only applies to AmountTransfer objects with the same token type. Also the pair of parties must be aligned, although source destination may be swapped in the second item.

operator fun plus(other: AmountTransfer<T, P>): AmountTransfer<T, P>

toDecimal

Convert the quantityDelta to a displayable format BigDecimal value. The conversion ratio is the same as for Amount of the same token type.

fun toDecimal(): BigDecimal

Companion Object Functions

fromDecimal

Construct an AmountTransfer object from an indicative/displayable BigDecimal source, applying rounding as specified. The token size is determined from the token type and is the same as for Amount of the same token.

fun <T : Any, P : Any> fromDecimal(displayQuantityDelta: BigDecimal, token: T, source: P, destination: P, rounding: RoundingMode = RoundingMode.DOWN): AmountTransfer<T, P>

zero

Helper to make a zero size AmountTransfer.

fun <T : Any, P : Any> zero(token: T, source: P, destination: P): AmountTransfer<T, P>