add query by creator

This commit is contained in:
liangping 2023-08-24 15:33:06 +08:00
parent 909fed3aa6
commit 48adbf4395
4 changed files with 39 additions and 4 deletions

View File

@ -27,6 +27,7 @@ export interface WasmRequestRegistry extends AbstractRegistry {
cosmwasm_contract_address_raw_query_data: Request<any>; cosmwasm_contract_address_raw_query_data: Request<any>;
cosmwasm_contract_address_smart_query_data: Request<any>; cosmwasm_contract_address_smart_query_data: Request<any>;
cosmwasm_contract_address_state: Request<PaginabledContractStates>; cosmwasm_contract_address_state: Request<PaginabledContractStates>;
cosmwasm_wasm_contracts_creator: Request<PaginabledContracts>;
} }
export const DEFAULT: WasmRequestRegistry = { export const DEFAULT: WasmRequestRegistry = {
@ -57,6 +58,10 @@ export const DEFAULT: WasmRequestRegistry = {
url: '/cosmwasm/wasm/v1/contract/{address}/state', url: '/cosmwasm/wasm/v1/contract/{address}/state',
adapter, adapter,
}, },
cosmwasm_wasm_contracts_creator: {
url: '/cosmwasm/wasm/v1/contracts/creator/{creator_address}',
adapter,
},
}; };
class WasmRestClient extends BaseRestClient<WasmRequestRegistry> { class WasmRestClient extends BaseRestClient<WasmRequestRegistry> {
@ -79,6 +84,11 @@ class WasmRestClient extends BaseRestClient<WasmRequestRegistry> {
getWasmContracts(address: string) { getWasmContracts(address: string) {
return this.request(this.registry.cosmwasm_contract_address, { address }); 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) { getWasmContractHistory(address: string) {
return this.request(this.registry.cosmwasm_contract_address_history, { return this.request(this.registry.cosmwasm_contract_address_history, {
address, address,

View File

@ -21,9 +21,20 @@ const wasmStore = useWasmStore();
function loadContract(pageNum: number) { function loadContract(pageNum: number) {
const pr = new PageRequest(); const pr = new PageRequest();
pr.setPage(pageNum); pr.setPage(pageNum);
if(String(props.code_id).search(/^[\d]+$/) > -1){
// query with code id
wasmStore.wasmClient.getWasmCodeContracts(props.code_id, pr).then((x) => { wasmStore.wasmClient.getWasmCodeContracts(props.code_id, pr).then((x) => {
response.value = x; response.value = x;
}); })
} else {
// query by creator
wasmStore.wasmClient.getWasmContractsByCreator(props.code_id, pr).then((x) => {
response.value = {
contracts: x.contract_addresses,
pagination: x.pagination,
};
})
}
} }
loadContract(1); loadContract(1);

View File

@ -5,6 +5,7 @@ import { ref } from 'vue';
import type { PaginabledCodeInfos } from './types'; import type { PaginabledCodeInfos } from './types';
import { PageRequest } from '@/types'; import { PageRequest } from '@/types';
import PaginationBar from '@/components/PaginationBar.vue'; import PaginationBar from '@/components/PaginationBar.vue';
import router from '@/router';
const props = defineProps(['chain']); const props = defineProps(['chain']);
@ -13,6 +14,7 @@ const codes = ref({} as PaginabledCodeInfos);
const pageRequest = ref(new PageRequest()) const pageRequest = ref(new PageRequest())
const wasmStore = useWasmStore(); const wasmStore = useWasmStore();
const dialog = useTxDialog() const dialog = useTxDialog()
const creator = ref("")
function pageload(pageNum: number) { function pageload(pageNum: number) {
pageRequest.value.setPage(pageNum) pageRequest.value.setPage(pageNum)
@ -21,10 +23,19 @@ function pageload(pageNum: number) {
}); });
} }
pageload(1) pageload(1)
function myContracts() {
router.push(`/${props.chain}/cosmwasm/${creator.value}/contracts`)
}
</script> </script>
<template> <template>
<div class="bg-base-100 px-4 pt-3 pb-4 rounded mb-4 shadow"> <div class="bg-base-100 px-4 pt-3 pb-4 rounded mb-4 shadow">
<h2 class="card-title truncate w-full">{{ $t('cosmwasm.title') }}</h2> <h2 class="card-title truncate w-full">{{ $t('cosmwasm.title') }}</h2>
<div class="join border border-primary">
<input v-model="creator" type=text class="input input-bordered w-40 join-item" placeholder="creator address" />
<button class="join-item btn btn-primary" @click="myContracts()">{{ $t('cosmwasm.btn_query') }}</button>
</div>
<div class="overflow-x-auto"> <div class="overflow-x-auto">
<table class="table table-compact w-full mt-4 text-sm"> <table class="table table-compact w-full mt-4 text-sm">
<thead> <thead>

View File

@ -65,5 +65,8 @@ export interface PaginabledCodeInfos extends PaginatedResponse {
code_infos: CodeInfo[]; code_infos: CodeInfo[];
} }
export interface PaginabledContracts extends PaginatedResponse { export interface PaginabledContracts extends PaginatedResponse {
contracts: string[]; // return type of cosmwasm_code_id_contracts
contracts?: string[];
// return type of cosmwasm_wasm_contracts_creator
contract_addresses?: string[];
} }