Closed shamtroon closed 2 years ago
Hi @shamtroon, I would assume you've solved this issue by now, but I just wanted to respond to this in case someone else was having an issue.
The methods serializeTransaction
/deserializeTransaction
expect JSON/Hex representations of a full transaction, which is why you're seeing an error that expiration
was missing (because it's included in a transaction and not in your JSON example above). There are examples of this: serialization and deserialization.
If you want to just serialize/deserialize an action's data, you need to pass the ABI as well to serialize
/deserialize
. There's an example of this deserialization here.
Lastly, if you want to serialize/deserialize an action's return value (new feature), then you need to pass the return value's type:
String RETURN_VALUE_ABI = "{\"version\":\"eosio::abi/1.2\",\"types\":[],\"structs\":[{\"name\":\"retval.complex\",\"base\":\"\",\"fields\":[{\"name\":\"user\",\"type\":\"name\"}]},{\"name\":\"retval.simple\",\"base\":\"\",\"fields\":[{\"name\":\"user\",\"type\":\"name\"}]},{\"name\":\"retval.null\",\"base\":\"\",\"fields\":[{\"name\":\"user\",\"type\":\"name\"}]},{\"name\":\"returnValue\",\"base\":\"\",\"fields\":[{\"name\":\"id\",\"type\":\"uint32\"},{\"name\":\"name\",\"type\":\"name\"}]}],\"actions\":[{\"name\":\"retval.complex\",\"type\":\"retval.complex\",\"ricardian_contract\":\"\"},{\"name\":\"retval.simple\",\"type\":\"retval.simple\",\"ricardian_contract\":\"\"},{\"name\":\"retval.null\",\"type\":\"retval.null\",\"ricardian_contract\":\"\"}],\"tables\":[],\"ricardian_clauses\":[],\"error_messages\":[],\"abi_extensions\":[],\"variants\":[]}";
String json = "10";
String returnValueType = "uint32";
String hexResult = null;
String jsonResult = null;
try {
AbiEosSerializationObject serializationObject = new AbiEosSerializationObject("contract", "retval.simple", returnValueType, RETURN_VALUE_ABI);
serializationObject.setJson(json);
abieos.serialize(serializationObject);
hexResult = serializationObject.getHex();
} catch (SerializeError err) {
err.printStackTrace();
}
try {
AbiEosSerializationObject serializationObject = new AbiEosSerializationObject("contract", "retval.simple", returnValueType, RETURN_VALUE_ABI);
serializationObject.setHex(hexResult);
abieos.deserialize(serializationObject);
jsonResult = serializationObject.getJson();
} catch (DeserializeError err) {
err.printStackTrace();
}
Thanks @jlamarr22 for your response, Yes you are right, I get some work-around and solved this issue. Actually I need to serialize action data, and got an example from you readme.md file so I tried, but it causes an exception. Kindly update this file as this example is nor working or causing issue.
Again thanks for response.
Hey guys, I want to serialize an action's data. I didn't get any function. But in your document you describe an example using "serializeTransaction(json)", but it accepts only transaction and I am providing only a sample json. Do you have any function which serialize any json ??
I tried this example but it cause exception that expiration is missing.