package cy.agorise.graphenej; import com.google.gson.JsonArray; import com.google.gson.JsonDeserializationContext; import com.google.gson.JsonDeserializer; import com.google.gson.JsonElement; import com.google.gson.JsonParseException; import java.lang.reflect.Type; import cy.agorise.graphenej.interfaces.ByteSerializable; import cy.agorise.graphenej.interfaces.JsonSerializable; import cy.agorise.graphenej.operations.TransferOperation; /** * Base class that represents a generic operation */ public abstract class BaseOperation implements ByteSerializable, JsonSerializable { public static final String KEY_FEE = "fee"; public static final String KEY_EXTENSIONS = "extensions"; protected OperationType type; protected Extensions extensions; public BaseOperation(OperationType type){ this.type = type; this.extensions = new Extensions(); } public byte getId() { return (byte) this.type.ordinal(); } public abstract void setFee(AssetAmount assetAmount); public JsonElement toJsonObject(){ JsonArray array = new JsonArray(); array.add(this.getId()); return array; } /** *
* De-serializer used to unpack data from a generic operation. The general format used in the * JSON-RPC blockchain API is the following: *
* *[OPERATION_ID, OPERATION_OBJECT]
* Where OPERATION_ID
is one of the operations defined in {@link cy.agorise.graphenej.OperationType}
* and OPERATION_OBJECT
is the actual operation serialized in the JSON format.
*
*[ * 0, * { * "fee": { * "amount": 264174, * "asset_id": "1.3.0" * }, * "from": "1.2.138632", * "to": "1.2.129848", * "amount": { * "amount": 100, * "asset_id": "1.3.0" * }, * "extensions": [] * } *] *