fromHex static method
Implementation
static AccountAddress fromHex(String addr) {
var address = HexString.ensure(addr);
// If an address hex has odd number of digits, padd the hex string with 0
// e.g. '1aa' would become '01aa'.
if (address.noPrefix().length % 2 != 0) {
address = HexString("0${address.noPrefix()}");
}
Uint8List addressBytes = address.toUint8Array();
if (addressBytes.length > AccountAddress.LENGTH) {
throw ArgumentError("Hex string is too long. Address's length is 32 bytes.");
} else if (addressBytes.length == AccountAddress.LENGTH) {
return AccountAddress(addressBytes);
}
final res = Uint8List(AccountAddress.LENGTH);
res.setAll(AccountAddress.LENGTH - addressBytes.length, addressBytes);
return AccountAddress(res);
}