Skip to content

Contract creation API #27

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Formatting
  • Loading branch information
Blackmorse committed Sep 29, 2023
commit 234cce4cadb71e1dfd45969a7709b45533d2656f
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ public List<Balance> balances(@NotNull List<String> addresses) throws EtherScanE
final List<List<String>> addressesAsBatches = BasicUtils.partition(addresses, 20);

for (final List<String> batch : addressesAsBatches) {
final String urlParams = ACT_BALANCE_MULTI_ACTION + TAG_LATEST_PARAM + ADDRESS_PARAM + BasicUtils.toAddressParam(batch);
final String urlParams = ACT_BALANCE_MULTI_ACTION + TAG_LATEST_PARAM + ADDRESS_PARAM
+ BasicUtils.toAddressParam(batch);
final BalanceResponseTO response = getRequest(urlParams, BalanceResponseTO.class);
if (response.getStatus() != 1) {
throw new EtherScanResponseException(response);
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/io/goodforgod/api/etherscan/ContractAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
import io.goodforgod.api.etherscan.error.EtherScanException;
import io.goodforgod.api.etherscan.model.Abi;
import io.goodforgod.api.etherscan.model.ContractCreation;
import org.jetbrains.annotations.NotNull;

import java.util.List;
import org.jetbrains.annotations.NotNull;

/**
* EtherScan - API Descriptions <a href="https://docs.etherscan.io/api-endpoints/contracts">...</a>
Expand All @@ -27,6 +26,7 @@ public interface ContractAPI {

/**
* Returns a contract's deployer address and transaction hash it was created, up to 5 at a time.
*
* @param contractAddresses - list of addresses to fetch
* @throws EtherScanException parent exception class
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@
import io.goodforgod.api.etherscan.model.response.ContractCreationResponseTO;
import io.goodforgod.api.etherscan.model.response.StringResponseTO;
import io.goodforgod.api.etherscan.util.BasicUtils;
import org.jetbrains.annotations.NotNull;

import java.util.List;
import java.util.stream.Collectors;
import org.jetbrains.annotations.NotNull;

/**
* Contract API Implementation
Expand Down Expand Up @@ -60,7 +59,8 @@ public Abi contractAbi(@NotNull String address) throws EtherScanException {
@Override
public List<ContractCreation> contractCreation(@NotNull List<String> contractAddresses) throws EtherScanException {
BasicUtils.validateAddresses(contractAddresses);
final String urlParam = ACT_CONTRACT_CREATION + ACT_CONTRACT_ADDRESSES_PARAM + BasicUtils.toAddressParam(contractAddresses);
final String urlParam = ACT_CONTRACT_CREATION + ACT_CONTRACT_ADDRESSES_PARAM
+ BasicUtils.toAddressParam(contractAddresses);
final ContractCreationResponseTO response = getRequest(urlParam, ContractCreationResponseTO.class);
if (response.getStatus() != 1 && response.getMessage().startsWith("NOTOK")) {
throw new EtherScanResponseException(response);
Expand All @@ -71,7 +71,7 @@ public List<ContractCreation> contractCreation(@NotNull List<String> contractAdd
.withContractCreator(to.getContractCreator())
.withContractAddress(to.getContractAddress())
.withTxHash(to.getTxHash())
.build()
).collect(Collectors.toList());
.build())
.collect(Collectors.toList());
}
}
3 changes: 3 additions & 0 deletions src/main/java/io/goodforgod/api/etherscan/StatisticAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
public interface StatisticAPI {

/**
* ERC20 token total Supply
* <a href=
* "https://docs.etherscan.io/api-endpoints/tokens#get-erc20-token-totalsupply-by-contractaddress">EtherScan<a>
* Returns the current amount of an ERC-20 token in circulation.
*
* @param contract contract address
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.Objects;

public class ContractCreation {

private final String contractAddress;
private final String contractCreator;
private final String txHash;
Expand All @@ -27,10 +28,13 @@ public String getTxHash() {

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
ContractCreation that = (ContractCreation) o;
return Objects.equals(contractAddress, that.contractAddress) && Objects.equals(contractCreator, that.contractCreator) && Objects.equals(txHash, that.txHash);
return Objects.equals(contractAddress, that.contractAddress) && Objects.equals(contractCreator, that.contractCreator)
&& Objects.equals(txHash, that.txHash);
}

@Override
Expand All @@ -52,6 +56,7 @@ public static ContractCreationBuilder builder() {
}

public static final class ContractCreationBuilder {

private String contractAddress;
private String contractCreator;
private String txHash;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
package io.goodforgod.api.etherscan.model.response;

public class ContractCreationResponseTO extends BaseListResponseTO<ContractCreationTO> {
}
public class ContractCreationResponseTO extends BaseListResponseTO<ContractCreationTO> {}
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
import io.goodforgod.api.etherscan.error.EtherScanInvalidAddressException;
import io.goodforgod.api.etherscan.model.Abi;
import io.goodforgod.api.etherscan.model.ContractCreation;
import org.junit.jupiter.api.Test;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import org.junit.jupiter.api.Test;

/**
* @author GoodforGod
Expand Down Expand Up @@ -45,8 +44,8 @@ void correctParamWithEmptyExpectedResult() {

@Test
void correctContractCreation() {
List<ContractCreation> contractCreations =
getApi().contract().contractCreation(Collections.singletonList("0xBB9bc244D798123fDe783fCc1C72d3Bb8C189413"));
List<ContractCreation> contractCreations = getApi().contract()
.contractCreation(Collections.singletonList("0xBB9bc244D798123fDe783fCc1C72d3Bb8C189413"));

assertEquals(1, contractCreations.size());
ContractCreation contractCreation = contractCreations.get(0);
Expand All @@ -58,8 +57,8 @@ void correctContractCreation() {

@Test
void correctMultipleContractCreation() {
List<ContractCreation> contractCreations =
getApi().contract().contractCreation(Arrays.asList("0xBB9bc244D798123fDe783fCc1C72d3Bb8C189413", "0x5EaC95ad5b287cF44E058dCf694419333b796123"));
List<ContractCreation> contractCreations = getApi().contract().contractCreation(
Arrays.asList("0xBB9bc244D798123fDe783fCc1C72d3Bb8C189413", "0x5EaC95ad5b287cF44E058dCf694419333b796123"));
assertEquals(2, contractCreations.size());

ContractCreation contractCreation1 = ContractCreation.builder()
Expand All @@ -81,6 +80,7 @@ void correctMultipleContractCreation() {
@Test
void contractCreationInvalidParamWithError() {
assertThrows(EtherScanInvalidAddressException.class,
() -> getApi().contract().contractCreation(Collections.singletonList("0xBBbc244D798123fDe783fCc1C72d3Bb8C189414")));
() -> getApi().contract()
.contractCreation(Collections.singletonList("0xBBbc244D798123fDe783fCc1C72d3Bb8C189414")));
}
}