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

Commitce54ab2

Browse files
author
Kotsias, Panagiotis-Christos
committed
Refactored structure
1 parentf76b976 commitce54ab2

File tree

9 files changed

+358
-0
lines changed

9 files changed

+358
-0
lines changed

‎etherscan/modules/__init__.py‎

Whitespace-only changes.

‎etherscan/modules/accounts.py‎

Lines changed: 265 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,265 @@
1+
fromfunctoolsimportreduce
2+
fromtypingimportList
3+
4+
frometherscan.utils.datatypesimportTxHash,WalletAddress
5+
frometherscan.enums.actions_enumimportActionsEnumasactions
6+
frometherscan.enums.fields_enumimportFieldsEnumasfields
7+
frometherscan.enums.modules_enumimportModulesEnumasmodules
8+
frometherscan.enums.tags_enumimportTagsEnumastags
9+
10+
11+
classAccounts:
12+
@staticmethod
13+
defget_eth_balance(wallet:WalletAddress)->str:
14+
url= (
15+
f"{fields.MODULE}"
16+
f"{modules.ACCOUNT}"
17+
f"{fields.ACTION}"
18+
f"{actions.BALANCE}"
19+
f"{fields.ADDRESS}"
20+
f"{wallet}"
21+
f"{fields.TAG}"
22+
f"{tags.LATEST}"
23+
)
24+
returnurl
25+
# r = requests.get(url)
26+
# return conversions.to_ticker_unit(parser.get_result(r))
27+
28+
@staticmethod
29+
defget_eth_balance_multiple(wallets:List[WalletAddress])->str:
30+
# max 20 wallets
31+
wallet_list=reduce(lambdaw1,w2:str(w1)+","+str(w2),wallets)
32+
url= (
33+
f"{fields.MODULE}"
34+
f"{modules.ACCOUNT}"
35+
f"{fields.ACTION}"
36+
f"{actions.BALANCE_MULTI}"
37+
f"{fields.ADDRESS}"
38+
f"{wallet_list}"
39+
f"{fields.TAG}"
40+
f"{tags.LATEST}"
41+
)
42+
returnurl
43+
# r = requests.get(url)
44+
# return [conversions.to_ticker_unit(r["balance"]) for r in parser.get_result(r)]
45+
46+
@staticmethod
47+
defget_hist_eth_balance_by_block(wallet:WalletAddress,block:int)->str:
48+
# throttled to 2 calls/sec
49+
# BUG: returns 'Error! Missing Or invalid Action name'
50+
url= (
51+
f"{fields.MODULE}"
52+
f"{modules.ACCOUNT}"
53+
f"{fields.ACTION}"
54+
f"{actions.BALANCE_HISTORY}"
55+
f"{fields.ADDRESS}"
56+
f"{wallet}"
57+
f"{fields.BLOCKNO}"
58+
f"{str(block)}"
59+
)
60+
returnurl
61+
62+
@staticmethod
63+
defget_normal_txs_by_address(
64+
wallet:WalletAddress,
65+
startblock:int=0000,
66+
endblock:int=99999999,
67+
sort:str="asc",
68+
)->str:
69+
# last 10,000 txs only
70+
url= (
71+
f"{fields.MODULE}"
72+
f"{modules.ACCOUNT}"
73+
f"{fields.ACTION}"
74+
f"{actions.TXLIST}"
75+
f"{fields.ADDRESS}"
76+
f"{wallet}"
77+
f"{fields.START_BLOCK}"
78+
f"{str(startblock)}"
79+
f"{fields.END_BLOCK}"
80+
f"{str(endblock)}"
81+
f"{fields.SORT}"
82+
f"{sort}"
83+
)
84+
returnurl
85+
86+
@staticmethod
87+
defget_normal_txs_by_address_paginated(
88+
wallet:WalletAddress,
89+
page:int,
90+
offset:int,
91+
startblock:int=0000,
92+
endblock:int=99999999,
93+
sort:str="asc",
94+
)->str:
95+
url= (
96+
f"{fields.MODULE}"
97+
f"{modules.ACCOUNT}"
98+
f"{fields.ACTION}"
99+
f"{actions.TXLIST}"
100+
f"{fields.ADDRESS}"
101+
f"{wallet}"
102+
f"{fields.START_BLOCK}"
103+
f"{str(startblock)}"
104+
f"{fields.END_BLOCK}"
105+
f"{str(endblock)}"
106+
f"{fields.SORT}"
107+
f"{sort}"
108+
f"{fields.PAGE}"
109+
f"{str(page)}"
110+
f"{fields.OFFSET}"
111+
f"{str(offset)}"
112+
)
113+
returnurl
114+
115+
@staticmethod
116+
defget_internal_txs_by_address(
117+
wallet:WalletAddress,
118+
startblock:int=0000,
119+
endblock:int=99999999,
120+
sort:str="asc",
121+
)->str:
122+
# last 10,000 txs only
123+
url= (
124+
f"{fields.MODULE}"
125+
f"{modules.ACCOUNT}"
126+
f"{fields.ACTION}"
127+
f"{actions.TXLIST_INTERNAL}"
128+
f"{fields.ADDRESS}"
129+
f"{wallet}"
130+
f"{fields.START_BLOCK}"
131+
f"{str(startblock)}"
132+
f"{fields.END_BLOCK}"
133+
f"{str(endblock)}"
134+
f"{fields.SORT}"
135+
f"{sort}"
136+
)
137+
returnurl
138+
139+
@staticmethod
140+
defget_internal_txs_by_address_paginated(
141+
wallet:WalletAddress,
142+
page:int,
143+
offset:int,
144+
startblock:int=0000,
145+
endblock:int=99999999,
146+
sort:str="asc",
147+
)->str:
148+
url= (
149+
f"{fields.MODULE}"
150+
f"{modules.ACCOUNT}"
151+
f"{fields.ACTION}"
152+
f"{actions.TXLIST_INTERNAL}"
153+
f"{fields.ADDRESS}"
154+
f"{wallet}"
155+
f"{fields.START_BLOCK}"
156+
f"{str(startblock)}"
157+
f"{fields.END_BLOCK}"
158+
f"{str(endblock)}"
159+
f"{fields.SORT}"
160+
f"{sort}"
161+
f"{fields.PAGE}"
162+
f"{str(page)}"
163+
f"{fields.OFFSET}"
164+
f"{str(offset)}"
165+
)
166+
returnurl
167+
168+
@staticmethod
169+
defget_internal_txs_by_txhash(txhash:TxHash)->str:
170+
# last 10,000 txs only
171+
url= (
172+
f"{fields.MODULE}"
173+
f"{modules.ACCOUNT}"
174+
f"{fields.ACTION}"
175+
f"{actions.TXLIST_INTERNAL}"
176+
f"{fields.TXHASH}"
177+
f"{txhash}"
178+
)
179+
returnurl
180+
181+
@staticmethod
182+
defget_internal_txs_by_block_range_paginated(
183+
startblock:int,endblock:int,page:int,offset:int,sort:str="asc",
184+
)->str:
185+
# last 10,000 txs only
186+
# BUG: returns empty message
187+
url= (
188+
f"{fields.MODULE}"
189+
f"{modules.ACCOUNT}"
190+
f"{fields.ACTION}"
191+
f"{actions.TXLIST_INTERNAL}"
192+
f"{fields.START_BLOCK}"
193+
f"{str(startblock)}"
194+
f"{fields.END_BLOCK}"
195+
f"{str(endblock)}"
196+
f"{fields.SORT}"
197+
f"{sort}"
198+
f"{fields.PAGE}"
199+
f"{str(page)}"
200+
f"{fields.OFFSET}"
201+
f"{str(offset)}"
202+
)
203+
returnurl
204+
205+
@staticmethod
206+
defget_erc20_token_transfer_events_by_address(
207+
wallet:WalletAddress,
208+
startblock:int=0,
209+
endblock:int=999999999,
210+
sort:str="asc",
211+
)->str:
212+
# last 10,000 txs only
213+
url= (
214+
f"{fields.MODULE}"
215+
f"{modules.ACCOUNT}"
216+
f"{fields.ACTION}"
217+
f"{actions.TOKENTX}"
218+
f"{fields.ADDRESS}"
219+
f"{wallet}"
220+
f"{fields.START_BLOCK}"
221+
f"{str(startblock)}"
222+
f"{fields.END_BLOCK}"
223+
f"{str(endblock)}"
224+
f"{fields.SORT}"
225+
f"{sort}"
226+
)
227+
returnurl
228+
229+
@staticmethod
230+
defget_erc721_token_transfer_events_by_address(
231+
wallet:WalletAddress,
232+
startblock:int=0,
233+
endblock:int=999999999,
234+
sort:str="asc",
235+
)->str:
236+
# last 10,000 txs only
237+
url= (
238+
f"{fields.MODULE}"
239+
f"{modules.ACCOUNT}"
240+
f"{fields.ACTION}"
241+
f"{actions.TOKENNFTTX}"
242+
f"{fields.ADDRESS}"
243+
f"{wallet}"
244+
f"{fields.START_BLOCK}"
245+
f"{str(startblock)}"
246+
f"{fields.END_BLOCK}"
247+
f"{str(endblock)}"
248+
f"{fields.SORT}"
249+
f"{sort}"
250+
)
251+
returnurl
252+
253+
@staticmethod
254+
defget_mined_blocks_by_address(wallet:WalletAddress)->str:
255+
url= (
256+
f"{fields.MODULE}"
257+
f"{modules.ACCOUNT}"
258+
f"{fields.ACTION}"
259+
f"{actions.GET_MINED_BLOCKS}"
260+
f"{fields.ADDRESS}"
261+
f"{wallet}"
262+
f"{fields.BLOCK_TYPE}"
263+
f"blocks"
264+
)
265+
returnurl

