mirror of
https://github.com/FlipsideCrypto/livequery-base.git
synced 2026-02-06 03:07:13 +00:00
parent
6273d35e95
commit
3f8b47aa5b
@ -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):
|
||||
|
||||
@ -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]
|
||||
|
||||
Loading…
Reference in New Issue
Block a user