mirror of
https://github.com/corda/corda.git
synced 2025-06-23 09:25:36 +00:00
Merge remote-tracking branch 'open/master' into colljos-merge-160118
This commit is contained in:
@ -158,7 +158,7 @@ class NotaryFlow {
|
||||
*/
|
||||
data class TransactionParts(val id: SecureHash, val inputs: List<StateRef>, val timestamp: TimeWindow?, val notary: Party?)
|
||||
|
||||
class NotaryException(val error: NotaryError) : FlowException("Error response from Notary - $error")
|
||||
class NotaryException(val error: NotaryError) : FlowException("Unable to notarise: $error")
|
||||
|
||||
@CordaSerializable
|
||||
sealed class NotaryError {
|
||||
@ -166,7 +166,7 @@ sealed class NotaryError {
|
||||
override fun toString() = "One or more input states for transaction $txId have been used in another transaction"
|
||||
}
|
||||
|
||||
/** Thrown if the time specified in the [TimeWindow] command is outside the allowed tolerance. */
|
||||
/** Occurs when time specified in the [TimeWindow] command is outside the allowed tolerance. */
|
||||
object TimeWindowInvalid : NotaryError()
|
||||
|
||||
data class TransactionInvalid(val cause: Throwable) : NotaryError() {
|
||||
@ -174,4 +174,8 @@ sealed class NotaryError {
|
||||
}
|
||||
|
||||
object WrongNotary : NotaryError()
|
||||
|
||||
data class General(val cause: String): NotaryError() {
|
||||
override fun toString() = cause
|
||||
}
|
||||
}
|
||||
|
@ -242,10 +242,14 @@ private fun IntProgression.toSpliterator(): Spliterator.OfInt {
|
||||
}
|
||||
|
||||
fun IntProgression.stream(parallel: Boolean = false): IntStream = StreamSupport.intStream(toSpliterator(), parallel)
|
||||
|
||||
inline fun <reified T> Stream<out T>.toTypedArray() = toTypedArray(T::class.java)
|
||||
// When toArray has filled in the array, the component type is no longer T? but T (that may itself be nullable):
|
||||
inline fun <reified T> Stream<out T>.toTypedArray(): Array<T> = uncheckedCast(toArray { size -> arrayOfNulls<T>(size) })
|
||||
fun <T> Stream<out T>.toTypedArray(componentType: Class<T>): Array<T> = toArray { size ->
|
||||
uncheckedCast<Any, Array<T?>>(java.lang.reflect.Array.newInstance(componentType, size))
|
||||
}
|
||||
|
||||
fun <T> Stream<out T?>.filterNotNull(): Stream<T> = uncheckedCast(filter(Objects::nonNull))
|
||||
fun <K, V> Stream<out Pair<K, V>>.toMap(): Map<K, V> = collect<LinkedHashMap<K, V>>(::LinkedHashMap, { m, (k, v) -> m.put(k, v) }, { m, t -> m.putAll(t) })
|
||||
fun <T> Class<T>.castIfPossible(obj: Any): T? = if (isInstance(obj)) cast(obj) else null
|
||||
|
||||
/** Returns a [DeclaredField] wrapper around the declared (possibly non-public) static field of the receiver [Class]. */
|
||||
|
@ -78,6 +78,9 @@ abstract class TrustedAuthorityNotaryService : NotaryService() {
|
||||
log.warn("Notary conflicts for $txId: $conflicts")
|
||||
throw notaryException(txId, e)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
log.error("Internal error", e)
|
||||
throw NotaryException(NotaryError.General("Service unavailable, please try again later"))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -19,9 +19,9 @@ import net.corda.finance.flows.CashIssueFlow
|
||||
import net.corda.node.internal.SecureCordaRPCOps
|
||||
import net.corda.node.internal.StartedNode
|
||||
import net.corda.node.services.Permissions.Companion.startFlow
|
||||
import net.corda.nodeapi.internal.config.User
|
||||
import net.corda.testing.ALICE_NAME
|
||||
import net.corda.testing.BOB_NAME
|
||||
import net.corda.testing.node.User
|
||||
import net.corda.testing.contracts.DummyContract
|
||||
import net.corda.testing.contracts.DummyContractV2
|
||||
import net.corda.testing.node.internal.RPCDriverDSL
|
||||
|
@ -3,6 +3,7 @@ package net.corda.core.internal
|
||||
import org.assertj.core.api.Assertions
|
||||
import org.junit.Assert.assertArrayEquals
|
||||
import org.junit.Test
|
||||
import java.io.Serializable
|
||||
import java.util.stream.IntStream
|
||||
import java.util.stream.Stream
|
||||
import kotlin.test.assertEquals
|
||||
@ -87,5 +88,17 @@ class InternalUtilsTest {
|
||||
val b: Array<String?> = Stream.of("one", "two", null).toTypedArray()
|
||||
assertEquals(Array<String?>::class.java, b.javaClass)
|
||||
assertArrayEquals(arrayOf("one", "two", null), b)
|
||||
val c: Array<CharSequence> = Stream.of("x", "y").toTypedArray(CharSequence::class.java)
|
||||
assertEquals(Array<CharSequence>::class.java, c.javaClass)
|
||||
assertArrayEquals(arrayOf("x", "y"), c)
|
||||
val d: Array<CharSequence?> = Stream.of("x", "y", null).toTypedArray(uncheckedCast(CharSequence::class.java))
|
||||
assertEquals(Array<CharSequence?>::class.java, d.javaClass)
|
||||
assertArrayEquals(arrayOf("x", "y", null), d)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Stream of Pairs toMap works`() {
|
||||
val m: Map<Comparable<*>, Serializable> = Stream.of<Pair<Comparable<*>, Serializable>>("x" to "y", 0 to 1, "x" to '2').toMap()
|
||||
assertEquals<Map<*, *>>(mapOf("x" to '2', 0 to 1), m)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user