Skip to content

Commit

Permalink
feat: support chrome v3
Browse files Browse the repository at this point in the history
  • Loading branch information
veryhappyok committed Mar 26, 2024
1 parent 7020d5a commit 5aaed60
Show file tree
Hide file tree
Showing 7 changed files with 106 additions and 61 deletions.
21 changes: 18 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ontology-ts-sdk",
"version": "2.0.1",
"version": "2.0.2",
"description": "Comprehensive TypeScript library for the Ontology blockchain.",
"main": "./lib/index.js",
"types": "./lib/types/index.d.ts",
Expand Down Expand Up @@ -76,7 +76,8 @@
"@ont-community/html5-websocket": "^2.0.2",
"@ont-dev/hdkey-secp256r1": "^1.1.2",
"@ont-dev/sm.js": "^0.1.7",
"axios": "^0.19.0",
"@vespaiach/axios-fetch-adapter": "^0.3.1",
"axios": "^0.19.2",
"babel-polyfill": "^6.26.0",
"base-58": "^0.0.1",
"base64-url": "^2.2.0",
Expand Down
65 changes: 39 additions & 26 deletions src/network/rest/restClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ import { ERROR_CODE } from './../../error';
* along with The ontology. If not, see <http://www.gnu.org/licenses/>.
*/

