mirror of
https://github.com/FlipsideCrypto/livequery-base.git
synced 2026-02-06 11:16:44 +00:00
add evm utils (#16)
This commit is contained in:
parent
18ffc7f1d2
commit
ef7562dc32
@ -78,7 +78,27 @@
|
||||
HANDLER = 'hex_to_int'
|
||||
sql: |
|
||||
{{ python_udf_hex_to_int_with_encoding() | indent(4) }}
|
||||
|
||||
- name: utils.udf_evm_text_signature
|
||||
signature:
|
||||
- [abi, VARIANT]
|
||||
return_type: TEXT
|
||||
options: |
|
||||
LANGUAGE PYTHON
|
||||
RUNTIME_VERSION = '3.8'
|
||||
HANDLER = 'get_simplified_signature'
|
||||
sql: |
|
||||
{{ create_udf_evm_text_signature() | indent(4) }}
|
||||
- name: utils.udf_keccak256
|
||||
signature:
|
||||
- [event_name, VARCHAR(255)]
|
||||
return_type: TEXT
|
||||
options: |
|
||||
LANGUAGE PYTHON
|
||||
RUNTIME_VERSION = '3.8'
|
||||
PACKAGES = ('pycryptodome==3.15.0')
|
||||
HANDLER = 'udf_encode'
|
||||
sql: |
|
||||
{{ create_udf_keccak256() | indent(4) }}
|
||||
- name: utils.udf_hex_to_string
|
||||
signature:
|
||||
- [hex, STRING]
|
||||
|
||||
@ -39,4 +39,38 @@ def hex_to_int(encoding, hex) -> str:
|
||||
return str(value)
|
||||
else:
|
||||
return str(int(hex, 16))
|
||||
{% endmacro %}
|
||||
|
||||
{% macro create_udf_keccak256() %}
|
||||
from Crypto.Hash import keccak
|
||||
|
||||
def udf_encode(event_name):
|
||||
keccak_hash = keccak.new(digest_bits=256)
|
||||
keccak_hash.update(event_name.encode('utf-8'))
|
||||
return '0x' + keccak_hash.hexdigest()
|
||||
{% endmacro %}
|
||||
|
||||
{% macro create_udf_evm_text_signature() %}
|
||||
|
||||
def get_simplified_signature(abi):
|
||||
def generate_signature(inputs):
|
||||
signature_parts = []
|
||||
for input_data in inputs:
|
||||
if 'components' in input_data:
|
||||
component_signature_parts = []
|
||||
components = input_data['components']
|
||||
component_signature_parts.extend(generate_signature(components))
|
||||
component_signature_parts[-1] = component_signature_parts[-1].rstrip(",")
|
||||
if input_data['type'].endswith('[]'):
|
||||
signature_parts.append("(" + "".join(component_signature_parts) + ")[],")
|
||||
else:
|
||||
signature_parts.append("(" + "".join(component_signature_parts) + "),")
|
||||
else:
|
||||
signature_parts.append(input_data['type'].replace('enum ', '').replace(' payable', '') + ",")
|
||||
return signature_parts
|
||||
|
||||
signature_parts = [abi['name'] + "("]
|
||||
signature_parts.extend(generate_signature(abi['inputs']))
|
||||
signature_parts[-1] = signature_parts[-1].rstrip(",") + ")"
|
||||
return "".join(signature_parts)
|
||||
{% endmacro %}
|
||||
Loading…
Reference in New Issue
Block a user