Skip to content

Commit 3a69c65

Browse files
committed
[1.1.1]
Merge remote-tracking branch 'origin/dev' into dev
2 parents 6070078 + 4bb51f6 commit 3a69c65

File tree

3 files changed

+125
-1
lines changed

3 files changed

+125
-1
lines changed

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

+19-1
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

+26
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 {
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)