Moved the various extension methods for creating Durations from Utils.kt to KotlinUtils.kt

This commit is contained in:
Shams Asari 2017-07-17 20:24:50 +01:00
parent 65ce5fec4b
commit 561a329064
43 changed files with 136 additions and 105 deletions

View File

@ -10,7 +10,7 @@ import net.corda.core.messaging.StateMachineTransactionMapping
import net.corda.core.messaging.StateMachineUpdate import net.corda.core.messaging.StateMachineUpdate
import net.corda.core.node.services.NetworkMapCache.MapChange import net.corda.core.node.services.NetworkMapCache.MapChange
import net.corda.core.node.services.Vault import net.corda.core.node.services.Vault
import net.corda.core.seconds import net.corda.core.utilities.seconds
import net.corda.core.transactions.SignedTransaction import net.corda.core.transactions.SignedTransaction
import net.corda.core.utilities.NetworkHostAndPort import net.corda.core.utilities.NetworkHostAndPort
import rx.Observable import rx.Observable

View File

@ -12,8 +12,8 @@ import net.corda.core.crypto.random63BitValue
import net.corda.core.future import net.corda.core.future
import net.corda.core.getOrThrow import net.corda.core.getOrThrow
import net.corda.core.messaging.RPCOps import net.corda.core.messaging.RPCOps
import net.corda.core.millis import net.corda.core.utilities.millis
import net.corda.core.seconds import net.corda.core.utilities.seconds
import net.corda.core.utilities.NetworkHostAndPort import net.corda.core.utilities.NetworkHostAndPort
import net.corda.core.utilities.Try import net.corda.core.utilities.Try
import net.corda.node.services.messaging.RPCServerConfiguration import net.corda.node.services.messaging.RPCServerConfiguration

View File

@ -2,9 +2,9 @@ package net.corda.client.rpc.internal
import net.corda.core.logElapsedTime import net.corda.core.logElapsedTime
import net.corda.core.messaging.RPCOps import net.corda.core.messaging.RPCOps
import net.corda.core.minutes import net.corda.core.utilities.minutes
import net.corda.core.crypto.random63BitValue import net.corda.core.crypto.random63BitValue
import net.corda.core.seconds import net.corda.core.utilities.seconds
import net.corda.core.utilities.NetworkHostAndPort import net.corda.core.utilities.NetworkHostAndPort
import net.corda.core.utilities.loggerFor import net.corda.core.utilities.loggerFor
import net.corda.nodeapi.ArtemisTcpTransport.Companion.tcpTransport import net.corda.nodeapi.ArtemisTcpTransport.Companion.tcpTransport

View File

@ -13,7 +13,7 @@ import net.corda.core.messaging.*
import net.corda.core.node.NodeInfo import net.corda.core.node.NodeInfo
import net.corda.core.node.services.Vault import net.corda.core.node.services.Vault
import net.corda.core.node.services.vault.* import net.corda.core.node.services.vault.*
import net.corda.core.seconds import net.corda.core.utilities.seconds
import net.corda.core.utilities.OpaqueBytes import net.corda.core.utilities.OpaqueBytes
import net.corda.core.utilities.loggerFor import net.corda.core.utilities.loggerFor
import net.corda.flows.CashIssueFlow import net.corda.flows.CashIssueFlow

View File

@ -3,7 +3,7 @@ package net.corda.client.rpc
import net.corda.client.rpc.internal.RPCClientConfiguration import net.corda.client.rpc.internal.RPCClientConfiguration
import net.corda.core.future import net.corda.core.future
import net.corda.core.messaging.RPCOps import net.corda.core.messaging.RPCOps
import net.corda.core.millis import net.corda.core.utilities.millis
import net.corda.core.crypto.random63BitValue import net.corda.core.crypto.random63BitValue
import net.corda.core.serialization.CordaSerializable import net.corda.core.serialization.CordaSerializable
import net.corda.node.services.messaging.RPCServerConfiguration import net.corda.node.services.messaging.RPCServerConfiguration

View File

@ -3,12 +3,11 @@ package net.corda.client.rpc
import com.google.common.base.Stopwatch import com.google.common.base.Stopwatch
import net.corda.client.rpc.internal.RPCClientConfiguration import net.corda.client.rpc.internal.RPCClientConfiguration
import net.corda.core.messaging.RPCOps import net.corda.core.messaging.RPCOps
import net.corda.core.minutes import net.corda.core.utilities.minutes
import net.corda.core.seconds import net.corda.core.utilities.seconds
import net.corda.core.utilities.div import net.corda.core.utilities.div
import net.corda.node.services.messaging.RPCServerConfiguration import net.corda.node.services.messaging.RPCServerConfiguration
import net.corda.testing.RPCDriverExposedDSLInterface import net.corda.testing.RPCDriverExposedDSLInterface
import net.corda.testing.driver.ShutdownManager
import net.corda.testing.measure import net.corda.testing.measure
import net.corda.testing.performance.startPublishingFixedRateInjector import net.corda.testing.performance.startPublishingFixedRateInjector
import net.corda.testing.performance.startReporter import net.corda.testing.performance.startReporter

View File

@ -36,14 +36,6 @@ import java.util.zip.ZipOutputStream
import kotlin.concurrent.withLock import kotlin.concurrent.withLock
import kotlin.reflect.KClass import kotlin.reflect.KClass
val Int.days: Duration get() = Duration.ofDays(this.toLong())
@Suppress("unused") // It's here for completeness
val Int.hours: Duration get() = Duration.ofHours(this.toLong())
val Int.minutes: Duration get() = Duration.ofMinutes(this.toLong())
val Int.seconds: Duration get() = Duration.ofSeconds(this.toLong())
val Int.millis: Duration get() = Duration.ofMillis(this.toLong())
// TODO: Review by EOY2016 if we ever found these utilities helpful. // TODO: Review by EOY2016 if we ever found these utilities helpful.
val Int.bd: BigDecimal get() = BigDecimal(this) val Int.bd: BigDecimal get() = BigDecimal(this)
val Double.bd: BigDecimal get() = BigDecimal(this) val Double.bd: BigDecimal get() = BigDecimal(this)

View File

