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>

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

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

Properties

destination

val destination: P

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.

quantityDelta

val quantityDelta: Long

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.

source

val source: P

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.

token

val token: T

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

Functions

apply

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

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.

equals

fun equals(other: Any?): Boolean

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

hashCode

fun hashCode(): Int

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

novate

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

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.

plus

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

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.

toDecimal

fun toDecimal(): BigDecimal

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

Companion Object Functions

fromDecimal

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

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.

zero

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

Helper to make a zero size AmountTransfer.

Extension Functions

contextLogger

fun Any.contextLogger(): Logger

When called from a companion object, returns the logger for the enclosing class.