This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class SampleContractV2 implements UpgradedContract<SampleStateV1, SampleStateV2> { | |
// This is used to identify our contract when building a transaction. | |
public static final String ID = "corda.samples.upgrades.contracts.v2.SampleContractV2"; | |
@Override | |
public void verify(LedgerTransaction tx) { | |
// Verify logic goes here | |
} | |
@NotNull |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@NotNull | |
@Override | |
public AttachmentConstraint getLegacyContractConstraint() { | |
// Return the HashAttachment Constraint of the previous jar. Calculate the SHA256 hash of the jar file. | |
return new HashAttachmentConstraint( | |
SecureHash.parse("92F25AD232C099F6BD309B0E99E9C7DF6C62A59C8C8CEA96920E23338D1212E8") | |
); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class SampleStateV2 implements ContractState { | |
private final String field1; | |
private final String field2; | |
// New field introduced in V2 | |
private final String field3; | |
// New fields should be Nullable, so that older states issued with previous could be transacted with the newer version. | |
public SampleStateV2(String field1, String field2, @Nullable String field3) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Sample Flow version 2 | |
@InitiatingFlow(version = 2) | |
@StartableByRPC | |
public class SampleFlow extends FlowLogic<SignedTransaction>{ | |
private final Party counterparty; | |
private final String someData; | |
public SampleFlow(Party counterparty , String someData) { | |
this.counterparty = counterparty; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@BelongsToContract(InsuranceContract.class) | |
public class Insurance implements QueryableState { | |
private final String policyNumber; | |
private final long insuredValue; | |
private final int duration; | |
private final int premium; | |
private final Party insurer; | |
private final Party insuree; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class InsuranceSchemaV1 extends MappedSchema { | |
public InsuranceSchemaV1() { | |
super(InsuranceSchemaFamily.class, 1, ImmutableList.of(PersistentInsurance.class)); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Entity | |
@Table(name = "INSURANCE_DETAIL") | |
public class PersistentInsurance extends PersistentState implements Serializable { | |
@Column private final String policyNumber; | |
@Column private final Long insuredValue; | |
@Column private final Integer duration; | |
@Column private final Integer premium; | |
public PersistentInsurance() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@NotNull | |
@Override | |
public PersistentState generateMappedObject(@NotNull MappedSchema schema) { | |
// Check if the schema is supported by the state | |
if(schema instanceof InsuranceSchemaV1){ | |
return new PersistentInsurance( | |
this.policyNumber, | |
this.insuredValue, | |
this.duration, | |
this.premium, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@CordaSerializable | |
public class VehicleDetail { | |
private final String registrationNumber; | |
private final String chasisNumber; | |
private final String make; | |
private final String model; | |
private final String variant; | |
private final String color; | |
private final String fuelType; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@BelongsToContract(InsuranceContract.class) | |
public class Insurance implements QueryableState { | |
private final VehicleDetail vehicleDetail; | |
// Other fields | |
// Update constructor to include vehicleDetail as parameter | |
public Insurance(String policyNumber, long insuredValue, int duration, | |
int premium, Party insurer, Party insuree, |
OlderNewer