export function serverHttp(host) {
this.host = host;
- this.request = function(path, body, net) {
+ this.request = function(path, body, net, method) {
var config = {
url: `${this.host[net]}${basePath}${path}`,
- method: 'POST',
+ method: method ? method : 'POST' ,
headers: {
Accept: 'application/json',
},
import accountsSDK from './sdk/accounts.js';
import transactionSDK from './sdk/transaction.js';
import walletSDK from './sdk/wallet.js';
+import querySDK from './sdk/query.js';
import {serverHttp, http} from './http.js';
function Bytom(serverHost, wasmPath, baseURL, token) {
this.sdk.accounts = new accountsSDK(this);
this.sdk.transaction = new transactionSDK(this);
this.sdk.wallet = new walletSDK(this);
+ this.sdk.query = new querySDK(this);
}
--- /dev/null
+import { handleAxiosError } from '../utils/http';
+
+function querySDK(bytom) {
+ this.bytom =bytom;
+ this.http = bytom.serverHttp;
+}
+/**
+ * Query the price of an asset on a given blockchain. asset_id is a hexdecimal string.
+ *
+ * @param {String} asset_id
+ */
+querySDK.prototype.asset = function(asset_id) {
+ let net = this.bytom.net;
+ let retPromise = new Promise((resolve, reject) => {
+ this.http.request('q/asset?asset_id=' + asset_id, null, net, 'GET').then(resp => {
+ resolve(resp.data);
+ }).catch(err => {
+ reject(handleAxiosError(err));
+ });
+ });
+ return retPromise;
+};
+
+/**
+ * Query the current height of a blockchain.
+ */
+querySDK.prototype.getblockcount = function() {
+ let net = this.bytom.net;
+ let retPromise = new Promise((resolve, reject) => {
+ this.http.request('q/getblockcount', null, net, 'GET').then(resp => {
+ resolve(resp.data);
+ }).catch(err => {
+ reject(handleAxiosError(err));
+ });
+ });
+ return retPromise;
+};
+
+export default querySDK;
\ No newline at end of file