Guest User

Untitled

a guest
May 23rd, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.69 KB | None | 0 0
  1. package com.example.state
  2.  
  3. import com.example.schema.LoanSchemaV1
  4. import net.corda.core.contracts.ContractState
  5. import net.corda.core.contracts.LinearState
  6. import net.corda.core.contracts.UniqueIdentifier
  7. import net.corda.core.identity.AbstractParty
  8. import net.corda.core.identity.Party
  9. import net.corda.core.schemas.MappedSchema
  10. import net.corda.core.schemas.PersistentState
  11. import net.corda.core.schemas.QueryableState
  12.  
  13. /**
  14. * The state object recording Loan agreements between two parties.
  15. *
  16. * A state must implement [ContractState] or one of its descendants.
  17. *
  18. * @param loanAmount the value of the loan.
  19. * @param lender the party lending the IOU.
  20. * @param borrower the party receiving and approving the loan.
  21. */
  22. data class LoanState(val loanAmount: Int,
  23. val borrower: Party,
  24. val interestRate: Int,
  25. val lender: List<Party>,
  26. override val linearId: UniqueIdentifier = UniqueIdentifier()):
  27. LinearState, QueryableState {
  28. /** The public keys of the involved parties. */
  29. override val participants: List<AbstractParty> get() = listOf(borrower)+lender
  30.  
  31. override fun generateMappedObject(schema: MappedSchema): PersistentState {
  32. return when (schema) {
  33. is LoanSchemaV1-> LoanSchemaV1.PersistentLoan(
  34. this.lender.toString(),
  35. this.borrower.name.toString(),
  36. this.loanAmount,
  37. this.interestRate,
  38. this.linearId.id
  39. )
  40. else -> throw IllegalArgumentException("Unrecognised schema $schema")
  41. }
  42. }
  43.  
  44. override fun supportedSchemas(): Iterable<MappedSchema> = listOf(LoanSchemaV1)
  45. }
Add Comment
Please, Sign In to add comment