Skip to content

Commit

Permalink
Merge pull request #264 from virtualeconomy/tokenIndex
Browse files Browse the repository at this point in the history
update last token index api
  • Loading branch information
ncying authored Feb 1, 2021
2 parents 923f523 + 1c5f96a commit a3d7852
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/main/scala/vsys/api/http/contract/ContractApiRoute.scala
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,18 @@ case class ContractApiRoute (settings: RestAPISettings, wallet: Wallet, utx: Utx
))
def lastToken: Route = (get & path("lastTokenIndex" / Segment)) { contractId =>
ByteStr.decodeBase58(contractId) match {
case Success(id) => complete(Json.obj(
"contractId" -> contractId,
"lastTokenIndex" -> state.contractTokens(id)
))
case _ => complete(InvalidAddress)
case Success(id) if ContractAccount.fromString(contractId).isRight => {
val lastTokenIndex = state.contractTokens(id) - 1
if (lastTokenIndex == -1) {
complete(CustomValidationError("No token generated in this contract"))
} else {
complete(Json.obj(
"contractId" -> contractId,
"lastTokenIndex" -> lastTokenIndex
))
}
}
case _ => complete(InvalidContractAddress)
}
}

Expand Down

1 comment on commit a3d7852

@morganx20

This comment was marked as spam.

Please sign in to comment.