Skip to content

Commit 64f9db3

Browse files
authored
Merge pull request GoodforGod#14 from GoodforGod/dev
[1.2.0]
2 parents 2969dc1 + 6f359b5 commit 64f9db3

File tree

7 files changed

+132
-5
lines changed

7 files changed

+132
-5
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ sonarqube {
3636

3737
dependencies {
3838
implementation "org.jetbrains:annotations:22.0.0"
39-
implementation "com.google.code.gson:gson:2.8.8"
39+
implementation "com.google.code.gson:gson:2.8.9"
4040

4141
testImplementation "junit:junit:4.13.1"
4242
}

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
groupId=com.github.goodforgod
22
artifactId=java-etherscan-api
3-
artifactVersion=1.1.1
3+
artifactVersion=1.2.0
44
buildNumber=1
55

66

src/main/java/io/api/etherscan/core/IAccountApi.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public interface IAccountApi {
9393
List<TxInternal> txsInternalByHash(String txhash) throws ApiException;
9494

9595
/**
96-
* All token txs for given address
96+
* All ERC-20 token txs for given address
9797
*
9898
* @param address get txs for
9999
* @param startBlock tx from this blockNumber
@@ -110,6 +110,24 @@ public interface IAccountApi {
110110
@NotNull
111111
List<TxToken> txsToken(String address) throws ApiException;
112112

113+
/**
114+
* All ERC-721 (NFT) token txs for given address
115+
*
116+
* @param address get txs for
117+
* @param startBlock tx from this blockNumber
118+
* @param endBlock tx to this blockNumber
119+
* @return txs for address
120+
* @throws ApiException parent exception class
121+
*/
122+
@NotNull
123+
List<TxToken> txsNftToken(String address, long startBlock, long endBlock) throws ApiException;
124+
125+
@NotNull
126+
List<TxToken> txsNftToken(String address, long startBlock) throws ApiException;
127+
128+
@NotNull
129+
List<TxToken> txsNftToken(String address) throws ApiException;
130+
113131
/**
114132
* All blocks mined by address
115133
*

src/main/java/io/api/etherscan/core/impl/AccountApiProvider.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public class AccountApiProvider extends BasicProvider implements IAccountApi {
3434
private static final String ACT_TX_ACTION = ACT_PREFIX + "txlist";
3535
private static final String ACT_TX_INTERNAL_ACTION = ACT_PREFIX + "txlistinternal";
3636
private static final String ACT_TX_TOKEN_ACTION = ACT_PREFIX + "tokentx";
37+
private static final String ACT_TX_NFT_TOKEN_ACTION = ACT_PREFIX + "tokennfttx";
3738
private static final String ACT_MINED_ACTION = ACT_PREFIX + "getminedblocks";
3839

3940
private static final String BLOCK_TYPE_PARAM = "&blocktype=blocks";
@@ -229,6 +230,31 @@ public List<TxToken> txsToken(final String address, final long startBlock, final
229230
return getRequestUsingOffset(urlParams, TxTokenResponseTO.class);
230231
}
231232

233+
@NotNull
234+
@Override
235+
public List<TxToken> txsNftToken(String address) throws ApiException {
236+
return txsNftToken(address, MIN_START_BLOCK);
237+
}
238+
239+
@NotNull
240+
@Override
241+
public List<TxToken> txsNftToken(String address, long startBlock) throws ApiException {
242+
return txsNftToken(address, startBlock, MAX_END_BLOCK);
243+
}
244+
245+
@NotNull
246+
@Override
247+
public List<TxToken> txsNftToken(String address, long startBlock, long endBlock) throws ApiException {
248+
BasicUtils.validateAddress(address);
249+
final BlockParam blocks = BasicUtils.compensateBlocks(startBlock, endBlock);
250+
251+
final String offsetParam = PAGE_PARAM + "%s" + OFFSET_PARAM + OFFSET_MAX;
252+
final String blockParam = START_BLOCK_PARAM + blocks.start() + END_BLOCK_PARAM + blocks.end();
253+
final String urlParams = ACT_TX_NFT_TOKEN_ACTION + offsetParam + ADDRESS_PARAM + address + blockParam + SORT_ASC_PARAM;
254+
255+
return getRequestUsingOffset(urlParams, TxTokenResponseTO.class);
256+
}
257+
232258
@NotNull
233259
@Override
234260
public List<Block> minedBlocks(final String address) throws ApiException {

src/main/java/io/api/etherscan/manager/impl/QueueManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
*/
1515
public class QueueManager implements IQueueManager, AutoCloseable {
1616

17-
public static final QueueManager DEFAULT_KEY_QUEUE = new QueueManager(1, 7);
17+
public static final QueueManager DEFAULT_KEY_QUEUE = new QueueManager(1, 5200L, 5200L, 0);
1818
public static final QueueManager PERSONAL_KEY_QUEUE = new QueueManager(5, 1100L, 1100L, 5);
1919

2020
private final ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor();

src/test/java/io/api/ApiRunner.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ public class ApiRunner extends Assert {
2020
? EtherScanApi.DEFAULT_KEY
2121
: key;
2222

23-
final QueueManager queueManager = new QueueManager(1, 1200L, 1200L, 0);
23+
final QueueManager queueManager = (EtherScanApi.DEFAULT_KEY.equals(apiKey))
24+
? QueueManager.DEFAULT_KEY_QUEUE
25+
: new QueueManager(1, 1200L, 1200L, 0);
26+
2427
api = new EtherScanApi(ApiRunner.apiKey, EthNetwork.MAINNET, queueManager);
2528
apiKovan = new EtherScanApi(ApiRunner.apiKey, EthNetwork.KOVAN, queueManager);
2629
apiRopsten = new EtherScanApi(ApiRunner.apiKey, EthNetwork.ROPSTEN, queueManager);
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
package io.api.etherscan.account;
2+
3+
import io.api.ApiRunner;
4+
import io.api.etherscan.error.InvalidAddressException;
5+
import io.api.etherscan.model.TxToken;
6+
import org.junit.Test;
7+
8+
import java.util.List;
9+
10+
/**
11+
* @author NGuggs
12+
* @since 11.28.2021
13+
*/
14+
public class AccountTxRc721TokenTest extends ApiRunner {
15+
16+
@Test
17+
public void correct() {
18+
List<TxToken> txs = getApi().account().txsNftToken("0x1a1ebe0d86f72884c3fd484ae1e796e08f8ffa67");
19+
assertNotNull(txs);
20+
assertEquals(16, txs.size());
21+
assertTxs(txs);
22+
assertNotEquals(0, txs.get(0).getGasPrice());
23+
assertNotEquals(-1, txs.get(0).getNonce());
24+
25+
assertNotNull(txs.get(0).toString());
26+
assertNotEquals(txs.get(0).toString(), txs.get(1).toString());
27+
28+
assertNotEquals(txs.get(0), txs.get(1));
29+
assertNotEquals(txs.get(0).hashCode(), txs.get(1).hashCode());
30+
31+
assertEquals(txs.get(1), txs.get(1));
32+
assertEquals(txs.get(1).hashCode(), txs.get(1).hashCode());
33+
}
34+
35+
@Test
36+
public void correctStartBlock() {
37+
List<TxToken> txs = getApi().account().txsNftToken("0x1a1ebe0d86f72884c3fd484ae1e796e08f8ffa67", 4762071);
38+
System.out.println(txs);
39+
assertNotNull(txs);
40+
assertEquals(5, txs.size());
41+
assertTxs(txs);
42+
}
43+
44+
@Test
45+
public void correctStartBlockEndBlock() {
46+
List<TxToken> txs = getApi().account().txsNftToken("0x1a1ebe0d86f72884c3fd484ae1e796e08f8ffa67", 4761862, 4761934);
47+
System.out.println(txs);
48+
assertNotNull(txs);
49+
assertEquals(11, txs.size());
50+
assertTxs(txs);
51+
}
52+
53+
@Test(expected = InvalidAddressException.class)
54+
public void invalidParamWithError() {
55+
getApi().account().txsNftToken("0x6ec53A8fBa6358d59B3C4476D82cc60A2B0FaD7");
56+
}
57+
58+
@Test
59+
public void correctParamWithEmptyExpectedResult() {
60+
List<TxToken> txs = getApi().account().txsNftToken("0x31ec53A8fBa6358d59B3C4476D82cc60A2B0FaD7");
61+
assertNotNull(txs);
62+
assertTrue(txs.isEmpty());
63+
}
64+
65+
private void assertTxs(List<TxToken> txs) {
66+
for (TxToken tx : txs) {
67+
assertNotNull(tx.getBlockHash());
68+
assertNotNull(tx.getTokenName());
69+
assertNotNull(tx.getTokenSymbol());
70+
assertNotNull(tx.getFrom());
71+
assertNotNull(tx.getTo());
72+
assertNotNull(tx.getTimeStamp());
73+
assertNotNull(tx.getTokenDecimal());
74+
assertNotEquals(-1, (tx.getConfirmations()));
75+
assertNotNull(tx.getGasUsed());
76+
assertNotEquals(-1, tx.getCumulativeGasUsed());
77+
assertNotEquals(-1, tx.getTransactionIndex());
78+
}
79+
}
80+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy