Révision 3298c34c
convert wei to ether (ETH) via 'fieldname.cdef'
| plugins/currency/ethereum/etherscan_balance_ | ||
|---|---|---|
| 20 | 20 |
|
| 21 | 21 |
=head1 INTERPRETATION |
| 22 | 22 |
|
| 23 |
This plugin shows the balance (ETH) of a given ethereum address. |
|
| 23 |
This plugin shows the ether balance (ETH) of a given ethereum address.
|
|
| 24 | 24 |
Account balance is queried via etherscan.io API L<https://etherscan.io/apis>. |
| 25 | 25 |
|
| 26 | 26 |
=head1 VERSION |
| ... | ... | |
| 69 | 69 |
"'etherscan_balance_<YOUR_PUBLIC_ETHEREUM_ADDRESS>'", file=sys.stderr) |
| 70 | 70 |
sys.exit(9) |
| 71 | 71 |
|
| 72 |
""" |
|
| 73 |
API result is in Wei. Convert Wei to Ether (ETH) via 'fieldname.cdef' |
|
| 74 |
1 : Wei |
|
| 75 |
10^12 : Szabo |
|
| 76 |
10^15 : Finney |
|
| 77 |
10^18 : Ether |
|
| 78 |
233874700000000000000000 Wei = 233,874.7 Ether |
|
| 79 |
""" |
|
| 72 | 80 |
if command == 'config': |
| 73 | 81 |
print("graph_title ETH {}".format(eth_address))
|
| 74 | 82 |
print("graph_info Ethereum Account Balance for Address {}".format(eth_address))
|
| 75 | 83 |
print("graph_vlabel Ethereum Balance")
|
| 76 | 84 |
print("graph_category other")
|
| 77 |
print("{}.label ETH".format(eth_address))
|
|
| 85 |
print("wei_balance_{0}.cdef wei_balance_{0},1000000000000000000,/".format(eth_address))
|
|
| 86 |
print("wei_balance_{}.label ETH".format(eth_address))
|
|
| 78 | 87 |
sys.exit(0) |
| 79 | 88 |
|
| 80 | 89 |
ethercan_balance_api_url = 'https://api.etherscan.io/api?module=account&action=balance&tag=latest&address=' + eth_address |
| ... | ... | |
| 99 | 108 |
sys.exit(9) |
| 100 | 109 |
|
| 101 | 110 |
try: |
| 102 |
float(etherscan_balance['result'])
|
|
| 111 |
eth = int(etherscan_balance['result'])
|
|
| 103 | 112 |
except: |
| 104 | 113 |
print("JSON result error!", file=sys.stderr)
|
| 105 | 114 |
sys.exit(9) |
| 106 | 115 |
|
| 107 |
""" |
|
| 108 |
API result is in Wei. Convert Wei to Ether (ETH). |
|
| 109 |
1 : Wei |
|
| 110 |
10^12 : Szabo |
|
| 111 |
10^15 : Finney |
|
| 112 |
10^18 : Ether |
|
| 113 |
233874700000000000000000 Wei = 233,874.7 Ether |
|
| 114 |
""" |
|
| 115 |
eth = float(etherscan_balance['result']) / 1000000000000000000 |
|
| 116 |
print("{}.value {:.2f}".format(eth_address, eth));
|
|
| 116 |
print("wei_balance_{}.value {}".format(eth_address, eth));
|
|
Formats disponibles : Unified diff