From 635ee8df7924604464151cf62b4caa03a42f28e7 Mon Sep 17 00:00:00 2001 From: Andrius Dagys Date: Mon, 21 Nov 2016 12:58:23 +0000 Subject: [PATCH] Rename bits -> bytes, as it normally indicates a byte array --- .../corda/client/impl/CordaRPCClientImpl.kt | 2 +- .../client/ClientRPCInfrastructureTests.kt | 4 +-- .../java/net/corda/core/crypto/Base58.java | 6 ++-- .../net/corda/core/contracts/Structures.kt | 2 +- .../net/corda/core/crypto/CryptoUtilities.kt | 28 +++++++++---------- .../net/corda/core/crypto/PublicKeyTree.kt | 2 +- .../net/corda/core/crypto/SecureHash.kt | 14 +++++----- .../net/corda/core/crypto/SignedData.kt | 2 +- .../net/corda/core/messaging/Messaging.kt | 2 +- .../net/corda/core/schemas/PersistentTypes.kt | 2 +- .../corda/core/serialization/ByteArrays.kt | 14 +++++----- .../net/corda/core/serialization/Kryo.kt | 14 +++++----- .../core/transactions/MerkleTransaction.kt | 7 +++-- .../core/transactions/SignedTransaction.kt | 2 +- .../core/transactions/TransactionBuilder.kt | 2 +- .../core/transactions/WireTransaction.kt | 10 +++---- .../net/corda/protocols/NotaryProtocol.kt | 6 ++-- .../corda/core/contracts/TransactionTests.kt | 4 +-- .../net/corda/core/crypto/SignedDataTest.kt | 4 +-- .../BroadcastTransactionProtocolTest.kt | 2 +- .../serialization/SerializationTokenTest.kt | 4 +-- .../TransactionSerializationTests.kt | 2 +- .../corda/core/utilities/NonEmptySetTest.kt | 4 +-- .../net/corda/contracts/CommercialPaper.kt | 4 +-- .../kotlin/net/corda/contracts/asset/Cash.kt | 2 +- .../node/services/api/AbstractNodeService.kt | 2 +- .../services/messaging/NodeMessagingClient.kt | 4 +-- .../node/services/messaging/RPCDispatcher.kt | 2 +- .../network/InMemoryNetworkMapCache.kt | 2 +- .../services/network/NetworkMapService.kt | 4 +-- .../transactions/RaftUniquenessProvider.kt | 2 +- .../net/corda/node/utilities/JDBCHashMap.kt | 2 +- .../net/corda/node/utilities/JsonSupport.kt | 3 +- .../net/corda/irs/api/NodeInterestRates.kt | 4 +-- 34 files changed, 84 insertions(+), 86 deletions(-) diff --git a/client/src/main/kotlin/net/corda/client/impl/CordaRPCClientImpl.kt b/client/src/main/kotlin/net/corda/client/impl/CordaRPCClientImpl.kt index 6d08f8c222..396e5d293b 100644 --- a/client/src/main/kotlin/net/corda/client/impl/CordaRPCClientImpl.kt +++ b/client/src/main/kotlin/net/corda/client/impl/CordaRPCClientImpl.kt @@ -195,7 +195,7 @@ class CordaRPCClientImpl(private val session: ClientSession, } catch (e: KryoException) { throw RPCException("Could not serialize RPC arguments", e) } - msg.writeBodyBufferBytes(serializedArgs.bits) + msg.writeBodyBufferBytes(serializedArgs.bytes) producer!!.send(ArtemisMessagingComponent.RPC_REQUESTS_QUEUE, msg) return kryo } diff --git a/client/src/test/kotlin/net/corda/client/ClientRPCInfrastructureTests.kt b/client/src/test/kotlin/net/corda/client/ClientRPCInfrastructureTests.kt index 6a1b1fd24c..ada6567c81 100644 --- a/client/src/test/kotlin/net/corda/client/ClientRPCInfrastructureTests.kt +++ b/client/src/test/kotlin/net/corda/client/ClientRPCInfrastructureTests.kt @@ -73,9 +73,9 @@ class ClientRPCInfrastructureTests { override val users: List get() = throw UnsupportedOperationException() } val dispatcher = object : RPCDispatcher(TestOpsImpl(), userService) { - override fun send(bits: SerializedBytes<*>, toAddress: String) { + override fun send(data: SerializedBytes<*>, toAddress: String) { val msg = serverSession.createMessage(false).apply { - writeBodyBufferBytes(bits.bits) + writeBodyBufferBytes(data.bytes) // Use the magic deduplication property built into Artemis as our message identity too putStringProperty(HDR_DUPLICATE_DETECTION_ID, SimpleString(UUID.randomUUID().toString())) } diff --git a/core/src/main/java/net/corda/core/crypto/Base58.java b/core/src/main/java/net/corda/core/crypto/Base58.java index c72ffd8255..ba4c8b1910 100644 --- a/core/src/main/java/net/corda/core/crypto/Base58.java +++ b/core/src/main/java/net/corda/core/crypto/Base58.java @@ -1,7 +1,7 @@ package net.corda.core.crypto; -import java.math.*; -import java.util.*; +import java.math.BigInteger; +import java.util.Arrays; /** * Base58 is a way to encode Bitcoin addresses (or arbitrary data) as alphanumeric strings. @@ -136,7 +136,7 @@ public class Base58 { throw new AddressFormatException("Input too short"); byte[] data = Arrays.copyOfRange(decoded, 0, decoded.length - 4); byte[] checksum = Arrays.copyOfRange(decoded, decoded.length - 4, decoded.length); - byte[] actualChecksum = Arrays.copyOfRange(SecureHash.sha256Twice(data).getBits(), 0, 4); + byte[] actualChecksum = Arrays.copyOfRange(SecureHash.sha256Twice(data).getBytes(), 0, 4); if (!Arrays.equals(checksum, actualChecksum)) throw new AddressFormatException("Checksum does not validate"); return data; diff --git a/core/src/main/kotlin/net/corda/core/contracts/Structures.kt b/core/src/main/kotlin/net/corda/core/contracts/Structures.kt index cf5a394082..649fabb248 100644 --- a/core/src/main/kotlin/net/corda/core/contracts/Structures.kt +++ b/core/src/main/kotlin/net/corda/core/contracts/Structures.kt @@ -315,7 +315,7 @@ interface FixableDealState : DealState { } /** Returns the SHA-256 hash of the serialised contents of this state (not cached!) */ -fun ContractState.hash(): SecureHash = SecureHash.sha256(serialize().bits) +fun ContractState.hash(): SecureHash = SecureHash.sha256(serialize().bytes) /** * A stateref is a pointer (reference) to a state, this is an equivalent of an "outpoint" in Bitcoin. It records which diff --git a/core/src/main/kotlin/net/corda/core/crypto/CryptoUtilities.kt b/core/src/main/kotlin/net/corda/core/crypto/CryptoUtilities.kt index 8404618c65..abd7b1ff18 100644 --- a/core/src/main/kotlin/net/corda/core/crypto/CryptoUtilities.kt +++ b/core/src/main/kotlin/net/corda/core/crypto/CryptoUtilities.kt @@ -28,7 +28,7 @@ open class DigitalSignature(bits: ByteArray) : OpaqueBytes(bits) { /** A digital signature that identifies who the public key is owned by. */ open class WithKey(val by: PublicKey, bits: ByteArray) : DigitalSignature(bits) { fun verifyWithECDSA(content: ByteArray) = by.verifyWithECDSA(content, this) - fun verifyWithECDSA(content: OpaqueBytes) = by.verifyWithECDSA(content.bits, this) + fun verifyWithECDSA(content: OpaqueBytes) = by.verifyWithECDSA(content.bytes, this) } // TODO: consider removing this as whoever needs to identify the signer should be able to derive it from the public key @@ -60,16 +60,16 @@ class DummyPublicKey(val s: String) : PublicKey, Comparable { object NullSignature : DigitalSignature.WithKey(NullPublicKey, ByteArray(32)) /** Utility to simplify the act of signing a byte array */ -fun PrivateKey.signWithECDSA(bits: ByteArray): DigitalSignature { +fun PrivateKey.signWithECDSA(bytes: ByteArray): DigitalSignature { val signer = EdDSAEngine() signer.initSign(this) - signer.update(bits) + signer.update(bytes) val sig = signer.sign() return DigitalSignature(sig) } -fun PrivateKey.signWithECDSA(bitsToSign: ByteArray, publicKey: PublicKey): DigitalSignature.WithKey { - return DigitalSignature.WithKey(publicKey, signWithECDSA(bitsToSign).bits) +fun PrivateKey.signWithECDSA(bytesToSign: ByteArray, publicKey: PublicKey): DigitalSignature.WithKey { + return DigitalSignature.WithKey(publicKey, signWithECDSA(bytesToSign).bytes) } val ed25519Curve = EdDSANamedCurveTable.getByName(EdDSANamedCurveTable.CURVE_ED25519_SHA512) @@ -77,13 +77,13 @@ val ed25519Curve = EdDSANamedCurveTable.getByName(EdDSANamedCurveTable.CURVE_ED2 fun parsePublicKeyBase58(base58String: String) = EdDSAPublicKey(EdDSAPublicKeySpec(Base58.decode(base58String), ed25519Curve)) fun PublicKey.toBase58String() = Base58.encode((this as EdDSAPublicKey).abyte) -fun KeyPair.signWithECDSA(bitsToSign: ByteArray) = private.signWithECDSA(bitsToSign, public) -fun KeyPair.signWithECDSA(bitsToSign: OpaqueBytes) = private.signWithECDSA(bitsToSign.bits, public) -fun KeyPair.signWithECDSA(bitsToSign: OpaqueBytes, party: Party) = signWithECDSA(bitsToSign.bits, party) -fun KeyPair.signWithECDSA(bitsToSign: ByteArray, party: Party): DigitalSignature.LegallyIdentifiable { +fun KeyPair.signWithECDSA(bytesToSign: ByteArray) = private.signWithECDSA(bytesToSign, public) +fun KeyPair.signWithECDSA(bytesToSign: OpaqueBytes) = private.signWithECDSA(bytesToSign.bytes, public) +fun KeyPair.signWithECDSA(bytesToSign: OpaqueBytes, party: Party) = signWithECDSA(bytesToSign.bytes, party) +fun KeyPair.signWithECDSA(bytesToSign: ByteArray, party: Party): DigitalSignature.LegallyIdentifiable { check(public in party.owningKey.keys) - val sig = signWithECDSA(bitsToSign) - return DigitalSignature.LegallyIdentifiable(party, sig.bits) + val sig = signWithECDSA(bytesToSign) + return DigitalSignature.LegallyIdentifiable(party, sig.bytes) } /** Utility to simplify the act of verifying a signature */ @@ -91,7 +91,7 @@ fun PublicKey.verifyWithECDSA(content: ByteArray, signature: DigitalSignature) { val verifier = EdDSAEngine() verifier.initVerify(this) verifier.update(content) - if (verifier.verify(signature.bits) == false) + if (verifier.verify(signature.bytes) == false) throw SignatureException("Signature did not match") } @@ -122,8 +122,8 @@ fun generateKeyPair(): KeyPair = KeyPairGenerator().generateKeyPair() */ fun entropyToKeyPair(entropy: BigInteger): KeyPair { val params = EdDSANamedCurveTable.getByName(EdDSANamedCurveTable.CURVE_ED25519_SHA512) - val bits = entropy.toByteArray().copyOf(params.curve.field.getb() / 8) - val priv = EdDSAPrivateKeySpec(bits, params) + val bytes = entropy.toByteArray().copyOf(params.curve.field.getb() / 8) + val priv = EdDSAPrivateKeySpec(bytes, params) val pub = EdDSAPublicKeySpec(priv.a, params) val key = KeyPair(EdDSAPublicKey(pub), EdDSAPrivateKey(priv)) return key diff --git a/core/src/main/kotlin/net/corda/core/crypto/PublicKeyTree.kt b/core/src/main/kotlin/net/corda/core/crypto/PublicKeyTree.kt index b3416b21a1..a1d6cb9ab4 100644 --- a/core/src/main/kotlin/net/corda/core/crypto/PublicKeyTree.kt +++ b/core/src/main/kotlin/net/corda/core/crypto/PublicKeyTree.kt @@ -32,7 +32,7 @@ sealed class PublicKeyTree { fun containsAny(otherKeys: Iterable) = keys.intersect(otherKeys).isNotEmpty() // TODO: implement a proper encoding/decoding mechanism - fun toBase58String(): String = Base58.encode(this.serialize().bits) + fun toBase58String(): String = Base58.encode(this.serialize().bytes) companion object { fun parseFromBase58(encoded: String) = Base58.decode(encoded).deserialize() diff --git a/core/src/main/kotlin/net/corda/core/crypto/SecureHash.kt b/core/src/main/kotlin/net/corda/core/crypto/SecureHash.kt index 50064cef78..f5bb961c72 100644 --- a/core/src/main/kotlin/net/corda/core/crypto/SecureHash.kt +++ b/core/src/main/kotlin/net/corda/core/crypto/SecureHash.kt @@ -8,15 +8,15 @@ import java.security.MessageDigest * Container for a cryptographically secure hash value. * Provides utilities for generating a cryptographic hash using different algorithms (currently only SHA-256 supported). */ -sealed class SecureHash(bits: ByteArray) : OpaqueBytes(bits) { +sealed class SecureHash(bytes: ByteArray) : OpaqueBytes(bytes) { /** SHA-256 is part of the SHA-2 hash function family. Generated hash is fixed size, 256-bits (32-bytes) */ - class SHA256(bits: ByteArray) : SecureHash(bits) { + class SHA256(bytes: ByteArray) : SecureHash(bytes) { init { - require(bits.size == 32) + require(bytes.size == 32) } } - override fun toString() = BaseEncoding.base16().encode(bits) + override fun toString() = BaseEncoding.base16().encode(bytes) fun prefixChars(prefixLen: Int = 6) = toString().substring(0, prefixLen) @@ -30,8 +30,8 @@ sealed class SecureHash(bits: ByteArray) : OpaqueBytes(bits) { } } - @JvmStatic fun sha256(bits: ByteArray) = SHA256(MessageDigest.getInstance("SHA-256").digest(bits)) - @JvmStatic fun sha256Twice(bits: ByteArray) = sha256(sha256(bits).bits) + @JvmStatic fun sha256(bytes: ByteArray) = SHA256(MessageDigest.getInstance("SHA-256").digest(bytes)) + @JvmStatic fun sha256Twice(bytes: ByteArray) = sha256(sha256(bytes).bytes) @JvmStatic fun sha256(str: String) = sha256(str.toByteArray()) @JvmStatic fun randomSHA256() = sha256(newSecureRandom().generateSeed(32)) @@ -41,4 +41,4 @@ sealed class SecureHash(bits: ByteArray) : OpaqueBytes(bits) { } fun ByteArray.sha256(): SecureHash.SHA256 = SecureHash.sha256(this) -fun OpaqueBytes.sha256(): SecureHash.SHA256 = SecureHash.sha256(this.bits) +fun OpaqueBytes.sha256(): SecureHash.SHA256 = SecureHash.sha256(this.bytes) diff --git a/core/src/main/kotlin/net/corda/core/crypto/SignedData.kt b/core/src/main/kotlin/net/corda/core/crypto/SignedData.kt index b9fb329886..bc377fd7c7 100644 --- a/core/src/main/kotlin/net/corda/core/crypto/SignedData.kt +++ b/core/src/main/kotlin/net/corda/core/crypto/SignedData.kt @@ -20,7 +20,7 @@ open class SignedData(val raw: SerializedBytes, val sig: DigitalSign */ @Throws(SignatureException::class) fun verified(): T { - sig.by.verifyWithECDSA(raw.bits, sig) + sig.by.verifyWithECDSA(raw.bytes, sig) val data = raw.deserialize() verifyData(data) return data diff --git a/core/src/main/kotlin/net/corda/core/messaging/Messaging.kt b/core/src/main/kotlin/net/corda/core/messaging/Messaging.kt index 876e517706..b76c041517 100644 --- a/core/src/main/kotlin/net/corda/core/messaging/Messaging.kt +++ b/core/src/main/kotlin/net/corda/core/messaging/Messaging.kt @@ -142,7 +142,7 @@ fun MessagingService.send(topic: String, sessionID: Long, payload: Any, to: Mess = send(TopicSession(topic, sessionID), payload, to, uuid) fun MessagingService.send(topicSession: TopicSession, payload: Any, to: MessageRecipients, uuid: UUID = UUID.randomUUID()) - = send(createMessage(topicSession, payload.serialize().bits, uuid), to) + = send(createMessage(topicSession, payload.serialize().bytes, uuid), to) interface MessageHandlerRegistration diff --git a/core/src/main/kotlin/net/corda/core/schemas/PersistentTypes.kt b/core/src/main/kotlin/net/corda/core/schemas/PersistentTypes.kt index d6eff87946..e690cd583d 100644 --- a/core/src/main/kotlin/net/corda/core/schemas/PersistentTypes.kt +++ b/core/src/main/kotlin/net/corda/core/schemas/PersistentTypes.kt @@ -61,6 +61,6 @@ data class PersistentStateRef( @Column(name = "output_index") var index: Int? ) : Serializable { - constructor(stateRef: StateRef) : this(stateRef.txhash.bits.toHexString(), stateRef.index) + constructor(stateRef: StateRef) : this(stateRef.txhash.bytes.toHexString(), stateRef.index) constructor() : this(null, null) } diff --git a/core/src/main/kotlin/net/corda/core/serialization/ByteArrays.kt b/core/src/main/kotlin/net/corda/core/serialization/ByteArrays.kt index 76464f60bc..a74cefe93c 100644 --- a/core/src/main/kotlin/net/corda/core/serialization/ByteArrays.kt +++ b/core/src/main/kotlin/net/corda/core/serialization/ByteArrays.kt @@ -9,9 +9,9 @@ import java.util.* * In an ideal JVM this would be a value type and be completely overhead free. Project Valhalla is adding such * functionality to Java, but it won't arrive for a few years yet! */ -open class OpaqueBytes(val bits: ByteArray) { +open class OpaqueBytes(val bytes: ByteArray) { init { - check(bits.isNotEmpty()) + check(bytes.isNotEmpty()) } companion object { @@ -21,16 +21,16 @@ open class OpaqueBytes(val bits: ByteArray) { override fun equals(other: Any?): Boolean { if (this === other) return true if (other !is OpaqueBytes) return false - return Arrays.equals(bits, other.bits) + return Arrays.equals(bytes, other.bytes) } - override fun hashCode() = Arrays.hashCode(bits) - override fun toString() = "[" + bits.toHexString() + "]" + override fun hashCode() = Arrays.hashCode(bytes) + override fun toString() = "[" + bytes.toHexString() + "]" - val size: Int get() = bits.size + val size: Int get() = bytes.size /** Returns a [ByteArrayInputStream] of the bytes */ - fun open() = ByteArrayInputStream(bits) + fun open() = ByteArrayInputStream(bytes) } fun ByteArray.opaque(): OpaqueBytes = OpaqueBytes(this) diff --git a/core/src/main/kotlin/net/corda/core/serialization/Kryo.kt b/core/src/main/kotlin/net/corda/core/serialization/Kryo.kt index 44cfaa17bb..4d94af47ec 100644 --- a/core/src/main/kotlin/net/corda/core/serialization/Kryo.kt +++ b/core/src/main/kotlin/net/corda/core/serialization/Kryo.kt @@ -72,11 +72,11 @@ val THREAD_LOCAL_KRYO = ThreadLocal.withInitial { createKryo() } * A type safe wrapper around a byte array that contains a serialised object. You can call [SerializedBytes.deserialize] * to get the original object back. */ -class SerializedBytes(bits: ByteArray) : OpaqueBytes(bits) { +class SerializedBytes(bytes: ByteArray) : OpaqueBytes(bytes) { // It's OK to use lazy here because SerializedBytes is configured to use the ImmutableClassSerializer. - val hash: SecureHash by lazy { bits.sha256() } + val hash: SecureHash by lazy { bytes.sha256() } - fun writeToFile(path: Path) = Files.write(path, bits) + fun writeToFile(path: Path) = Files.write(path, bytes) } // Some extension functions that make deserialisation convenient and provide auto-casting of the result. @@ -86,14 +86,14 @@ fun ByteArray.deserialize(kryo: Kryo = THREAD_LOCAL_KRYO.get()): T { } fun OpaqueBytes.deserialize(kryo: Kryo = THREAD_LOCAL_KRYO.get()): T { - return this.bits.deserialize(kryo) + return this.bytes.deserialize(kryo) } // The more specific deserialize version results in the bytes being cached, which is faster. @JvmName("SerializedBytesWireTransaction") fun SerializedBytes.deserialize(kryo: Kryo = THREAD_LOCAL_KRYO.get()): WireTransaction = WireTransaction.deserialize(this, kryo) -fun SerializedBytes.deserialize(kryo: Kryo = THREAD_LOCAL_KRYO.get()): T = bits.deserialize(kryo) +fun SerializedBytes.deserialize(kryo: Kryo = THREAD_LOCAL_KRYO.get()): T = bytes.deserialize(kryo) /** * A serialiser that avoids writing the wrapper class to the byte stream, thus ensuring [SerializedBytes] is a pure @@ -101,8 +101,8 @@ fun SerializedBytes.deserialize(kryo: Kryo = THREAD_LOCAL_KRYO.get( */ object SerializedBytesSerializer : Serializer>() { override fun write(kryo: Kryo, output: Output, obj: SerializedBytes) { - output.writeVarInt(obj.bits.size, true) - output.writeBytes(obj.bits) + output.writeVarInt(obj.bytes.size, true) + output.writeBytes(obj.bytes) } override fun read(kryo: Kryo, input: Input, type: Class>): SerializedBytes { diff --git a/core/src/main/kotlin/net/corda/core/transactions/MerkleTransaction.kt b/core/src/main/kotlin/net/corda/core/transactions/MerkleTransaction.kt index afd7cd4199..dc8b269b54 100644 --- a/core/src/main/kotlin/net/corda/core/transactions/MerkleTransaction.kt +++ b/core/src/main/kotlin/net/corda/core/transactions/MerkleTransaction.kt @@ -4,12 +4,13 @@ import net.corda.core.contracts.Command import net.corda.core.contracts.ContractState import net.corda.core.contracts.StateRef import net.corda.core.contracts.TransactionState -import net.corda.core.crypto.* -import net.corda.core.serialization.* import net.corda.core.crypto.MerkleTreeException import net.corda.core.crypto.PartialMerkleTree import net.corda.core.crypto.SecureHash import net.corda.core.crypto.sha256 +import net.corda.core.serialization.createKryo +import net.corda.core.serialization.extendKryoHash +import net.corda.core.serialization.serialize import java.util.* /** @@ -29,7 +30,7 @@ fun WireTransaction.calculateLeavesHashes(): List { return resultHashes } -fun SecureHash.hashConcat(other: SecureHash) = (this.bits + other.bits).sha256() +fun SecureHash.hashConcat(other: SecureHash) = (this.bytes + other.bytes).sha256() fun serializedHash(x: T): SecureHash { val kryo = extendKryoHash(createKryo()) //Dealing with HashMaps inside states. diff --git a/core/src/main/kotlin/net/corda/core/transactions/SignedTransaction.kt b/core/src/main/kotlin/net/corda/core/transactions/SignedTransaction.kt index aedbda4aef..c8a1700542 100644 --- a/core/src/main/kotlin/net/corda/core/transactions/SignedTransaction.kt +++ b/core/src/main/kotlin/net/corda/core/transactions/SignedTransaction.kt @@ -82,7 +82,7 @@ data class SignedTransaction(val txBits: SerializedBytes, @Throws(SignatureException::class) fun checkSignaturesAreValid() { for (sig in sigs) { - sig.verifyWithECDSA(id.bits) + sig.verifyWithECDSA(id.bytes) } } diff --git a/core/src/main/kotlin/net/corda/core/transactions/TransactionBuilder.kt b/core/src/main/kotlin/net/corda/core/transactions/TransactionBuilder.kt index aac493468c..ffb4ca6513 100644 --- a/core/src/main/kotlin/net/corda/core/transactions/TransactionBuilder.kt +++ b/core/src/main/kotlin/net/corda/core/transactions/TransactionBuilder.kt @@ -97,7 +97,7 @@ open class TransactionBuilder( fun signWith(key: KeyPair): TransactionBuilder { check(currentSigs.none { it.by == key.public }) { "This partial transaction was already signed by ${key.public}" } val data = toWireTransaction().id - addSignatureUnchecked(key.signWithECDSA(data.bits)) + addSignatureUnchecked(key.signWithECDSA(data.bytes)) return this } diff --git a/core/src/main/kotlin/net/corda/core/transactions/WireTransaction.kt b/core/src/main/kotlin/net/corda/core/transactions/WireTransaction.kt index 7f1be20a3a..69fc8315c9 100644 --- a/core/src/main/kotlin/net/corda/core/transactions/WireTransaction.kt +++ b/core/src/main/kotlin/net/corda/core/transactions/WireTransaction.kt @@ -37,8 +37,8 @@ class WireTransaction( init { checkInvariants() } // Cache the serialised form of the transaction and its hash to give us fast access to it. - @Volatile @Transient private var cachedBits: SerializedBytes? = null - val serialized: SerializedBytes get() = cachedBits ?: serialize().apply { cachedBits = this } + @Volatile @Transient private var cachedBytes: SerializedBytes? = null + val serialized: SerializedBytes get() = cachedBytes ?: serialize().apply { cachedBytes = this } //We need cashed leaves hashes and whole tree for an id and Partial Merkle Tree calculation. @Volatile @Transient private var cachedLeavesHashes: List? = null @@ -50,9 +50,9 @@ class WireTransaction( override val id: SecureHash get() = merkleTree.hash companion object { - fun deserialize(bits: SerializedBytes, kryo: Kryo = THREAD_LOCAL_KRYO.get()): WireTransaction { - val wtx = bits.bits.deserialize(kryo) - wtx.cachedBits = bits + fun deserialize(data: SerializedBytes, kryo: Kryo = THREAD_LOCAL_KRYO.get()): WireTransaction { + val wtx = data.bytes.deserialize(kryo) + wtx.cachedBytes = data return wtx } } diff --git a/core/src/main/kotlin/net/corda/protocols/NotaryProtocol.kt b/core/src/main/kotlin/net/corda/protocols/NotaryProtocol.kt index d335a78402..68f644f5c7 100644 --- a/core/src/main/kotlin/net/corda/protocols/NotaryProtocol.kt +++ b/core/src/main/kotlin/net/corda/protocols/NotaryProtocol.kt @@ -61,7 +61,7 @@ object NotaryProtocol { progressTracker.currentStep = VALIDATING when (notaryResult) { is Result.Success -> { - validateSignature(notaryResult.sig, stx.id.bits) + validateSignature(notaryResult.sig, stx.id.bytes) notaryResult.sig } is Result.Error -> { @@ -103,7 +103,7 @@ object NotaryProtocol { beforeCommit(stx, reqIdentity) commitInputStates(wtx, reqIdentity) - val sig = sign(stx.id.bits) + val sig = sign(stx.id.bytes) Result.Success(sig) } catch(e: NotaryException) { Result.Error(e.error) @@ -135,7 +135,7 @@ object NotaryProtocol { uniquenessProvider.commit(tx.inputs, tx.id, reqIdentity) } catch (e: UniquenessException) { val conflictData = e.error.serialize() - val signedConflict = SignedData(conflictData, sign(conflictData.bits)) + val signedConflict = SignedData(conflictData, sign(conflictData.bytes)) throw NotaryException(NotaryError.Conflict(tx, signedConflict)) } } diff --git a/core/src/test/kotlin/net/corda/core/contracts/TransactionTests.kt b/core/src/test/kotlin/net/corda/core/contracts/TransactionTests.kt index b0db3d3559..33834af680 100644 --- a/core/src/test/kotlin/net/corda/core/contracts/TransactionTests.kt +++ b/core/src/test/kotlin/net/corda/core/contracts/TransactionTests.kt @@ -34,8 +34,8 @@ class TransactionTests { type = TransactionType.General(), timestamp = null ) - val bits: SerializedBytes = wtx.serialized - fun make(vararg keys: KeyPair) = SignedTransaction(bits, keys.map { it.signWithECDSA(wtx.id.bits) }, wtx.id) + val bytes: SerializedBytes = wtx.serialized + fun make(vararg keys: KeyPair) = SignedTransaction(bytes, keys.map { it.signWithECDSA(wtx.id.bytes) }, wtx.id) assertFailsWith { make().verifySignatures() } assertEquals( diff --git a/core/src/test/kotlin/net/corda/core/crypto/SignedDataTest.kt b/core/src/test/kotlin/net/corda/core/crypto/SignedDataTest.kt index 1047939df7..56ed35eba9 100644 --- a/core/src/test/kotlin/net/corda/core/crypto/SignedDataTest.kt +++ b/core/src/test/kotlin/net/corda/core/crypto/SignedDataTest.kt @@ -12,7 +12,7 @@ class SignedDataTest { @Test fun `make sure correctly signed data is released`() { val keyPair = generateKeyPair() - val sig = keyPair.private.signWithECDSA(serialized.bits, keyPair.public) + val sig = keyPair.private.signWithECDSA(serialized.bytes, keyPair.public) val wrappedData = SignedData(serialized, sig) val unwrappedData = wrappedData.verified() @@ -23,7 +23,7 @@ class SignedDataTest { fun `make sure incorrectly signed data raises an exception`() { val keyPairA = generateKeyPair() val keyPairB = generateKeyPair() - val sig = keyPairA.private.signWithECDSA(serialized.bits, keyPairB.public) + val sig = keyPairA.private.signWithECDSA(serialized.bytes, keyPairB.public) val wrappedData = SignedData(serialized, sig) wrappedData.verified() } diff --git a/core/src/test/kotlin/net/corda/core/protocols/BroadcastTransactionProtocolTest.kt b/core/src/test/kotlin/net/corda/core/protocols/BroadcastTransactionProtocolTest.kt index 454826c28e..8fae2f3398 100644 --- a/core/src/test/kotlin/net/corda/core/protocols/BroadcastTransactionProtocolTest.kt +++ b/core/src/test/kotlin/net/corda/core/protocols/BroadcastTransactionProtocolTest.kt @@ -26,7 +26,7 @@ class BroadcastTransactionProtocolTest { @Property fun serialiseDeserialiseOfNotifyMessageWorks(@From(NotifyTxRequestMessageGenerator::class) message: NotifyTxRequest) { val kryo = createKryo() - val serialized = message.serialize().bits + val serialized = message.serialize().bytes val deserialized = kryo.readClassAndObject(Input(serialized)) assertEquals(deserialized, message) } diff --git a/core/src/test/kotlin/net/corda/core/serialization/SerializationTokenTest.kt b/core/src/test/kotlin/net/corda/core/serialization/SerializationTokenTest.kt index bc542c38b0..eca0ee8c8d 100644 --- a/core/src/test/kotlin/net/corda/core/serialization/SerializationTokenTest.kt +++ b/core/src/test/kotlin/net/corda/core/serialization/SerializationTokenTest.kt @@ -30,9 +30,9 @@ class SerializationTokenTest { val numBytes: Int get() = bytes.size - override fun hashCode() = bytes.bits.size + override fun hashCode() = bytes.size - override fun equals(other: Any?) = other is LargeTokenizable && other.bytes.bits.size == this.bytes.bits.size + override fun equals(other: Any?) = other is LargeTokenizable && other.bytes.size == this.bytes.size } @Test diff --git a/core/src/test/kotlin/net/corda/core/serialization/TransactionSerializationTests.kt b/core/src/test/kotlin/net/corda/core/serialization/TransactionSerializationTests.kt index 4aea91a608..954a04d19b 100644 --- a/core/src/test/kotlin/net/corda/core/serialization/TransactionSerializationTests.kt +++ b/core/src/test/kotlin/net/corda/core/serialization/TransactionSerializationTests.kt @@ -68,7 +68,7 @@ class TransactionSerializationTests { signedTX.verifySignatures() // Corrupt the data and ensure the signature catches the problem. - signedTX.id.bits[5] = 0 + signedTX.id.bytes[5] = 0 assertFailsWith(SignatureException::class) { signedTX.verifySignatures() } diff --git a/core/src/test/kotlin/net/corda/core/utilities/NonEmptySetTest.kt b/core/src/test/kotlin/net/corda/core/utilities/NonEmptySetTest.kt index 44f91afbce..fc2232e019 100644 --- a/core/src/test/kotlin/net/corda/core/utilities/NonEmptySetTest.kt +++ b/core/src/test/kotlin/net/corda/core/utilities/NonEmptySetTest.kt @@ -8,9 +8,9 @@ import com.google.common.collect.testing.testers.CollectionAddAllTester import com.google.common.collect.testing.testers.CollectionClearTester import com.google.common.collect.testing.testers.CollectionRemoveAllTester import com.google.common.collect.testing.testers.CollectionRetainAllTester +import junit.framework.TestSuite import net.corda.core.serialization.deserialize import net.corda.core.serialization.serialize -import junit.framework.TestSuite import org.junit.Test import org.junit.runner.RunWith import org.junit.runners.Suite @@ -104,7 +104,7 @@ class NonEmptySetTest { @Test fun `serialize deserialize`() { val expected: NonEmptySet = nonEmptySetOf(-17, 22, 17) - val serialized = expected.serialize().bits + val serialized = expected.serialize().bytes val actual = serialized.deserialize>() assertEquals(expected, actual) diff --git a/finance/src/main/kotlin/net/corda/contracts/CommercialPaper.kt b/finance/src/main/kotlin/net/corda/contracts/CommercialPaper.kt index a14c0ec68f..3794ee6ade 100644 --- a/finance/src/main/kotlin/net/corda/contracts/CommercialPaper.kt +++ b/finance/src/main/kotlin/net/corda/contracts/CommercialPaper.kt @@ -88,13 +88,13 @@ class CommercialPaper : Contract { return when (schema) { is CommercialPaperSchemaV1 -> CommercialPaperSchemaV1.PersistentCommericalPaperState( issuanceParty = this.issuance.party.owningKey.toBase58String(), - issuanceRef = this.issuance.reference.bits, + issuanceRef = this.issuance.reference.bytes, owner = this.owner.toBase58String(), maturity = this.maturityDate, faceValue = this.faceValue.quantity, currency = this.faceValue.token.product.currencyCode, faceValueIssuerParty = this.faceValue.token.issuer.party.owningKey.toBase58String(), - faceValueIssuerRef = this.faceValue.token.issuer.reference.bits + faceValueIssuerRef = this.faceValue.token.issuer.reference.bytes ) else -> throw IllegalArgumentException("Unrecognised schema $schema") } diff --git a/finance/src/main/kotlin/net/corda/contracts/asset/Cash.kt b/finance/src/main/kotlin/net/corda/contracts/asset/Cash.kt index 5bee4fd506..a436afb253 100644 --- a/finance/src/main/kotlin/net/corda/contracts/asset/Cash.kt +++ b/finance/src/main/kotlin/net/corda/contracts/asset/Cash.kt @@ -108,7 +108,7 @@ class Cash : OnLedgerAsset() { pennies = this.amount.quantity, currency = this.amount.token.product.currencyCode, issuerParty = this.amount.token.issuer.party.owningKey.toBase58String(), - issuerRef = this.amount.token.issuer.reference.bits + issuerRef = this.amount.token.issuer.reference.bytes ) else -> throw IllegalArgumentException("Unrecognised schema $schema") } diff --git a/node/src/main/kotlin/net/corda/node/services/api/AbstractNodeService.kt b/node/src/main/kotlin/net/corda/node/services/api/AbstractNodeService.kt index af209088c2..9ea584162f 100644 --- a/node/src/main/kotlin/net/corda/node/services/api/AbstractNodeService.kt +++ b/node/src/main/kotlin/net/corda/node/services/api/AbstractNodeService.kt @@ -37,7 +37,7 @@ abstract class AbstractNodeService(val services: ServiceHubInternal) : Singleton val response = handler(request) // If the return type R is Unit, then do not send a response if (response.javaClass != Unit.javaClass) { - val msg = net.createMessage(topic, request.sessionID, response.serialize().bits) + val msg = net.createMessage(topic, request.sessionID, response.serialize().bytes) net.send(msg, request.replyTo) } } catch(e: Exception) { diff --git a/node/src/main/kotlin/net/corda/node/services/messaging/NodeMessagingClient.kt b/node/src/main/kotlin/net/corda/node/services/messaging/NodeMessagingClient.kt index 07320bcadc..d1fc9e21dd 100644 --- a/node/src/main/kotlin/net/corda/node/services/messaging/NodeMessagingClient.kt +++ b/node/src/main/kotlin/net/corda/node/services/messaging/NodeMessagingClient.kt @@ -426,10 +426,10 @@ class NodeMessagingClient(override val config: NodeConfiguration, var dispatcher: RPCDispatcher? = null private fun createRPCDispatcher(ops: RPCOps, userService: RPCUserService) = object : RPCDispatcher(ops, userService) { - override fun send(bits: SerializedBytes<*>, toAddress: String) { + override fun send(data: SerializedBytes<*>, toAddress: String) { state.locked { val msg = session!!.createMessage(false).apply { - writeBodyBufferBytes(bits.bits) + writeBodyBufferBytes(data.bytes) // Use the magic deduplication property built into Artemis as our message identity too putStringProperty(HDR_DUPLICATE_DETECTION_ID, SimpleString(UUID.randomUUID().toString())) } diff --git a/node/src/main/kotlin/net/corda/node/services/messaging/RPCDispatcher.kt b/node/src/main/kotlin/net/corda/node/services/messaging/RPCDispatcher.kt index acd154bf5a..bb30852022 100644 --- a/node/src/main/kotlin/net/corda/node/services/messaging/RPCDispatcher.kt +++ b/node/src/main/kotlin/net/corda/node/services/messaging/RPCDispatcher.kt @@ -100,7 +100,7 @@ abstract class RPCDispatcher(val ops: RPCOps, val userService: RPCUserService) { send(responseBits, replyTo) } - abstract fun send(bits: SerializedBytes<*>, toAddress: String) + abstract fun send(data: SerializedBytes<*>, toAddress: String) fun start(rpcConsumer: ClientConsumer, rpcNotificationConsumer: ClientConsumer?, onExecutor: AffinityExecutor) { rpcNotificationConsumer?.setMessageHandler { msg -> diff --git a/node/src/main/kotlin/net/corda/node/services/network/InMemoryNetworkMapCache.kt b/node/src/main/kotlin/net/corda/node/services/network/InMemoryNetworkMapCache.kt index f81c552a95..a9bb893011 100644 --- a/node/src/main/kotlin/net/corda/node/services/network/InMemoryNetworkMapCache.kt +++ b/node/src/main/kotlin/net/corda/node/services/network/InMemoryNetworkMapCache.kt @@ -110,7 +110,7 @@ open class InMemoryNetworkMapCache : SingletonSerializeAsToken(), NetworkMapCach try { val req = message.data.deserialize() val ackMessage = net.createMessage(NetworkMapService.PUSH_ACK_PROTOCOL_TOPIC, DEFAULT_SESSION_ID, - NetworkMapService.UpdateAcknowledge(req.mapVersion, net.myAddress).serialize().bits) + NetworkMapService.UpdateAcknowledge(req.mapVersion, net.myAddress).serialize().bytes) net.send(ackMessage, req.replyTo) processUpdatePush(req) } catch(e: NodeMapError) { diff --git a/node/src/main/kotlin/net/corda/node/services/network/NetworkMapService.kt b/node/src/main/kotlin/net/corda/node/services/network/NetworkMapService.kt index d3244225c7..ceacaa7c95 100644 --- a/node/src/main/kotlin/net/corda/node/services/network/NetworkMapService.kt +++ b/node/src/main/kotlin/net/corda/node/services/network/NetworkMapService.kt @@ -199,7 +199,7 @@ abstract class AbstractNetworkMapService // TODO: Once we have a better established messaging system, we can probably send // to a MessageRecipientGroup that nodes join/leave, rather than the network map // service itself managing the group - val update = NetworkMapService.Update(wireReg, mapVersion, net.myAddress).serialize().bits + val update = NetworkMapService.Update(wireReg, mapVersion, net.myAddress).serialize().bytes val message = net.createMessage(NetworkMapService.PUSH_PROTOCOL_TOPIC, DEFAULT_SESSION_ID, update) subscribers.locked { @@ -333,7 +333,7 @@ class NodeRegistration(val node: NodeInfo, val serial: Long, val type: AddOrRemo */ fun toWire(privateKey: PrivateKey): WireNodeRegistration { val regSerialized = this.serialize() - val regSig = privateKey.signWithECDSA(regSerialized.bits, node.legalIdentity.owningKey.singleKey) + val regSig = privateKey.signWithECDSA(regSerialized.bytes, node.legalIdentity.owningKey.singleKey) return WireNodeRegistration(regSerialized, regSig) } diff --git a/node/src/main/kotlin/net/corda/node/services/transactions/RaftUniquenessProvider.kt b/node/src/main/kotlin/net/corda/node/services/transactions/RaftUniquenessProvider.kt index 2eeeb584e7..feaa2f9153 100644 --- a/node/src/main/kotlin/net/corda/node/services/transactions/RaftUniquenessProvider.kt +++ b/node/src/main/kotlin/net/corda/node/services/transactions/RaftUniquenessProvider.kt @@ -117,7 +117,7 @@ class RaftUniquenessProvider(storagePath: Path, myAddress: HostAndPort, clusterA */ private fun encode(items: List>): Map { fun StateRef.encoded() = "$txhash:$index" - return items.map { it.first.encoded() to it.second.serialize().bits }.toMap() + return items.map { it.first.encoded() to it.second.serialize().bytes }.toMap() } private fun decode(items: Map): Map { diff --git a/node/src/main/kotlin/net/corda/node/utilities/JDBCHashMap.kt b/node/src/main/kotlin/net/corda/node/utilities/JDBCHashMap.kt index 740f7f56d3..8b5f961e3c 100644 --- a/node/src/main/kotlin/net/corda/node/utilities/JDBCHashMap.kt +++ b/node/src/main/kotlin/net/corda/node/utilities/JDBCHashMap.kt @@ -52,7 +52,7 @@ class JDBCHashMap(tableName: String, fun bytesToBlob(value: SerializedBytes<*>, finalizables: MutableList<() -> Unit>): Blob { val blob = TransactionManager.current().connection.createBlob() finalizables += { blob.free() } - blob.setBytes(1, value.bits) + blob.setBytes(1, value.bytes) return blob } diff --git a/node/src/main/kotlin/net/corda/node/utilities/JsonSupport.kt b/node/src/main/kotlin/net/corda/node/utilities/JsonSupport.kt index 1f790334b8..056eda9b95 100644 --- a/node/src/main/kotlin/net/corda/node/utilities/JsonSupport.kt +++ b/node/src/main/kotlin/net/corda/node/utilities/JsonSupport.kt @@ -15,7 +15,6 @@ import net.corda.core.node.NodeInfo import net.corda.core.node.services.IdentityService import net.corda.core.serialization.deserialize import net.corda.core.serialization.serialize -import net.corda.core.crypto.* import net.i2p.crypto.eddsa.EdDSAPublicKey import java.math.BigDecimal import java.time.LocalDate @@ -113,7 +112,7 @@ object JsonSupport { object NodeInfoSerializer : JsonSerializer() { override fun serialize(value: NodeInfo, gen: JsonGenerator, serializers: SerializerProvider) { - gen.writeString(Base58.encode(value.serialize().bits)) + gen.writeString(Base58.encode(value.serialize().bytes)) } } diff --git a/samples/irs-demo/src/main/kotlin/net/corda/irs/api/NodeInterestRates.kt b/samples/irs-demo/src/main/kotlin/net/corda/irs/api/NodeInterestRates.kt index c54f84f34e..ef8903e806 100644 --- a/samples/irs-demo/src/main/kotlin/net/corda/irs/api/NodeInterestRates.kt +++ b/samples/irs-demo/src/main/kotlin/net/corda/irs/api/NodeInterestRates.kt @@ -13,12 +13,10 @@ import net.corda.core.node.services.ServiceType import net.corda.core.protocols.ProtocolLogic import net.corda.core.serialization.SingletonSerializeAsToken import net.corda.core.transactions.FilteredTransaction -import net.corda.core.transactions.WireTransaction import net.corda.core.utilities.ProgressTracker import net.corda.irs.protocols.FixingProtocol import net.corda.irs.protocols.RatesFixProtocol import net.corda.node.services.api.AcceptsFileUpload -import net.corda.node.services.api.ServiceHubInternal import net.corda.node.utilities.AbstractJDBCHashSet import net.corda.node.utilities.FiberBox import net.corda.node.utilities.JDBCHashedTable @@ -224,7 +222,7 @@ object NodeInterestRates { // // Note that we will happily sign an invalid transaction: we don't bother trying to validate the whole // thing. This is so that later on we can start using tear-offs. - return signingKey.signWithECDSA(merkleRoot.bits, identity) + return signingKey.signWithECDSA(merkleRoot.bytes, identity) } }