Untrack build files

This commit is contained in:
Brian Ford 2020-07-10 10:22:38 -04:00
parent fbb3b2fd28
commit fcdff1fcad
17 changed files with 1 additions and 330 deletions

2
.gitignore vendored
View File

@ -1,4 +1,4 @@
udm_events.egg-info/
chainwalkers_utils.egg-info/
dist/
*.pyc
__pycache__

View File

@ -1 +0,0 @@
from eth_utils.jsonrpc import JsonRpcCaller

View File

@ -1,7 +0,0 @@
def hex_to_decimal(hex_value):
if hex_value == '0x':
return 0
return int(hex_value, 16)
def decimal_to_hex(decimal):
return hex(decimal)

View File

@ -1,62 +0,0 @@
import requests
import json
import base64
import time
class RpcCallFailedException(Exception):
pass
class JsonRpcCaller(object):
def __init__(self, node_url, user=None, password=None, tls=False, tlsVerify=False):
self.url = node_url
self.user = user
self.password = password
self.tls = tls
self.tlsVerify = tlsVerify
def _make_rpc_call(self, headers, payload, json):
try:
response = requests.post(
self.url,
headers=headers,
data=payload,
json=json,
verify=(self.tls and self.tlsVerify)
)
except Exception as e:
raise RpcCallFailedException(e)
if response.status_code != 200:
raise RpcCallFailedException("Invalid status code: %s" % response.status_code)
responseJson = response.json(parse_float=lambda f: f)
if type(responseJson) != list:
if "error" in responseJson and responseJson["error"] is not None:
raise RpcCallFailedException("RPC call error: %s" % responseJson["error"])
else:
return responseJson.get('result')
else:
result = []
for subResult in responseJson:
if "error" in subResult and subResult["error"] is not None:
raise RpcCallFailedException("RPC call error: %s" % subResult["error"])
else:
result.append(subResult["result"])
return result
def call(self, method, params=None, query=None):
if params is None:
params = []
headers = {'content-type': 'application/json'}
payload = json.dumps({"jsonrpc": "2.0", "id": "0", "method": method, "params": params})
if query: # GQL Hack
return self._make_rpc_call(headers, payload=None, json={'query': query})
return self._make_rpc_call(headers, payload, json=None)
def bulk_call(self, methodParamsTuples):
headers = {'content-type': 'application/json'}
payload = json.dumps([{"jsonrpc": "2.0", "id": "0", "method": method, "params": params}
for method, params in methodParamsTuples])
return self._make_rpc_call(headers, payload)

View File

@ -1 +0,0 @@
from tendermint.rpc import TendermintRPC

View File

@ -1,85 +0,0 @@
import json
import requests
class TendermintRPC:
def __init__(self, node_url):
self.node_url = node_url
def get_block_height(self):
try:
response = requests.get(self.node_url+ '/abci_info?')
response.raise_for_status()
data = response.json()
return data['result']['response']['last_block_height']
except Exception as err:
print(f'An error occured retrieving the latest block height: {err}')
def get_block(self, height):
try:
response = requests.get(self.node_url + '/block?height=' + str(height))
response.raise_for_status()
data = response.json()
block = self.init_block(data['result'])
block_results = self.get_block_results(height)
# Capture transactions and underlying events
block_transactions = self.get_transactions_by_block(height)
if block_transactions['txs']:
for tx in block_transactions['txs']:
block_tx = self.get_transactions_by_hash(tx['hash'])
block.add_transaction(block_tx)
# Capture begin block events ()
if block_results['results']['begin_block']:
for event in block_results['results']['begin_block']['events']:
block.begin_block.append(event)
block.end_block = block_results['results']['end_block']
block_validators = self.get_block_validators(height)
for validator in block_validators['validators']:
block.validators.append(validator)
return block
except Exception as err:
print(f'An error occured retrieving block: {err}')
def get_block_results(self, height):
try:
response = requests.get(self.node_url + '/block_results?height=' + str(height))
response.raise_for_status()
data = response.json()
return data['result']
except Exception as err:
print(f'An error occured retrieving the results of block height: {err}')
# Need ANKR to turn on indexing at node level for this call to work properly
def get_transactions_by_block(self, height):
try:
response = requests.get(self.node_url + '/tx_search?query=\"tx.height=' + str(height) + '\"&prove=true')
response.raise_for_status()
data = response.json()
return data['result']
except Exception as err:
print(f'An error occured retrieving the transactions in block: {err}')
def get_transactions_by_hash(self, tx_hash):
try:
response = requests.get(self.node_url + '/tx?hash=' + tx_hash)
response.raise_for_status()
data = response.json()
return data
except Exception as err:
print(f'An error occured retrieving the transaction by hash: {err}')
# Currently returning the following response "Height must be less than or equal to the current blockchain height"
def get_block_validators(self, height):
try:
response = requests.get(self.node_url + '/validators?height=' + str(height))
response.raise_for_status()
data = response.json()
return data['result']
except Exception as err:
print(f'An error occured retrieving the validators for block height: {err}')

View File

@ -1 +0,0 @@
from tendermint.rpc import TendermintRPC

View File

