mirror of
https://github.com/corda/corda.git
synced 2025-06-13 04:38:19 +00:00
Cross provider Issuer Reference database storage (#2032)
* consistent storage of Issuer Reference using `ByteArray` Kotlin type in Schema definition and a custom Hibernate Type to map this to a VARBINARY database type. Creation of a new Issued type now also validates maximum size permissible (512).
This commit is contained in:
@ -45,9 +45,17 @@ interface NamedByHash {
|
||||
*/
|
||||
@CordaSerializable
|
||||
data class Issued<out P : Any>(val issuer: PartyAndReference, val product: P) {
|
||||
init {
|
||||
require(issuer.reference.bytes.size <= MAX_ISSUER_REF_SIZE) { "Maximum issuer reference size is $MAX_ISSUER_REF_SIZE." }
|
||||
}
|
||||
override fun toString() = "$product issued by $issuer"
|
||||
}
|
||||
|
||||
/**
|
||||
* The maximum permissible size of an issuer reference.
|
||||
*/
|
||||
const val MAX_ISSUER_REF_SIZE = 512
|
||||
|
||||
/**
|
||||
* Strips the issuer and returns an [Amount] of the raw token directly. This is useful when you are mixing code that
|
||||
* cares about specific issuers with code that will accept any, or which is imposing issuer constraints via some
|
||||
|
@ -103,3 +103,5 @@ fun ByteArray.sha256(): SecureHash.SHA256 = SecureHash.sha256(this)
|
||||
* Compute the SHA-256 hash for the contents of the [OpaqueBytes].
|
||||
*/
|
||||
fun OpaqueBytes.sha256(): SecureHash.SHA256 = SecureHash.sha256(this.bytes)
|
||||
|
||||
|
||||
|
@ -1,12 +1,12 @@
|
||||
package net.corda.core.schemas
|
||||
|
||||
import net.corda.core.contracts.ContractState
|
||||
import net.corda.core.contracts.FungibleAsset
|
||||
import net.corda.core.contracts.OwnableState
|
||||
import net.corda.core.contracts.UniqueIdentifier
|
||||
import net.corda.core.contracts.*
|
||||
import net.corda.core.identity.AbstractParty
|
||||
import org.hibernate.annotations.Type
|
||||
import java.util.*
|
||||
import javax.persistence.*
|
||||
import javax.persistence.Column
|
||||
import javax.persistence.ElementCollection
|
||||
import javax.persistence.MappedSuperclass
|
||||
|
||||
/**
|
||||
* JPA representation of the common schema entities
|
||||
@ -74,7 +74,8 @@ object CommonSchemaV1 : MappedSchema(schemaFamily = CommonSchema.javaClass, vers
|
||||
@Column(name = "issuer_name")
|
||||
var issuer: AbstractParty,
|
||||
|
||||
@Column(name = "issuer_reference")
|
||||
@Column(name = "issuer_ref", length = MAX_ISSUER_REF_SIZE)
|
||||
@Type(type = "corda-wrapper-binary")
|
||||
var issuerRef: ByteArray
|
||||
) : PersistentState()
|
||||
}
|
Reference in New Issue
Block a user