Search in sources :

Example 1 with VerificationStruct

use of net.cryptonomica.returns.VerificationStruct in project cryptonomica by Cryptonomica.

the class EthNodeAPI method getVerificationDataFromSmartContract.

// 
@ApiMethod(name = "getVerificationFromSC", path = "getVerificationFromSC", httpMethod = ApiMethod.HttpMethod.GET)
@SuppressWarnings("unused")
public VerificationStruct getVerificationDataFromSmartContract(// final HttpServletRequest httpServletRequest,
final User googleUser, @Named("ethereumAcc") final String ethereumAcc) throws IllegalArgumentException, UnauthorizedException {
    // ensure registered user ( - may be later only for verified):
    CryptonomicaUser cryptonomicaUser = UserTools.ensureCryptonomicaRegisteredUser(googleUser);
    // check form:
    LOG.warning("ethereumAcc" + ethereumAcc);
    if (ethereumAcc == null || ethereumAcc.equals("")) {
        throw new IllegalArgumentException("Provided text is to short or empty");
    }
    String tomcatWeb3jAPIkey = ofy().load().key(Key.create(AppSettings.class, "tomcatweb3jAPIkey")).now().getValue();
    String urlHost = "https://tomcatweb3j.cryptonomica.net";
    String urlPath = "/getVerification";
    String urlAddress = urlHost + urlPath;
    // HashMap<String, String> queryMap = new HashMap<>();
    // queryMap.put("address", ethereumAcc);
    String postRequestBody = "address=" + ethereumAcc;
    HTTPResponse httpResponse = HttpService.postRequestWithAPIkey(urlAddress, postRequestBody, tomcatWeb3jAPIkey);
    // LOG.warning("httpResponse: " + new Gson().toJson(httpResponse));
    byte[] httpResponseContentBytes = httpResponse.getContent();
    String httpResponseContentString = new String(httpResponseContentBytes, StandardCharsets.UTF_8);
    // Test:
    // Object resObj = new Gson().fromJson(httpResponseContentString, Object.class); // --- exception
    // LOG.warning("resObj: " + new Gson().toJson(resObj));
    LOG.warning("httpResponseContentString: " + httpResponseContentString);
    VerificationStruct verificationStruct = GSON.fromJson(httpResponseContentString, VerificationStruct.class);
    /* header:
        content-type:  application/json;charset=utf-8
        body:
        {
            "fingerprint": "",
            "keyCertificateValidUntil": 0,
            "firstName": "",
            "lastName": "",
            "birthDate": 0,
            "nationality": "",
            "verificationAddedOn": 0,
            "revokedOn": 0
        }
        */
    return verificationStruct;
}
Also used : VerificationStruct(net.cryptonomica.returns.VerificationStruct) AppSettings(net.cryptonomica.entities.AppSettings) HTTPResponse(com.google.appengine.api.urlfetch.HTTPResponse) CryptonomicaUser(net.cryptonomica.entities.CryptonomicaUser) ApiMethod(com.google.api.server.spi.config.ApiMethod)

Aggregations

ApiMethod (com.google.api.server.spi.config.ApiMethod)1 HTTPResponse (com.google.appengine.api.urlfetch.HTTPResponse)1 AppSettings (net.cryptonomica.entities.AppSettings)1 CryptonomicaUser (net.cryptonomica.entities.CryptonomicaUser)1 VerificationStruct (net.cryptonomica.returns.VerificationStruct)1