Search in sources :

Example 1 with ScriptFunction

use of org.starcoin.types.ScriptFunction in project starcoin-java by starcoinorg.

the class ScriptFunctionDeserializer method deserialize.

@Override
public ScriptFunction deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException {
    JsonNode node = jsonParser.getCodec().readTree(jsonParser);
    ModuleId module = ParseUtil.parseObject(jsonParser, node.get("module"), ModuleId.class);
    Identifier function = new Identifier(node.get("function").asText());
    List<TypeTag> tyArgs = ParseUtil.parseObjectList(jsonParser, node.get("type_args"), TypeTag.class);
    List<Bytes> args = ParseUtil.parseBytesList(node.get("args"));
    ;
    return new ScriptFunction(module, function, tyArgs, args);
}
Also used : ModuleId(org.starcoin.types.ModuleId) Bytes(com.novi.serde.Bytes) Identifier(org.starcoin.types.Identifier) ScriptFunction(org.starcoin.types.ScriptFunction) JsonNode(com.fasterxml.jackson.databind.JsonNode) TypeTag(org.starcoin.types.TypeTag)

Example 2 with ScriptFunction

use of org.starcoin.types.ScriptFunction in project starcoin-java by starcoinorg.

the class ScriptFunctionObj method toScriptFunction.

public ScriptFunction toScriptFunction() {
    List<TypeTag> tyAargsTypeTag = Lists.newArrayList();
    if (tyArgs != null) {
        tyAargsTypeTag = tyArgs.stream().map(TypeObj::toTypeTag).collect(Collectors.toList());
    }
    Identifier name = new Identifier(getModuleName());
    ModuleId moduleId = new ModuleId(AccountAddressUtils.create(getModuleAddress()), name);
    Identifier function = new Identifier(getFunctionName());
    ScriptFunction scriptFunction = new ScriptFunction(moduleId, function, tyAargsTypeTag, args);
    return scriptFunction;
}
Also used : ModuleId(org.starcoin.types.ModuleId) Identifier(org.starcoin.types.Identifier) ScriptFunction(org.starcoin.types.ScriptFunction) TypeTag(org.starcoin.types.TypeTag)

Aggregations

Identifier (org.starcoin.types.Identifier)2 ModuleId (org.starcoin.types.ModuleId)2 ScriptFunction (org.starcoin.types.ScriptFunction)2 TypeTag (org.starcoin.types.TypeTag)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 Bytes (com.novi.serde.Bytes)1