def to_protobuf(self) -> Send: token = Token() token.denom = self._symbol token.amount = self._amount_amino input_addr = Input() input_addr.address = decode_address(self._from_address) input_addr.coins.extend([token]) output_addr = Output() output_addr.address = decode_address(self._to_address) output_addr.coins.extend([token]) msg = Send() msg.inputs.extend([input_addr]) msg.outputs.extend([output_addr]) return msg
def to_protobuf(self) -> Send: input_addr = Input() output_addr = Output() for transfer in self._transfers: token = Token() token.denom = transfer.symbol token.amount = encode_number(transfer.amount) input_addr.coins.extend([token]) output_addr.coins.extend([token]) input_addr.address = decode_address(self._from_address) output_addr.address = decode_address(self._to_address) msg = Send() msg.inputs.extend([input_addr]) msg.outputs.extend([output_addr]) return msg
def check_address(address, prefix): """Checks whether an address is valid. :param address: the bech32 address to decode :type address: str :param prefix: bnb or tbnb :type prefix: str :returns: True or False """ try: if not address.startswith(prefix): return False decoded_address = bech32_decode(address) decoded_address_length = len(decode_address(address)) if decoded_address_length == DECODED_ADDRESS_LEN and decoded_address[ 0] == prefix: return True except: return False
def convert_to_hex_address(bnb_address): decoded_addr = segwit_addr.decode_address(bnb_address) return decoded_addr.hex().upper()
def address_decoded(self): return decode_address(self._address)
def test_decode_invalid_address(): assert decode_address('tbnb10a6kkxlf823w9lwr6l9hzw4uyphcw7qzrud5') is None
def test_decode_address(): expected = binascii.unhexlify(b'7f756b1be93aa2e2fdc3d7cb713abc206f877802') assert decode_address( 'tbnb10a6kkxlf823w9lwr6l9hzw4uyphcw7qzrud5rr') == expected