-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix module name in app.go and remove import duplicated file in app.go
- Loading branch information
Showing
35 changed files
with
6,778 additions
and
149 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,4 +18,5 @@ | |
.DS_Store | ||
.vscode/ | ||
test/* | ||
ts-client/* | ||
ts-client/* | ||
vue/node_modules/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,200 @@ | ||
import { Client, registry, MissingWalletError } from 'thesixnetwork-sixnft-client-ts' | ||
|
||
import { BaseAccount } from "thesixnetwork-sixnft-client-ts/cosmos.auth.v1beta1/types" | ||
import { ModuleAccount } from "thesixnetwork-sixnft-client-ts/cosmos.auth.v1beta1/types" | ||
import { Params } from "thesixnetwork-sixnft-client-ts/cosmos.auth.v1beta1/types" | ||
|
||
|
||
export { BaseAccount, ModuleAccount, Params }; | ||
|
||
function initClient(vuexGetters) { | ||
return new Client(vuexGetters['common/env/getEnv'], vuexGetters['common/wallet/signer']) | ||
} | ||
|
||
function mergeResults(value, next_values) { | ||
for (let prop of Object.keys(next_values)) { | ||
if (Array.isArray(next_values[prop])) { | ||
value[prop]=[...value[prop], ...next_values[prop]] | ||
}else{ | ||
value[prop]=next_values[prop] | ||
} | ||
} | ||
return value | ||
} | ||
|
||
type Field = { | ||
name: string; | ||
type: unknown; | ||
} | ||
function getStructure(template) { | ||
let structure: {fields: Field[]} = { fields: [] } | ||
for (const [key, value] of Object.entries(template)) { | ||
let field = { name: key, type: typeof value } | ||
structure.fields.push(field) | ||
} | ||
return structure | ||
} | ||
const getDefaultState = () => { | ||
return { | ||
Accounts: {}, | ||
Account: {}, | ||
Params: {}, | ||
|
||
_Structure: { | ||
BaseAccount: getStructure(BaseAccount.fromPartial({})), | ||
ModuleAccount: getStructure(ModuleAccount.fromPartial({})), | ||
Params: getStructure(Params.fromPartial({})), | ||
|
||
}, | ||
_Registry: registry, | ||
_Subscriptions: new Set(), | ||
} | ||
} | ||
|
||
// initial state | ||
const state = getDefaultState() | ||
|
||
export default { | ||
namespaced: true, | ||
state, | ||
mutations: { | ||
RESET_STATE(state) { | ||
Object.assign(state, getDefaultState()) | ||
}, | ||
QUERY(state, { query, key, value }) { | ||
state[query][JSON.stringify(key)] = value | ||
}, | ||
SUBSCRIBE(state, subscription) { | ||
state._Subscriptions.add(JSON.stringify(subscription)) | ||
}, | ||
UNSUBSCRIBE(state, subscription) { | ||
state._Subscriptions.delete(JSON.stringify(subscription)) | ||
} | ||
}, | ||
getters: { | ||
getAccounts: (state) => (params = { params: {}}) => { | ||
if (!(<any> params).query) { | ||
(<any> params).query=null | ||
} | ||
return state.Accounts[JSON.stringify(params)] ?? {} | ||
}, | ||
getAccount: (state) => (params = { params: {}}) => { | ||
if (!(<any> params).query) { | ||
(<any> params).query=null | ||
} | ||
return state.Account[JSON.stringify(params)] ?? {} | ||
}, | ||
getParams: (state) => (params = { params: {}}) => { | ||
if (!(<any> params).query) { | ||
(<any> params).query=null | ||
} | ||
return state.Params[JSON.stringify(params)] ?? {} | ||
}, | ||
|
||
getTypeStructure: (state) => (type) => { | ||
return state._Structure[type].fields | ||
}, | ||
getRegistry: (state) => { | ||
return state._Registry | ||
} | ||
}, | ||
actions: { | ||
init({ dispatch, rootGetters }) { | ||
console.log('Vuex module: cosmos.auth.v1beta1 initialized!') | ||
if (rootGetters['common/env/client']) { | ||
rootGetters['common/env/client'].on('newblock', () => { | ||
dispatch('StoreUpdate') | ||
}) | ||
} | ||
}, | ||
resetState({ commit }) { | ||
commit('RESET_STATE') | ||
}, | ||
unsubscribe({ commit }, subscription) { | ||
commit('UNSUBSCRIBE', subscription) | ||
}, | ||
async StoreUpdate({ state, dispatch }) { | ||
state._Subscriptions.forEach(async (subscription) => { | ||
try { | ||
const sub=JSON.parse(subscription) | ||
await dispatch(sub.action, sub.payload) | ||
}catch(e) { | ||
throw new Error('Subscriptions: ' + e.message) | ||
} | ||
}) | ||
}, | ||
|
||
|
||
|
||
|
||
|
||
|
||
async QueryAccounts({ commit, rootGetters, getters }, { options: { subscribe, all} = { subscribe:false, all:false}, params, query=null }) { | ||
try { | ||
const key = params ?? {}; | ||
const client = initClient(rootGetters); | ||
let value= (await client.CosmosAuthV1Beta1.query.queryAccounts(query ?? undefined)).data | ||
|
||
|
||
while (all && (<any> value).pagination && (<any> value).pagination.next_key!=null) { | ||
let next_values=(await client.CosmosAuthV1Beta1.query.queryAccounts({...query ?? {}, 'pagination.key':(<any> value).pagination.next_key} as any)).data | ||
value = mergeResults(value, next_values); | ||
} | ||
commit('QUERY', { query: 'Accounts', key: { params: {...key}, query}, value }) | ||
if (subscribe) commit('SUBSCRIBE', { action: 'QueryAccounts', payload: { options: { all }, params: {...key},query }}) | ||
return getters['getAccounts']( { params: {...key}, query}) ?? {} | ||
} catch (e) { | ||
throw new Error('QueryClient:QueryAccounts API Node Unavailable. Could not perform query: ' + e.message) | ||
|
||
} | ||
}, | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
async QueryAccount({ commit, rootGetters, getters }, { options: { subscribe, all} = { subscribe:false, all:false}, params, query=null }) { | ||
try { | ||
const key = params ?? {}; | ||
const client = initClient(rootGetters); | ||
let value= (await client.CosmosAuthV1Beta1.query.queryAccount( key.address)).data | ||
|
||
|
||
commit('QUERY', { query: 'Account', key: { params: {...key}, query}, value }) | ||
if (subscribe) commit('SUBSCRIBE', { action: 'QueryAccount', payload: { options: { all }, params: {...key},query }}) | ||
return getters['getAccount']( { params: {...key}, query}) ?? {} | ||
} catch (e) { | ||
throw new Error('QueryClient:QueryAccount API Node Unavailable. Could not perform query: ' + e.message) | ||
|
||
} | ||
}, | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
async QueryParams({ commit, rootGetters, getters }, { options: { subscribe, all} = { subscribe:false, all:false}, params, query=null }) { | ||
try { | ||
const key = params ?? {}; | ||
const client = initClient(rootGetters); | ||
let value= (await client.CosmosAuthV1Beta1.query.queryParams()).data | ||
|
||
|
||
commit('QUERY', { query: 'Params', key: { params: {...key}, query}, value }) | ||
if (subscribe) commit('SUBSCRIBE', { action: 'QueryParams', payload: { options: { all }, params: {...key},query }}) | ||
return getters['getParams']( { params: {...key}, query}) ?? {} | ||
} catch (e) { | ||
throw new Error('QueryClient:QueryParams API Node Unavailable. Could not perform query: ' + e.message) | ||
|
||
} | ||
}, | ||
|
||
|
||
|
||
|
||
} | ||
} |
Oops, something went wrong.