forked from cerc-io/cosmos-explorer
move wasm client out of wasm store
This commit is contained in:
parent
f91b26abba
commit
180e4b9f2b
30
chains/mainnet/neutron.json
Normal file
30
chains/mainnet/neutron.json
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
{
|
||||||
|
"chain_name": "neutron",
|
||||||
|
"api": [
|
||||||
|
{"provider": "Polkachu", "address": "https://neutron-api.polkachu.com"},
|
||||||
|
{"provider": "NodeStake", "address": "https://api.neutron.nodestake.top"},
|
||||||
|
{"provider": "Allnodes", "address": "https://neutron-rest.publicnode.com"}
|
||||||
|
],
|
||||||
|
"rpc": [
|
||||||
|
{"provider": "Polkachu", "address": "https://neutron-rpc.polkachu.com"},
|
||||||
|
{"provider": "NodeStake", "address": "https://rpc.neutron.nodestake.top"},
|
||||||
|
{"provider": "Allnodes", "address": "https://neutron-rpc.publicnode.com:443"}
|
||||||
|
],
|
||||||
|
"provider_chain": {
|
||||||
|
"api": ["https://api-cosmoshub-ia.cosmosia.notional.ventures"]
|
||||||
|
},
|
||||||
|
"features": ["dashboard", "blocks", "ibc", "cosmwasm", "uptime", "parameters", "state-sync", "consensus", "supply", "widget"],
|
||||||
|
"sdk_version": "0.45.1",
|
||||||
|
"coin_type": "118",
|
||||||
|
"min_tx_fee": "8000",
|
||||||
|
"assets": [{
|
||||||
|
"base": "untrn",
|
||||||
|
"symbol": "NTRN",
|
||||||
|
"exponent": "6",
|
||||||
|
"coingecko_id": "neutron",
|
||||||
|
"logo": "/logos/neutron.svg"
|
||||||
|
}],
|
||||||
|
"addr_prefix": "neutron",
|
||||||
|
"theme_color": "#161723",
|
||||||
|
"logo": "/logos/neutron.svg"
|
||||||
|
}
|
119
src/modules/[chain]/cosmwasm/WasmClient.ts
Normal file
119
src/modules/[chain]/cosmwasm/WasmClient.ts
Normal file
@ -0,0 +1,119 @@
|
|||||||
|
import { BaseRestClient } from '@/libs/client';
|
||||||
|
import { adapter, type AbstractRegistry, type Request } from '@/libs/registry';
|
||||||
|
import { defineStore } from 'pinia';
|
||||||
|
import type {
|
||||||
|
CodeInfo,
|
||||||
|
ContractInfo,
|
||||||
|
PaginabledCodeInfos,
|
||||||
|
PaginabledContractHistory,
|
||||||
|
PaginabledContracts,
|
||||||
|
PaginabledContractStates,
|
||||||
|
WasmParam,
|
||||||
|
} from './types';
|
||||||
|
import { toBase64 } from '@cosmjs/encoding';
|
||||||
|
import { useBlockchain } from '@/stores';
|
||||||
|
import { PageRequest } from '@/types';
|
||||||
|
|
||||||
|
export interface WasmRequestRegistry extends AbstractRegistry {
|
||||||
|
cosmwasm_code: Request<PaginabledCodeInfos>;
|
||||||
|
cosmwasm_code_id: Request<CodeInfo>;
|
||||||
|
cosmwasm_code_id_contracts: Request<PaginabledContracts>;
|
||||||
|
cosmwasm_param: Request<WasmParam>;
|
||||||
|
cosmwasm_contract_address: Request<{
|
||||||
|
address: string;
|
||||||
|
contract_info: ContractInfo;
|
||||||
|
}>;
|
||||||
|
cosmwasm_contract_address_history: Request<PaginabledContractHistory>;
|
||||||
|
cosmwasm_contract_address_raw_query_data: Request<any>;
|
||||||
|
cosmwasm_contract_address_smart_query_data: Request<any>;
|
||||||
|
cosmwasm_contract_address_state: Request<PaginabledContractStates>;
|
||||||
|
cosmwasm_wasm_contracts_creator: Request<PaginabledContracts>;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const DEFAULT_VERSION: WasmRequestRegistry = {
|
||||||
|
cosmwasm_code: { url: '/cosmwasm/wasm/v1/code', adapter },
|
||||||
|
cosmwasm_code_id: { url: '/cosmwasm/wasm/v1/code/{code_id}', adapter },
|
||||||
|
cosmwasm_code_id_contracts: {
|
||||||
|
url: '/cosmwasm/wasm/v1/code/{code_id}/contracts',
|
||||||
|
adapter,
|
||||||
|
},
|
||||||
|
cosmwasm_param: { url: '/cosmwasm/wasm/v1/codes/params', adapter },
|
||||||
|
cosmwasm_contract_address: {
|
||||||
|
url: '/cosmwasm/wasm/v1/contract/{address}',
|
||||||
|
adapter,
|
||||||
|
},
|
||||||
|
cosmwasm_contract_address_history: {
|
||||||
|
url: '/cosmwasm/wasm/v1/contract/{address}/history',
|
||||||
|
adapter,
|
||||||
|
},
|
||||||
|
cosmwasm_contract_address_raw_query_data: {
|
||||||
|
url: '/cosmwasm/wasm/v1/contract/{address}/raw/{query_data}',
|
||||||
|
adapter,
|
||||||
|
},
|
||||||
|
cosmwasm_contract_address_smart_query_data: {
|
||||||
|
url: '/cosmwasm/wasm/v1/contract/{address}/smart/{query_data}',
|
||||||
|
adapter,
|
||||||
|
},
|
||||||
|
cosmwasm_contract_address_state: {
|
||||||
|
url: '/cosmwasm/wasm/v1/contract/{address}/state',
|
||||||
|
adapter,
|
||||||
|
},
|
||||||
|
cosmwasm_wasm_contracts_creator: {
|
||||||
|
url: '/cosmwasm/wasm/v1/contracts/creator/{creator_address}',
|
||||||
|
adapter,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export class WasmRestClient extends BaseRestClient<WasmRequestRegistry> {
|
||||||
|
getWasmCodeList(pr?: PageRequest) {
|
||||||
|
if(!pr) pr = new PageRequest()
|
||||||
|
const query = `?${pr.toQueryString()}`
|
||||||
|
return this.request(this.registry.cosmwasm_code, {}, query);
|
||||||
|
}
|
||||||
|
getWasmCodeById(code_id: string) {
|
||||||
|
return this.request(this.registry.cosmwasm_code, { code_id }); // `code_id` is a param in above url
|
||||||
|
}
|
||||||
|
getWasmCodeContracts(code_id: string, page?: PageRequest) {
|
||||||
|
if(!page) page = new PageRequest()
|
||||||
|
const query = `?${page.toQueryString()}`
|
||||||
|
return this.request(this.registry.cosmwasm_code_id_contracts, { code_id }, query);
|
||||||
|
}
|
||||||
|
getWasmParams() {
|
||||||
|
return this.request(this.registry.cosmwasm_param, {});
|
||||||
|
}
|
||||||
|
getWasmContracts(address: string) {
|
||||||
|
return this.request(this.registry.cosmwasm_contract_address, { address });
|
||||||
|
}
|
||||||
|
getWasmContractsByCreator(creator_address: string, page?: PageRequest) {
|
||||||
|
if(!page) page = new PageRequest()
|
||||||
|
const query = `?${page.toQueryString()}`
|
||||||
|
return this.request(this.registry.cosmwasm_wasm_contracts_creator, { creator_address }, query);
|
||||||
|
}
|
||||||
|
getWasmContractHistory(address: string) {
|
||||||
|
return this.request(this.registry.cosmwasm_contract_address_history, {
|
||||||
|
address,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
getWasmContractRawQuery(address: string, query: string) {
|
||||||
|
const query_data = toBase64(new TextEncoder().encode(query));
|
||||||
|
return this.request(
|
||||||
|
this.registry.cosmwasm_contract_address_raw_query_data,
|
||||||
|
{ address, query_data }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
getWasmContractSmartQuery(address: string, query: string) {
|
||||||
|
const query_data = toBase64(new TextEncoder().encode(query));
|
||||||
|
return this.request(
|
||||||
|
this.registry.cosmwasm_contract_address_smart_query_data,
|
||||||
|
{ address, query_data }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
getWasmContractStates(address: string, pr: PageRequest) {
|
||||||
|
if(!pr) pr = new PageRequest()
|
||||||
|
const query = `?${pr.toQueryString()}`
|
||||||
|
return this.request(this.registry.cosmwasm_contract_address_state, {
|
||||||
|
address,
|
||||||
|
}, query);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,121 +1,7 @@
|
|||||||
import { BaseRestClient } from '@/libs/client';
|
|
||||||
import { adapter, type AbstractRegistry, type Request } from '@/libs/registry';
|
|
||||||
import { defineStore } from 'pinia';
|
import { defineStore } from 'pinia';
|
||||||
import type {
|
|
||||||
CodeInfo,
|
|
||||||
ContractInfo,
|
|
||||||
PaginabledCodeInfos,
|
|
||||||
PaginabledContractHistory,
|
|
||||||
PaginabledContracts,
|
|
||||||
PaginabledContractStates,
|
|
||||||
WasmParam,
|
|
||||||
} from './types';
|
|
||||||
import { toBase64 } from '@cosmjs/encoding';
|
|
||||||
import { useBlockchain } from '@/stores';
|
import { useBlockchain } from '@/stores';
|
||||||
import { PageRequest } from '@/types';
|
import { DEFAULT_VERSION, WasmRestClient } from './WasmClient';
|
||||||
|
import { get, post } from '@/libs';
|
||||||
export interface WasmRequestRegistry extends AbstractRegistry {
|
|
||||||
cosmwasm_code: Request<PaginabledCodeInfos>;
|
|
||||||
cosmwasm_code_id: Request<CodeInfo>;
|
|
||||||
cosmwasm_code_id_contracts: Request<PaginabledContracts>;
|
|
||||||
cosmwasm_param: Request<WasmParam>;
|
|
||||||
cosmwasm_contract_address: Request<{
|
|
||||||
address: string;
|
|
||||||
contract_info: ContractInfo;
|
|
||||||
}>;
|
|
||||||
cosmwasm_contract_address_history: Request<PaginabledContractHistory>;
|
|
||||||
cosmwasm_contract_address_raw_query_data: Request<any>;
|
|
||||||
cosmwasm_contract_address_smart_query_data: Request<any>;
|
|
||||||
cosmwasm_contract_address_state: Request<PaginabledContractStates>;
|
|
||||||
cosmwasm_wasm_contracts_creator: Request<PaginabledContracts>;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const DEFAULT: WasmRequestRegistry = {
|
|
||||||
cosmwasm_code: { url: '/cosmwasm/wasm/v1/code', adapter },
|
|
||||||
cosmwasm_code_id: { url: '/cosmwasm/wasm/v1/code/{code_id}', adapter },
|
|
||||||
cosmwasm_code_id_contracts: {
|
|
||||||
url: '/cosmwasm/wasm/v1/code/{code_id}/contracts',
|
|
||||||
adapter,
|
|
||||||
},
|
|
||||||
cosmwasm_param: { url: '/cosmwasm/wasm/v1/codes/params', adapter },
|
|
||||||
cosmwasm_contract_address: {
|
|
||||||
url: '/cosmwasm/wasm/v1/contract/{address}',
|
|
||||||
adapter,
|
|
||||||
},
|
|
||||||
cosmwasm_contract_address_history: {
|
|
||||||
url: '/cosmwasm/wasm/v1/contract/{address}/history',
|
|
||||||
adapter,
|
|
||||||
},
|
|
||||||
cosmwasm_contract_address_raw_query_data: {
|
|
||||||
url: '/cosmwasm/wasm/v1/contract/{address}/raw/{query_data}',
|
|
||||||
adapter,
|
|
||||||
},
|
|
||||||
cosmwasm_contract_address_smart_query_data: {
|
|
||||||
url: '/cosmwasm/wasm/v1/contract/{address}/smart/{query_data}',
|
|
||||||
adapter,
|
|
||||||
},
|
|
||||||
cosmwasm_contract_address_state: {
|
|
||||||
url: '/cosmwasm/wasm/v1/contract/{address}/state',
|
|
||||||
adapter,
|
|
||||||
},
|
|
||||||
cosmwasm_wasm_contracts_creator: {
|
|
||||||
url: '/cosmwasm/wasm/v1/contracts/creator/{creator_address}',
|
|
||||||
adapter,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
class WasmRestClient extends BaseRestClient<WasmRequestRegistry> {
|
|
||||||
getWasmCodeList(pr?: PageRequest) {
|
|
||||||
if(!pr) pr = new PageRequest()
|
|
||||||
const query = `?${pr.toQueryString()}`
|
|
||||||
return this.request(this.registry.cosmwasm_code, {}, query);
|
|
||||||
}
|
|
||||||
getWasmCodeById(code_id: string) {
|
|
||||||
return this.request(this.registry.cosmwasm_code, { code_id }); // `code_id` is a param in above url
|
|
||||||
}
|
|
||||||
getWasmCodeContracts(code_id: string, page?: PageRequest) {
|
|
||||||
if(!page) page = new PageRequest()
|
|
||||||
const query = `?${page.toQueryString()}`
|
|
||||||
return this.request(this.registry.cosmwasm_code_id_contracts, { code_id }, query);
|
|
||||||
}
|
|
||||||
getWasmParams() {
|
|
||||||
return this.request(this.registry.cosmwasm_param, {});
|
|
||||||
}
|
|
||||||
getWasmContracts(address: string) {
|
|
||||||
return this.request(this.registry.cosmwasm_contract_address, { address });
|
|
||||||
}
|
|
||||||
getWasmContractsByCreator(creator_address: string, page?: PageRequest) {
|
|
||||||
if(!page) page = new PageRequest()
|
|
||||||
const query = `?${page.toQueryString()}`
|
|
||||||
return this.request(this.registry.cosmwasm_wasm_contracts_creator, { creator_address }, query);
|
|
||||||
}
|
|
||||||
getWasmContractHistory(address: string) {
|
|
||||||
return this.request(this.registry.cosmwasm_contract_address_history, {
|
|
||||||
address,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
getWasmContractRawQuery(address: string, query: string) {
|
|
||||||
const query_data = toBase64(new TextEncoder().encode(query));
|
|
||||||
return this.request(
|
|
||||||
this.registry.cosmwasm_contract_address_raw_query_data,
|
|
||||||
{ address, query_data }
|
|
||||||
);
|
|
||||||
}
|
|
||||||
getWasmContractSmartQuery(address: string, query: string) {
|
|
||||||
const query_data = toBase64(new TextEncoder().encode(query));
|
|
||||||
return this.request(
|
|
||||||
this.registry.cosmwasm_contract_address_smart_query_data,
|
|
||||||
{ address, query_data }
|
|
||||||
);
|
|
||||||
}
|
|
||||||
getWasmContractStates(address: string, pr: PageRequest) {
|
|
||||||
if(!pr) pr = new PageRequest()
|
|
||||||
const query = `?${pr.toQueryString()}`
|
|
||||||
return this.request(this.registry.cosmwasm_contract_address_state, {
|
|
||||||
address,
|
|
||||||
}, query);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export const useWasmStore = defineStore('module-wasm', {
|
export const useWasmStore = defineStore('module-wasm', {
|
||||||
state: () => {
|
state: () => {
|
||||||
@ -124,7 +10,15 @@ export const useWasmStore = defineStore('module-wasm', {
|
|||||||
getters: {
|
getters: {
|
||||||
wasmClient() {
|
wasmClient() {
|
||||||
const blockchain = useBlockchain();
|
const blockchain = useBlockchain();
|
||||||
return new WasmRestClient(blockchain.endpoint.address, DEFAULT);
|
return new WasmRestClient(blockchain.endpoint.address, DEFAULT_VERSION);
|
||||||
},
|
},
|
||||||
|
// fetchVerification() {
|
||||||
|
// get("https://prod.neutron.compiler.welldonestudio.io/neutron-deploy-histories/pion-1?contract=neutron1gesll6lepas7xzt22pg7r07v9vd652md82z8m2fqp5zt43rznu5sl42s74")
|
||||||
|
// },
|
||||||
|
// requestVerification() {
|
||||||
|
// post("https://prod.neutron.compiler.welldonestudio.io/verification/neutron", {"contractAddress": address, "chainId": baseStore.latest?.block.header.chain_id}).then(res => {
|
||||||
|
// console.log("verification:", res)
|
||||||
|
// })
|
||||||
|
// }
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
@ -43,9 +43,7 @@ onMounted(() => {
|
|||||||
chainStore.rpc.getTxs("?order_by=2&events=execute._contract_address='{address}'", { address }, page.value).then(res => {
|
chainStore.rpc.getTxs("?order_by=2&events=execute._contract_address='{address}'", { address }, page.value).then(res => {
|
||||||
txs.value = res
|
txs.value = res
|
||||||
})
|
})
|
||||||
post("https://prod.neutron.compiler.welldonestudio.io/verification/neutron", {"contractAddress": address, "chainId": baseStore.latest?.block.header.chain_id}).then(res => {
|
|
||||||
console.log("verification:", res)
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
|
|
||||||
function pageload(pageNum: number) {
|
function pageload(pageNum: number) {
|
||||||
|
Loading…
Reference in New Issue
Block a user