Commit 2d92d930 authored by Bitcoin Please's avatar Bitcoin Please

Renamed `accounts` to `indicies` to allow for `getAccounts` objects.

parent 82b4e93f
......@@ -13,9 +13,12 @@ const setAssets = (state, _source) => {
/* Retrieve current assets. */
// const assets = state.assets
try {
assets = msgpack.decode(Buffer.from(state.assets, 'hex'))
/* Validate assets. */
if (state.assets) {
assets = msgpack.decode(Buffer.from(state.assets, 'hex'))
}
} catch (err) {
console.error(err)
console.error(err) // eslint-disable-line no-console
assets = state.assets
}
......@@ -24,7 +27,7 @@ const setAssets = (state, _source) => {
...assets,
..._source,
}
console.log('SYSTEM ASSETS (updated):', updated)
// console.log('SYSTEM ASSETS (updated):', updated)
/* Set updated (merged) assets. */
state.assets = msgpack.encode(updated).toString('hex')
......
......@@ -9,6 +9,7 @@ import getDerivationPath from './wallet/getters/getDerivationPath'
import getDustAmount from './wallet/getters/getDustAmount'
import getHDNode from './wallet/getters/getHDNode'
import getHistory from './wallet/getters/getHistory'
import getIndicies from './wallet/getters/getIndicies'
import getMnemonic from './wallet/getters/getMnemonic'
/* Import modules (actions). */
......@@ -20,19 +21,12 @@ import updateCoins from './wallet/actions/updateCoins'
import updateOutbox from './wallet/actions/updateOutbox'
/* Import modules (mutations). */
import setAccounts from './wallet/mutations/setAccounts'
import setCoins from './wallet/mutations/setCoins'
import setEmptyWallet from './wallet/mutations/setEmptyWallet'
import setIndicies from './wallet/mutations/setIndicies'
/* Initialize state. */
const state = {
/**
* Accounts
*
* Manages the index of account addresses.
*/
accounts: null,
/**
* Coins
*
......@@ -54,6 +48,13 @@ const state = {
*/
inbox: null,
/**
* (Account) Indices
*
* Manages the indices of account addresses.
*/
indices: null,
/**
* Outbox
*
......@@ -73,6 +74,7 @@ const getters = {
getDustAmount,
getHDNode,
getHistory,
getIndicies,
getMnemonic,
}
......@@ -88,9 +90,9 @@ const actions = {
/* Mutations. */
const mutations = {
setAccounts,
setCoins,
setEmptyWallet,
setIndicies,
}
/* Export. */
......
......@@ -16,11 +16,11 @@ const addCoin = ({ commit, getters }, _pkg) => {
}
/* Set chain id. */
const chainId = _pkg.chainId
// console.log('ADD NEW COIN (chainid):', chainId)
const chainid = _pkg.chainid
// console.log('ADD NEW COIN (chainid):', chainid)
/* Increment deposit account. */
switch(chainId) {
switch(chainid) {
case 0:
/* Increment deposit index. */
accounts.deposit++
......
......@@ -4,27 +4,6 @@
const initWallet = ({ commit }) => {
console.info('Initializing wallet...') // eslint-disable-line no-console
/**
* Accounts Model
*
* Manages the indexes of account (addresses) and their respective
* derivation paths.
*
* Deposit : m/44'/145'/0'/0/<index>
* Change : m/44'/145'/0'/1/<index>
* Causes Cash : m/44'/145'/0'/6767/<index>
* Nito Cash : m/44'/145'/0'/7867/<index>
*/
const accountsModel = {
deposit: 0,
change: 0,
causes: 0,
nito: 0,
}
/* Commit accounts. */
commit('setAccounts', accountsModel)
/**
* Coins Model
*
......@@ -51,6 +30,27 @@ const initWallet = ({ commit }) => {
/* Commit coins. */
commit('setCoins', coinsModel)
/**
* Indicies Model
*
* Manages the indicies of account (addresses) and their respective
* derivation paths.
*
* Deposit : m/44'/145'/0'/0/<index>
* Change : m/44'/145'/0'/1/<index>
* Causes Cash : m/44'/145'/0'/6767/<index>
* Nito Cash : m/44'/145'/0'/7867/<index>
*/
const indiciesModel = {
deposit: 0,
change: 0,
causes: 0,
nito: 0,
}
/* Commit indicies. */
commit('setIndicies', indiciesModel)
/* Return success. */
return true
}
......
......@@ -160,7 +160,7 @@ const updateCoins = async ({ dispatch, getters, rootGetters }) => {
// console.log('UPDATE COINS (cashAddrs)', cashAddrs)
/* Initialize WIF. */
let chainId = null
let chainid = null
/* Initialize WIF. */
let wif = null
......@@ -169,7 +169,7 @@ const updateCoins = async ({ dispatch, getters, rootGetters }) => {
for (let i = 0; i < accounts.length; i++) {
if (accounts[i].address === searchAddr) {
/* Set chain id. */
chainId = accounts[i].chainId
chainid = accounts[i].chainid
/* Set WIF. */
wif = accounts[i].wif
......@@ -209,7 +209,7 @@ const updateCoins = async ({ dispatch, getters, rootGetters }) => {
/* Create coin package. */
const pkg = {
// sessionId,
chainId,
chainid,
coin,
}
......
......@@ -5,9 +5,9 @@ import Nito from 'nitojs'
/**
* Load (Derivation) Path
*/
const loadPath = (_getters, _accounts, _chainId, _acctIdx) => {
const loadPath = (_getters, _accounts, _chainid, _acctIdx) => {
/* Set derivation path. */
const path = _getters.getDerivationPath(_chainId, _acctIdx)
const path = _getters.getDerivationPath(_chainid, _acctIdx)
// console.log('GET ACCOUNTS (path)', path)
/* Initialize HD node. */
......@@ -26,7 +26,7 @@ const loadPath = (_getters, _accounts, _chainId, _acctIdx) => {
/* Add to all receiving (pool). */
_accounts.push({
acctIdx: _acctIdx,
chainId: _chainId,
chainid: _chainid,
address,
wif,
})
......@@ -41,32 +41,32 @@ const loadPath = (_getters, _accounts, _chainId, _acctIdx) => {
*/
const getAccounts = (state, getters) => {
/* Validate state. */
if (!state || !state.accounts) {
return null
if (!state || !state.indicies) {
throw new Error('Current state is invalid. Missing `wallet.indicies`.')
}
/* Initialize accounts. */
const accounts = []
/* Initialize account indexes. */
const acctIndexes = msgpack.decode(Buffer.from(state.accounts, 'hex'))
/* Initialize account indicies. */
const acctIndexes = msgpack.decode(Buffer.from(state.indicies, 'hex'))
/* Loop through ALL (deposit) indexes (inclusive). */
/* Loop through ALL (deposit) indicies (inclusive). */
for (let i = 0; i <= acctIndexes.deposit; i++) {
loadPath(getters, accounts, 0, i)
}
/* Loop through ALL (change) indexes (inclusive). */
/* Loop through ALL (change) indicies (inclusive). */
for (let i = 0; i <= acctIndexes.change; i++) {
loadPath(getters, accounts, 1, i)
}
/* Loop through ALL (causes) indexes (inclusive). */
/* Loop through ALL (causes) indicies (inclusive). */
for (let i = 0; i <= acctIndexes.causes; i++) {
loadPath(getters, accounts, 6767, i)
}
/* Loop through ALL (nito) indexes (inclusive). */
/* Loop through ALL (nito) indicies (inclusive). */
for (let i = 0; i <= acctIndexes.nito; i++) {
loadPath(getters, accounts, 7867, i)
}
......
......@@ -12,12 +12,12 @@ const getAddress = (state, getters) => (_account) => {
return null
}
/* Request accounts. */
const accounts = getters.getAccounts
// console.log('GET ADDRESS (accounts):', accounts)
/* Request indicies. */
const indicies = getters.getIndicies
// console.log('GET ADDRESS (indicies):', indicies)
/* Initialize current (coin) index. */
const currentIndex = accounts[_account]
const currentIndex = indicies[_account]
// console.log('GET ADDRESS (currentIndex):', currentIndex)
/* Initialize chain. */
......
......@@ -8,9 +8,19 @@
* The `address_index` allows for an unlimited number of addresses to be
* generated for each session.
*/
const getDerivationPath = () => (_chainId, _acctIndex) => {
const getDerivationPath = () => (_chainid, _acctIdx) => {
/* Validate chain id. */
if (!Number.isInteger(_chainid)) {
throw new Error('Invalid chain id.')
}
/* Validate account index. */
if (!Number.isInteger(_acctIdx)) {
throw new Error('Invalid account index.')
}
/* Return (hardened) derivation path. */
return `m/44'/145'/0'/${_chainId}/${_acctIndex}`
return `m/44'/145'/0'/${_chainid}/${_acctIdx}`
}
/* Export module. */
......
/* Import modules. */
import msgpack from 'msgpack-lite'
/**
* Get Indicies
*/
const getIndicies = (state) => {
/* Validate state. */
if (!state || !state.indicies) {
return null
}
/* Initialize indicies. */
const indicies = msgpack.decode(Buffer.from(state.indicies, 'hex'))
/* Return indicies. */
return indicies
}
/* Export module. */
export default getIndicies
......@@ -2,12 +2,12 @@
import msgpack from 'msgpack-lite'
/**
* Set Accounts
* Set Indicies
*/
const setAccounts = (state, _accounts) => {
/* Set accounts. */
state.accounts = msgpack.encode(_accounts).toString('hex')
const setIndicies = (state, _indicies) => {
/* Set indicies. */
state.indicies = msgpack.encode(_indicies).toString('hex')
}
/* Export module. */
export default setAccounts
export default setIndicies
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment