Skip to content

Commit

Permalink
chore(api): use neoscan for all api calls (#228)
Browse files Browse the repository at this point in the history
* chore(api): use neoscan for all api calls

* chore(claim): exctract gas claim into shared function

* chore(balance): use relative path for shared pod file
  • Loading branch information
mhuggins authored Jun 15, 2018
1 parent 922b254 commit ad2550f
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 46 deletions.
21 changes: 2 additions & 19 deletions src/browser/actions/makeClaimActions.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,11 @@
import { createActions } from 'spunky';
import { api } from '@cityofzion/neon-js';

import claimGas from 'shared/util/claimGas';

import generateDAppActionId from './generateDAppActionId';

export const ID = 'claim';

const claimGas = async ({ net, address, wif }) => {
const config = {
net,
address,
privateKey: wif
};

api.setApiSwitch(1);
const { response: { result, txid } } = await api.claimGas(config);
api.setApiSwitch(0); // only temporarily use neonDB for gasClaims

if (!result) {
throw new Error('Claim failed.');
}

return txid;
};

export default function makeClaimActions(sessionId, requestId) {
const id = generateDAppActionId(sessionId, `${ID}-${requestId}`);

Expand Down
2 changes: 1 addition & 1 deletion src/browser/actions/makeStorageActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const getStorage = async ({ net, scriptHash, key, encodeInput, decodeOutput }) =
throw new Error(`Invalid key: "${key}"`);
}

const endpoint = await api.loadBalance(api.getRPCEndpointFrom, { net });
const endpoint = await api.getRPCEndpointFrom({ net }, api.neoscan);
const { result } =
await rpc.Query.getStorage(scriptHash, encodeInput
? u.str2hexstring(key)
Expand Down
2 changes: 1 addition & 1 deletion src/browser/actions/makeTestInvokeActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const testInvoke = async ({ net, scriptHash, operation, args, encodeArgs }) => {
throw new Error(`Invalid arguments: "${args}"`);
}

const endpoint = await api.loadBalance(api.getRPCEndpointFrom, { net });
const endpoint = await api.getRPCEndpointFrom({ net }, api.neoscan);
const script = createScript(scriptHash, operation, args, encodeArgs);
const { result } = await rpc.Query.invokeScript(script).execute(endpoint);

Expand Down
2 changes: 1 addition & 1 deletion src/shared/actions/balancesActions.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createActions } from 'spunky';

import getBalances from 'shared/util/getBalances';
import getBalances from '../util/getBalances';

export const ID = 'balances';

Expand Down
21 changes: 2 additions & 19 deletions src/shared/actions/claimActions.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,8 @@
import { createActions } from 'spunky';
import { api } from '@cityofzion/neon-js';

export const ID = 'claim';

const claimGas = async ({ net, address, wif }) => {
const config = {
net,
address,
privateKey: wif
};

api.setApiSwitch(1);
const { response: { result, txid } } = await api.claimGas(config);
api.setApiSwitch(0); // only temporarily use neonDB for gasClaims
import claimGas from '../util/claimGas';

if (!result) {
throw new Error('Claim failed.');
}

return txid;
};
export const ID = 'claim';

export default createActions(ID, ({ net, address, wif }) => () => {
return claimGas({ net, address, wif });
Expand Down
17 changes: 17 additions & 0 deletions src/shared/util/claimGas.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { api } from '@cityofzion/neon-js';

export default async function claimGas({ net, address, wif }) {
const config = {
net,
address,
privateKey: wif
};

const { response: { result, txid } } = await api.claimGas(config, api.neoscan);

if (!result) {
throw new Error('Claim failed.');
}

return txid;
}
5 changes: 1 addition & 4 deletions src/shared/util/getBalances.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,7 @@ export default async function getBalances({ net, address, tokens }) {

// asset balances
promises.push((async () => {
const assetBalances = await api.loadBalance(api.getBalanceFrom, {
net,
address
});
const assetBalances = await api.getBalanceFrom({ net, address }, api.neoscan);

const { assets } = assetBalances.balance;

Expand Down
2 changes: 1 addition & 1 deletion src/shared/util/sendAsset.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default async function sendAsset({ net, asset, amount, receiver, address,
intents
};

const { response: { result, txid } } = await api.sendAsset(config);
const { response: { result, txid } } = await api.sendAsset(config, api.neoscan);

if (!result) {
throw new Error('Invocation failed.');
Expand Down

0 comments on commit ad2550f

Please sign in to comment.