@ -1,5 +1,7 @@
package net.corda.core.crypto package net.corda.core.crypto
import net.corda.core.utilities.days
import net.corda.core.utilities.millis
import org.bouncycastle.asn1.ASN1Encodable import org.bouncycastle.asn1.ASN1Encodable
import org.bouncycastle.asn1.x500.X500Name import org.bouncycastle.asn1.x500.X500Name
import org.bouncycastle.asn1.x500.X500NameBuilder import org.bouncycastle.asn1.x500.X500NameBuilder
@ -33,7 +35,7 @@ object X509Utilities {
val CORDA_CLIENT_TLS = "cordaclienttls" val CORDA_CLIENT_TLS = "cordaclienttls"
val CORDA_CLIENT_CA = "cordaclientca" val CORDA_CLIENT_CA = "cordaclientca"
private val DEFAULT_VALIDITY_WINDOW = Pair(Duration.ofMillis(0), Duration.ofDays(365 * 10)) private val DEFAULT_VALIDITY_WINDOW = Pair(0.millis, 3650.days)
/** /**
* Helper function to return the latest out of an instant and an optional date. * Helper function to return the latest out of an instant and an optional date.
*/ */

View File

@ -1,7 +1,7 @@
package net.corda.core.node.services package net.corda.core.node.services
import net.corda.core.contracts.TimeWindow import net.corda.core.contracts.TimeWindow
import net.corda.core.seconds import net.corda.core.utilities.seconds
import net.corda.core.until import net.corda.core.until
import java.time.Clock import java.time.Clock
import java.time.Duration import java.time.Duration

View File

@ -3,8 +3,15 @@ package net.corda.core.utilities
import net.corda.core.serialization.CordaSerializable import net.corda.core.serialization.CordaSerializable
import org.slf4j.Logger import org.slf4j.Logger
import org.slf4j.LoggerFactory import org.slf4j.LoggerFactory
import java.time.Duration
import kotlin.reflect.KProperty import kotlin.reflect.KProperty
//
// READ ME FIRST:
// This is a collection of public utilities useful only for Kotlin code. If you're looking to add a public utility that
// is also relevant to Java then put it in Utils.kt.
//
/** /**
* Get the [Logger] for a class using the syntax * Get the [Logger] for a class using the syntax
* *
@ -22,6 +29,36 @@ inline fun Logger.debug(msg: () -> String) {
if (isDebugEnabled) debug(msg()) if (isDebugEnabled) debug(msg())
} }
/**
* Extension method for easier construction of [Duration]s in terms of integer days: `val twoDays = 2.days`.
* @see Duration.ofDays
*/
inline val Int.days: Duration get() = Duration.ofDays(toLong())
/**
* Extension method for easier construction of [Duration]s in terms of integer hours: `val twoHours = 2.hours`.
* @see Duration.ofHours
*/
inline val Int.hours: Duration get() = Duration.ofHours(toLong())
/**
* Extension method for easier construction of [Duration]s in terms of integer minutes: `val twoMinutes = 2.minutes`.
* @see Duration.ofMinutes
*/
inline val Int.minutes: Duration get() = Duration.ofMinutes(toLong())
/**
* Extension method for easier construction of [Duration]s in terms of integer seconds: `val twoSeconds = 2.seconds`.
* @see Duration.ofSeconds
*/
inline val Int.seconds: Duration get() = Duration.ofSeconds(toLong())
/**
* Extension method for easier construction of [Duration]s in terms of integer milliseconds: `val twoMillis = 2.millis`.
* @see Duration.ofMillis
*/
inline val Int.millis: Duration get() = Duration.ofMillis(toLong())
/** /**
* A simple wrapper that enables the use of Kotlin's `val x by transient { ... }` syntax. Such a property * A simple wrapper that enables the use of Kotlin's `val x by transient { ... }` syntax. Such a property
* will not be serialized, and if it's missing (or the first time it's accessed), the initializer will be * will not be serialized, and if it's missing (or the first time it's accessed), the initializer will be

View File

@ -1,7 +1,7 @@
package net.corda.core.node.services package net.corda.core.node.services
import net.corda.core.contracts.TimeWindow import net.corda.core.contracts.TimeWindow
import net.corda.core.seconds import net.corda.core.utilities.seconds
import org.junit.Test import org.junit.Test
import java.time.Clock import java.time.Clock
import java.time.Instant import java.time.Instant

View File

@ -3,7 +3,7 @@ package net.corda.core.serialization
import net.corda.core.contracts.* import net.corda.core.contracts.*
import net.corda.core.crypto.SecureHash import net.corda.core.crypto.SecureHash
import net.corda.core.identity.AbstractParty import net.corda.core.identity.AbstractParty
import net.corda.core.seconds import net.corda.core.utilities.seconds
import net.corda.core.transactions.TransactionBuilder import net.corda.core.transactions.TransactionBuilder
import net.corda.testing.* import net.corda.testing.*
import net.corda.testing.node.MockServices import net.corda.testing.node.MockServices

View File

@ -20,13 +20,13 @@ import net.corda.core.transactions.WireTransaction
import net.corda.core.utilities.ProgressTracker import net.corda.core.utilities.ProgressTracker
import net.corda.core.utilities.ProgressTracker.Step import net.corda.core.utilities.ProgressTracker.Step
import net.corda.core.utilities.UntrustworthyData import net.corda.core.utilities.UntrustworthyData
import net.corda.core.utilities.seconds
import net.corda.core.utilities.unwrap import net.corda.core.utilities.unwrap
import net.corda.testing.DUMMY_PUBKEY_1 import net.corda.testing.DUMMY_PUBKEY_1
import net.corda.testing.contracts.DummyContract import net.corda.testing.contracts.DummyContract
import net.corda.testing.contracts.DummyState import net.corda.testing.contracts.DummyState
import org.bouncycastle.asn1.x500.X500Name import org.bouncycastle.asn1.x500.X500Name
import java.security.PublicKey import java.security.PublicKey
import java.time.Duration
import java.time.Instant import java.time.Instant
// We group our two flows inside a singleton object to indicate that they work // We group our two flows inside a singleton object to indicate that they work
@ -280,11 +280,11 @@ object FlowCookbook {
// We can also define a time window as an ``Instant`` +/- a time // We can also define a time window as an ``Instant`` +/- a time
// tolerance (e.g. 30 seconds): // tolerance (e.g. 30 seconds):
// DOCSTART 42 // DOCSTART 42
val ourTimeWindow2: TimeWindow = TimeWindow.withTolerance(Instant.now(), Duration.ofSeconds(30)) val ourTimeWindow2: TimeWindow = TimeWindow.withTolerance(Instant.now(), 30.seconds)
// DOCEND 42 // DOCEND 42
// Or as a start-time plus a duration: // Or as a start-time plus a duration:
// DOCSTART 43 // DOCSTART 43
val ourTimeWindow3: TimeWindow = TimeWindow.fromStartAndDuration(Instant.now(), Duration.ofSeconds(30)) val ourTimeWindow3: TimeWindow = TimeWindow.fromStartAndDuration(Instant.now(), 30.seconds)
// DOCEND 43 // DOCEND 43
/**----------------------- /**-----------------------
@ -326,7 +326,7 @@ object FlowCookbook {
// DOCEND 44 // DOCEND 44
// Or as a start time plus a duration (e.g. 45 seconds): // Or as a start time plus a duration (e.g. 45 seconds):
// DOCSTART 45 // DOCSTART 45
regTxBuilder.setTimeWindow(serviceHub.clock.instant(), Duration.ofSeconds(45)) regTxBuilder.setTimeWindow(serviceHub.clock.instant(), 45.seconds)
// DOCEND 45 // DOCEND 45
/**---------------------- /**----------------------

View File

@ -15,9 +15,9 @@ import net.corda.core.node.ServiceHub
import net.corda.core.node.services.linearHeadsOfType import net.corda.core.node.services.linearHeadsOfType
import net.corda.core.serialization.CordaSerializable import net.corda.core.serialization.CordaSerializable
import net.corda.core.transactions.SignedTransaction import net.corda.core.transactions.SignedTransaction
import net.corda.core.utilities.seconds
import net.corda.core.utilities.unwrap import net.corda.core.utilities.unwrap
import java.security.PublicKey import java.security.PublicKey
import java.time.Duration
// DOCSTART 1 // DOCSTART 1
// Helper method to locate the latest Vault version of a LinearState from a possibly out of date StateRef // Helper method to locate the latest Vault version of a LinearState from a possibly out of date StateRef
@ -123,7 +123,7 @@ class SubmitTradeApprovalFlow(val tradeId: String,
// Create the TransactionBuilder and populate with the new state. // Create the TransactionBuilder and populate with the new state.
val tx = TransactionType.General.Builder(notary) val tx = TransactionType.General.Builder(notary)
.withItems(tradeProposal, Command(TradeApprovalContract.Commands.Issue(), listOf(tradeProposal.source.owningKey))) .withItems(tradeProposal, Command(TradeApprovalContract.Commands.Issue(), listOf(tradeProposal.source.owningKey)))
tx.setTimeWindow(serviceHub.clock.instant(), Duration.ofSeconds(60)) tx.setTimeWindow(serviceHub.clock.instant(), 60.seconds)
// We can automatically sign as there is no untrusted data. // We can automatically sign as there is no untrusted data.
val signedTx = serviceHub.signInitialTransaction(tx) val signedTx = serviceHub.signInitialTransaction(tx)
// Notarise and distribute. // Notarise and distribute.
@ -184,7 +184,7 @@ class SubmitCompletionFlow(val ref: StateRef, val verdict: WorkflowState) : Flow
newState, newState,
Command(TradeApprovalContract.Commands.Completed(), Command(TradeApprovalContract.Commands.Completed(),
listOf(serviceHub.myInfo.legalIdentity.owningKey, latestRecord.state.data.source.owningKey))) listOf(serviceHub.myInfo.legalIdentity.owningKey, latestRecord.state.data.source.owningKey)))
tx.setTimeWindow(serviceHub.clock.instant(), Duration.ofSeconds(60)) tx.setTimeWindow(serviceHub.clock.instant(), 60.seconds)
// We can sign this transaction immediately as we have already checked all the fields and the decision // We can sign this transaction immediately as we have already checked all the fields and the decision
// is ultimately a manual one from the caller. // is ultimately a manual one from the caller.
// As a SignedTransaction we can pass the data around certain that it cannot be modified, // As a SignedTransaction we can pass the data around certain that it cannot be modified,

View File

@ -10,15 +10,15 @@ import net.corda.core.contracts.*
import net.corda.core.contracts.clauses.* import net.corda.core.contracts.clauses.*
import net.corda.core.crypto.SecureHash import net.corda.core.crypto.SecureHash
import net.corda.core.crypto.entropyToKeyPair import net.corda.core.crypto.entropyToKeyPair
import net.corda.core.crypto.testing.NULL_PARTY import net.corda.core.crypto.random63BitValue
import net.corda.core.identity.AbstractParty import net.corda.core.identity.AbstractParty
import net.corda.core.identity.AnonymousParty import net.corda.core.identity.AnonymousParty
import net.corda.core.identity.Party import net.corda.core.identity.Party
import net.corda.core.crypto.random63BitValue
import net.corda.core.serialization.CordaSerializable import net.corda.core.serialization.CordaSerializable
import net.corda.core.transactions.TransactionBuilder import net.corda.core.transactions.TransactionBuilder
import net.corda.core.utilities.Emoji import net.corda.core.utilities.Emoji
import net.corda.core.utilities.NonEmptySet import net.corda.core.utilities.NonEmptySet
import net.corda.core.utilities.seconds
import org.bouncycastle.asn1.x500.X500Name import org.bouncycastle.asn1.x500.X500Name
import java.math.BigInteger import java.math.BigInteger
import java.security.PublicKey import java.security.PublicKey
@ -202,7 +202,7 @@ class Obligation<P : Any> : Contract {
"amount in settle command ${command.value.amount} matches settled total $totalAmountSettled" using (command.value.amount == totalAmountSettled) "amount in settle command ${command.value.amount} matches settled total $totalAmountSettled" using (command.value.amount == totalAmountSettled)
"signatures are present from all obligors" using command.signers.containsAll(requiredSigners) "signatures are present from all obligors" using command.signers.containsAll(requiredSigners)
"there are no zero sized inputs" using inputs.none { it.amount.quantity == 0L } "there are no zero sized inputs" using inputs.none { it.amount.quantity == 0L }
"at obligor ${obligor} the obligations after settlement balance" using "at obligor $obligor the obligations after settlement balance" using
(inputAmount == outputAmount + Amount(totalPenniesSettled, groupingKey)) (inputAmount == outputAmount + Amount(totalPenniesSettled, groupingKey))
} }
return setOf(command.value) return setOf(command.value)
@ -264,7 +264,7 @@ class Obligation<P : Any> : Contract {
/** When the contract must be settled by. */ /** When the contract must be settled by. */
val dueBefore: Instant, val dueBefore: Instant,
val timeTolerance: Duration = Duration.ofSeconds(30) val timeTolerance: Duration = 30.seconds
) { ) {
val product: P val product: P
get() = acceptableIssuedProducts.map { it.product }.toSet().single() get() = acceptableIssuedProducts.map { it.product }.toSet().single()

View File

@ -12,7 +12,7 @@ import net.corda.core.identity.AbstractParty
import net.corda.core.identity.Party import net.corda.core.identity.Party
import net.corda.core.node.NodeInfo import net.corda.core.node.NodeInfo
import net.corda.core.node.services.ServiceType import net.corda.core.node.services.ServiceType
import net.corda.core.seconds import net.corda.core.utilities.seconds
import net.corda.core.serialization.CordaSerializable import net.corda.core.serialization.CordaSerializable
import net.corda.core.transactions.SignedTransaction import net.corda.core.transactions.SignedTransaction
import net.corda.core.transactions.TransactionBuilder import net.corda.core.transactions.TransactionBuilder

View File

@ -8,7 +8,7 @@ import net.corda.core.identity.AbstractParty
import net.corda.core.identity.AnonymousParty import net.corda.core.identity.AnonymousParty
import net.corda.core.identity.Party import net.corda.core.identity.Party
import net.corda.core.node.NodeInfo import net.corda.core.node.NodeInfo
import net.corda.core.seconds import net.corda.core.utilities.seconds
import net.corda.core.serialization.CordaSerializable import net.corda.core.serialization.CordaSerializable
import net.corda.core.transactions.SignedTransaction import net.corda.core.transactions.SignedTransaction
import net.corda.core.transactions.TransactionBuilder import net.corda.core.transactions.TransactionBuilder

View File

@ -3,12 +3,12 @@ package net.corda.contracts
import net.corda.contracts.asset.* import net.corda.contracts.asset.*
import net.corda.testing.contracts.fillWithSomeTestCash import net.corda.testing.contracts.fillWithSomeTestCash
import net.corda.core.contracts.* import net.corda.core.contracts.*
import net.corda.core.days import net.corda.core.utilities.days
import net.corda.core.identity.AnonymousParty import net.corda.core.identity.AnonymousParty
import net.corda.core.identity.Party import net.corda.core.identity.Party
import net.corda.core.node.services.Vault import net.corda.core.node.services.Vault
import net.corda.core.node.services.VaultService import net.corda.core.node.services.VaultService
import net.corda.core.seconds import net.corda.core.utilities.seconds
import net.corda.core.transactions.SignedTransaction import net.corda.core.transactions.SignedTransaction
import net.corda.node.utilities.configureDatabase import net.corda.node.utilities.configureDatabase
import net.corda.testing.* import net.corda.testing.*

View File

@ -6,16 +6,16 @@ import net.corda.contracts.asset.Obligation.Lifecycle
import net.corda.core.contracts.* import net.corda.core.contracts.*
import net.corda.core.crypto.SecureHash import net.corda.core.crypto.SecureHash
import net.corda.core.crypto.testing.NULL_PARTY import net.corda.core.crypto.testing.NULL_PARTY
import net.corda.core.hours
import net.corda.core.identity.AbstractParty import net.corda.core.identity.AbstractParty
import net.corda.core.identity.AnonymousParty import net.corda.core.identity.AnonymousParty
import net.corda.core.utilities.NonEmptySet import net.corda.core.utilities.NonEmptySet
import net.corda.core.utilities.OpaqueBytes import net.corda.core.utilities.OpaqueBytes
import net.corda.core.utilities.days
import net.corda.core.utilities.hours
import net.corda.testing.* import net.corda.testing.*
import net.corda.testing.contracts.DummyState import net.corda.testing.contracts.DummyState
import net.corda.testing.node.MockServices import net.corda.testing.node.MockServices
import org.junit.Test import org.junit.Test
import java.time.Duration
import java.time.Instant import java.time.Instant
import java.time.temporal.ChronoUnit import java.time.temporal.ChronoUnit
import java.util.* import java.util.*
@ -272,7 +272,7 @@ class ObligationTests {
@Test @Test
fun `generate set lifecycle`() { fun `generate set lifecycle`() {
// We don't actually verify the states, this is just here to make things look sensible // We don't actually verify the states, this is just here to make things look sensible
val dueBefore = TEST_TX_TIME - Duration.ofDays(7) val dueBefore = TEST_TX_TIME - 7.days
// Generate a transaction issuing the obligation // Generate a transaction issuing the obligation
var tx = TransactionType.General.Builder(null).apply { var tx = TransactionType.General.Builder(null).apply {
@ -534,8 +534,8 @@ class ObligationTests {
} }
// Try defaulting an obligation due in the future // Try defaulting an obligation due in the future
val pastTestTime = TEST_TX_TIME - Duration.ofDays(7) val pastTestTime = TEST_TX_TIME - 7.days
val futureTestTime = TEST_TX_TIME + Duration.ofDays(7) val futureTestTime = TEST_TX_TIME + 7.days
transaction("Settlement") { transaction("Settlement") {
input(oneMillionDollars.OBLIGATION between Pair(ALICE, BOB) `at` futureTestTime) input(oneMillionDollars.OBLIGATION between Pair(ALICE, BOB) `at` futureTestTime)
output("Alice's defaulted $1,000,000 obligation to Bob") { (oneMillionDollars.OBLIGATION between Pair(ALICE, BOB) `at` futureTestTime).copy(lifecycle = Lifecycle.DEFAULTED) } output("Alice's defaulted $1,000,000 obligation to Bob") { (oneMillionDollars.OBLIGATION between Pair(ALICE, BOB) `at` futureTestTime).copy(lifecycle = Lifecycle.DEFAULTED) }

View File

@ -7,7 +7,7 @@ import net.corda.core.contracts.DOLLARS
import net.corda.core.flows.FlowLogic import net.corda.core.flows.FlowLogic
import net.corda.core.flows.StartableByRPC import net.corda.core.flows.StartableByRPC
import net.corda.core.messaging.startFlow import net.corda.core.messaging.startFlow
import net.corda.core.minutes import net.corda.core.utilities.minutes
import net.corda.core.node.services.ServiceInfo import net.corda.core.node.services.ServiceInfo
import net.corda.core.utilities.OpaqueBytes import net.corda.core.utilities.OpaqueBytes
import net.corda.core.utilities.div import net.corda.core.utilities.div

View File

@ -10,6 +10,7 @@ import net.corda.core.node.services.ServiceInfo
import net.corda.core.serialization.CordaSerializable import net.corda.core.serialization.CordaSerializable
import net.corda.core.serialization.deserialize import net.corda.core.serialization.deserialize
import net.corda.core.serialization.serialize import net.corda.core.serialization.serialize
import net.corda.core.utilities.seconds
import net.corda.node.internal.Node import net.corda.node.internal.Node
import net.corda.node.services.api.DEFAULT_SESSION_ID import net.corda.node.services.api.DEFAULT_SESSION_ID
import net.corda.node.services.messaging.* import net.corda.node.services.messaging.*

View File

@ -6,7 +6,7 @@ import net.corda.core.crypto.cert
import net.corda.core.crypto.random63BitValue import net.corda.core.crypto.random63BitValue
import net.corda.core.getOrThrow import net.corda.core.getOrThrow
import net.corda.core.node.NodeInfo import net.corda.core.node.NodeInfo
import net.corda.core.seconds import net.corda.core.utilities.seconds
import net.corda.core.utilities.NonEmptySet import net.corda.core.utilities.NonEmptySet
import net.corda.node.internal.NetworkMapInfo import net.corda.node.internal.NetworkMapInfo
import net.corda.node.services.config.configureWithDevSSLCertificate import net.corda.node.services.config.configureWithDevSSLCertificate

View File

@ -8,11 +8,7 @@ import net.corda.core.*
import net.corda.core.messaging.RPCOps import net.corda.core.messaging.RPCOps
import net.corda.core.node.ServiceHub import net.corda.core.node.ServiceHub
import net.corda.core.node.services.ServiceInfo import net.corda.core.node.services.ServiceInfo
import net.corda.core.seconds import net.corda.core.utilities.*
import net.corda.core.utilities.NetworkHostAndPort
import net.corda.core.utilities.loggerFor
import net.corda.core.utilities.parseNetworkHostAndPort
import net.corda.core.utilities.trace
import net.corda.node.VersionInfo import net.corda.node.VersionInfo
import net.corda.node.serialization.NodeClock import net.corda.node.serialization.NodeClock
import net.corda.node.services.RPCUserService import net.corda.node.services.RPCUserService

View File

@ -4,17 +4,15 @@ import net.corda.core.crypto.*
import net.corda.core.identity.AnonymousParty import net.corda.core.identity.AnonymousParty
import net.corda.core.identity.PartyAndCertificate import net.corda.core.identity.PartyAndCertificate
import net.corda.core.node.services.IdentityService import net.corda.core.node.services.IdentityService
import net.corda.core.utilities.days
import net.corda.flows.AnonymisedIdentity import net.corda.flows.AnonymisedIdentity
import org.bouncycastle.cert.X509CertificateHolder
import org.bouncycastle.operator.ContentSigner import org.bouncycastle.operator.ContentSigner
import java.security.KeyPair import java.security.KeyPair
import java.security.PublicKey import java.security.PublicKey
import java.security.Security import java.security.Security
import java.security.cert.CertPath
import java.security.cert.CertificateFactory import java.security.cert.CertificateFactory
import java.security.cert.X509Certificate import java.security.cert.X509Certificate
import java.time.Duration import java.time.Duration
import java.util.*
/** /**
* Generates a new random [KeyPair], adds it to the internal key storage, then generates a corresponding * Generates a new random [KeyPair], adds it to the internal key storage, then generates a corresponding
@ -33,7 +31,7 @@ fun freshCertificate(identityService: IdentityService,
issuerSigner: ContentSigner, issuerSigner: ContentSigner,
revocationEnabled: Boolean = false): AnonymisedIdentity { revocationEnabled: Boolean = false): AnonymisedIdentity {
val issuerCertificate = issuer.certificate val issuerCertificate = issuer.certificate
val window = X509Utilities.getCertificateValidityWindow(Duration.ZERO, Duration.ofDays(10 * 365), issuerCertificate) val window = X509Utilities.getCertificateValidityWindow(Duration.ZERO, 3650.days, issuerCertificate)
val ourCertificate = Crypto.createCertificate(CertificateType.IDENTITY, issuerCertificate.subject, issuerSigner, issuer.name, subjectPublicKey, window) val ourCertificate = Crypto.createCertificate(CertificateType.IDENTITY, issuerCertificate.subject, issuerSigner, issuer.name, subjectPublicKey, window)
val certFactory = CertificateFactory.getInstance("X509") val certFactory = CertificateFactory.getInstance("X509")
val ourCertPath = certFactory.generateCertPath(listOf(ourCertificate.cert) + issuer.certPath.certificates) val ourCertPath = certFactory.generateCertPath(listOf(ourCertificate.cert) + issuer.certPath.certificates)

View File

@ -11,9 +11,7 @@ import net.corda.core.internal.div
import net.corda.core.node.NodeInfo import net.corda.core.node.NodeInfo
import net.corda.core.node.services.NetworkMapCache import net.corda.core.node.services.NetworkMapCache
import net.corda.core.node.services.NetworkMapCache.MapChange import net.corda.core.node.services.NetworkMapCache.MapChange
import net.corda.core.utilities.NetworkHostAndPort import net.corda.core.utilities.*
import net.corda.core.utilities.debug
import net.corda.core.utilities.loggerFor
import net.corda.node.internal.Node import net.corda.node.internal.Node
import net.corda.node.services.RPCUserService import net.corda.node.services.RPCUserService
import net.corda.node.services.config.NodeConfiguration import net.corda.node.services.config.NodeConfiguration

View File

@ -14,7 +14,7 @@ import com.google.common.collect.SetMultimap
import com.google.common.util.concurrent.ThreadFactoryBuilder import com.google.common.util.concurrent.ThreadFactoryBuilder
import net.corda.core.crypto.random63BitValue import net.corda.core.crypto.random63BitValue
import net.corda.core.messaging.RPCOps import net.corda.core.messaging.RPCOps
import net.corda.core.seconds import net.corda.core.utilities.seconds
import net.corda.core.serialization.KryoPoolWithContext import net.corda.core.serialization.KryoPoolWithContext
import net.corda.core.utilities.* import net.corda.core.utilities.*
import net.corda.node.services.RPCUserService import net.corda.node.services.RPCUserService

View File

@ -1,6 +1,5 @@
package net.corda.node.utilities.registration package net.corda.node.utilities.registration
import net.corda.core.*
import net.corda.core.crypto.CertificateType import net.corda.core.crypto.CertificateType
import net.corda.core.crypto.Crypto import net.corda.core.crypto.Crypto
import net.corda.core.crypto.X509Utilities import net.corda.core.crypto.X509Utilities
@ -9,6 +8,7 @@ import net.corda.core.crypto.X509Utilities.CORDA_CLIENT_TLS
import net.corda.core.crypto.X509Utilities.CORDA_ROOT_CA import net.corda.core.crypto.X509Utilities.CORDA_ROOT_CA
import net.corda.core.crypto.cert import net.corda.core.crypto.cert
import net.corda.core.internal.* import net.corda.core.internal.*
import net.corda.core.utilities.seconds
import net.corda.node.services.config.NodeConfiguration import net.corda.node.services.config.NodeConfiguration
import net.corda.node.utilities.* import net.corda.node.utilities.*
import org.bouncycastle.cert.path.CertPath import org.bouncycastle.cert.path.CertPath

View File

@ -8,7 +8,6 @@ import net.corda.core.contracts.*
import net.corda.core.crypto.DigitalSignature import net.corda.core.crypto.DigitalSignature
import net.corda.core.crypto.SecureHash import net.corda.core.crypto.SecureHash
import net.corda.core.crypto.sign import net.corda.core.crypto.sign
import net.corda.core.crypto.toStringShort
import net.corda.core.flows.FlowLogic import net.corda.core.flows.FlowLogic
import net.corda.core.flows.InitiatedBy import net.corda.core.flows.InitiatedBy
import net.corda.core.flows.InitiatingFlow import net.corda.core.flows.InitiatingFlow
@ -27,6 +26,7 @@ import net.corda.core.serialization.serialize
import net.corda.core.transactions.SignedTransaction import net.corda.core.transactions.SignedTransaction
import net.corda.core.transactions.TransactionBuilder import net.corda.core.transactions.TransactionBuilder
import net.corda.core.transactions.WireTransaction import net.corda.core.transactions.WireTransaction
import net.corda.core.utilities.days
import net.corda.core.utilities.toNonEmptySet import net.corda.core.utilities.toNonEmptySet
import net.corda.core.utilities.unwrap import net.corda.core.utilities.unwrap
import net.corda.flows.TwoPartyTradeFlow.Buyer import net.corda.flows.TwoPartyTradeFlow.Buyer

View File

@ -6,7 +6,7 @@ import net.corda.core.crypto.generateKeyPair
import net.corda.core.getOrThrow import net.corda.core.getOrThrow
import net.corda.core.identity.Party import net.corda.core.identity.Party
import net.corda.core.node.services.ServiceInfo import net.corda.core.node.services.ServiceInfo
import net.corda.core.seconds import net.corda.core.utilities.seconds
import net.corda.core.transactions.WireTransaction import net.corda.core.transactions.WireTransaction
import net.corda.core.flows.NotaryChangeFlow import net.corda.core.flows.NotaryChangeFlow
import net.corda.core.flows.StateReplacementException import net.corda.core.flows.StateReplacementException

View File

@ -1,7 +1,7 @@
package net.corda.node.services.events package net.corda.node.services.events
import net.corda.core.contracts.* import net.corda.core.contracts.*
import net.corda.core.days import net.corda.core.utilities.days
import net.corda.core.flows.FlowLogic import net.corda.core.flows.FlowLogic
import net.corda.core.flows.FlowLogicRef import net.corda.core.flows.FlowLogicRef
import net.corda.core.flows.FlowLogicRefFactory import net.corda.core.flows.FlowLogicRefFactory

View File

@ -10,7 +10,7 @@ import net.corda.core.flows.NotaryException
import net.corda.core.flows.NotaryFlow import net.corda.core.flows.NotaryFlow
import net.corda.core.getOrThrow import net.corda.core.getOrThrow
import net.corda.core.node.services.ServiceInfo import net.corda.core.node.services.ServiceInfo
import net.corda.core.seconds import net.corda.core.utilities.seconds
import net.corda.core.transactions.SignedTransaction import net.corda.core.transactions.SignedTransaction
import net.corda.node.internal.AbstractNode import net.corda.node.internal.AbstractNode
import net.corda.node.services.network.NetworkMapService import net.corda.node.services.network.NetworkMapService

View File

@ -8,12 +8,12 @@ import net.corda.contracts.asset.DUMMY_CASH_ISSUER
import net.corda.core.contracts.* import net.corda.core.contracts.*
import net.corda.core.crypto.entropyToKeyPair import net.corda.core.crypto.entropyToKeyPair
import net.corda.core.crypto.toBase58String import net.corda.core.crypto.toBase58String
import net.corda.core.days import net.corda.core.utilities.days
import net.corda.core.identity.Party import net.corda.core.identity.Party
import net.corda.core.node.services.* import net.corda.core.node.services.*
import net.corda.core.node.services.vault.* import net.corda.core.node.services.vault.*
import net.corda.core.node.services.vault.QueryCriteria.* import net.corda.core.node.services.vault.QueryCriteria.*
import net.corda.core.seconds import net.corda.core.utilities.seconds
import net.corda.core.transactions.SignedTransaction import net.corda.core.transactions.SignedTransaction
import net.corda.core.utilities.OpaqueBytes import net.corda.core.utilities.OpaqueBytes
import net.corda.core.utilities.NonEmptySet import net.corda.core.utilities.NonEmptySet

View File

@ -6,6 +6,8 @@ import co.paralleluniverse.fibers.Suspendable
import co.paralleluniverse.strands.Strand import co.paralleluniverse.strands.Strand
import com.google.common.util.concurrent.SettableFuture import com.google.common.util.concurrent.SettableFuture
import net.corda.core.getOrThrow import net.corda.core.getOrThrow
import net.corda.core.utilities.hours
import net.corda.core.utilities.minutes
import net.corda.testing.node.TestClock import net.corda.testing.node.TestClock
import org.junit.After import org.junit.After
import org.junit.Before import org.junit.Before
@ -44,7 +46,7 @@ class ClockUtilsTest {
@Test @Test
fun `test waiting negative time for a deadline`() { fun `test waiting negative time for a deadline`() {
assertFalse(stoppedClock.awaitWithDeadline(stoppedClock.instant().minus(Duration.ofHours(1))), "Should have reached deadline") assertFalse(stoppedClock.awaitWithDeadline(stoppedClock.instant().minus(1.hours)), "Should have reached deadline")
} }
@Test @Test
@ -56,13 +58,13 @@ class ClockUtilsTest {
@Test @Test
fun `test waiting negative time for a deadline with incomplete future`() { fun `test waiting negative time for a deadline with incomplete future`() {
val future = SettableFuture.create<Boolean>() val future = SettableFuture.create<Boolean>()
assertFalse(stoppedClock.awaitWithDeadline(stoppedClock.instant().minus(Duration.ofHours(1)), future), "Should have reached deadline") assertFalse(stoppedClock.awaitWithDeadline(stoppedClock.instant().minus(1.hours), future), "Should have reached deadline")
} }
@Test @Test
fun `test waiting for a deadline with future completed before wait`() { fun `test waiting for a deadline with future completed before wait`() {
val advancedClock = Clock.offset(stoppedClock, Duration.ofHours(1)) val advancedClock = Clock.offset(stoppedClock, 1.hours)
val future = SettableFuture.create<Boolean>() val future = SettableFuture.create<Boolean>()
completeNow(future) completeNow(future)
assertTrue(stoppedClock.awaitWithDeadline(advancedClock.instant(), future), "Should not have reached deadline") assertTrue(stoppedClock.awaitWithDeadline(advancedClock.instant(), future), "Should not have reached deadline")
@ -70,7 +72,7 @@ class ClockUtilsTest {
@Test @Test
fun `test waiting for a deadline with future completed after wait`() { fun `test waiting for a deadline with future completed after wait`() {
val advancedClock = Clock.offset(stoppedClock, Duration.ofHours(1)) val advancedClock = Clock.offset(stoppedClock, 1.hours)
val future = SettableFuture.create<Boolean>() val future = SettableFuture.create<Boolean>()
completeAfterWaiting(future) completeAfterWaiting(future)
assertTrue(stoppedClock.awaitWithDeadline(advancedClock.instant(), future), "Should not have reached deadline") assertTrue(stoppedClock.awaitWithDeadline(advancedClock.instant(), future), "Should not have reached deadline")
@ -78,38 +80,38 @@ class ClockUtilsTest {
@Test @Test
fun `test waiting for a deadline with clock advance`() { fun `test waiting for a deadline with clock advance`() {
val advancedClock = Clock.offset(stoppedClock, Duration.ofHours(1)) val advancedClock = Clock.offset(stoppedClock, 1.hours)
val testClock = TestClock(stoppedClock) val testClock = TestClock(stoppedClock)
advanceClockAfterWait(testClock, Duration.ofHours(1)) advanceClockAfterWait(testClock, 1.hours)
assertFalse(testClock.awaitWithDeadline(advancedClock.instant()), "Should have reached deadline") assertFalse(testClock.awaitWithDeadline(advancedClock.instant()), "Should have reached deadline")
} }
@Test @Test
fun `test waiting for a deadline with clock advance and incomplete future`() { fun `test waiting for a deadline with clock advance and incomplete future`() {
val advancedClock = Clock.offset(stoppedClock, Duration.ofHours(1)) val advancedClock = Clock.offset(stoppedClock, 1.hours)
val testClock = TestClock(stoppedClock) val testClock = TestClock(stoppedClock)
val future = SettableFuture.create<Boolean>() val future = SettableFuture.create<Boolean>()
advanceClockAfterWait(testClock, Duration.ofHours(1)) advanceClockAfterWait(testClock, 1.hours)
assertFalse(testClock.awaitWithDeadline(advancedClock.instant(), future), "Should have reached deadline") assertFalse(testClock.awaitWithDeadline(advancedClock.instant(), future), "Should have reached deadline")
} }
@Test @Test
fun `test waiting for a deadline with clock advance and complete future`() { fun `test waiting for a deadline with clock advance and complete future`() {
val advancedClock = Clock.offset(stoppedClock, Duration.ofHours(2)) val advancedClock = Clock.offset(stoppedClock, 2.hours)
val testClock = TestClock(stoppedClock) val testClock = TestClock(stoppedClock)
val future = SettableFuture.create<Boolean>() val future = SettableFuture.create<Boolean>()
advanceClockAfterWait(testClock, Duration.ofHours(1)) advanceClockAfterWait(testClock, 1.hours)
completeAfterWaiting(future) completeAfterWaiting(future)
assertTrue(testClock.awaitWithDeadline(advancedClock.instant(), future), "Should not have reached deadline") assertTrue(testClock.awaitWithDeadline(advancedClock.instant(), future), "Should not have reached deadline")
} }
@Test @Test
fun `test waiting for a deadline with multiple clock advance and incomplete future`() { fun `test waiting for a deadline with multiple clock advance and incomplete future`() {
val advancedClock = Clock.offset(stoppedClock, Duration.ofHours(1)) val advancedClock = Clock.offset(stoppedClock, 1.hours)
val testClock = TestClock(stoppedClock) val testClock = TestClock(stoppedClock)
val future = SettableFuture.create<Boolean>() val future = SettableFuture.create<Boolean>()
for (advance in 1..6) { for (advance in 1..6) {
advanceClockAfterWait(testClock, Duration.ofMinutes(10)) advanceClockAfterWait(testClock, 10.minutes)
} }
assertFalse(testClock.awaitWithDeadline(advancedClock.instant(), future), "Should have reached deadline") assertFalse(testClock.awaitWithDeadline(advancedClock.instant(), future), "Should have reached deadline")
} }
@ -126,7 +128,7 @@ class ClockUtilsTest {
} }
val testClock = TestClock(stoppedClock) val testClock = TestClock(stoppedClock)
val advancedClock = Clock.offset(stoppedClock, Duration.ofHours(10)) val advancedClock = Clock.offset(stoppedClock, 10.hours)
try { try {
testClock.awaitWithDeadline(advancedClock.instant(), SettableFuture.create<Boolean>()) testClock.awaitWithDeadline(advancedClock.instant(), SettableFuture.create<Boolean>())
@ -138,7 +140,7 @@ class ClockUtilsTest {
@Test @Test
@Suspendable @Suspendable
fun `test waiting for a deadline with multiple clock advance and incomplete JDK8 future on Fibers`() { fun `test waiting for a deadline with multiple clock advance and incomplete JDK8 future on Fibers`() {
val advancedClock = Clock.offset(stoppedClock, Duration.ofHours(1)) val advancedClock = Clock.offset(stoppedClock, 1.hours)
val testClock = TestClock(stoppedClock) val testClock = TestClock(stoppedClock)
val future = CompletableFuture<Boolean>() val future = CompletableFuture<Boolean>()
val scheduler = FiberExecutorScheduler("test", executor) val scheduler = FiberExecutorScheduler("test", executor)
@ -151,7 +153,7 @@ class ClockUtilsTest {
while (fiber.state != Strand.State.TIMED_WAITING) { while (fiber.state != Strand.State.TIMED_WAITING) {
Strand.sleep(1) Strand.sleep(1)
} }
testClock.advanceBy(Duration.ofMinutes(10)) testClock.advanceBy(10.minutes)
}).start() }).start()
} }
assertFalse(future.getOrThrow(), "Should have reached deadline") assertFalse(future.getOrThrow(), "Should have reached deadline")
@ -160,7 +162,7 @@ class ClockUtilsTest {
@Test @Test
@Suspendable @Suspendable
fun `test waiting for a deadline with multiple clock advance and incomplete Guava future on Fibers`() { fun `test waiting for a deadline with multiple clock advance and incomplete Guava future on Fibers`() {
val advancedClock = Clock.offset(stoppedClock, Duration.ofHours(1)) val advancedClock = Clock.offset(stoppedClock, 1.hours)
val testClock = TestClock(stoppedClock) val testClock = TestClock(stoppedClock)
val future = SettableFuture.create<Boolean>() val future = SettableFuture.create<Boolean>()
val scheduler = FiberExecutorScheduler("test", executor) val scheduler = FiberExecutorScheduler("test", executor)
@ -173,7 +175,7 @@ class ClockUtilsTest {
while (fiber.state != Strand.State.TIMED_WAITING) { while (fiber.state != Strand.State.TIMED_WAITING) {
Strand.sleep(1) Strand.sleep(1)
} }
testClock.advanceBy(Duration.ofMinutes(10)) testClock.advanceBy(10.minutes)
}).start() }).start()
} }
assertFalse(future.getOrThrow(), "Should have reached deadline") assertFalse(future.getOrThrow(), "Should have reached deadline")

View File

@ -5,6 +5,8 @@ import co.paralleluniverse.fibers.Suspendable
import co.paralleluniverse.strands.Strand import co.paralleluniverse.strands.Strand
import net.corda.core.RetryableException import net.corda.core.RetryableException
import net.corda.core.getOrThrow import net.corda.core.getOrThrow
import net.corda.core.utilities.hours
import net.corda.core.utilities.minutes
import net.corda.testing.node.TestClock import net.corda.testing.node.TestClock
import org.junit.After import org.junit.After
import org.junit.Before import org.junit.Before
@ -50,7 +52,7 @@ class FiberBoxTest {
@Test @Test
fun `readWithDeadline with no wait`() { fun `readWithDeadline with no wait`() {
val advancedClock = Clock.offset(stoppedClock, Duration.ofHours(1)) val advancedClock = Clock.offset(stoppedClock, 1.hours)
mutex.write { integer = 1 } mutex.write { integer = 1 }
assertEquals(1, mutex.readWithDeadline(realClock, advancedClock.instant()) { integer }) assertEquals(1, mutex.readWithDeadline(realClock, advancedClock.instant()) { integer })
@ -58,7 +60,7 @@ class FiberBoxTest {
@Test @Test
fun `readWithDeadline with stopped clock and background write`() { fun `readWithDeadline with stopped clock and background write`() {
val advancedClock = Clock.offset(stoppedClock, Duration.ofHours(1)) val advancedClock = Clock.offset(stoppedClock, 1.hours)
assertEquals(1, mutex.readWithDeadline(stoppedClock, advancedClock.instant()) { assertEquals(1, mutex.readWithDeadline(stoppedClock, advancedClock.instant()) {
backgroundWrite() backgroundWrite()
@ -68,22 +70,22 @@ class FiberBoxTest {
@Test(expected = TestRetryableException::class) @Test(expected = TestRetryableException::class)
fun `readWithDeadline with clock advanced`() { fun `readWithDeadline with clock advanced`() {
val advancedClock = Clock.offset(stoppedClock, Duration.ofHours(1)) val advancedClock = Clock.offset(stoppedClock, 1.hours)
val testClock = TestClock(stoppedClock) val testClock = TestClock(stoppedClock)
assertEquals(1, mutex.readWithDeadline(testClock, advancedClock.instant()) { assertEquals(1, mutex.readWithDeadline(testClock, advancedClock.instant()) {
backgroundAdvanceClock(testClock, Duration.ofHours(1)) backgroundAdvanceClock(testClock, 1.hours)
if (integer == 1) 0 else throw TestRetryableException("Not 1") if (integer == 1) 0 else throw TestRetryableException("Not 1")
}) })
} }
@Test @Test
fun `readWithDeadline with clock advanced 5x and background write`() { fun `readWithDeadline with clock advanced 5x and background write`() {
val advancedClock = Clock.offset(stoppedClock, Duration.ofHours(1)) val advancedClock = Clock.offset(stoppedClock, 1.hours)
val testClock = TestClock(stoppedClock) val testClock = TestClock(stoppedClock)
assertEquals(5, mutex.readWithDeadline(testClock, advancedClock.instant()) { assertEquals(5, mutex.readWithDeadline(testClock, advancedClock.instant()) {
backgroundAdvanceClock(testClock, Duration.ofMinutes(10)) backgroundAdvanceClock(testClock, 10.minutes)
backgroundWrite() backgroundWrite()
if (integer == 5) 5 else throw TestRetryableException("Not 5") if (integer == 5) 5 else throw TestRetryableException("Not 5")
}) })
@ -97,7 +99,7 @@ class FiberBoxTest {
@Test(expected = TestRetryableException::class) @Test(expected = TestRetryableException::class)
@Suspendable @Suspendable
fun `readWithDeadline with clock advanced on Fibers`() { fun `readWithDeadline with clock advanced on Fibers`() {
val advancedClock = Clock.offset(stoppedClock, Duration.ofHours(1)) val advancedClock = Clock.offset(stoppedClock, 1.hours)
val testClock = TestClock(stoppedClock) val testClock = TestClock(stoppedClock)
val future = CompletableFuture<Int>() val future = CompletableFuture<Int>()
val scheduler = FiberExecutorScheduler("test", executor) val scheduler = FiberExecutorScheduler("test", executor)
@ -116,7 +118,7 @@ class FiberBoxTest {
while (fiber.state != Strand.State.TIMED_WAITING) { while (fiber.state != Strand.State.TIMED_WAITING) {
Strand.sleep(1) Strand.sleep(1)
} }
testClock.advanceBy(Duration.ofMinutes(10)) testClock.advanceBy(10.minutes)
}).start() }).start()
} }
assertEquals(2, future.getOrThrow()) assertEquals(2, future.getOrThrow())
@ -130,7 +132,7 @@ class FiberBoxTest {
@Test @Test
@Suspendable @Suspendable
fun `readWithDeadline with background write on Fibers`() { fun `readWithDeadline with background write on Fibers`() {
val advancedClock = Clock.offset(stoppedClock, Duration.ofHours(1)) val advancedClock = Clock.offset(stoppedClock, 1.hours)
val testClock = TestClock(stoppedClock) val testClock = TestClock(stoppedClock)
val future = CompletableFuture<Int>() val future = CompletableFuture<Int>()
val scheduler = FiberExecutorScheduler("test", executor) val scheduler = FiberExecutorScheduler("test", executor)

View File

@ -6,15 +6,16 @@ import net.corda.core.getOrThrow
import net.corda.core.node.services.ServiceInfo import net.corda.core.node.services.ServiceInfo
import net.corda.core.toFuture import net.corda.core.toFuture
import net.corda.core.utilities.NetworkHostAndPort import net.corda.core.utilities.NetworkHostAndPort
import net.corda.testing.DUMMY_BANK_A import net.corda.core.utilities.seconds
import net.corda.testing.DUMMY_BANK_B
import net.corda.testing.DUMMY_NOTARY
import net.corda.irs.api.NodeInterestRates import net.corda.irs.api.NodeInterestRates
import net.corda.irs.contract.InterestRateSwap import net.corda.irs.contract.InterestRateSwap
import net.corda.irs.utilities.uploadFile import net.corda.irs.utilities.uploadFile
import net.corda.node.services.config.FullNodeConfiguration import net.corda.node.services.config.FullNodeConfiguration
import net.corda.node.services.transactions.SimpleNotaryService import net.corda.node.services.transactions.SimpleNotaryService
import net.corda.nodeapi.User import net.corda.nodeapi.User
import net.corda.testing.DUMMY_BANK_A
import net.corda.testing.DUMMY_BANK_B
import net.corda.testing.DUMMY_NOTARY
import net.corda.testing.IntegrationTestCategory import net.corda.testing.IntegrationTestCategory
import net.corda.testing.driver.driver import net.corda.testing.driver.driver
import net.corda.testing.http.HttpApi import net.corda.testing.http.HttpApi
@ -25,13 +26,12 @@ import rx.Observable
import java.net.URL import java.net.URL
import java.time.Duration import java.time.Duration
import java.time.LocalDate import java.time.LocalDate
import java.time.temporal.ChronoUnit
class IRSDemoTest : IntegrationTestCategory { class IRSDemoTest : IntegrationTestCategory {
val rpcUser = User("user", "password", emptySet()) val rpcUser = User("user", "password", emptySet())
val currentDate: LocalDate = LocalDate.now() val currentDate: LocalDate = LocalDate.now()
val futureDate: LocalDate = currentDate.plusMonths(6) val futureDate: LocalDate = currentDate.plusMonths(6)
val maxWaitTime: Duration = Duration.of(60, ChronoUnit.SECONDS) val maxWaitTime: Duration = 60.seconds
@Test @Test
fun `runs IRS demo`() { fun `runs IRS demo`() {

View File

@ -12,7 +12,7 @@ import net.corda.core.flows.SchedulableFlow
import net.corda.core.identity.Party import net.corda.core.identity.Party
import net.corda.core.node.NodeInfo import net.corda.core.node.NodeInfo
import net.corda.core.node.services.ServiceType import net.corda.core.node.services.ServiceType
import net.corda.core.seconds import net.corda.core.utilities.seconds
import net.corda.core.serialization.CordaSerializable import net.corda.core.serialization.CordaSerializable
import net.corda.core.transactions.SignedTransaction import net.corda.core.transactions.SignedTransaction
import net.corda.core.transactions.TransactionBuilder import net.corda.core.transactions.TransactionBuilder

View File

@ -1,7 +1,11 @@
package net.corda.irs.utilities package net.corda.irs.utilities
import net.corda.core.contracts.TimeWindow import net.corda.core.contracts.TimeWindow
import java.time.* import net.corda.core.utilities.hours
import java.time.LocalDate
import java.time.LocalTime
import java.time.ZoneId
import java.time.ZonedDateTime
/** /**
* This whole file exists as short cuts to get demos working. In reality we'd have static data and/or rules engine * This whole file exists as short cuts to get demos working. In reality we'd have static data and/or rules engine
@ -16,5 +20,5 @@ fun suggestInterestRateAnnouncementTimeWindow(index: String, source: String, dat
// Here we apply a blanket announcement time of 11:45 London irrespective of source or index // Here we apply a blanket announcement time of 11:45 London irrespective of source or index
val time = LocalTime.of(11, 45) val time = LocalTime.of(11, 45)
val zoneId = ZoneId.of("Europe/London") val zoneId = ZoneId.of("Europe/London")
return TimeWindow.fromStartAndDuration(ZonedDateTime.of(date, time, zoneId).toInstant(), Duration.ofHours(24)) return TimeWindow.fromStartAndDuration(ZonedDateTime.of(date, time, zoneId).toInstant(), 24.hours)
} }

View File

@ -2,7 +2,7 @@ package net.corda.irs.contract
import net.corda.contracts.* import net.corda.contracts.*
import net.corda.core.contracts.* import net.corda.core.contracts.*
import net.corda.core.seconds import net.corda.core.utilities.seconds
import net.corda.core.transactions.SignedTransaction import net.corda.core.transactions.SignedTransaction
import net.corda.testing.DUMMY_NOTARY import net.corda.testing.DUMMY_NOTARY
import net.corda.testing.DUMMY_NOTARY_KEY import net.corda.testing.DUMMY_NOTARY_KEY

View File

@ -2,7 +2,7 @@ package net.corda.vega.flows
import net.corda.core.contracts.StateAndRef import net.corda.core.contracts.StateAndRef
import net.corda.core.identity.Party import net.corda.core.identity.Party
import net.corda.core.seconds import net.corda.core.utilities.seconds
import net.corda.core.flows.AbstractStateReplacementFlow import net.corda.core.flows.AbstractStateReplacementFlow
import net.corda.core.flows.StateReplacementException import net.corda.core.flows.StateReplacementException
import net.corda.vega.contracts.RevisionedState import net.corda.vega.contracts.RevisionedState

View File

@ -4,7 +4,7 @@ import com.google.common.util.concurrent.Futures
import net.corda.client.rpc.CordaRPCClient import net.corda.client.rpc.CordaRPCClient
import net.corda.core.contracts.DOLLARS import net.corda.core.contracts.DOLLARS
import net.corda.core.getOrThrow import net.corda.core.getOrThrow
import net.corda.core.millis import net.corda.core.utilities.millis
import net.corda.core.node.services.ServiceInfo import net.corda.core.node.services.ServiceInfo
import net.corda.testing.DUMMY_BANK_A import net.corda.testing.DUMMY_BANK_A
import net.corda.testing.DUMMY_BANK_B import net.corda.testing.DUMMY_BANK_B

View File

@ -5,7 +5,7 @@ import net.corda.contracts.CommercialPaper
import net.corda.contracts.asset.DUMMY_CASH_ISSUER import net.corda.contracts.asset.DUMMY_CASH_ISSUER
import net.corda.core.contracts.* import net.corda.core.contracts.*
import net.corda.core.crypto.SecureHash import net.corda.core.crypto.SecureHash
import net.corda.core.days import net.corda.core.utilities.days
import net.corda.core.flows.FinalityFlow import net.corda.core.flows.FinalityFlow
import net.corda.core.flows.FlowLogic import net.corda.core.flows.FlowLogic
import net.corda.core.flows.InitiatingFlow import net.corda.core.flows.InitiatingFlow
@ -14,7 +14,7 @@ import net.corda.core.identity.AbstractParty
import net.corda.core.identity.AnonymousParty import net.corda.core.identity.AnonymousParty
import net.corda.core.identity.Party import net.corda.core.identity.Party
import net.corda.core.node.NodeInfo import net.corda.core.node.NodeInfo
import net.corda.core.seconds import net.corda.core.utilities.seconds
import net.corda.core.transactions.SignedTransaction import net.corda.core.transactions.SignedTransaction
import net.corda.core.utilities.ProgressTracker import net.corda.core.utilities.ProgressTracker
import net.corda.flows.TwoPartyTradeFlow import net.corda.flows.TwoPartyTradeFlow

View File

@ -4,7 +4,7 @@ import net.corda.core.contracts.*
import net.corda.testing.contracts.DummyContract import net.corda.testing.contracts.DummyContract
import net.corda.core.crypto.SecureHash import net.corda.core.crypto.SecureHash
import net.corda.core.identity.Party import net.corda.core.identity.Party
import net.corda.core.seconds import net.corda.core.utilities.seconds
import net.corda.core.transactions.TransactionBuilder import net.corda.core.transactions.TransactionBuilder
import java.security.PublicKey import java.security.PublicKey
import java.time.Duration import java.time.Duration

View File

@ -4,7 +4,7 @@ import com.google.common.util.concurrent.ListenableFuture
import com.google.common.util.concurrent.RateLimiter import com.google.common.util.concurrent.RateLimiter
import com.google.common.util.concurrent.SettableFuture import com.google.common.util.concurrent.SettableFuture
import net.corda.core.catch import net.corda.core.catch
import net.corda.core.minutes import net.corda.core.utilities.minutes
import net.corda.core.until import net.corda.core.until
import net.corda.core.utilities.loggerFor import net.corda.core.utilities.loggerFor
import net.corda.demobench.model.NodeConfig import net.corda.demobench.model.NodeConfig