Skip to content

Commit 1f76be1

Browse files
committed
Account provider in progress
1 parent 13b9f09 commit 1f76be1

File tree

8 files changed

+270
-12
lines changed

8 files changed

+270
-12
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package io.api.core;
2+
3+
/**
4+
* ! NO DESCRIPTION !
5+
*
6+
* @author GoodforGod
7+
* @since 28.10.2018
8+
*/
9+
public abstract class BasicProvider {
10+
11+
protected final String url;
12+
13+
public BasicProvider(final String module,
14+
final String apiKey) {
15+
this.url = "https://api.etherscan.io/api?module=" + module + "&apikey=" + apiKey + "&action=";
16+
}
17+
18+
19+
}

src/main/java/io/api/core/account/AccountProvider.java

Lines changed: 0 additions & 11 deletions
This file was deleted.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package io.api.core.account;
2+
3+
import io.api.model.Balance;
4+
import io.api.model.Transaction;
5+
6+
import java.util.List;
7+
import java.util.Optional;
8+
9+
/**
10+
* EtherScan - API Descriptions
11+
* https://etherscan.io/apis#accounts
12+
*
13+
* @author GoodforGod
14+
* @since 28.10.2018
15+
*/
16+
public interface IAccountProvider {
17+
18+
Optional<Balance> balance(String address);
19+
20+
/**
21+
* Maximum 20 address for batch request
22+
* If address > 20, then there will be more than 1 request
23+
*/
24+
List<Balance> balances(List<String> addresses);
25+
26+
/** All transactions */
27+
List<Transaction> transactions(String address);
28+
/** Only last 10000 transactions */
29+
List<Transaction> transactions(String address, int startBlock);
30+
/** Only last 10000 transactions */
31+
List<Transaction> transactions(String address, int startBlock, int endBlock);
32+
33+
/** All internal transactions */
34+
List<Transaction> transactionsInternal(String address);
35+
/** Only last 10000 transactions */
36+
List<Transaction> transactionsInternal(String address, int startBlock);
37+
/** Only last 10000 transactions */
38+
List<Transaction> transactionsInternal(String address, int startBlock, int endBlock);
39+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package io.api.core.account.impl;
2+
3+
import io.api.core.BasicProvider;
4+
5+
/**
6+
* ! NO DESCRIPTION !
7+
*
8+
* @author GoodforGod
9+
* @since 28.10.2018
10+
*/
11+
public class AccountProvider extends BasicProvider {
12+
13+
public AccountProvider(final String apiKey) {
14+
super("account", apiKey);
15+
}
16+
}

src/main/java/io/api/core/contract/ContractProvider.java renamed to src/main/java/io/api/core/contract/IContractProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66
* @author GoodforGod
77
* @since 28.10.2018
88
*/
9-
public class ContractProvider {
9+
public interface IContractProvider {
1010

1111
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package io.api.core.contract.impl;
2+
3+
import io.api.core.BasicProvider;
4+
import io.api.core.contract.IContractProvider;
5+
6+
/**
7+
* ! NO DESCRIPTION !
8+
*
9+
* @author GoodforGod
10+
* @since 28.10.2018
11+
*/
12+
public class ContractProvider extends BasicProvider implements IContractProvider {
13+
14+
public ContractProvider(final String apiKey) {
15+
super("contract", apiKey);
16+
}
17+
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
package io.api.model;
2+
3+
/**
4+
* ! NO DESCRIPTION !
5+
*
6+
* @author GoodforGod
7+
* @since 28.10.2018
8+
*/
9+
public class Balance {
10+
11+
/** Balance in Wei */
12+
private final long balance;
13+
private final String address;
14+
15+
public Balance(final String address,
16+
final long balance) {
17+
this.address = address;
18+
this.balance = balance;
19+
}
20+
21+
public String getAddress() {
22+
return address;
23+
}
24+
25+
public long getWei() {
26+
return balance;
27+
}
28+
29+
public double getKwei() {
30+
return balance / 1000;
31+
}
32+
33+
public double getMwei() {
34+
return balance / 1000000;
35+
}
36+
37+
public double getGwei() {
38+
return balance / 1000000000;
39+
}
40+
41+
public double getEther() {
42+
return balance / 1000000000000000L;
43+
}
44+
45+
@Override
46+
public boolean equals(Object o) {
47+
if (this == o) return true;
48+
if (o == null || getClass() != o.getClass()) return false;
49+
50+
Balance balance1 = (Balance) o;
51+
52+
if (Double.compare(balance1.balance, balance) != 0) return false;
53+
return address.equals(balance1.address);
54+
}
55+
56+
@Override
57+
public int hashCode() {
58+
int result;
59+
long temp;
60+
result = address.hashCode();
61+
temp = Double.doubleToLongBits(balance);
62+
result = 31 * result + (int) (temp ^ (temp >>> 32));
63+
return result;
64+
}
65+
66+
@Override
67+
public String toString() {
68+
return "Balance{" +
69+
"address='" + address + '\'' +
70+
", balance=" + balance +
71+
'}';
72+
}
73+
}
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
package io.api.model;
2+
3+
/**
4+
* ! NO DESCRIPTION !
5+
*
6+
* @author GoodforGod
7+
* @since 28.10.2018
8+
*/
9+
public class Transaction {
10+
11+
private String blockNumber;
12+
private String blockHash;
13+
private String timeStamp;
14+
private String hash;
15+
private String nonce;
16+
private String confirmations;
17+
18+
private String txreceipt_status;
19+
private String transactionIndex;
20+
private String from;
21+
private String to;
22+
private String value;
23+
24+
private String gas;
25+
private String gasPrice;
26+
private String gasUsed;
27+
private String cumulativeGasUsed;
28+
private boolean isError;
29+
private String input;
30+
private String contractAddress;
31+
32+
//<editor-fold desc="Getters">
33+
public String getBlockNumber() {
34+
return blockNumber;
35+
}
36+
37+
public String getBlockHash() {
38+
return blockHash;
39+
}
40+
41+
public String getTimeStamp() {
42+
return timeStamp;
43+
}
44+
45+
public String getHash() {
46+
return hash;
47+
}
48+
49+
public String getNonce() {
50+
return nonce;
51+
}
52+
53+
public String getConfirmations() {
54+
return confirmations;
55+
}
56+
57+
public String getTxreceipt_status() {
58+
return txreceipt_status;
59+
}
60+
61+
public String getTransactionIndex() {
62+
return transactionIndex;
63+
}
64+
65+
public String getFrom() {
66+
return from;
67+
}
68+
69+
public String getTo() {
70+
return to;
71+
}
72+
73+
public String getValue() {
74+
return value;
75+
}
76+
77+
public String getGas() {
78+
return gas;
79+
}
80+
81+
public String getGasPrice() {
82+
return gasPrice;
83+
}
84+
85+
public String getGasUsed() {
86+
return gasUsed;
87+
}
88+
89+
public String getCumulativeGasUsed() {
90+
return cumulativeGasUsed;
91+
}
92+
93+
public boolean getIsError() {
94+
return isError;
95+
}
96+
97+
public String getInput() {
98+
return input;
99+
}
100+
101+
public String getContractAddress() {
102+
return contractAddress;
103+
}
104+
//</editor-fold>
105+
}

0 commit comments

Comments
 (0)