package io.emeraldpay.etherjar.contract;

import io.emeraldpay.etherjar.domain.Address;
import io.emeraldpay.etherjar.hex.HexData;

import java.util.function.Function;

public class ContractReadCall<T> extends ContractCall {

    private final Function<HexData, T> processor;

    public ContractReadCall(Address contract, ContractData data, Function<HexData, T> processor) {
        super(contract, data);
        this.processor = processor;
    }

    public Function<HexData, T> getProcessor() {
        return processor;
    }

    public T processResult(HexData result) {
        return processor.apply(result);
    }
}

@@ -123,16 +123,152 @@
 HexData;
+%0Aimport io.emeraldpay.etherjar.rpc.Commands;%0Aimport io.emeraldpay.etherjar.rpc.RpcCall;%0Aimport io.emeraldpay.etherjar.rpc.json.BlockTag;
 %0A%0Aimport
@@ -751,11 +751,664 @@
 );%0A    %7D
+%0A%0A    @SuppressWarnings(%22unchecked%22)%0A    public Class%3CT%3E getTargetClass() %7B%0A        return (Class%3CT%3E) Object.class;%0A    %7D%0A%0A    public RpcCall%3CString, T%3E toRpcCall() %7B%0A        return toRpcCall(BlockTag.LATEST);%0A    %7D%0A%0A    public RpcCall%3CString, T%3E toRpcCall(BlockTag block) %7B%0A        return Commands.eth()%0A            .call(this.toJson(), block)%0A            .converted(getTargetClass(), (hex) -%3E processResult(HexData.from(hex)));%0A    %7D%0A%0A    public RpcCall%3CString, T%3E toRpcCall(Long height) %7B%0A        return Commands.eth()%0A            .call(this.toJson(), height)%0A            .converted(getTargetClass(), (hex) -%3E processResult(HexData.from(hex)));%0A    %7D
 %0A%7D%0A

create eth_call request from ContractReadCall