com.github.DNAProject.network.rest.Interfaces Maven / Gradle / Ivy
The newest version!
/*
* Copyright (C) 2018 The DNA Authors
* This file is part of The DNA library.
*
* The DNA is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* The DNA is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with The DNA. If not, see .
*
*/
package com.github.DNAProject.network.rest;
import com.github.DNAProject.common.ErrorCode;
import com.github.DNAProject.network.exception.RestfulException;
import java.util.HashMap;
import java.util.Map;
/**
*
*/
class Interfaces {
private String url;
public Interfaces(String url) {
this.url = url;
}
public String getUrl() {
return url;
}
public String sendTransaction(boolean preExec, String userid, String action, String version, String data) throws RestfulException {
Map params = new HashMap();
if (userid != null) {
params.put("userid", userid);
}
if (preExec) {
params.put("preExec", "1");
}
Map body = new HashMap();
body.put("Action", action);
body.put("Version", version);
body.put("Data", data);
try {
return http.post(url + UrlConsts.Url_send_transaction, params, body);
} catch (Exception e) {
throw new RestfulException(ErrorCode.ConnectUrlErr(url), e);
}
}
public String getTransaction(String txhash, boolean raw) throws RestfulException {
Map params = new HashMap();
if (raw) {
params.put("raw", "1");
}
try {
return http.get(url + UrlConsts.Url_get_transaction + txhash, params);
} catch (Exception e) {
throw new RestfulException(ErrorCode.ConnectUrlErr + url, e);
}
}
public String getNodeCount() throws RestfulException {
Map params = new HashMap();
try {
return http.get(url + UrlConsts.Url_get_node_count, params);
} catch (Exception e) {
throw new RestfulException(ErrorCode.ConnectUrlErr + url, e);
}
}
public String getBlockHeight() throws RestfulException {
Map params = new HashMap();
try {
return http.get(url + UrlConsts.Url_get_block_height, params);
} catch (Exception e) {
throw new RestfulException(ErrorCode.ConnectUrlErr + url, e);
}
}
public String getBlock(int height, String raw) throws RestfulException {
Map params = new HashMap();
params.put("raw", raw);
try {
return http.get(url + UrlConsts.Url_get_block_by_height + height, params);
} catch (Exception e) {
throw new RestfulException(ErrorCode.ConnectUrlErr + url, e);
}
}
public String getBlock(String hash, String raw) throws RestfulException {
Map params = new HashMap();
params.put("raw", raw);
try {
return http.get(url + UrlConsts.Url_get_block_by_hash + hash, params);
} catch (Exception e) {
throw new RestfulException(ErrorCode.ConnectUrlErr + url, e);
}
}
public String getContract(String hash) throws RestfulException {
Map params = new HashMap();
params.put("raw", "1");
try {
return http.get(url + UrlConsts.Url_get_contract_state + hash, params);
} catch (Exception e) {
throw new RestfulException(ErrorCode.ConnectUrlErr + url, e);
}
}
public String getContractJson(String hash) throws RestfulException {
Map params = new HashMap();
try {
return http.get(url + UrlConsts.Url_get_contract_state + hash, params);
} catch (Exception e) {
throw new RestfulException(ErrorCode.ConnectUrlErr + url, e);
}
}
public String getSmartCodeEvent(int height) throws RestfulException {
Map params = new HashMap();
try {
return http.get(url + UrlConsts.Url_get_smartcodeevent_txs_by_height + height, params);
} catch (Exception e) {
throw new RestfulException(ErrorCode.ConnectUrlErr + url, e);
}
}
public String getSmartCodeEvent(String hash) throws RestfulException {
Map params = new HashMap();
try {
return http.get(url + UrlConsts.Url_get_smartcodeevent_by_txhash + hash, params);
} catch (Exception e) {
throw new RestfulException(ErrorCode.ConnectUrlErr + url, e);
}
}
public String getBlockHeightByTxHash(String hash) throws RestfulException {
Map params = new HashMap();
try {
return http.get(url + UrlConsts.Url_get_block_height_by_txhash + hash, params);
} catch (Exception e) {
throw new RestfulException(ErrorCode.ConnectUrlErr + url, e);
}
}
public String getStorage(String codehash, String key) throws RestfulException {
Map params = new HashMap();
try {
return http.get(url + UrlConsts.Url_get_storage + codehash + "/" + key, params);
} catch (Exception e) {
throw new RestfulException(ErrorCode.ConnectUrlErr + url, e);
}
}
public String getMerkleProof(String hash) throws RestfulException {
Map params = new HashMap();
try {
return http.get(url + UrlConsts.Url_get_merkleproof + hash, params);
} catch (Exception e) {
throw new RestfulException(ErrorCode.ConnectUrlErr + url, e);
}
}
public String getMemPoolTxCount() throws RestfulException {
Map params = new HashMap();
try {
return http.get(url + UrlConsts.Url_get_mem_pool_tx_count, params);
} catch (Exception e) {
throw new RestfulException(ErrorCode.ConnectUrlErr + url, e);
}
}
public String getMemPoolTxState(String hash) throws RestfulException {
Map params = new HashMap();
try {
return http.get(url + UrlConsts.Url_get_mem_pool_tx_state + hash, params);
} catch (Exception e) {
throw new RestfulException(ErrorCode.ConnectUrlErr + url, e);
}
}
public String getBalance(String address) throws RestfulException {
Map params = new HashMap();
try {
return http.get(url + UrlConsts.Url_get_account_balance + address, params);
} catch (Exception e) {
throw new RestfulException(ErrorCode.ConnectUrlErr + url, e);
}
}
public String getTransactionJson(String txhash) throws RestfulException {
Map params = new HashMap();
try {
return http.get(url + UrlConsts.Url_get_transaction + txhash, params);
} catch (Exception e) {
throw new RestfulException(ErrorCode.ConnectUrlErr + url, e);
}
}
public String getBlockJson(int height) throws RestfulException {
Map params = new HashMap();
try {
return http.get(url + UrlConsts.Url_get_block_by_height + height, params);
} catch (Exception e) {
throw new RestfulException(ErrorCode.ConnectUrlErr + url, e);
}
}
public String getBlockJson(String hash) throws RestfulException {
Map params = new HashMap();
try {
return http.get(url + UrlConsts.Url_get_block_by_hash + hash, params);
} catch (Exception e) {
throw new RestfulException(ErrorCode.ConnectUrlErr + url, e);
}
}
public String getAllowance(String asset, String from, String to) throws RestfulException {
Map params = new HashMap();
try {
return http.get(url + UrlConsts.Url_get_allowance + asset + "/" + from + "/" + to, params);
} catch (Exception e) {
throw new RestfulException(ErrorCode.ConnectUrlErr + url, e);
}
}
public String getVersion() throws RestfulException {
Map params = new HashMap();
try {
return http.get(url + UrlConsts.Url_get_version, params);
} catch (Exception e) {
throw new RestfulException(ErrorCode.ConnectUrlErr + url, e);
}
}
public String getGrantOng(String address) throws RestfulException {
Map params = new HashMap();
try {
return http.get(url + UrlConsts.Url_get_grant_ong+ "/" +address, params);
} catch (Exception e) {
throw new RestfulException(ErrorCode.ConnectUrlErr + url, e);
}
}
public String getNetworkId() throws RestfulException {
Map params = new HashMap();
try {
return http.get(url + UrlConsts.Url_get_networkid, params);
} catch (Exception e) {
throw new RestfulException(ErrorCode.ConnectUrlErr + url, e);
}
}
public String getNodeSyncStatus() throws RestfulException {
Map params = new HashMap();
try {
return http.get(url + UrlConsts.Url_get_syncstatus, params);
} catch (Exception e) {
throw new RestfulException(ErrorCode.ConnectUrlErr + url, e);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy