Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit4bb51f6

Browse files
authored
Merge pull requestGoodforGod#13 from NGuggs/master
Add support for ERC-721 (NFT) Tokens
2 parents2969dc1 +478faf9 commit4bb51f6

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‎

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(Stringtxhash)throwsApiException;
9494

9595
/**
96-
* All token txs for given address
96+
* AllERC-20token 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(Stringaddress)throwsApiException;
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(Stringaddress,longstartBlock,longendBlock)throwsApiException;
124+
125+
@NotNull
126+
List<TxToken>txsNftToken(Stringaddress,longstartBlock)throwsApiException;
127+
128+
@NotNull
129+
List<TxToken>txsNftToken(Stringaddress)throwsApiException;
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
privatestaticfinalStringACT_TX_ACTION =ACT_PREFIX +"txlist";
3535
privatestaticfinalStringACT_TX_INTERNAL_ACTION =ACT_PREFIX +"txlistinternal";
3636
privatestaticfinalStringACT_TX_TOKEN_ACTION =ACT_PREFIX +"tokentx";
37+
privatestaticfinalStringACT_TX_NFT_TOKEN_ACTION =ACT_PREFIX +"tokennfttx";
3738
privatestaticfinalStringACT_MINED_ACTION =ACT_PREFIX +"getminedblocks";
3839

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

233+
@NotNull
234+
@Override
235+
publicList<TxToken>txsNftToken(Stringaddress)throwsApiException {
236+
returntxsNftToken(address,MIN_START_BLOCK);
237+
}
238+
239+
@NotNull
240+
@Override
241+
publicList<TxToken>txsNftToken(Stringaddress,longstartBlock)throwsApiException {
242+
returntxsNftToken(address,startBlock,MAX_END_BLOCK);
243+
}
244+
245+
@NotNull
246+
@Override
247+
publicList<TxToken>txsNftToken(Stringaddress,longstartBlock,longendBlock)throwsApiException {
248+
BasicUtils.validateAddress(address);
249+
finalBlockParamblocks =BasicUtils.compensateBlocks(startBlock,endBlock);
250+
251+
finalStringoffsetParam =PAGE_PARAM +"%s" +OFFSET_PARAM +OFFSET_MAX;
252+
finalStringblockParam =START_BLOCK_PARAM +blocks.start() +END_BLOCK_PARAM +blocks.end();
253+
finalStringurlParams =ACT_TX_NFT_TOKEN_ACTION +offsetParam +ADDRESS_PARAM +address +blockParam +SORT_ASC_PARAM;
254+
255+
returngetRequestUsingOffset(urlParams,TxTokenResponseTO.class);
256+
}
257+
232258
@NotNull
233259
@Override
234260
publicList<Block>minedBlocks(finalStringaddress)throwsApiException {
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
packageio.api.etherscan.account;
2+
3+
importio.api.ApiRunner;
4+
importio.api.etherscan.error.InvalidAddressException;
5+
importio.api.etherscan.model.TxToken;
6+
importorg.junit.Test;
7+
8+
importjava.util.List;
9+
10+
/**
11+
* @author NGuggs
12+
* @since 11.28.2021
13+
*/
14+
publicclassAccountTxRc721TokenTestextendsApiRunner {
15+
16+
@Test
17+
publicvoidcorrect() {
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+
publicvoidcorrectStartBlock() {
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+
publicvoidcorrectStartBlockEndBlock() {
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+
publicvoidinvalidParamWithError() {
55+
getApi().account().txsNftToken("0x6ec53A8fBa6358d59B3C4476D82cc60A2B0FaD7");
56+
}
57+
58+
@Test
59+
publicvoidcorrectParamWithEmptyExpectedResult() {
60+
List<TxToken>txs =getApi().account().txsNftToken("0x31ec53A8fBa6358d59B3C4476D82cc60A2B0FaD7");
61+
assertNotNull(txs);
62+
assertTrue(txs.isEmpty());
63+
}
64+
65+
privatevoidassertTxs(List<TxToken>txs) {
66+
for (TxTokentx :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)

[8]ページ先頭

©2009-2025 Movatter.jp