‎etherscan/modules/contracts.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
classContracts:
2+
pass

‎etherscan/modules/tokens.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
classTokens:
2+
pass

‎etherscan/modules/transactions.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
classTransactions:
2+
pass

‎etherscan/utils/__init__.py‎

Whitespace-only changes.

‎etherscan/utils/conversions.py‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
fromdecimalimportDecimal
2+
3+
4+
classConversions:
5+
@staticmethod
6+
defto_ticker_unit(val:int,decimals:int=18)->Decimal:
7+
factor=Decimal("10")**Decimal("-{}".format(decimals))
8+
returnDecimal(val)*factor
9+
10+
@staticmethod
11+
defto_smallest_unit(val:int,decimals:int=18)->Decimal:
12+
factor=Decimal("10")**Decimal("+{}".format(decimals))
13+
returnDecimal(val)*factor

‎etherscan/utils/datatypes.py‎

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
frometherscan.enums.messages_enumimportMessagesEnumasmsgs
2+
3+
_CONTRACT_LEN=42
4+
_TX_LEN=66
5+
_WALLET_LEN=42
6+
7+
8+
classBaseAddress:
9+
def__init__(self):
10+
self._address=""
11+
self._maxlen=0
12+
13+
def_check_0x(self,address:str):
14+
ifaddress[:2]!="0x":
15+
raiseValueError(msgs.INVALID_ADDRESS)
16+
returnaddress
17+
18+
def_check_len(self,address:str):
19+
iflen(address)!=self._maxlen:
20+
raiseValueError(msgs.INVALID_ADDRESS)
21+
returnaddress
22+
23+
def__repr__(self):
24+
returnself._address
25+
26+
def__str__(self):
27+
returnself._address
28+
29+
def__add__(self,val:str):
30+
returnself._address+val
31+
32+
def__len__(self):
33+
returnlen(self._address)
34+
35+
36+
classContractAddress(BaseAddress):
37+
def__init__(self,address:str):
38+
self._maxlen=_CONTRACT_LEN
39+
self._address=self._check_len(self._check_0x(address))
40+
41+
42+
classTxHash(BaseAddress):
43+
def__init__(self,address:str):
44+
self._maxlen=_TX_LEN
45+
self._address=self._check_len(self._check_0x(address))
46+
47+
48+
classWalletAddress(BaseAddress):
49+
def__init__(self,address:str):
50+
self._maxlen=_WALLET_LEN
51+
self._address=self._check_len(self._check_0x(address))
52+

‎etherscan/utils/parsing.py‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
importrequests
2+
3+
4+
classResponseParser:
5+
@staticmethod
6+
def_get_content(response:requests.Response):
7+
returnresponse.json()
8+
9+
@staticmethod
10+
defget_status(response:requests.Response):
11+
c=ResponseParser._get_content(response)
12+
returnc["status"]
13+
14+
@staticmethod
15+
defget_message(response:requests.Response):
16+
c=ResponseParser._get_content(response)
17+
returnc["message"]
18+
19+
@staticmethod
20+
defget_result(response:requests.Response):
21+
c=ResponseParser._get_content(response)
22+
returnc["result"]

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp