BIGINT fix for H2 coin selection. (#1659)

This commit is contained in:
Rick Parker 2017-09-27 15:15:34 +01:00 committed by GitHub
parent 0c910640bb
commit 39160de0a3
3 changed files with 16 additions and 5 deletions

View File

@ -15,17 +15,28 @@ import java.util.*
@JvmField val JPY: Currency = Currency.getInstance("JPY") @JvmField val JPY: Currency = Currency.getInstance("JPY")
@JvmField val RUB: Currency = Currency.getInstance("RUB") @JvmField val RUB: Currency = Currency.getInstance("RUB")
fun <T : Any> AMOUNT(amount: Int, token: T): Amount<T> = Amount.fromDecimal(BigDecimal.valueOf(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: Double, token: T): Amount<T> = Amount.fromDecimal(BigDecimal.valueOf(amount), token) fun <T : Any> AMOUNT(amount: Double, token: T): Amount<T> = Amount.fromDecimal(BigDecimal.valueOf(amount), token)
fun DOLLARS(amount: Int): Amount<Currency> = AMOUNT(amount, USD) fun DOLLARS(amount: Int): Amount<Currency> = AMOUNT(amount, USD)
fun DOLLARS(amount: Long): Amount<Currency> = AMOUNT(amount, USD)
fun DOLLARS(amount: Double): Amount<Currency> = AMOUNT(amount, USD) fun DOLLARS(amount: Double): Amount<Currency> = AMOUNT(amount, USD)
fun POUNDS(amount: Int): Amount<Currency> = AMOUNT(amount, GBP) fun POUNDS(amount: Int): Amount<Currency> = AMOUNT(amount, GBP)
fun POUNDS(amount: Long): Amount<Currency> = AMOUNT(amount, GBP)
fun POUNDS(amount: Double): Amount<Currency> = AMOUNT(amount, GBP)
fun SWISS_FRANCS(amount: Int): Amount<Currency> = AMOUNT(amount, CHF) fun SWISS_FRANCS(amount: Int): Amount<Currency> = AMOUNT(amount, CHF)
fun SWISS_FRANCS(amount: Long): Amount<Currency> = AMOUNT(amount, CHF)
fun SWISS_FRANCS(amount: Double): Amount<Currency> = AMOUNT(amount, CHF)
val Int.DOLLARS: Amount<Currency> get() = DOLLARS(this) val Int.DOLLARS: Amount<Currency> get() = DOLLARS(this)
val Long.DOLLARS: Amount<Currency> get() = DOLLARS(this)
val Double.DOLLARS: Amount<Currency> get() = DOLLARS(this) val Double.DOLLARS: Amount<Currency> get() = DOLLARS(this)
val Int.POUNDS: Amount<Currency> get() = POUNDS(this) val Int.POUNDS: Amount<Currency> get() = POUNDS(this)
val Long.POUNDS: Amount<Currency> get() = POUNDS(this)
val Double.POUNDS: Amount<Currency> get() = POUNDS(this)
val Int.SWISS_FRANCS: Amount<Currency> get() = SWISS_FRANCS(this) val Int.SWISS_FRANCS: Amount<Currency> get() = SWISS_FRANCS(this)
val Long.SWISS_FRANCS: Amount<Currency> get() = SWISS_FRANCS(this)
val Double.SWISS_FRANCS: Amount<Currency> get() = SWISS_FRANCS(this)
infix fun Currency.`issued by`(deposit: PartyAndReference) = issuedBy(deposit) infix fun Currency.`issued by`(deposit: PartyAndReference) = issuedBy(deposit)
infix fun Amount<Currency>.`issued by`(deposit: PartyAndReference) = issuedBy(deposit) infix fun Amount<Currency>.`issued by`(deposit: PartyAndReference) = issuedBy(deposit)

View File

@ -77,7 +77,7 @@ class CashSelectionH2Impl : CashSelection {
spendLock.withLock { spendLock.withLock {
val statement = services.jdbcSession().createStatement() val statement = services.jdbcSession().createStatement()
try { try {
statement.execute("CALL SET(@t, 0);") statement.execute("CALL SET(@t, CAST(0 AS BIGINT));")
// we select spendable states irrespective of lock but prioritised by unlocked ones (Eg. null) // we select spendable states irrespective of lock but prioritised by unlocked ones (Eg. null)
// the softLockReserve update will detect whether we try to lock states locked by others // the softLockReserve update will detect whether we try to lock states locked by others

View File

@ -44,17 +44,17 @@ private class TraderDemo {
} }
// What happens next depends on the role. The buyer sits around waiting for a trade to start. The seller role // What happens next depends on the role. The buyer sits around waiting for a trade to start. The seller role
// will contact the buyer and actually make something happen. // will contact the buyer and actually make something happen. We intentionally use large amounts here.
val role = options.valueOf(roleArg)!! val role = options.valueOf(roleArg)!!
if (role == Role.BANK) { if (role == Role.BANK) {
val bankHost = NetworkHostAndPort("localhost", bankRpcPort) val bankHost = NetworkHostAndPort("localhost", bankRpcPort)
CordaRPCClient(bankHost).use("demo", "demo") { CordaRPCClient(bankHost).use("demo", "demo") {
TraderDemoClientApi(it.proxy).runIssuer(1100.DOLLARS, buyerName, sellerName) TraderDemoClientApi(it.proxy).runIssuer(1_100_000_000_000.DOLLARS, buyerName, sellerName)
} }
} else { } else {
val sellerHost = NetworkHostAndPort("localhost", sellerRpcPort) val sellerHost = NetworkHostAndPort("localhost", sellerRpcPort)
CordaRPCClient(sellerHost).use("demo", "demo") { CordaRPCClient(sellerHost).use("demo", "demo") {
TraderDemoClientApi(it.proxy).runSeller(1000.DOLLARS, buyerName) TraderDemoClientApi(it.proxy).runSeller(1_000_000_000_000.DOLLARS, buyerName)
} }
} }
} }