add/encode-udf-base58 (#81)

* new udfs

* typo
This commit is contained in:
drethereum 2023-12-21 18:56:47 -05:00 committed by GitHub
parent 6273d35e95
commit 3f8b47aa5b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 37 additions and 0 deletions

View File

@ -122,6 +122,32 @@ def transform(events: list):
{% endmacro %}
{% macro create_udf_base58_to_hex() %}
def transform_base58_to_hex(base58):
if base58 is None:
return 'Invalid input'
ALPHABET = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"
base_count = len(ALPHABET)
num = 0
for char in base58:
num *= base_count
if char in ALPHABET:
num += ALPHABET.index(char)
else:
return 'Invalid character in input'
hex_string = hex(num)[2:]
if len(hex_string) % 2 != 0:
hex_string = '0' + hex_string
return '0x' + hex_string
{% endmacro %}
{% macro create_udf_hex_to_base58() %}
def transform_hex_to_base58(hex):

View File

@ -238,6 +238,17 @@
RETURNS NULL ON NULL INPUT
sql: evm/decode/log
- name: {{ schema }}.udf_base58_to_hex
signature:
- [base58, STRING]
return_type: TEXT
options: |
LANGUAGE PYTHON
RUNTIME_VERSION = '3.8'
HANDLER = 'transform_base58_to_hex'
sql: |
{{ create_udf_base58_to_hex() | indent(4) }}
- name: {{ schema }}.udf_hex_to_base58
signature:
- [hex, STRING]