@SuppressWarnings("unchecked") private void prepareEthGetCode(String binary) throws IOException { EthGetCode ethGetCode = new EthGetCode(); ethGetCode.setResult(Numeric.prependHexPrefix(binary)); Request<?, EthGetCode> ethGetCodeRequest = mock(Request.class); when(ethGetCodeRequest.send()) .thenReturn(ethGetCode); when(web3j.ethGetCode(ADDRESS, DefaultBlockParameterName.LATEST)) .thenReturn((Request) ethGetCodeRequest); }
public String getCode() { return getResult(); } }
@Test public void testGetCode() { buildResponse( "{\n" + " \"id\":1,\n" + " \"jsonrpc\": \"2.0\",\n" + " \"result\": \"0x600160008035811a818181146012578301005b601b60013560255" + "65b8060005260206000f25b600060078202905091905056\"\n" + "}" ); EthGetCode ethGetCode = deserialiseResponse(EthGetCode.class); assertThat(ethGetCode.getCode(), is("0x600160008035811a818181146012578301005b601b60013560255" + "65b8060005260206000f25b600060078202905091905056")); }
@Test public void testEthGetCode() throws Exception { EthGetCode ethGetCode = web3j.ethGetCode(config.validContractAddress(), DefaultBlockParameter.valueOf(config.validBlock())).send(); assertThat(ethGetCode.getCode(), is(config.validContractCode())); }
@InvokeOnHeader(Web3jConstants.ETH_GET_CODE) void ethGetCode(Message message) throws IOException { DefaultBlockParameter atBlock = toBlockParameter(message.getHeader(Web3jConstants.AT_BLOCK, configuration::getAtBlock, Object.class)); String address = message.getHeader(Web3jConstants.ADDRESS, configuration::getAddress, String.class); Request<?, EthGetCode> request = web3j.ethGetCode(address, atBlock); setRequestId(message, request); EthGetCode response = request.send(); boolean hasError = checkForError(message, response); if (!hasError) { message.setBody(response.getCode()); } }
public SmartContractByteCode getCode(EthAddress address) { try { return SmartContractByteCode.of(web3j.ethGetCode(address.withLeading0x(), DefaultBlockParameterName.LATEST).send().getCode()); } catch (IOException e) { throw new IOError(e); } }
@ScalarFunction("isContract") @Description("isContract") @SqlType(StandardTypes.BOOLEAN) public static boolean isContract(@SqlType(StandardTypes.VARCHAR) Slice address) throws IOException { return !web3j.ethGetCode(address.toStringUtf8(), DefaultBlockParameter.valueOf(LATEST)).send().getCode().equals(ZERO_X); } }