demos: Fix demo RPC serialisation after rebase

This commit is contained in:
Andras Slemmer 2016-12-08 11:58:09 +00:00
parent 9117ec9860
commit 4fe1d48e4a
4 changed files with 53 additions and 8 deletions

View File

@ -441,7 +441,7 @@ fun createKryo(k: Kryo = Kryo()): Kryo {
/** This ensures any kotlin objects that implement [DeserializeAsKotlinObjectDef] are read back in as singletons. */
addDefaultSerializer(DeserializeAsKotlinObjectDef::class.java, KotlinObjectSerializer)
addDefaultSerializer(InputStream::class.java, InputStreamSerializer)
addDefaultSerializer(BufferedInputStream::class.java, InputStreamSerializer)
ImmutableListSerializer.registerSerializers(k)
ImmutableSetSerializer.registerSerializers(k)

View File

@ -1,5 +1,6 @@
package net.corda.core.utilities
import net.corda.core.ErrorOr
import net.corda.core.crypto.CompositeKey
import net.corda.core.crypto.Party
import net.corda.core.messaging.CordaRPCOps
@ -16,12 +17,15 @@ class ApiUtils(val rpc: CordaRPCOps) {
* Usage: withParty(key) { doSomethingWith(it) }
*/
fun withParty(partyKeyStr: String, notFound: (String) -> Response = defaultNotFound, found: (Party) -> Response): Response {
return try {
val party = try {
val partyKey = CompositeKey.parseFromBase58(partyKeyStr)
val party = rpc.partyFromKey(partyKey)
if (party == null) notFound("Unknown party") else found(party)
ErrorOr(rpc.partyFromKey(partyKey))
} catch (e: IllegalArgumentException) {
notFound("Invalid base58 key passed for party key")
ErrorOr.of(Exception("Invalid base58 key passed for party key $e"))
}
return party.bind { if (it == null) ErrorOr.of(Exception("Unknown party")) else ErrorOr(found(it)) }.match(
onValue = { it },
onError = { notFound(it.toString()) }
)
}
}

View File

@ -40,6 +40,8 @@ import org.slf4j.Logger
import org.slf4j.LoggerFactory
import rx.Notification
import rx.Observable
import java.io.BufferedInputStream
import java.io.InputStream
import java.time.Instant
import java.time.LocalDateTime
import java.util.*
@ -143,6 +145,8 @@ private class RPCKryo(observableSerializer: Serializer<Observable<Any>>? = null)
ImmutableMapSerializer.registerSerializers(this)
ImmutableMultimapSerializer.registerSerializers(this)
register(BufferedInputStream::class.java, InputStreamSerializer)
noReferencesWithin<WireTransaction>()
register(ErrorOr::class.java)

View File

@ -1,15 +1,19 @@
package net.corda.irs.plugin
import net.corda.core.contracts.StateRef
import com.esotericsoftware.kryo.Kryo
import net.corda.core.contracts.*
import net.corda.core.crypto.Party
import net.corda.core.node.CordaPluginRegistry
import net.corda.irs.api.InterestRateSwapAPI
import net.corda.irs.contract.InterestRateSwap
import net.corda.irs.contract.*
import net.corda.irs.flows.AutoOfferFlow
import net.corda.irs.flows.ExitServerFlow
import net.corda.irs.flows.FixingFlow
import net.corda.irs.flows.UpdateBusinessDayFlow
import java.math.BigDecimal
import java.time.Duration
import java.time.LocalDate
import java.util.*
import java.util.function.Function
class IRSPlugin : CordaPluginRegistry() {
@ -20,8 +24,41 @@ class IRSPlugin : CordaPluginRegistry() {
override val servicePlugins = listOf(Function(FixingFlow::Service))
override val requiredFlows: Map<String, Set<String>> = mapOf(
AutoOfferFlow.Requester::class.java.name to setOf(InterestRateSwap.State::class.java.name),
UpdateBusinessDayFlow.Broadcast::class.java.name to setOf(java.time.LocalDate::class.java.name),
UpdateBusinessDayFlow.Broadcast::class.java.name to setOf(LocalDate::class.java.name),
ExitServerFlow.Broadcast::class.java.name to setOf(kotlin.Int::class.java.name),
FixingFlow.FixingRoleDecider::class.java.name to setOf(StateRef::class.java.name, Duration::class.java.name),
FixingFlow.Floater::class.java.name to setOf(Party::class.java.name, FixingFlow.FixingSession::class.java.name))
override fun registerRPCKryoTypes(kryo: Kryo): Boolean {
kryo.apply {
register(InterestRateSwap::class.java)
register(InterestRateSwap.State::class.java)
register(InterestRateSwap.FixedLeg::class.java)
register(InterestRateSwap.FloatingLeg::class.java)
register(InterestRateSwap.Calculation::class.java)
register(InterestRateSwap.Common::class.java)
register(Expression::class.java)
register(HashMap::class.java)
register(LinkedHashMap::class.java)
register(RatioUnit::class.java)
register(Tenor::class.java)
register(Tenor.TimeUnit::class.java)
register(BusinessCalendar::class.java)
register(Comparable::class.java)
register(ReferenceRate::class.java)
register(UnknownType::class.java)
register(DayCountBasisDay::class.java)
register(DayCountBasisYear::class.java)
register(FixedRate::class.java)
register(PercentageRatioUnit::class.java)
register(BigDecimal::class.java)
register(AccrualAdjustment::class.java)
register(Frequency::class.java)
register(PaymentRule::class.java)
register(DateRollConvention::class.java)
register(LocalDate::class.java)
register(FixingFlow.FixingSession::class.java)
}
return true
}
}