Skip to content

Commit

Permalink
Always require FT Loan in Asset record, make MISMO loan optional (#57)
Browse files Browse the repository at this point in the history
* Require all Asset records to have a Figure Tech loan in the same key-value pair as before

* Remove support for Asset records with a MISMO loan metadata but no Figure Tech loan

* Allow the MISMO loan metadata in an Asset record to be added or removed when executing RecordLoanContract at any record state
  • Loading branch information
rpatel-figure authored Feb 7, 2023
1 parent 2841511 commit bdecde0
Show file tree
Hide file tree
Showing 4 changed files with 143 additions and 206 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import io.provenance.scope.loan.LoanScopeFacts
import io.provenance.scope.loan.LoanScopeProperties.assetLoanKey
import io.provenance.scope.loan.LoanScopeProperties.assetMismoKey
import io.provenance.scope.loan.utility.ContractRequirementType.VALID_INPUT
import io.provenance.scope.loan.utility.documentModificationValidation
import io.provenance.scope.loan.utility.documentValidation
import io.provenance.scope.loan.utility.eNoteInputValidation
import io.provenance.scope.loan.utility.isSet
Expand All @@ -24,7 +23,6 @@ import io.provenance.scope.loan.utility.orError
import io.provenance.scope.loan.utility.raiseError
import io.provenance.scope.loan.utility.servicingRightsInputValidation
import io.provenance.scope.loan.utility.toFigureTechLoan
import io.provenance.scope.loan.utility.toMISMOLoan
import io.provenance.scope.loan.utility.tryUnpackingAs
import io.provenance.scope.loan.utility.uliValidation
import io.provenance.scope.loan.utility.updateServicingData
Expand Down Expand Up @@ -61,16 +59,16 @@ open class RecordLoanContract(
newAsset.type.isNotBlank() orError "Asset is missing type",
)
}
if (newAsset.containsKv(assetLoanKey) xor newAsset.containsKv(assetMismoKey)) {
newAsset.kvMap[assetLoanKey]?.let { newLoanValue ->
if (newAsset.containsKv(assetLoanKey)) {
newAsset.kvMap[assetLoanKey]!!.let { newLoanValue ->
newLoanValue.tryUnpackingAs<FigureTechLoan, Unit>("input asset's \"${assetLoanKey}\"") { newLoan ->
if (existingAsset.isSet()) {
existingAsset!!.kvMap[assetLoanKey]?.toFigureTechLoan()?.also { existingLoan ->
requireThat(
(existingLoan.id == newLoan.id) orError "Cannot change loan ID",
(existingLoan.originatorName == newLoan.originatorName) orError "Cannot change loan originator name",
)
} ?: raiseError("The input asset had key \"${assetLoanKey}\" but the existing asset did not")
}
} else {
requireThat(
newLoan.id.isValid() orError "Loan must have valid ID",
Expand All @@ -81,24 +79,13 @@ open class RecordLoanContract(
}
}
}
newAsset.kvMap[assetMismoKey]?.let { newLoanValue ->
newLoanValue.tryUnpackingAs<MISMOLoanMetadata, Unit>("input asset's \"${assetMismoKey}\"") { newLoan ->
documentValidation(newLoan.document)
if (existingAsset.isSet()) {
existingAsset!!.kvMap[assetMismoKey]?.toMISMOLoan()?.also { existingLoan ->
// TODO: Allow doc with different checksum to replace existing one or not?
documentModificationValidation(existingLoan.document, newLoan.document)
requireThat(
(existingLoan.uli == newLoan.uli) orError "Cannot change loan ULI",
)
} ?: raiseError("The input asset had key \"${assetMismoKey}\" but the existing asset did not")
} else {
uliValidation(newLoan.uli)
}
}
}
} else {
raiseError("Exactly one of \"${assetLoanKey}\" or \"${assetMismoKey}\" must be a key in the input asset")
raiseError("\"${assetLoanKey}\" must be a key in the input asset")
}
newAsset.kvMap[assetMismoKey]?.let { newMismoLoanValue ->
newMismoLoanValue.tryUnpackingAs<MISMOLoanMetadata, Unit>("input asset's \"${assetMismoKey}\"") { newLoan ->
documentValidation(newLoan.document)
}
}
}
}
Expand Down
Loading

0 comments on commit bdecde0

Please sign in to comment.