Remove unnecessary this in sample code + minor changes to contract paragraph

This commit is contained in:
Tommy Lillehagen 2017-10-06 10:29:29 +01:00
parent d499ee32bb
commit b5a77a7a9c
3 changed files with 27 additions and 27 deletions

View File

@ -31,7 +31,7 @@ class CommercialPaperTest {
transaction { transaction {
attachments(CP_PROGRAM_ID) attachments(CP_PROGRAM_ID)
input(CP_PROGRAM_ID) { inState } input(CP_PROGRAM_ID) { inState }
this.verifies() verifies()
} }
} }
} }
@ -46,7 +46,7 @@ class CommercialPaperTest {
input(CP_PROGRAM_ID) { inState } input(CP_PROGRAM_ID) { inState }
command(MEGA_CORP_PUBKEY) { CommercialPaper.Commands.Move() } command(MEGA_CORP_PUBKEY) { CommercialPaper.Commands.Move() }
attachments(CP_PROGRAM_ID) attachments(CP_PROGRAM_ID)
this.verifies() verifies()
} }
} }
} }
@ -61,7 +61,7 @@ class CommercialPaperTest {
input(CP_PROGRAM_ID) { inState } input(CP_PROGRAM_ID) { inState }
command(MEGA_CORP_PUBKEY) { CommercialPaper.Commands.Move() } command(MEGA_CORP_PUBKEY) { CommercialPaper.Commands.Move() }
attachments(CP_PROGRAM_ID) attachments(CP_PROGRAM_ID)
this `fails with` "the state is propagated" `fails with`("the state is propagated")
} }
} }
} }
@ -76,9 +76,9 @@ class CommercialPaperTest {
input(CP_PROGRAM_ID) { inState } input(CP_PROGRAM_ID) { inState }
command(MEGA_CORP_PUBKEY) { CommercialPaper.Commands.Move() } command(MEGA_CORP_PUBKEY) { CommercialPaper.Commands.Move() }
attachments(CP_PROGRAM_ID) attachments(CP_PROGRAM_ID)
this `fails with` "the state is propagated" `fails with`("the state is propagated")
output(CP_PROGRAM_ID, "alice's paper") { inState.withOwner(ALICE) } output(CP_PROGRAM_ID, "alice's paper") { inState.withOwner(ALICE) }
this.verifies() verifies()
} }
} }
} }
@ -95,11 +95,11 @@ class CommercialPaperTest {
// The wrong pubkey. // The wrong pubkey.
command(BIG_CORP_PUBKEY) { CommercialPaper.Commands.Issue() } command(BIG_CORP_PUBKEY) { CommercialPaper.Commands.Issue() }
timeWindow(TEST_TX_TIME) timeWindow(TEST_TX_TIME)
this `fails with` "output states are issued by a command signer" `fails with`("output states are issued by a command signer")
} }
command(MEGA_CORP_PUBKEY) { CommercialPaper.Commands.Issue() } command(MEGA_CORP_PUBKEY) { CommercialPaper.Commands.Issue() }
timeWindow(TEST_TX_TIME) timeWindow(TEST_TX_TIME)
this.verifies() verifies()
} }
} }
} }
@ -115,11 +115,11 @@ class CommercialPaperTest {
// The wrong pubkey. // The wrong pubkey.
command(BIG_CORP_PUBKEY) { CommercialPaper.Commands.Issue() } command(BIG_CORP_PUBKEY) { CommercialPaper.Commands.Issue() }
timeWindow(TEST_TX_TIME) timeWindow(TEST_TX_TIME)
this `fails with` "output states are issued by a command signer" `fails with`("output states are issued by a command signer")
} }
command(MEGA_CORP_PUBKEY) { CommercialPaper.Commands.Issue() } command(MEGA_CORP_PUBKEY) { CommercialPaper.Commands.Issue() }
timeWindow(TEST_TX_TIME) timeWindow(TEST_TX_TIME)
this.verifies() verifies()
} }
} }
// DOCEND 7 // DOCEND 7
@ -141,7 +141,7 @@ class CommercialPaperTest {
command(MEGA_CORP_PUBKEY) { CommercialPaper.Commands.Issue() } command(MEGA_CORP_PUBKEY) { CommercialPaper.Commands.Issue() }
attachments(CP_PROGRAM_ID) attachments(CP_PROGRAM_ID)
timeWindow(TEST_TX_TIME) timeWindow(TEST_TX_TIME)
this.verifies() verifies()
} }
@ -152,7 +152,7 @@ class CommercialPaperTest {
output(CP_PROGRAM_ID, "alice's paper") { "paper".output<ICommercialPaperState>().withOwner(ALICE) } output(CP_PROGRAM_ID, "alice's paper") { "paper".output<ICommercialPaperState>().withOwner(ALICE) }
command(ALICE_PUBKEY) { Cash.Commands.Move() } command(ALICE_PUBKEY) { Cash.Commands.Move() }
command(MEGA_CORP_PUBKEY) { CommercialPaper.Commands.Move() } command(MEGA_CORP_PUBKEY) { CommercialPaper.Commands.Move() }
this.verifies() verifies()
} }
} }
} }
@ -174,7 +174,7 @@ class CommercialPaperTest {
command(MEGA_CORP_PUBKEY) { CommercialPaper.Commands.Issue() } command(MEGA_CORP_PUBKEY) { CommercialPaper.Commands.Issue() }
attachments(CP_PROGRAM_ID) attachments(CP_PROGRAM_ID)
timeWindow(TEST_TX_TIME) timeWindow(TEST_TX_TIME)
this.verifies() verifies()
} }
transaction("Trade") { transaction("Trade") {
@ -184,7 +184,7 @@ class CommercialPaperTest {
output(CP_PROGRAM_ID, "alice's paper") { "paper".output<ICommercialPaperState>().withOwner(ALICE) } output(CP_PROGRAM_ID, "alice's paper") { "paper".output<ICommercialPaperState>().withOwner(ALICE) }
command(ALICE_PUBKEY) { Cash.Commands.Move() } command(ALICE_PUBKEY) { Cash.Commands.Move() }
command(MEGA_CORP_PUBKEY) { CommercialPaper.Commands.Move() } command(MEGA_CORP_PUBKEY) { CommercialPaper.Commands.Move() }
this.verifies() verifies()
} }
transaction { transaction {
@ -192,10 +192,10 @@ class CommercialPaperTest {
// We moved a paper to another pubkey. // We moved a paper to another pubkey.
output(CP_PROGRAM_ID, "bob's paper") { "paper".output<ICommercialPaperState>().withOwner(BOB) } output(CP_PROGRAM_ID, "bob's paper") { "paper".output<ICommercialPaperState>().withOwner(BOB) }
command(MEGA_CORP_PUBKEY) { CommercialPaper.Commands.Move() } command(MEGA_CORP_PUBKEY) { CommercialPaper.Commands.Move() }
this.verifies() verifies()
} }
this.fails() fails()
} }
} }
// DOCEND 9 // DOCEND 9
@ -216,7 +216,7 @@ class CommercialPaperTest {
command(MEGA_CORP_PUBKEY) { CommercialPaper.Commands.Issue() } command(MEGA_CORP_PUBKEY) { CommercialPaper.Commands.Issue() }
attachments(CP_PROGRAM_ID) attachments(CP_PROGRAM_ID)
timeWindow(TEST_TX_TIME) timeWindow(TEST_TX_TIME)
this.verifies() verifies()
} }
transaction("Trade") { transaction("Trade") {
@ -226,7 +226,7 @@ class CommercialPaperTest {
output(CP_PROGRAM_ID, "alice's paper") { "paper".output<ICommercialPaperState>().withOwner(ALICE) } output(CP_PROGRAM_ID, "alice's paper") { "paper".output<ICommercialPaperState>().withOwner(ALICE) }
command(ALICE_PUBKEY) { Cash.Commands.Move() } command(ALICE_PUBKEY) { Cash.Commands.Move() }
command(MEGA_CORP_PUBKEY) { CommercialPaper.Commands.Move() } command(MEGA_CORP_PUBKEY) { CommercialPaper.Commands.Move() }
this.verifies() verifies()
} }
tweak { tweak {
@ -235,13 +235,13 @@ class CommercialPaperTest {
// We moved a paper to another pubkey. // We moved a paper to another pubkey.
output(CP_PROGRAM_ID, "bob's paper") { "paper".output<ICommercialPaperState>().withOwner(BOB) } output(CP_PROGRAM_ID, "bob's paper") { "paper".output<ICommercialPaperState>().withOwner(BOB) }
command(MEGA_CORP_PUBKEY) { CommercialPaper.Commands.Move() } command(MEGA_CORP_PUBKEY) { CommercialPaper.Commands.Move() }
this.verifies() verifies()
} }
this.fails() fails()
} }
this.verifies() verifies()
} }
} }
// DOCEND 10 // DOCEND 10
} }

View File

@ -476,7 +476,7 @@ generate methods should operate on the same transaction. You can see an example
for the commercial paper contract. for the commercial paper contract.
The paper is given to us as a ``StateAndRef<CommercialPaper.State>`` object. This is exactly what it sounds like: The paper is given to us as a ``StateAndRef<CommercialPaper.State>`` object. This is exactly what it sounds like:
a small object that has a (copy of) a state object, and also the (txhash, index) that indicates the location of this a small object that has a (copy of a) state object, and also the ``(txhash, index)`` that indicates the location of this
state on the ledger. state on the ledger.
We add the existing paper state as an input, the same paper state with the owner field adjusted as an output, We add the existing paper state as an input, the same paper state with the owner field adjusted as an output,

View File

@ -114,7 +114,7 @@ The above code however doesn't compile:
Error:(35, 27) java: incompatible types: bad return type in lambda expression missing return value Error:(35, 27) java: incompatible types: bad return type in lambda expression missing return value
This is deliberate: The DSL forces us to specify either ``this.verifies()`` or ``this `fails with` "some text"`` on the This is deliberate: The DSL forces us to specify either ``verifies()`` or ```fails with`("some text")`` on the
last line of ``transaction``: last line of ``transaction``:
.. container:: codeset .. container:: codeset
@ -160,7 +160,7 @@ When run, that code produces the following error:
net.corda.core.contracts.TransactionVerificationException$ContractRejection: java.lang.IllegalStateException: the state is propagated net.corda.core.contracts.TransactionVerificationException$ContractRejection: java.lang.IllegalStateException: the state is propagated
The transaction verification failed, because we wanted to move paper but didn't specify an output - but the state should be propagated. The transaction verification failed, because we wanted to move paper but didn't specify an output - but the state should be propagated.
However we can specify that this is an intended behaviour by changing ``this.verifies()`` to ``this `fails with` "the state is propagated"``: However we can specify that this is an intended behaviour by changing ``verifies()`` to ```fails with`("the state is propagated")``:
.. container:: codeset .. container:: codeset
@ -256,7 +256,7 @@ Now that we know how to define a single transaction, let's look at how to define
:dedent: 4 :dedent: 4
In this example we declare that ``ALICE`` has $900 but we don't care where from. For this we can use In this example we declare that ``ALICE`` has $900 but we don't care where from. For this we can use
``unverifiedTransaction``. Note how we don't need to specify ``this.verifies()``. ``unverifiedTransaction``. Note how we don't need to specify ``verifies()``.
Notice that we labelled output with ``"alice's $900"``, also in transaction named ``"Issuance"`` Notice that we labelled output with ``"alice's $900"``, also in transaction named ``"Issuance"``
we labelled a commercial paper with ``"paper"``. Now we can subsequently refer to them in other transactions, e.g. we labelled a commercial paper with ``"paper"``. Now we can subsequently refer to them in other transactions, e.g.
@ -265,7 +265,7 @@ by ``input("alice's $900")`` or ``"paper".output<ICommercialPaperState>()``.
The last transaction named ``"Trade"`` exemplifies simple fact of selling the ``CommercialPaper`` to Alice for her $900, The last transaction named ``"Trade"`` exemplifies simple fact of selling the ``CommercialPaper`` to Alice for her $900,
$100 less than the face value at 10% interest after only 7 days. $100 less than the face value at 10% interest after only 7 days.
We can also test whole ledger calling ``this.verifies()`` and ``this.fails()`` on the ledger level. We can also test whole ledger calling ``verifies()`` and ``fails()`` on the ledger level.
To do so let's create a simple example that uses the same input twice: To do so let's create a simple example that uses the same input twice:
.. container:: codeset .. container:: codeset
@ -283,7 +283,7 @@ To do so let's create a simple example that uses the same input twice:
:dedent: 4 :dedent: 4
The transactions ``verifies()`` individually, however the state was spent twice! That's why we need the global ledger The transactions ``verifies()`` individually, however the state was spent twice! That's why we need the global ledger
verification (``this.fails()`` at the end). As in previous examples we can use ``tweak`` to create a local copy of the whole ledger: verification (``fails()`` at the end). As in previous examples we can use ``tweak`` to create a local copy of the whole ledger:
.. container:: codeset .. container:: codeset