This repository has been archived by the owner on Aug 16, 2019. It is now read-only.
/
IOUState.java
74 lines (66 loc) · 2.48 KB
/
IOUState.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package com.example.state;
import com.example.contract.IOUContract;
import com.example.schema.IOUSchemaV1;
import com.google.common.collect.ImmutableList;
import net.corda.core.contracts.BelongsToContract;
import net.corda.core.contracts.LinearState;
import net.corda.core.contracts.UniqueIdentifier;
import net.corda.core.identity.AbstractParty;
import net.corda.core.identity.Party;
import net.corda.core.schemas.MappedSchema;
import net.corda.core.schemas.PersistentState;
import net.corda.core.schemas.QueryableState;
import java.util.Arrays;
import java.util.List;
/**
* The state object recording IOU agreements between two parties.
*
* A state must implement [ContractState] or one of its descendants.
*/
@BelongsToContract(IOUContract.class)
public class IOUState implements LinearState, QueryableState {
private final Integer value;
private final Party lender;
private final Party borrower;
private final UniqueIdentifier linearId;
/**
* @param value the value of the IOU.
* @param lender the party issuing the IOU.
* @param borrower the party receiving and approving the IOU.
*/
public IOUState(Integer value,
Party lender,
Party borrower,
UniqueIdentifier linearId)
{
this.value = value;
this.lender = lender;
this.borrower = borrower;
this.linearId = linearId;
}
public Integer getValue() { return value; }
public Party getLender() { return lender; }
public Party getBorrower() { return borrower; }
@Override public UniqueIdentifier getLinearId() { return linearId; }
@Override public List<AbstractParty> getParticipants() {
return Arrays.asList(lender, borrower);
}
@Override public PersistentState generateMappedObject(MappedSchema schema) {
if (schema instanceof IOUSchemaV1) {
return new IOUSchemaV1.PersistentIOU(
this.lender.getName().toString(),
this.borrower.getName().toString(),
this.value,
this.linearId.getId());
} else {
throw new IllegalArgumentException("Unrecognised schema $schema");
}
}
@Override public Iterable<MappedSchema> supportedSchemas() {
return ImmutableList.of(new IOUSchemaV1());
}
@Override
public String toString() {
return String.format("IOUState(value=%s, lender=%s, borrower=%s, linearId=%s)", value, lender, borrower, linearId);
}
}