Skip to content

Instantly share code, notes, and snippets.

@apemon
Created December 31, 2018 11:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save apemon/e8425439deb0b28598515817b05a7250 to your computer and use it in GitHub Desktop.
Save apemon/e8425439deb0b28598515817b05a7250 to your computer and use it in GitHub Desktop.
@CordaService
class ProxyNameOracle(val services: ServiceHub): SingletonSerializeAsToken() {
private val myKey = services.myInfo.legalIdentities.first().owningKey
fun query(identifier: String): ProxyName {
val databaseService = services.cordaService(ProxyNameDatabaseService::class.java)
return databaseService.queryProxyName(identifier)
}
fun sign(ftx: FilteredTransaction): TransactionSignature {
ftx.verify()
val proxyNameDatabaseService = services.cordaService(ProxyNameDatabaseService::class.java)
fun isCorrectCommand(elem: Any) = when {
elem is Command<*> && elem.value is AccountTransferContract.OracleCommand -> {
val command = elem.value as AccountTransferContract.OracleCommand
myKey in elem.signers && proxyNameDatabaseService.queryProxyName(command.identifier).equals(command.proxy)
}
else -> false
}
val isValid = ftx.checkWithFun(::isCorrectCommand)
if (isValid) {
return services.createSignature(ftx, myKey)
} else {
throw IllegalArgumentException("Oracle signature requested over invalid transaction.")
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment