Merge pull request #44 from FlipsideCrypto/AN-4890/base58

AN-4890/base58
This commit is contained in:
drethereum 2024-06-27 12:58:28 -06:00 committed by GitHub
commit 9a91c3025f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 15 additions and 5 deletions

View File

@ -160,7 +160,7 @@
- name: {{ schema }}.udf_base58_to_hex
signature:
- [input, STRING]
- [base58, STRING]
return_type: TEXT
options: |
LANGUAGE PYTHON

View File

@ -181,15 +181,23 @@ def transform(events: dict):
{% macro create_udf_base58_to_hex() %}
def transform_base58_to_hex(input):
if input is None:
def transform_base58_to_hex(base58):
if base58 is None:
return 'Invalid input'
ALPHABET = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"
base_count = len(ALPHABET)
num = 0
for char in input:
leading_zeros = 0
for char in base58:
if char == '1':
leading_zeros += 1
else:
break
for char in base58:
num *= base_count
if char in ALPHABET:
num += ALPHABET.index(char)
@ -201,7 +209,9 @@ def transform_base58_to_hex(input):
if len(hex_string) % 2 != 0:
hex_string = '0' + hex_string
return '0x' + hex_string
hex_leading_zeros = '00' * leading_zeros
return '0x' + hex_leading_zeros + hex_string
{% endmacro %}