@bloks/api
Advanced tools
Comparing version 3.5.81 to 3.5.82
{ | ||
"name": "@bloks/api", | ||
"version": "3.5.81", | ||
"version": "3.5.82", | ||
"description": "", | ||
@@ -13,5 +13,6 @@ "publishConfig": { | ||
"dependencies": { | ||
"@bloks/constants": "^3.5.81", | ||
"@bloks/utils": "^3.5.81", | ||
"@bloks/constants": "^3.5.82", | ||
"@bloks/utils": "^3.5.82", | ||
"@eoscafe/hyperion": "^3.2.4", | ||
"@eoscafe/light-api": "^1.0.0", | ||
"@feathersjs/client": "^4.3.1", | ||
@@ -22,3 +23,3 @@ "axios": "^0.19.0", | ||
}, | ||
"gitHead": "9a020438add5e90b991b11621a9da664bf32ed0c" | ||
"gitHead": "658ff5d0e59c32b80afc2e76bf2eea6da51065ff" | ||
} |
125
src/index.js
@@ -25,4 +25,5 @@ import axios from 'axios' | ||
import { Api, JsonRpc, Serialize } from '@jafri/eosjs2' | ||
import { constants } from '@bloks/constants' | ||
import { constants, chainToNetworkConstantsMap } from '@bloks/constants' | ||
import { JsonRpc as HyperionRpc } from '@eoscafe/hyperion' | ||
import { JsonRpc as LightApiRpc } from "@eoscafe/light-api" | ||
@@ -737,50 +738,90 @@ const chainToRexMap = { | ||
async getKeyAccounts (key, sidechain = false) { | ||
if (constants.HISTORY_TYPES.includes('dfuse')) { | ||
try { | ||
const { account_names } = await this.feathers.restApp.service('dfuse').find({ | ||
query: { | ||
type: 'state_key_accounts', | ||
publicKey: key, | ||
options: {} | ||
} | ||
}) | ||
return account_names | ||
} catch (e) { | ||
console.log(e) | ||
console.log('No accounts found associated with key:', key) | ||
return [] | ||
} | ||
} else if (sidechain) { | ||
async dfuseGetKeyAccounts (key, bloksApi = constants.API_URL) { | ||
try { | ||
const { data: { block_num, account_names } } = await axios.get( | ||
`${bloksApi}/dfuse?type=state_key_accounts&publicKey=${key}` | ||
) | ||
} else { | ||
const { account_names } = await this.eosActions.history_get_key_accounts(key) | ||
return account_names | ||
return account_names && account_names.length | ||
? account_names | ||
: [] | ||
} catch (e) { | ||
console.log(e) | ||
console.log('No dfuse accounts found associated with key:', key) | ||
return [] | ||
} | ||
} | ||
async getSidechainKeyAccounts (key) { | ||
if (constants.HISTORY_TYPES.includes('dfuse')) { | ||
try { | ||
const { account_names } = await this.feathers.restApp.service('dfuse').find({ | ||
query: { | ||
type: 'state_key_accounts', | ||
publicKey: key, | ||
options: {} | ||
} | ||
}) | ||
return account_names | ||
} catch (e) { | ||
console.log(e) | ||
console.log('No accounts found associated with key:', key) | ||
async nativeGetKeyAccounts (key, eosActionUrls = constants.ACTIONS_ENDPOINTS) { | ||
try { | ||
const eosActions = new JsonRpc(eosActionUrls, { fetch }) | ||
const { account_names } = await eosActions.history_get_key_accounts(key) | ||
return account_names && account_names.length | ||
? account_names | ||
: [] | ||
} catch (e) { | ||
console.log(e) | ||
console.log('No native accounts found associated with key:', key) | ||
return [] | ||
} | ||
} | ||
async hyperionGetKeyAccounts (key, hyperionUrl = constants.HYPERION_URL) { | ||
try { | ||
const hyperion = new HyperionRpc(hyperionUrl, { fetch }) | ||
const { account_names } = await hyperion.get_key_accounts(key) | ||
return account_names && account_names.length | ||
? account_names | ||
: [] | ||
} catch (e) { | ||
console.log(e) | ||
console.log('No native accounts found associated with key:', key) | ||
return [] | ||
} | ||
} | ||
async lightGetKeyAccounts (key, lightUrl = constants.LIGHT_API) { | ||
try { | ||
const lightApi = new LightApiRpc(lightUrl, { fetch }) | ||
const result = await lightApi.get_key_accounts(key) | ||
console.log(result) | ||
} catch (e) { | ||
console.log(e) | ||
console.log('No native accounts found associated with key:', key) | ||
return [] | ||
} | ||
} | ||
async getKeyAccountsByType (key, type, constants = constants) { | ||
switch (type) { | ||
case 'dfuse': | ||
return await this.dfuseGetKeyAccounts(key, constants.API_URL) | ||
case 'native': | ||
return await this.nativeGetKeyAccounts(key, constants.ACTIONS_ENDPOINTS) | ||
case 'hyperion': | ||
return await this.hyperionGetKeyAccounts(key, constants.HYPERION_URL) | ||
default: | ||
return [] | ||
} | ||
} else if (sidechain) { | ||
} | ||
} | ||
} else { | ||
const { account_names } = await this.eosActions.history_get_key_accounts(key) | ||
return account_names | ||
async getKeyAccounts (key) { | ||
// TODO: TEMP | ||
if (constants.CHAIN === 'telos') { | ||
return await this.hyperionGetKeyAccounts(key) | ||
} | ||
for (const historyType of constants.HISTORY_TYPES) { | ||
return await this.getKeyAccountsByType(key, historyType, constants) | ||
} | ||
return [] | ||
} | ||
async getKeyAccountsForAllChains (key) { | ||
return await this.lightGetKeyAccounts(key, constants.LIGHT_API) | ||
} | ||
async getUsersFromKeys (keys) { | ||
@@ -946,3 +987,3 @@ let users = [] | ||
} = {}) { | ||
let q = query || `(auth:${accountName} OR | ||
let q = query || `(auth:${accountName} OR | ||
receiver:${accountName} OR | ||
@@ -1557,3 +1598,3 @@ data.to:${accountName} OR | ||
}) | ||
return result.rows.length > 0 && result.rows[0].account_name === account | ||
@@ -1560,0 +1601,0 @@ ? result.rows[0] |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
97306
1662
8
7
+ Added@eoscafe/light-api@^1.0.0
+ Added@eoscafe/light-api@1.0.0(transitive)
Updated@bloks/constants@^3.5.82
Updated@bloks/utils@^3.5.82