@ -1,88 +0,0 @@
import json
import requests
class TendermintRPC:
def __init__(self, node_url):
self.node_url = node_url
def get_block_height(self):
try:
response = requests.get(self.node_url+ '/abci_info?')
response.raise_for_status()
data = response.json()
return data['result']['response']['last_block_height']
except Exception as err:
print(f'An error occured retrieving the latest block height: {err}')
def get_block(self, height):
try:
response = requests.get(self.node_url + '/block?height=' + str(height))
response.raise_for_status()
data = response.json()
block = self.init_block(data['result'])
block_results = self.get_block_results(height)
# Capture transactions and underlying events
block_transactions = self.get_transactions_by_block(height)
if block_transactions['txs']:
for tx in block_transactions['txs']:
block_tx = self.get_transactions_by_hash(tx['hash'])
block.add_transaction(block_tx)
# Capture begin block events ()
if block_results['results']['begin_block']:
for event in block_results['results']['begin_block']['events']:
block.begin_block.append(event)
block.end_block = block_results['results']['end_block']
# block_validators = self.get_block_validators(height)
# for validator in block_validators['validators']:
# block.validators.append(validator)
return block
except Exception as err:
print(f'An error occured retrieving block: {err}')
def get_block_results(self, height):
try:
response = requests.get(self.node_url + '/block_results?height=' + str(height))
response.raise_for_status()
data = response.json()
return data['result']
except Exception as err:
print(f'An error occured retrieving the results of block height: {err}')
# Need ANKR to turn on indexing at node level for this call to work properly
def get_transactions_by_block(self, height):
try:
response = requests.get(self.node_url + '/tx_search?query=\"tx.height=' + str(height) + '\"&prove=true')
response.raise_for_status()
data = response.json()
return data['result']
except Exception as err:
print(f'An error occured retrieving the transactions in block: {err}')
def get_transactions_by_hash(self, tx_hash):
try:
response = requests.get(self.node_url + '/tx?hash=' + tx_hash)
response.raise_for_status()
data = response.json()
return data
except Exception as err:
print(f'An error occured retrieving the transaction by hash: {err}')
# Currently returning the following response "Height must be less than or equal to the current blockchain height"
def get_block_validators(self, height):
try:
response = requests.get(self.node_url + '/validators?height=' + str(height))
response.raise_for_status()
data = response.json()
return data['result']
except Exception as err:
print(f'An error occured retrieving the validators for block height: {err}')
def init_block(self, blockDict):
return BlockSchema(blockDict)

View File

@ -1,40 +0,0 @@
class BlockSchema(object):
def __init__(self, data):
self.hash = data['block_meta']['hash']
self.chain_id = data['block_meta']['header']['chain_id']
self.height = data['block_meta']['header']['height']
self.timestamp = data['block_meta']['header']['time']
self.parts = data['block_meta']['block_id']['parts']
self.num_txs = data['block_meta']['header']['num_txs']
self.total_txs_onchain = data['block_meta']['header']['total_txs']
self.parent_hash = data['block_meta']['header']['last_block_id']['hash']
self.last_commit_hash = data['block_meta']['header']['last_commit_hash']
self.data_hash = data['block_meta']['header']['data_hash']
self.validators_hash = data['block_meta']['header']['validators_hash']
self.next_validators_hash = data['block_meta']['header']['next_validators_hash']
self.consensus_hash = data['block_meta']['header']['consensus_hash']
self.app_hash = data['block_meta']['header']['app_hash']
self.last_results_hash = data['block_meta']['header']['last_results_hash']
self.evidence_hash = data['block_meta']['header']['evidence_hash']
self.proposer_address = data['block_meta']['header']['proposer_address']
self.encoded_txs = data['block']['data']['txs']
self.evidence = data['block']['evidence']['evidence']
self.transactions = []
self.precommits = data['block']['last_commit']['precommits']
self.validators =[]
self.begin_block = []
self.end_block = {}
def add_transaction(self, transaction):
self.transactions.append(transaction)
def get_transactions(self):
return self.transactions
def __repr__(self):
header = "block height: %d, tx count %d" % (int(self.height), len(self.transactions))
transactions = []
for tx in self.transactions:
transactions.append(str(tx))
return "\n".join([header] + transactions)

View File

@ -1,27 +0,0 @@
Metadata-Version: 2.1
Name: chainwalkers-utils
Version: 0.0.5
Summary: Collection of utilities to be used across chainwalkers repos
Home-page: git@github.com:FlipsideCrypto/chainwalkers-utils.git
Author: Brian Ford
Author-email: brian@flipsidecrypto.com
License: unlicense
Description: # Chainwalker Utilities
This repo is home to Flipsides chainwalkers python utilities package. A central repo that packeges up various python modules that can be used across chainwalkers projects.
## Modules
### Tendermint Utils
Collection of common methods used to interact with tendermint based chains (Cosmos, Kava, Binance)
### Eth utils
Collection of common methods used across eth based chains
## Install
`pip install git+ssh://git@github.com/FlipsideCrypto/chainwalkers-utils.git`
Platform: UNKNOWN
Description-Content-Type: text/markdown

View File

@ -1,13 +0,0 @@
README.md
setup.py
chainwalkers_utils.egg-info/PKG-INFO
chainwalkers_utils.egg-info/SOURCES.txt
chainwalkers_utils.egg-info/dependency_links.txt
chainwalkers_utils.egg-info/not-zip-safe
chainwalkers_utils.egg-info/top_level.txt
eth_utils/__init__.py
eth_utils/decimals.py
eth_utils/jsonrpc.py
tendermint_utils/__init__.py
tendermint_utils/rpc.py
tendermint_utils/schema.py

View File

@ -1 +0,0 @@

View File

@ -1,2 +0,0 @@
eth_utils
tendermint_utils

Binary file not shown.

Binary file not shown.

Binary file not shown.