Created
December 31, 2018 11:54
-
-
Save apemon/e8425439deb0b28598515817b05a7250 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
@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