Skip to content

Commit cebc169

Browse files
committed
Patch to 0.7.0
- added internal transactions and examples
1 parent 04966ed commit cebc169

File tree

9 files changed

+306
-215
lines changed

9 files changed

+306
-215
lines changed

.idea/misc.xml

Lines changed: 4 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/py-etherscan-api.iml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/workspace.xml

Lines changed: 215 additions & 199 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

etherscan/accounts.py

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def get_balance_multiple(self):
4747
req = self.connect()
4848
return req['result']
4949

50-
def get_transaction_page(self, page=1, offset=10000, sort='asc') -> list:
50+
def get_transaction_page(self, page=1, offset=10000, sort='asc', internal=False) -> list:
5151
"""
5252
Get a page of transactions, each transaction returns list of dict with keys:
5353
nonce
@@ -72,17 +72,27 @@ def get_transaction_page(self, page=1, offset=10000, sort='asc') -> list:
7272
sort options:
7373
'asc' -> ascending order
7474
'des' -> descending order
75+
76+
internal options:
77+
True -> Gets the internal transactions of a smart contract
78+
False -> (default) get normal external transactions
7579
"""
76-
self.action = self.URL_BASES['action'] + 'txlist'
80+
if internal:
81+
self.action = self.URL_BASES['action'] + 'txlistinternal'
82+
else:
83+
self.action = self.URL_BASES['action'] + 'txlist'
7784
self.page = self.URL_BASES['page'] + str(page)
7885
self.offset = self.URL_BASES['offset'] + str(offset)
7986
self.sort = self.URL_BASES['sort'] + sort
8087
self.make_url(call_type='transactions')
8188
req = self.connect()
8289
return req['result']
8390

84-
def get_all_transactions(self, offset=10000, sort='asc') -> list:
85-
self.action = self.URL_BASES['action'] + 'txlist'
91+
def get_all_transactions(self, offset=10000, sort='asc', internal=False) -> list:
92+
if internal:
93+
self.action = self.URL_BASES['action'] + 'txlistinternal'
94+
else:
95+
self.action = self.URL_BASES['action'] + 'txlist'
8696
self.page = self.URL_BASES['page'] + str(1)
8797
self.offset = self.URL_BASES['offset'] + str(offset)
8898
self.sort = self.URL_BASES['sort'] + sort
@@ -142,6 +152,13 @@ def get_all_blocks_mined(self, blocktype='blocks', offset=10000) -> list:
142152
print("page {} added".format(page_number[0]))
143153
self.page = self.URL_BASES['page'] + str(int(page_number[0]) + 1)
144154

155+
def get_internal_by_hash(self, tx_hash=''):
156+
"""
157+
Currently not implemented
158+
:return:
159+
"""
160+
pass
161+
145162
def update_transactions(self, address, trans):
146163
"""
147164
Gets last page of transactions (last 10k trans) and updates current trans book (book)

etherscan/contracts.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from .client import Client
2+
3+
4+
class Contract(Client):
5+
def __init__(self, address=Client.dao_address, api_key='YourApiKeyToken'):
6+
Client.__init__(self, address=address, api_key=api_key)
7+
self.module = self.URL_BASES['module'] + 'contract'
8+
9+
def make_url(self, call_type=''):
10+
if call_type == 'getabi':
11+
self.url = self.URL_BASES['prefix'] \
12+
+ self.module \
13+
+ self.action \
14+
+ self.address \
15+
+ self.key
16+
17+
def get_abi(self):
18+
self.action = self.URL_BASES['action'] + 'getabi'
19+
self.make_url(call_type='getabi')
20+
req = self.connect()
21+
return req['result']

examples/accounts/Accounts Examples Notebook.ipynb

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"cells": [
33
{
44
"cell_type": "code",
5-
"execution_count": 8,
5+
"execution_count": 2,
66
"metadata": {
77
"collapsed": false
88
},
@@ -11,8 +11,7 @@
1111
"name": "stdout",
1212
"output_type": "stream",
1313
"text": [
14-
"The autoreload extension is already loaded. To reload it, use:\n",
15-
" %reload_ext autoreload\n"
14+
"The autoreload extension is already loaded. To reload it, use:\n %reload_ext autoreload\n"
1615
]
1716
}
1817
],
@@ -41,7 +40,7 @@
4140
},
4241
{
4342
"cell_type": "code",
44-
"execution_count": 15,
43+
"execution_count": 6,
4544
"metadata": {
4645
"collapsed": false
4746
},
@@ -440,7 +439,9 @@
440439
"collapsed": true
441440
},
442441
"outputs": [],
443-
"source": []
442+
"source": [
443+
""
444+
]
444445
}
445446
],
446447
"metadata": {
@@ -452,16 +453,36 @@
452453
"language_info": {
453454
"codemirror_mode": {
454455
"name": "ipython",
455-
"version": 3
456+
"version": 3.0
456457
},
457458
"file_extension": ".py",
458459
"mimetype": "text/x-python",
459460
"name": "python",
460461
"nbconvert_exporter": "python",
461462
"pygments_lexer": "ipython3",
462-
"version": "3.5.1"
463+
"version": "3.5.2"
464+
},
465+
"latex_envs": {
466+
"bibliofile": "biblio.bib",
467+
"cite_by": "apalike",
468+
"current_citInitial": 1.0,
469+
"eqLabelWithNumbers": true,
470+
"eqNumInitial": 0.0
471+
},
472+
"toc": {
473+
"nav_menu": {
474+
"height": "121px",
475+
"width": "252px"
476+
},
477+
"navigate_menu": true,
478+
"number_sections": true,
479+
"sideBar": true,
480+
"threshold": 4.0,
481+
"toc_cell": false,
482+
"toc_section_display": "block",
483+
"toc_window_display": false
463484
}
464485
},
465486
"nbformat": 4,
466487
"nbformat_minor": 0
467-
}
488+
}

examples/accounts/get_all_transactions.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
key = json.loads(key_file.read())['key']
66

77
# address = ['0xddbd2b932c763ba5b1b7ae3b362eac3e8d40121a', '0xddbd2b932c763ba5b1b7ae3b362eac3e8d40121a']
8-
address = '0x5bda447c0c2ade0a0b6daf22c88505f9e55f0c61 '
8+
address = '0x49edf201c1e139282643d5e7c6fb0c7219ad1db7'
99

1010
api = Account(address=address, api_key=key)
11-
transactions = api.get_all_transactions(offset=10000, sort='asc')
11+
transactions = api.get_all_transactions(offset=10000, sort='asc', internal=True)
12+
1213
print(transactions[0])

examples/contracts/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

examples/contracts/get_abi.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from etherscan.contracts import Contract
2+
import json
3+
4+
with open('../../api_key.json', mode='r') as key_file:
5+
key = json.loads(key_file.read())['key']
6+
7+
address = '0xfb6916095ca1df60bb79ce92ce3ea74c37c5d359'
8+
9+
api = Contract(address=address, api_key=key)
10+
abi = api.get_abi()
11+
print(abi)

0 commit comments

Comments
 (0)