corda-training-template
corda-training-template copied to clipboard
Cannot Issue an IOU on Corda-Training-Template Java-Src
The IOUIssueFlow takes a parameter of IOUState state
. As described in creating-an-instance-of-a-class, we can provide the state object to the flow via the crash shell as (also tried without the dollar sign):
flow start IOUIssueFlow$InitiatorFlow state: { amount: $10, lender: "O=ParticipantB, L=New York, C=GB", borrower: "O=ParticipantC, L=Paris, C=FR" }
This statement works with the Kotlin version of the corda-training-template but throws the following error in the Java version:
No matching constructor found:
- [net.corda.training.state.IOUState]: Could not parse as a command: Cannot construct instance of `net.corda.training.state.IOUState` (no Creators, like default construct, exist): cannot deserialize from Object value (no delegate- or property-based Creator)
at [Source: UNKNOWN; line: -1, column: -1]
Although I am not using the default constructor, the default constructor should still be called by this()
:
@ConstructorForDeserialization
public IOUState(Amount<Currency> amount, Party lender, Party borrower, UniqueIdentifier linearId){
this.amount = amount;
this.lender = lender;
this.borrower = borrower;
this.linearId = linearId;
}
public IOUState(Amount<Currency> amount, Party lender, Party borrower) {
this(amount, lender, borrower, new UniqueIdentifier());
}
What is the proper syntax to issue an IOU state in the corda-training-template?
hello,
I'm getting the same error
flow start IOUIssueFlow$InitiatorFlow arg0: {amount: $1000, lender: "O=Supplier Service,OU=coffeebeans,L=Sydney,C=AU", borrower: "O=Consumer Service,OU=coffeebeans,L=Sydney,C=AU"}
and response
No matching constructor found:
- [class com.coffeebeans.creditum.state.IOUState]: Could not parse as a command: Cannot construct instance of `com.coffeebeans.creditum.state.IOUState` (no Creators, like default construct, exist): cannot deserialize from Object value (no delegate- or property-based Creator)
at [Source: UNKNOWN; line: -1, column: -1]
I found the issue with my code
Maven compiler plugin was defaulting to 3.1 which means that <maven.compiler.parameters>true</maven.compiler.parameters>
was not picked up since this property was added only since version 3.6.2
, check here
On Top of that, I had to change the IOUState constructor by making is json creator. The constructor now looks like this,
@JsonCreator
public IOUState(@JsonProperty("amount") final Amount<Currency> amount,
@JsonProperty("lender") final Party lender,
@JsonProperty("borrower") final Party borrower) {
this(amount, lender, borrower, new Amount<>(0, amount.getToken()), new UniqueIdentifier());
}
Now running the flow works
flow start IOUIssueFlow$InitiatorFlow state: {amount: $1000, lender: "O=Supplier Service,OU=coffeebeans,L=Sydney,C=AU", borrower: "O=Consumer Service,OU=coffeebeans,L=Sydney,C=AU"}
✓ Starting
Requesting signature by notary service
Requesting signature by Notary service
Validating response from Notary service
✓ Broadcasting transaction to participants
▶︎ Done
Flow completed with result: SignedTransaction(id=8FDB7BBC182A0EDAF27CCBD958A9AC49057ED094B13B1957B07BAF3FFC045EE4)
Then querying the vault results in
Sun Jun 07 21:33:20 UTC 2020>>> run vaultQuery contractStateType: com.coffeebeans.creditum.state.IOUState
states:
- state:
data: !<com.coffeebeans.creditum.state.IOUState>
amount: "1000.00 USD"
lender: "OU=coffeebeans, O=Supplier Service, L=Sydney, C=AU"
borrower: "OU=coffeebeans, O=Consumer Service, L=Sydney, C=AU"
paid: "0.00 USD"
linearId:
externalId: null
id: "846828dd-b83e-410a-b144-4d955d2fddc7"
contract: "com.coffeebeans.creditum.contract.IOUContract"
notary: "OU=coffeebeans, O=Notary Service, L=Sydney, C=AU"
encumbrance: null
constraint: !<net.corda.core.contracts.HashAttachmentConstraint>
attachmentId: "A97FC1D2E210A7BC8FE75705E29A5AF284245A3D5E7AC1D945D41D61D5EBACDB"
ref:
txhash: "8FDB7BBC182A0EDAF27CCBD958A9AC49057ED094B13B1957B07BAF3FFC045EE4"
index: 0
statesMetadata:
- ref:
txhash: "8FDB7BBC182A0EDAF27CCBD958A9AC49057ED094B13B1957B07BAF3FFC045EE4"
index: 0
contractStateClassName: "com.coffeebeans.creditum.state.IOUState"
recordedTime: "2020-06-07T21:33:20.398Z"
consumedTime: null
status: "UNCONSUMED"
notary: "OU=coffeebeans, O=Notary Service, L=Sydney, C=AU"
lockId: null
lockUpdateTime: null
relevancyStatus: "RELEVANT"
constraintInfo:
constraint:
attachmentId: "A97FC1D2E210A7BC8FE75705E29A5AF284245A3D5E7AC1D945D41D61D5EBACDB"
totalStatesAvailable: -1
stateTypes: "UNCONSUMED"
otherResults: []