Search in sources :

Example 1 with BytesValueList

use of com.jd.blockchain.ledger.BytesValueList in project jdchain-core by blockchain-jd-com.

the class InstantiatedContractCode method doProcessEvent.

@Override
protected BytesValue doProcessEvent(Object contractInstance, ContractEventContext eventContext) {
    // 反序列化参数;
    Method handleMethod = contractDefinition.getType().getHandleMethod(eventContext.getEvent());
    if (handleMethod == null) {
        throw new ContractException(String.format("Contract[%s:%s] has no handle method to handle event[%s]!", getAddress().toString(), contractDefinition.getType().getName(), eventContext.getEvent()));
    }
    BytesValueList bytesValues = eventContext.getArgs();
    Object[] args = BytesValueEncoding.decode(bytesValues, handleMethod.getParameterTypes());
    return BytesValueEncoding.encodeSingle(ReflectionUtils.invokeMethod(handleMethod, contractInstance, args), handleMethod.getReturnType());
}
Also used : ContractException(com.jd.blockchain.contract.ContractException) BytesValueList(com.jd.blockchain.ledger.BytesValueList) Method(java.lang.reflect.Method)

Aggregations

ContractException (com.jd.blockchain.contract.ContractException)1 BytesValueList (com.jd.blockchain.ledger.BytesValueList)1 Method (java.lang.reflect.Method)1