Last active
May 20, 2018 02:44
-
-
Save ayinot/0edab64b4251bbcdbd923d8d175d314c to your computer and use it in GitHub Desktop.
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
package com.example.state | |
import com.example.schema.LoanSchemaV1 | |
import net.corda.core.contracts.ContractState | |
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 | |
/** | |
* The state object recording Loan agreements between two parties. | |
* | |
* A state must implement [ContractState] or one of its descendants. | |
* | |
* @param loanAmount the value of the loan. | |
* @param lender the party lending the IOU. | |
* @param borrower the party receiving and approving the loan. | |
*/ | |
data class LoanState(val loanAmount: Int, | |
val borrower: Party, | |
val interestRate: Int, | |
val lender: List<Party>, | |
override val linearId: UniqueIdentifier = UniqueIdentifier()): | |
LinearState, QueryableState { | |
/** The public keys of the involved parties. */ | |
override val participants: List<AbstractParty> get() = listOf(borrower)+lender | |
override fun generateMappedObject(schema: MappedSchema): PersistentState { | |
return when (schema) { | |
is LoanSchemaV1-> LoanSchemaV1.PersistentLoan( | |
this.lender.toString(), | |
this.borrower.name.toString(), | |
this.loanAmount, | |
this.interestRate, | |
this.linearId.id | |
) | |
else -> throw IllegalArgumentException("Unrecognised schema $schema") | |
} | |
} | |
override fun supportedSchemas(): Iterable<MappedSchema> = listOf(LoanSchemaV1) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment