Remove deprecated code

*Remove dummy public keys in preference for EdDSA keys generated from fixed entropy sources, as a more accurate reflection of real uses. Also eliminates a serialization format issue with dummy keys which would have to be resolved otherwise.
* Remove deprecated 'by' keyword from contracts DSL
* Remove deprecated parts of CordaPluginRegistry
This commit is contained in:
Ross Nicoll 2017-08-15 01:17:36 +01:00 committed by GitHub
parent 62576b12b3
commit 8f8a5ff774
11 changed files with 52 additions and 107 deletions

View File

@ -55,13 +55,6 @@ object Requirements {
infix inline fun String.using(expr: Boolean) {
if (!expr) throw IllegalArgumentException("Failed requirement: $this")
}
// Avoid overloading Kotlin keywords
@Deprecated("This function is deprecated, use 'using' instead",
ReplaceWith("using (expr)", "net.corda.core.contracts.Requirements.using"))
@Suppress("NOTHING_TO_INLINE") // Inlining this takes it out of our committed ABI.
infix inline fun String.by(expr: Boolean) {
using(expr)
}
}
inline fun <R> requireThat(body: Requirements.() -> R) = Requirements.body()

View File

@ -4,7 +4,6 @@ import net.corda.core.crypto.SignatureMetadata
import net.corda.core.crypto.TransactionSignature
import net.corda.core.identity.AnonymousParty
import net.corda.core.serialization.CordaSerializable
import java.math.BigInteger
import java.security.PublicKey
@CordaSerializable
@ -18,18 +17,5 @@ object NullPublicKey : PublicKey, Comparable<PublicKey> {
val NULL_PARTY = AnonymousParty(NullPublicKey)
// TODO: Clean up this duplication between Null and Dummy public key
@CordaSerializable
@Deprecated("Has encoding format problems, consider entropyToKeyPair() instead")
class DummyPublicKey(val s: String) : PublicKey, Comparable<PublicKey> {
override fun getAlgorithm() = "DUMMY"
override fun getEncoded() = s.toByteArray()
override fun getFormat() = "ASN.1"
override fun compareTo(other: PublicKey): Int = BigInteger(encoded).compareTo(BigInteger(other.encoded))
override fun equals(other: Any?) = other is DummyPublicKey && other.s == s
override fun hashCode(): Int = s.hashCode()
override fun toString() = "PUBKEY[$s]"
}
/** A signature with a key and value of zero. Useful when you want a signature object that you know won't ever be used. */
val NULL_SIGNATURE = TransactionSignature(ByteArray(32), NullPublicKey, SignatureMetadata(1, -1))

View File

@ -13,34 +13,6 @@ import java.util.function.Function
* to extend a Corda node with additional application services.
*/
abstract class CordaPluginRegistry {
@Suppress("unused")
@Deprecated("This is no longer in use, moved to WebServerPluginRegistry class in webserver module",
level = DeprecationLevel.ERROR, replaceWith = ReplaceWith("net.corda.webserver.services.WebServerPluginRegistry"))
open val webApis: List<Function<CordaRPCOps, out Any>> get() = emptyList()
@Suppress("unused")
@Deprecated("This is no longer in use, moved to WebServerPluginRegistry class in webserver module",
level = DeprecationLevel.ERROR, replaceWith = ReplaceWith("net.corda.webserver.services.WebServerPluginRegistry"))
open val staticServeDirs: Map<String, String> get() = emptyMap()
@Suppress("unused")
@Deprecated("This is no longer needed. Instead annotate any flows that need to be invoked via RPC with " +
"@StartableByRPC and any scheduled flows with @SchedulableFlow", level = DeprecationLevel.ERROR)
open val requiredFlows: Map<String, Set<String>> get() = emptyMap()
/**
* List of lambdas constructing additional long lived services to be hosted within the node.
* They expect a single [PluginServiceHub] parameter as input.
* The [PluginServiceHub] will be fully constructed before the plugin service is created and will
* allow access to the Flow factory and Flow initiation entry points there.
*/
@Suppress("unused")
@Deprecated("This is no longer used. If you need to create your own service, such as an oracle, then use the " +
"@CordaService annotation. For flow registrations use @InitiatedBy.", level = DeprecationLevel.ERROR)
open val servicePlugins: List<Function<PluginServiceHub, out Any>> get() = emptyList()
/**
* Optionally whitelist types for use in object serialization, as we lock down the types that can be serialized.
*

View File

@ -28,13 +28,13 @@ import org.jetbrains.annotations.NotNull;
import java.security.GeneralSecurityException;
import java.security.PublicKey;
import java.security.SignatureException;
import java.time.Duration;
import java.time.Instant;
import java.util.List;
import java.util.Set;
import static net.corda.core.contracts.ContractsDSL.requireThat;
import static net.corda.testing.TestConstants.getDUMMY_PUBKEY_1;
import static net.corda.testing.TestConstants.getALICE_KEY;
// We group our two flows inside a singleton object to indicate that they work
// together.
@ -109,7 +109,7 @@ public class FlowCookbookJava {
// We'll be using a dummy public key for demonstration purposes.
// These are built in to Corda, and are generally used for writing
// tests.
PublicKey dummyPubKey = getDUMMY_PUBKEY_1();
PublicKey dummyPubKey = getALICE_KEY().getPublic();
/*---------------------------
* IDENTIFYING OTHER NODES *

View File

@ -23,7 +23,7 @@ import net.corda.core.utilities.ProgressTracker.Step
import net.corda.core.utilities.UntrustworthyData
import net.corda.core.utilities.seconds
import net.corda.core.utilities.unwrap
import net.corda.testing.DUMMY_PUBKEY_1
import net.corda.testing.ALICE_PUBKEY
import net.corda.testing.contracts.DummyContract
import net.corda.testing.contracts.DummyState
import org.bouncycastle.asn1.x500.X500Name
@ -92,7 +92,7 @@ object FlowCookbook {
// We'll be using a dummy public key for demonstration purposes.
// These are built in to Corda, and are generally used for writing
// tests.
val dummyPubKey: PublicKey = DUMMY_PUBKEY_1
val dummyPubKey: PublicKey = ALICE_PUBKEY
/**--------------------------
* IDENTIFYING OTHER NODES *

View File

@ -8,8 +8,6 @@ import org.junit.Test;
import static net.corda.core.contracts.ContractsDSL.DOLLARS;
import static net.corda.core.contracts.ContractsDSL.issuedBy;
import static net.corda.testing.TestConstants.getDUMMY_PUBKEY_1;
import static net.corda.testing.TestConstants.getDUMMY_PUBKEY_2;
import static net.corda.testing.CoreTestUtils.*;
/**
@ -18,8 +16,8 @@ import static net.corda.testing.CoreTestUtils.*;
public class CashTestsJava {
private final OpaqueBytes defaultRef = new OpaqueBytes(new byte[]{1});
private final PartyAndReference defaultIssuer = getMEGA_CORP().ref(defaultRef);
private final Cash.State inState = new Cash.State(issuedBy(DOLLARS(1000), defaultIssuer), new AnonymousParty(getDUMMY_PUBKEY_1()));
private final Cash.State outState = new Cash.State(inState.getAmount(), new AnonymousParty(getDUMMY_PUBKEY_2()));
private final Cash.State inState = new Cash.State(issuedBy(DOLLARS(1000), defaultIssuer), new AnonymousParty(getMEGA_CORP_PUBKEY()));
private final Cash.State outState = new Cash.State(inState.getAmount(), new AnonymousParty(getMINI_CORP_PUBKEY()));
@Test
public void trivial() {
@ -29,7 +27,7 @@ public class CashTestsJava {
tx.failsWith("the amounts balance");
tx.tweak(tw -> {
tw.output(new Cash.State(issuedBy(DOLLARS(2000), defaultIssuer), new AnonymousParty(getDUMMY_PUBKEY_2())));
tw.output(new Cash.State(issuedBy(DOLLARS(2000), defaultIssuer), new AnonymousParty(getMINI_CORP_PUBKEY())));
return tw.failsWith("the amounts balance");
});
@ -40,7 +38,7 @@ public class CashTestsJava {
});
tx.tweak(tw -> {
tw.output(outState);
tw.command(getDUMMY_PUBKEY_2(), new Cash.Commands.Move());
tw.command(getMINI_CORP_PUBKEY(), new Cash.Commands.Move());
return tw.failsWith("the owning keys are a subset of the signing keys");
});
tx.tweak(tw -> {
@ -48,14 +46,14 @@ public class CashTestsJava {
// issuedBy() can't be directly imported because it conflicts with other identically named functions
// with different overloads (for some reason).
tw.output(CashKt.issuedBy(outState, getMINI_CORP()));
tw.command(getDUMMY_PUBKEY_1(), new Cash.Commands.Move());
tw.command(getMEGA_CORP_PUBKEY(), new Cash.Commands.Move());
return tw.failsWith("at least one cash input");
});
// Simple reallocation works.
return tx.tweak(tw -> {
tw.output(outState);
tw.command(getDUMMY_PUBKEY_1(), new Cash.Commands.Move());
tw.command(getMEGA_CORP_PUBKEY(), new Cash.Commands.Move());
return tw.verifies();
});
});

View File

@ -153,7 +153,7 @@ class CommercialPaperTestsGeneric {
fun `key mismatch at issue`() {
transaction {
output { thisTest.getPaper() }
command(DUMMY_PUBKEY_1) { thisTest.getIssueCommand(DUMMY_NOTARY) }
command(MINI_CORP_PUBKEY) { thisTest.getIssueCommand(DUMMY_NOTARY) }
timeWindow(TEST_TX_TIME)
this `fails with` "output states are issued by a command signer"
}

View File

@ -30,11 +30,11 @@ class CashTests : TestDependencyInjectionBase() {
val defaultIssuer = MEGA_CORP.ref(defaultRef)
val inState = Cash.State(
amount = 1000.DOLLARS `issued by` defaultIssuer,
owner = AnonymousParty(DUMMY_PUBKEY_1)
owner = AnonymousParty(ALICE_PUBKEY)
)
// Input state held by the issuer
val issuerInState = inState.copy(owner = defaultIssuer.party)
val outState = issuerInState.copy(owner = AnonymousParty(DUMMY_PUBKEY_2))
val outState = issuerInState.copy(owner = AnonymousParty(BOB_PUBKEY))
fun Cash.State.editDepositRef(ref: Byte) = copy(
amount = Amount(amount.quantity, token = amount.token.copy(amount.token.issuer.copy(reference = OpaqueBytes.of(ref))))
@ -91,19 +91,19 @@ class CashTests : TestDependencyInjectionBase() {
}
tweak {
output { outState }
command(DUMMY_PUBKEY_2) { Cash.Commands.Move() }
command(BOB_PUBKEY) { Cash.Commands.Move() }
this `fails with` "the owning keys are a subset of the signing keys"
}
tweak {
output { outState }
output { outState `issued by` MINI_CORP }
command(DUMMY_PUBKEY_1) { Cash.Commands.Move() }
command(ALICE_PUBKEY) { Cash.Commands.Move() }
this `fails with` "at least one cash input"
}
// Simple reallocation works.
tweak {
output { outState }
command(DUMMY_PUBKEY_1) { Cash.Commands.Move() }
command(ALICE_PUBKEY) { Cash.Commands.Move() }
this.verifies()
}
}
@ -127,14 +127,14 @@ class CashTests : TestDependencyInjectionBase() {
// institution is allowed to issue as much cash as they want.
transaction {
output { outState }
command(DUMMY_PUBKEY_1) { Cash.Commands.Issue() }
command(ALICE_PUBKEY) { Cash.Commands.Issue() }
this `fails with` "output states are issued by a command signer"
}
transaction {
output {
Cash.State(
amount = 1000.DOLLARS `issued by` MINI_CORP.ref(12, 34),
owner = AnonymousParty(DUMMY_PUBKEY_1)
owner = AnonymousParty(ALICE_PUBKEY)
)
}
tweak {
@ -151,13 +151,13 @@ class CashTests : TestDependencyInjectionBase() {
initialiseTestSerialization()
// Test generation works.
val tx: WireTransaction = TransactionBuilder(notary = null).apply {
Cash().generateIssue(this, 100.DOLLARS `issued by` MINI_CORP.ref(12, 34), owner = AnonymousParty(DUMMY_PUBKEY_1), notary = DUMMY_NOTARY)
Cash().generateIssue(this, 100.DOLLARS `issued by` MINI_CORP.ref(12, 34), owner = AnonymousParty(ALICE_PUBKEY), notary = DUMMY_NOTARY)
}.toWireTransaction()
assertTrue(tx.inputs.isEmpty())
val s = tx.outputsOfType<Cash.State>().single()
assertEquals(100.DOLLARS `issued by` MINI_CORP.ref(12, 34), s.amount)
assertEquals(MINI_CORP as AbstractParty, s.amount.token.issuer.party)
assertEquals(AnonymousParty(DUMMY_PUBKEY_1), s.owner)
assertEquals(AnonymousParty(ALICE_PUBKEY), s.owner)
assertTrue(tx.commands[0].value is Cash.Commands.Issue)
assertEquals(MINI_CORP_PUBKEY, tx.commands[0].signers[0])
}
@ -168,7 +168,7 @@ class CashTests : TestDependencyInjectionBase() {
// Test issuance from an issued amount
val amount = 100.DOLLARS `issued by` MINI_CORP.ref(12, 34)
val tx: WireTransaction = TransactionBuilder(notary = null).apply {
Cash().generateIssue(this, amount, owner = AnonymousParty(DUMMY_PUBKEY_1), notary = DUMMY_NOTARY)
Cash().generateIssue(this, amount, owner = AnonymousParty(ALICE_PUBKEY), notary = DUMMY_NOTARY)
}.toWireTransaction()
assertTrue(tx.inputs.isEmpty())
assertEquals(tx.outputs[0], tx.outputs[0])
@ -183,7 +183,7 @@ class CashTests : TestDependencyInjectionBase() {
// Move fails: not allowed to summon money.
tweak {
command(DUMMY_PUBKEY_1) { Cash.Commands.Move() }
command(ALICE_PUBKEY) { Cash.Commands.Move() }
this `fails with` "the amounts balance"
}
@ -246,7 +246,7 @@ class CashTests : TestDependencyInjectionBase() {
fun testMergeSplit() {
// Splitting value works.
transaction {
command(DUMMY_PUBKEY_1) { Cash.Commands.Move() }
command(ALICE_PUBKEY) { Cash.Commands.Move() }
tweak {
input { inState }
val splits4 = inState.amount.splitEvenly(4)
@ -313,7 +313,7 @@ class CashTests : TestDependencyInjectionBase() {
input {
inState.copy(
amount = 150.POUNDS `issued by` defaultIssuer,
owner = AnonymousParty(DUMMY_PUBKEY_2)
owner = AnonymousParty(BOB_PUBKEY)
)
}
output { outState.copy(amount = 1150.DOLLARS `issued by` defaultIssuer) }
@ -324,7 +324,7 @@ class CashTests : TestDependencyInjectionBase() {
input { inState }
input { inState `issued by` MINI_CORP }
output { outState }
command(DUMMY_PUBKEY_1) { Cash.Commands.Move() }
command(ALICE_PUBKEY) { Cash.Commands.Move() }
this `fails with` "the amounts balance"
}
// Can't combine two different deposits at the same issuer.
@ -390,7 +390,7 @@ class CashTests : TestDependencyInjectionBase() {
input { inState }
output { outState.copy(amount = inState.amount - (200.DOLLARS `issued by` defaultIssuer)) }
command(MEGA_CORP_PUBKEY) { Cash.Commands.Exit(200.DOLLARS `issued by` defaultIssuer) }
command(DUMMY_PUBKEY_1) { Cash.Commands.Move() }
command(ALICE_PUBKEY) { Cash.Commands.Move() }
this `fails with` "the amounts balance"
}
}
@ -404,20 +404,20 @@ class CashTests : TestDependencyInjectionBase() {
// Can't merge them together.
tweak {
output { inState.copy(owner = AnonymousParty(DUMMY_PUBKEY_2), amount = 2000.DOLLARS `issued by` defaultIssuer) }
output { inState.copy(owner = AnonymousParty(BOB_PUBKEY), amount = 2000.DOLLARS `issued by` defaultIssuer) }
this `fails with` "the amounts balance"
}
// Missing MiniCorp deposit
tweak {
output { inState.copy(owner = AnonymousParty(DUMMY_PUBKEY_2)) }
output { inState.copy(owner = AnonymousParty(DUMMY_PUBKEY_2)) }
output { inState.copy(owner = AnonymousParty(BOB_PUBKEY)) }
output { inState.copy(owner = AnonymousParty(BOB_PUBKEY)) }
this `fails with` "the amounts balance"
}
// This works.
output { inState.copy(owner = AnonymousParty(DUMMY_PUBKEY_2)) }
output { inState.copy(owner = AnonymousParty(DUMMY_PUBKEY_2)) `issued by` MINI_CORP }
command(DUMMY_PUBKEY_1) { Cash.Commands.Move() }
output { inState.copy(owner = AnonymousParty(BOB_PUBKEY)) }
output { inState.copy(owner = AnonymousParty(BOB_PUBKEY)) `issued by` MINI_CORP }
command(ALICE_PUBKEY) { Cash.Commands.Move() }
this.verifies()
}
}
@ -426,12 +426,12 @@ class CashTests : TestDependencyInjectionBase() {
fun multiCurrency() {
// Check we can do an atomic currency trade tx.
transaction {
val pounds = Cash.State(658.POUNDS `issued by` MINI_CORP.ref(3, 4, 5), AnonymousParty(DUMMY_PUBKEY_2))
input { inState `owned by` AnonymousParty(DUMMY_PUBKEY_1) }
val pounds = Cash.State(658.POUNDS `issued by` MINI_CORP.ref(3, 4, 5), AnonymousParty(BOB_PUBKEY))
input { inState `owned by` AnonymousParty(ALICE_PUBKEY) }
input { pounds }
output { inState `owned by` AnonymousParty(DUMMY_PUBKEY_2) }
output { pounds `owned by` AnonymousParty(DUMMY_PUBKEY_1) }
command(DUMMY_PUBKEY_1, DUMMY_PUBKEY_2) { Cash.Commands.Move() }
output { inState `owned by` AnonymousParty(BOB_PUBKEY) }
output { pounds `owned by` AnonymousParty(ALICE_PUBKEY) }
command(ALICE_PUBKEY, BOB_PUBKEY) { Cash.Commands.Move() }
this.verifies()
}
@ -444,7 +444,7 @@ class CashTests : TestDependencyInjectionBase() {
val OUR_KEY: KeyPair by lazy { generateKeyPair() }
val OUR_IDENTITY_1: AbstractParty get() = AnonymousParty(OUR_KEY.public)
val THEIR_IDENTITY_1 = AnonymousParty(DUMMY_PUBKEY_2)
val THEIR_IDENTITY_1 = AnonymousParty(MINI_CORP_PUBKEY)
fun makeCash(amount: Amount<Currency>, corp: Party, depositRef: Byte = 1) =
StateAndRef(
@ -745,7 +745,7 @@ class CashTests : TestDependencyInjectionBase() {
transaction {
input("MEGA_CORP cash")
output("MEGA_CORP cash".output<Cash.State>().copy(owner = AnonymousParty(DUMMY_PUBKEY_1)))
output("MEGA_CORP cash".output<Cash.State>().copy(owner = AnonymousParty(ALICE_PUBKEY)))
command(MEGA_CORP_PUBKEY) { Cash.Commands.Move() }
this.verifies()
}

View File

@ -44,7 +44,7 @@ class ObligationTests {
quantity = 1000.DOLLARS.quantity,
beneficiary = CHARLIE
)
val outState = inState.copy(beneficiary = AnonymousParty(DUMMY_PUBKEY_2))
val outState = inState.copy(beneficiary = AnonymousParty(BOB_PUBKEY))
val miniCorpServices = MockServices(MINI_CORP_KEY)
val notaryServices = MockServices(DUMMY_NOTARY_KEY)
@ -81,7 +81,7 @@ class ObligationTests {
}
tweak {
output { outState }
command(DUMMY_PUBKEY_2) { Obligation.Commands.Move() }
command(BOB_PUBKEY) { Obligation.Commands.Move() }
this `fails with` "the owning keys are a subset of the signing keys"
}
tweak {
@ -629,7 +629,7 @@ class ObligationTests {
inState.copy(
quantity = 15000,
template = megaCorpPoundSettlement,
beneficiary = AnonymousParty(DUMMY_PUBKEY_2)
beneficiary = AnonymousParty(BOB_PUBKEY)
)
}
output { outState.copy(quantity = 115000) }
@ -702,19 +702,19 @@ class ObligationTests {
// Can't merge them together.
tweak {
output { inState.copy(beneficiary = AnonymousParty(DUMMY_PUBKEY_2), quantity = 200000L) }
output { inState.copy(beneficiary = AnonymousParty(BOB_PUBKEY), quantity = 200000L) }
this `fails with` "the amounts balance"
}
// Missing MiniCorp deposit
tweak {
output { inState.copy(beneficiary = AnonymousParty(DUMMY_PUBKEY_2)) }
output { inState.copy(beneficiary = AnonymousParty(DUMMY_PUBKEY_2)) }
output { inState.copy(beneficiary = AnonymousParty(BOB_PUBKEY)) }
output { inState.copy(beneficiary = AnonymousParty(BOB_PUBKEY)) }
this `fails with` "the amounts balance"
}
// This works.
output { inState.copy(beneficiary = AnonymousParty(DUMMY_PUBKEY_2)) }
output { inState.copy(beneficiary = AnonymousParty(DUMMY_PUBKEY_2)) `issued by` MINI_CORP }
output { inState.copy(beneficiary = AnonymousParty(BOB_PUBKEY)) }
output { inState.copy(beneficiary = AnonymousParty(BOB_PUBKEY)) `issued by` MINI_CORP }
command(CHARLIE.owningKey) { Obligation.Commands.Move() }
this.verifies()
}
@ -724,12 +724,12 @@ class ObligationTests {
fun multiCurrency() {
// Check we can do an atomic currency trade tx.
transaction {
val pounds = Obligation.State(Lifecycle.NORMAL, MINI_CORP, megaCorpPoundSettlement, 658.POUNDS.quantity, AnonymousParty(DUMMY_PUBKEY_2))
val pounds = Obligation.State(Lifecycle.NORMAL, MINI_CORP, megaCorpPoundSettlement, 658.POUNDS.quantity, AnonymousParty(BOB_PUBKEY))
input { inState `owned by` CHARLIE }
input { pounds }
output { inState `owned by` AnonymousParty(DUMMY_PUBKEY_2) }
output { inState `owned by` AnonymousParty(BOB_PUBKEY) }
output { pounds `owned by` CHARLIE }
command(CHARLIE.owningKey, DUMMY_PUBKEY_2) { Obligation.Commands.Move() }
command(CHARLIE.owningKey, BOB_PUBKEY) { Obligation.Commands.Move() }
this.verifies()
}

View File

@ -171,7 +171,7 @@ class RequeryConfigurationTest : TestDependencyInjectionBase() {
index = txnState.index
stateStatus = Vault.StateStatus.UNCONSUMED
contractStateClassName = DummyContract.SingleOwnerState::class.java.name
contractState = DummyContract.SingleOwnerState(owner = AnonymousParty(DUMMY_PUBKEY_1)).serialize().bytes
contractState = DummyContract.SingleOwnerState(owner = AnonymousParty(MEGA_CORP_PUBKEY)).serialize().bytes
notaryName = txn.tx.notary!!.name.toString()
notaryKey = txn.tx.notary!!.owningKey.toBase58String()
recordedTime = Instant.now()

View File

@ -7,7 +7,6 @@ import net.corda.core.contracts.TypeOnlyCommandData
import net.corda.core.crypto.CertificateAndKeyPair
import net.corda.core.crypto.entropyToKeyPair
import net.corda.core.crypto.generateKeyPair
import net.corda.core.crypto.testing.DummyPublicKey
import net.corda.core.identity.Party
import net.corda.core.identity.PartyAndCertificate
import net.corda.core.internal.concurrent.transpose
@ -26,9 +25,6 @@ import java.time.Instant
// A dummy time at which we will be pretending test transactions are created.
val TEST_TX_TIME: Instant get() = Instant.parse("2015-04-17T12:00:00.00Z")
val DUMMY_PUBKEY_1: PublicKey get() = DummyPublicKey("x1")
val DUMMY_PUBKEY_2: PublicKey get() = DummyPublicKey("x2")
val DUMMY_KEY_1: KeyPair by lazy { generateKeyPair() }
val DUMMY_KEY_2: KeyPair by lazy { generateKeyPair() }