Skip to content

Commit

Permalink
fix invalid getSchema call, added isExist methods
Browse files Browse the repository at this point in the history
  • Loading branch information
alkopnin committed Sep 18, 2018
1 parent 94318d6 commit dcb55a6
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ object CreateClaimDefinitionFlow {
return credentialDefinition.claimDefId

} catch (t: Throwable) {
logger.error("New credential definition creating was failed", t)
logger.error("New credential definition has been failed", t)
throw FlowException(t.message)
}
}
Expand All @@ -94,7 +94,7 @@ object CreateClaimDefinitionFlow {
}

private fun checkNoCredentialDefinitionOnIndy() {
if(indyUser().retrieveCredentialDefinitionBySchemaId(schemaId) != null)
if(indyUser().isCredentialDefinitionExist(schemaId))
throw IndyCredentialDefinitionAlreadyExistsException(schemaId,
"Credential definition already exist on Indy ledger")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ object CreateSchemaFlow {
override fun call(): String {
try {
// check if schema already exists
if(indyUser().retrieveSchema(schemaName, schemaVersion) == null)
if(indyUser().isSchemaExist(schemaName, schemaVersion))
throw IndySchemaAlreadyExistsException(schemaName, schemaVersion)

// create schema
Expand All @@ -61,7 +61,7 @@ object CreateSchemaFlow {
return schema.id

} catch (t: Throwable) {
logger.error("New schema creating was failed", t)
logger.error("New schema creating has been failed", t)
throw FlowException(t.message)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,18 @@ open class IndyUser {
return retrieveSchemaById(schemaId)
}

/**
* Check if schema exist on ledger
*
* @param name schema name
* @param version schema version
*
* @return true if exist otherwise false
*/
fun isSchemaExist(name: String, version: String): Boolean {
return (null != retrieveSchema(name, version))
}

/**
* Retrieves claim definition from ledger by schema Id
*
Expand All @@ -650,7 +662,7 @@ open class IndyUser {
* @return claim definition or null if it doesn't exist in ledger
*/
fun retrieveCredentialDefinitionBySchemaId(schemaId: String): CredentialDefinition? {
val schema = retrieveSchema(schemaId)
val schema = retrieveSchemaById(schemaId)
?: throw IndySchemaNotFoundException(schemaId, "Indy ledger does't have proper states")

val credentialDefinitionId = IndyUser.buildCredentialDefinitionId(did, schema.seqNo!!)
Expand All @@ -667,6 +679,17 @@ open class IndyUser {
fun retrieveCredentialDefinitionById(credentialDefinitionId: String) =
ledgerService.retrieveCredentialDefinition(credentialDefinitionId)

/**
* Check if credential definition exist on ledger
*
* @param schemaId schema id
*
* @return true if exist otherwise false
*/
fun isCredentialDefinitionExist(schemaId: String): Boolean {
return (retrieveCredentialDefinitionBySchemaId(schemaId) != null)
}

/**
* Retrieves revocation registry entry from ledger
*
Expand Down

0 comments on commit dcb55a6

Please sign in to comment.