public byte[] Encode(object value) { var strValue = value as string; if (strValue != null && strValue.ToLower().StartsWith("cfx")) { var oldAddress = Base32.Decode(strValue); value = oldAddress.Address; strValue = oldAddress.Address; } if ((strValue != null) && !strValue.StartsWith("0x", StringComparison.Ordinal)) { value = "0x" + value; } var addr = _intTypeEncoder.Encode(value); for (var i = 0; i < 12; i++) { if ((addr[i] != 0) && (addr[i] != 0xFF)) { throw new Exception("Invalid address (should be 20 bytes length): " + addr.ToHex()); } if (addr[i] == 0xFF) { addr[i] = 0; } } return(addr); }
public byte[] Encode(object value) { if (!(value is bool)) { throw new Exception("Wrong value for bool type: " + value); } return(_intTypeEncoder.Encode((bool)value ? 1 : 0)); }