"address terra" Code Answer's
You're definitely familiar with the best coding language Whatever that developers use to develop their projects and they get all their queries like "address terra" answered properly. Developers are finding an appropriate answer about address terra related to the Whatever coding language. By visiting this online portal developers get answers concerning Whatever codes question like address terra. Enter your desired code related query in the search bar and get every piece of information about Whatever code related question on address terra.
address terra
"""Special Bech32 String Types"""
from __future__ import annotations
from typing import NewType
from bech32 import bech32_decode, bech32_encode
__all__ = [
"AccAddress",
"ValAddress",
"AccPubKey",
"ValPubKey",
"ValConsPubKey",
"is_acc_address",
"is_acc_pubkey",
"is_val_address",
"is_val_pubkey",
"is_valcons_pubkey",
"to_acc_address",
"to_acc_pubkey",
"to_val_address",
"to_val_pubkey",
]
def check_prefix_and_length(prefix: str, data: str, length: int):
vals = bech32_decode(data)
return vals[0] == prefix and len(data) == length
AccAddress = NewType("AccAddress", str)
AccAddress.__doc__ = """Terra Bech32 Account Address -- type alias of str."""
ValAddress = NewType("ValAddress", str)
ValAddress.__doc__ = """Terra Bech32 Validator Operator Address -- type alias of str."""
AccPubKey = NewType("AccPubKey", str)
AccPubKey.__doc__ = """Terra Bech32 Account Address -- type alias of str."""
ValPubKey = NewType("ValPubKey", str)
ValPubKey.__doc__ = """Terra Bech32 Validator PubKey -- type alias of str."""
ValConsPubKey = NewType("ValConsPubKey", str)
ValConsPubKey.__doc__ = (
"""Terra Bech32 Validator Conensus PubKey -- type alias of str."""
)
[docs]def is_acc_address(data: str) -> bool:
"""Checks whether the given string is a properly formatted Terra account address.
Args:
data (str): string to check
Returns:
bool: whether the string is a proper account address
"""
return check_prefix_and_length("terra", data, 44)
[docs]def to_acc_address(data: ValAddress) -> AccAddress:
"""Converts a validator operator address into an account address.
Args:
data (ValAddress): validator operator address
Raises:
ValueError: if provided string is not Bech32
Returns:
AccAddress: account address
"""
vals = bech32_decode(data)
if vals[1] is None:
raise ValueError(f"invalid bech32: {data}")
return AccAddress(bech32_encode("terra", vals[1]))
[docs]def is_val_address(data: str) -> bool:
"""Checks whether the given string is a properly formatted Terra validator operator
address.
Args:
data (str): string to check
Returns:
bool: whether the string is a proper validator address
"""
return check_prefix_and_length("terravaloper", data, 51)
[docs]def to_val_address(data: AccAddress) -> ValAddress:
"""Converts an account address into a validator operator address.
Args:
data (AccAddress): account address
Raises:
ValueError: if provided string is not Bech32
Returns:
ValAddress: validator operator address
"""
vals = bech32_decode(data)
if vals[1] is None:
raise ValueError(f"invalid bech32: {data}")
return ValAddress(bech32_encode("terravaloper", vals[1]))
[docs]def is_acc_pubkey(data: str) -> bool:
"""Checks whether the provided string is a properly formatted Terra account pubkey.
Args:
data (str): string to check
Returns:
bool: whether string is account pubkey
"""
return check_prefix_and_length("terrapub", data, 76)
[docs]def to_acc_pubkey(data: ValPubKey) -> AccPubKey:
"""Converts a validator pubkey into an account pubkey.
Args:
data (ValPubKey): validator pubkey
Raises:
ValueError: if provided string is not Bech32
Returns:
AccPubKey: account pubkey
"""
vals = bech32_decode(data)
if vals[1] is None:
raise ValueError(f"invalid bech32: {data}")
return AccPubKey(bech32_encode("terrapub", vals[1]))
def is_val_pubkey(data: str) -> bool:
"""Checks whether provided string is a properly formatted Terra validator pubkey.
Args:
data (str): string to check
Returns:
bool: whether string is validator pubkey
"""
return check_prefix_and_length("terravaloperpub", data, 83)
def to_val_pubkey(data: AccPubKey) -> ValPubKey:
"""Converts an account pubkey into a validator pubkey.
Args:
data (AccPubKey): account pubkey
Raises:
ValueError: if provided string is not Bech32
Returns:
ValPubKey: validator pubkey
"""
vals = bech32_decode(data)
if vals[1] is None:
raise ValueError(f"invalid bech32: {data}")
return ValPubKey(bech32_encode("terravaloperpub", vals[1]))
def is_valcons_pubkey(data: str) -> ValConsPubKey:
"""Checks whether provided string is a properly formatted Terra validator consensus
pubkey.
Args:
data (str): string to check
Returns:
ValConsPubKey: validator consensus pubkey
"""
return check_prefix_and_length("terravalconspub", data, 83)
Source: terra-project.github.io
All those coders who are working on the Whatever based application and are stuck on address terra can get a collection of related answers to their query. Programmers need to enter their query on address terra related to Whatever code and they'll get their ambiguities clear immediately. On our webpage, there are tutorials about address terra for the programmers working on Whatever code while coding their module. Coders are also allowed to rectify already present answers of address terra while working on the Whatever language code. Developers can add up suggestions if they deem fit any other answer relating to "address terra". Visit this developer's friendly online web community, CodeProZone, and get your queries like address terra resolved professionally and stay updated to the latest Whatever updates.