import axios from 'axios';
import axios, { AxiosRequestConfig } from 'axios';
import fetchAdapter from "@vespaiach/axios-fetch-adapter";
import { TEST_ONT_URL } from '../../consts';
import { Address } from '../../crypto/address';
import UrlConsts from './urlConsts';
Expand All @@ -31,6 +32,8 @@ export default class RestClient {
*/
url: string;

config: undefined | AxiosRequestConfig;

/**
* Version of restful api
*/
Expand All @@ -41,8 +44,9 @@ export default class RestClient {
*/
action: string = 'sendrawtransaction';

constructor(url ?: string) {
constructor(url ?: string, useFetch?: boolean) {
this.url = url || TEST_ONT_URL.REST_URL;
this.config = useFetch ? { adapter: fetchAdapter } : undefined;
if (this.url[this.url.length - 1] === '/') {
this.url = this.url.substring(0, this.url.length - 1);
}
Expand Down Expand Up @@ -102,7 +106,7 @@ export default class RestClient {
Data : hexData
};

return axios.post(url, body).then((res) => {
return axios.post(url, body, this.config).then((res) => {
return res.data;
});
}
Expand All @@ -129,7 +133,8 @@ export default class RestClient {
param.set('raw', '1');
let url = this.url + UrlConsts.Url_get_transaction + txHash;
url += this.concatParams(param);
return axios.get(url).then((res) => {

return axios.get(url, this.config).then((res) => {
return res.data;
});
}
Expand All @@ -144,7 +149,8 @@ export default class RestClient {
param.set('raw', '0');
let url = this.url + UrlConsts.Url_get_transaction + txHash;
url += this.concatParams(param);
return axios.get(url).then((res) => {

return axios.get(url, this.config).then((res) => {
return res.data;
});
}
Expand All @@ -165,7 +171,8 @@ export default class RestClient {
*/
getNodeCount(): Promise<any> {
const url = this.url + UrlConsts.Url_get_node_count;
return axios.get(url).then((res) => {

return axios.get(url, this.config).then((res) => {
return res.data;
});
}
Expand All @@ -175,7 +182,8 @@ export default class RestClient {
*/
getBlockHeight(): Promise<any> {
const url = this.url + UrlConsts.Url_get_block_height;
return axios.get(url).then((res) => {

return axios.get(url, this.config).then((res) => {
return res.data;
});
}
Expand All @@ -196,7 +204,7 @@ export default class RestClient {
}
url += this.concatParams(params);

return axios.get(url).then((res) => {
return axios.get(url, this.config).then((res) => {
return res.data;
});
}
Expand All @@ -213,7 +221,7 @@ export default class RestClient {
url += this.concatParams(params);

// console.log('url: '+url);
return axios.get(url).then((res) => {
return axios.get(url, this.config).then((res) => {
return res.data;
});
}
Expand All @@ -227,7 +235,8 @@ export default class RestClient {
params.set('raw', '0');
let url = this.url + UrlConsts.Url_get_contract_state + codeHash;
url += this.concatParams(params);
return axios.get(url).then((res) => {

return axios.get(url, this.config).then((res) => {
return res.data;
});
}
Expand All @@ -245,7 +254,8 @@ export default class RestClient {
} else if (typeof value === 'number') {
url = this.url + UrlConsts.Url_get_smartcodeevent_txs_by_height + value;
}
return axios.get(url).then((res) => {

return axios.get(url, this.config).then((res) => {
return res.data;
});
}
Expand All @@ -256,7 +266,8 @@ export default class RestClient {
*/
getBlockHeightByTxHash(hash: string): Promise<any> {
const url = this.url + UrlConsts.Url_get_block_height_by_txhash + hash;
return axios.get(url).then((res) => {

return axios.get(url, this.config).then((res) => {
return res.data;
});
}
Expand All @@ -268,7 +279,8 @@ export default class RestClient {
*/
getStorage(codeHash: string, key: string): Promise<any> {
const url = this.url + UrlConsts.Url_get_storage + codeHash + '/' + key;
return axios.get(url).then((res) => {

return axios.get(url, this.config).then((res) => {
return res.data;
});
}
Expand All @@ -283,7 +295,7 @@ export default class RestClient {
// tslint:disable-next-line:no-console
// console.log('url: ' + url);

return axios.get(url).then((res) => {
return axios.get(url, this.config).then((res) => {
return res.data;
});
}
Expand All @@ -295,7 +307,8 @@ export default class RestClient {
*/
getBalance(address: Address): Promise<any> {
const url = this.url + UrlConsts.Url_get_account_balance + address.toBase58();
return axios.get(url).then((res) => {

return axios.get(url, this.config).then((res) => {
return res.data;
});
}
Expand All @@ -307,7 +320,7 @@ export default class RestClient {
*/
getBalanceV2(address: Address): Promise<any> {
const url = this.url + UrlConsts.Url_get_account_balance_v2 + address.toBase58();
return axios.get(url).then((res) => {
return axios.get(url, this.config).then((res) => {
return res.data;
});
}
Expand All @@ -324,7 +337,7 @@ export default class RestClient {
url = this.url + UrlConsts.Url_get_block_by_hash + value;
}

return axios.get(url).then((res) => {
return axios.get(url, this.config).then((res) => {
return res.data;
});
}
Expand All @@ -342,7 +355,7 @@ export default class RestClient {
}
const url = this.url + UrlConsts.Url_get_allowance +
asset.toLowerCase() + '/' + from.toBase58() + '/' + to.toBase58();
return axios.get(url).then((res) => {
return axios.get(url, this.config).then((res) => {
return res.data;
});
}
Expand All @@ -360,56 +373,56 @@ export default class RestClient {
}
const url = this.url + UrlConsts.Url_get_allowance_v2 +
asset.toLowerCase() + '/' + from.toBase58() + '/' + to.toBase58();
return axios.get(url).then((res) => {
return axios.get(url, this.config).then((res) => {
return res.data;
});
}

getUnboundOng(address: Address): Promise<any> {
const url = this.url + UrlConsts.Url_get_unbound_ong + address.toBase58();
return axios.get(url).then((res) => {
return axios.get(url, this.config).then((res) => {
return res.data;
});
}

getBlockTxsByHeight(height: number): Promise<any> {
const url = this.url + UrlConsts.Url_get_block_txs_by_height + height;
return axios.get(url).then((res) => {
return axios.get(url, this.config).then((res) => {
return res.data;
});
}

getGasPrice(): Promise<any> {
const url = this.url + UrlConsts.Url_get_gasprice ;
return axios.get(url).then((res) => {
return axios.get(url, this.config).then((res) => {
return res.data;
});
}

getGrantOng(address: Address): Promise<any> {
const url = this.url + UrlConsts.Url_get_grant_ong + address.toBase58();
return axios.get(url).then((res) => {
return axios.get(url, this.config).then((res) => {
return res.data;
});
}

getMempoolTxCount(): Promise<any> {
const url = this.url + UrlConsts.Url_get_mempool_txcount;
return axios.get(url).then((res) => {
return axios.get(url, this.config).then((res) => {
return res.data;
});
}

getMempoolTxState(hash: string): Promise<any> {
const url = this.url + UrlConsts.Url_get_mempool_txstate + hash;
return axios.get(url).then((res) => {
return axios.get(url, this.config).then((res) => {
return res.data;
});
}

getVersion(): Promise<any> {
const url = this.url + UrlConsts.Url_get_version;
return axios.get(url).then((res) => {
return axios.get(url, this.config).then((res) => {
return res.data;
});
}
Expand Down
Loading

0 comments on commit 5aaed60

Please sign in to comment.