diff --git a/src/store/index.js b/src/store/index.js index 5ddded1..38db0bb 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -1,10 +1,8 @@ import { createStore } from 'vuex' import util from '@/store/modules/util' -import stark from '@/store/modules/stark' export default createStore({ modules: { util, - stark, }, }) diff --git a/src/store/modules/stark.js b/src/store/modules/stark.js deleted file mode 100644 index 8fe30dd..0000000 --- a/src/store/modules/stark.js +++ /dev/null @@ -1,107 +0,0 @@ -import { ec, defaultProvider, Provider, stark, encode } from 'starknet' -import utils from '@/utils' - -const state = { - privateKey: '', - publicKeyX: '', - publicKeyY: '', - txStatus: '', - txSuccess: false, - outputs: [], -} - -const getters = { - privateKey: (state) => state.privateKey, - publicKeyX: (state) => state.publicKeyX, - publicKeyY: (state) => state.publicKeyY, - txStatus: (state) => state.txStatus, - txSuccess: (state) => state.txSuccess, - outputs: (state) => state.outputs, -} - -const actions = { - async checkTx({ commit }, data) { - let stat - let sty = false - if (data.is_testnet) { - stat = await defaultProvider.getTransactionStatus(data.txHash) - } else { - const prov = new Provider({ network: 'mainnet-alpha' }) - stat = await prov.getTransactionStatus(data.txHash) - } - if ( - stat.tx_status === 'ACCEPTED_ON_L1' || - stat.tx_status === 'ACCEPTED_ON_L2' || - stat.tx_status === 'RECIEVED' - ) { - sty = true - } - commit('setTxStatus', stat.tx_status) - commit('setTxSuccess', sty) - }, - async callContract({ commit }, data) { - let cd = { - contract_address: data.contract, - entry_point_selector: stark.getSelectorFromName(data.entry), - } - - const inArr = data.inputs.split(',').filter((elem) => { - const tElem = utils.toBN(elem) - if (tElem !== '') { - return tElem - } - }) - if (inArr.length > 0) { - cd.calldata = inArr - } - if (data.is_testnet) { - let stat = await defaultProvider.callContract(cd) - if (stat.result) { - commit('setCallOutput', stat.result) - } - } else { - const prov = new Provider({ network: 'mainnet-alpha' }) - let stat = await prov.callContract(cd) - if (stat.result) { - commit('setCallOutput', stat.result) - } - } - }, - getStarkKey({ commit }) { - const privatekey = `0x${encode.buf2hex( - ec.starkCurve.utils.randomPrivateKey() - )}` - - commit('setPrivateKey', privatekey) - commit('setPubX', ec.starkCurve.getStarkKey(privatekey)) - }, -} - -const mutations = { - setPrivateKey(state, priv) { - state.privateKey = priv - }, - setPubX(state, pubX) { - state.publicKeyX = pubX - }, - setPubY(state, pubY) { - state.publicKeyY = pubY - }, - setTxStatus(state, stat) { - state.txStatus = stat - }, - setTxSuccess(state, style) { - state.txSuccess = style - }, - setCallOutput(state, co) { - state.outputs = co - }, -} - -export default { - namespaced: true, - state, - getters, - actions, - mutations, -} diff --git a/src/store/modules/util.js b/src/store/modules/util.js index 14b0cbd..92c8221 100644 --- a/src/store/modules/util.js +++ b/src/store/modules/util.js @@ -1,7 +1,3 @@ -// import { getStarknet } from "@argent/get-starknet"; -// import { stark } from "starknet"; -// const getSelectorFromName = stark.getSelectorFromName; - const state = { utilPane: 1, } diff --git a/src/utils/index.js b/src/utils/index.js index 36051c1..1209550 100644 --- a/src/utils/index.js +++ b/src/utils/index.js @@ -1,5 +1,5 @@ import BN from 'bn.js' -import { hash } from 'starknet' +import { hash, byteArray, CallData } from 'starknet' function asciiToHex(str) { let arr1 = ['0x'] @@ -17,6 +17,13 @@ function toSelector(val) { return toBN(hash.getSelectorFromName(val)) } +function toByteArray(val) { + if (!val) { + return '' + } + return CallData.compile(byteArray.byteArrayFromString(val)).toString() +} + function toBN(val) { if (!val) { return '' @@ -113,6 +120,7 @@ export default { toBig3, isDecimal, toHex, + toByteArray, toSelector, startWith0xAndIsHex, } diff --git a/src/views/Converter.vue b/src/views/Converter.vue index d17996b..21ce8d0 100644 --- a/src/views/Converter.vue +++ b/src/views/Converter.vue @@ -20,6 +20,10 @@ :dataBag="feltArrayComp" title="felt array:" /> +