mirror of
https://github.com/corda/corda.git
synced 2025-06-18 07:08:15 +00:00
Merge from master
This commit is contained in:
@ -21,12 +21,6 @@ class InsufficientBalanceException(val amountMissing: Amount<*>) : Exception() {
|
||||
* (GBP, USD, oil, shares in company <X>, etc.) and any additional metadata (issuer, grade, class, etc.).
|
||||
*/
|
||||
interface FungibleAsset<T> : OwnableState {
|
||||
/**
|
||||
* Where the underlying asset backing this ledger entry can be found. The reference
|
||||
* is only intended for use by the issuer, and is not intended to be meaningful to others.
|
||||
*/
|
||||
val deposit: PartyAndReference
|
||||
val issuanceDef: Issued<T>
|
||||
val amount: Amount<Issued<T>>
|
||||
/**
|
||||
* There must be an ExitCommand signed by these keys to destroy the amount. While all states require their
|
||||
@ -55,7 +49,6 @@ interface FungibleAsset<T> : OwnableState {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Small DSL extensions.
|
||||
|
||||
/** Sums the asset states in the list, returning null if there are none. */
|
||||
|
@ -30,8 +30,8 @@ abstract class CordaPluginRegistry {
|
||||
|
||||
/**
|
||||
* List of additional long lived services to be hosted within the node.
|
||||
* They are expected to have a single parameter constructor that takes a ServiceHubInternal as input.
|
||||
* The ServiceHubInternal will be fully constructed before the plugin service is created and will
|
||||
* They are expected to have a single parameter constructor that takes a [PluginServiceHub] as input.
|
||||
* The [PluginServiceHub] will be fully constructed before the plugin service is created and will
|
||||
* allow access to the protocol factory and protocol initiation entry points there.
|
||||
*/
|
||||
open val servicePlugins: List<Class<*>> = emptyList()
|
||||
|
@ -0,0 +1,30 @@
|
||||
package com.r3corda.core.node
|
||||
|
||||
import com.r3corda.core.crypto.Party
|
||||
import com.r3corda.core.protocols.ProtocolLogic
|
||||
import kotlin.reflect.KClass
|
||||
|
||||
/**
|
||||
* A service hub to be used by the [CordaPluginRegistry]
|
||||
*/
|
||||
interface PluginServiceHub : ServiceHub {
|
||||
/**
|
||||
* Register the protocol factory we wish to use when a initiating party attempts to communicate with us. The
|
||||
* registration is done against a marker [KClass] which is sent in the session handshake by the other party. If this
|
||||
* marker class has been registered then the corresponding factory will be used to create the protocol which will
|
||||
* communicate with the other side. If there is no mapping then the session attempt is rejected.
|
||||
* @param markerClass The marker [KClass] present in a session initiation attempt, which is a 1:1 mapping to a [Class]
|
||||
* using the <pre>::class</pre> construct. Conventionally this is a [ProtocolLogic] subclass, however any class can
|
||||
* be used, with the default being the class of the initiating protocol. This enables the registration to be of the
|
||||
* form: registerProtocolInitiator(InitiatorProtocol::class, ::InitiatedProtocol)
|
||||
* @param protocolFactory The protocol factory generating the initiated protocol.
|
||||
*/
|
||||
|
||||
// TODO: remove dependency on Kotlin relfection (Kotlin KClass -> Java Class).
|
||||
fun registerProtocolInitiator(markerClass: KClass<*>, protocolFactory: (Party) -> ProtocolLogic<*>)
|
||||
|
||||
/**
|
||||
* Return the protocol factory that has been registered with [markerClass], or null if no factory is found.
|
||||
*/
|
||||
fun getProtocolFactory(markerClass: Class<*>): ((Party) -> ProtocolLogic<*>)?
|
||||
}
|
@ -177,7 +177,9 @@ interface VaultService {
|
||||
fun getTransactionNotes(txnId: SecureHash): Iterable<String>
|
||||
|
||||
/**
|
||||
* Fungible Asset operations
|
||||
* [InsufficientBalanceException] is thrown when a Cash Spending transaction fails because
|
||||
* there is insufficient quantity for a given currency (and optionally set of Issuer Parties).
|
||||
* Note: an [Amount] of [Currency] is only fungible for a given Issuer Party within a [FungibleAsset]
|
||||
**/
|
||||
@Throws(InsufficientBalanceException::class)
|
||||
fun generateSpend(tx: TransactionBuilder,
|
||||
|
27
core/src/main/kotlin/com/r3corda/core/utilities/ApiUtils.kt
Normal file
27
core/src/main/kotlin/com/r3corda/core/utilities/ApiUtils.kt
Normal file
@ -0,0 +1,27 @@
|
||||
package com.r3corda.core.utilities
|
||||
|
||||
import com.r3corda.core.crypto.Party
|
||||
import com.r3corda.core.crypto.parsePublicKeyBase58
|
||||
import com.r3corda.core.node.ServiceHub
|
||||
import javax.ws.rs.core.Response
|
||||
|
||||
/**
|
||||
* Utility functions to reduce boilerplate when developing HTTP APIs
|
||||
*/
|
||||
class ApiUtils(val services: ServiceHub) {
|
||||
private val defaultNotFound = { msg: String -> Response.status(Response.Status.NOT_FOUND).entity(msg).build() }
|
||||
|
||||
/**
|
||||
* Get a party and then execute the passed function with the party public key as a parameter.
|
||||
* Usage: withParty(key) { doSomethingWith(it) }
|
||||
*/
|
||||
fun withParty(partyKeyStr: String, notFound: (String) -> Response = defaultNotFound, found: (Party) -> Response): Response {
|
||||
return try {
|
||||
val partyKey = parsePublicKeyBase58(partyKeyStr)
|
||||
val party = services.identityService.partyFromKey(partyKey)
|
||||
if(party == null) notFound("Unknown party") else found(party)
|
||||
} catch (e: IllegalArgumentException) {
|
||||
notFound("Invalid base58 key passed for party key")
|
||||
}
|
||||
}
|
||||
}
|
@ -230,6 +230,10 @@ class X509UtilitiesTest {
|
||||
clientParams.endpointIdentificationAlgorithm = "HTTPS" // enable hostname checking
|
||||
clientSocket.sslParameters = clientParams
|
||||
clientSocket.useClientMode = true
|
||||
// We need to specify this explicitly because by default the client binds to 'localhost' and we want it to bind
|
||||
// to whatever <hostname> resolves to(as that's what the server binds to). In particular on Debian <hostname>
|
||||
// resolves to 127.0.1.1 instead of the external address of the interface, so the ssl handshake fails.
|
||||
clientSocket.bind(InetSocketAddress(InetAddress.getLocalHost(), 0))
|
||||
|
||||
val lock = Object()
|
||||
var done = false
|
||||
@ -281,4 +285,4 @@ class X509UtilitiesTest {
|
||||
serverSocket.close()
|
||||
assertTrue(done)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user