Skip to content
Permalink
Browse files

[DEVOPS-1195] Integrate query-balance endpoint

  • Loading branch information...
nikolaglumac committed Mar 13, 2019
1 parent 7ed5028 commit 1dcd33a02d1d37aef89dca5ddf91c6fdd60e3a89
@@ -1,6 +1,6 @@
{
"url": "https://github.com/input-output-hk/cardano-sl",
"rev": "b4be5cf965d8563e98f4e2f1c75b37a332f9d742",
"sha256": "13hj7a5l6k25a9inwybsgpfp0d2nn8l87278bfljjmhsvkijll9v",
"rev": "5a00ac5e84a432c71829bad89ddac12ce84262c9",
"sha256": "0l7ifcssx13ddwsrn12v40km54b65xgb48cy3y0y6934qaf645r0",
"fetchSubmodules": false
}
@@ -80,19 +80,9 @@ export type ExtractWalletsMainResponse = ExtractedWallets;
/**
* Channel for generating wallet key file
*/
export const GenerateKeyFileChannelName = 'GenerateKeyFileChannel';
export type GenerateKeyFileRendererRequest = {
wallet: ExtractedWallet,
filePath?: string,
};
export type GenerateKeyFileMainResponse = string;

/**
* Channel for deleting wallet key file
*/
export const DeleteKeyFileChannelName = 'DeleteKeyFileChannel';
export type DeleteKeyFileRendererRequest = { filePath: string };
export type DeleteKeyFileMainResponse = void;
export const GenerateRawSecretChannelName = 'GenerateRawSecretChannel';
export type GenerateRawSecretRendererRequest = { wallet: ExtractedWallet };
export type GenerateRawSecretMainResponse = string;

/**
* Channel for matching extracted wallets passwords

This file was deleted.

Oops, something went wrong.

This file was deleted.

Oops, something went wrong.
@@ -0,0 +1,25 @@
// @flow
import cbor from 'cbor';
import { MainIpcChannel } from './lib/MainIpcChannel';
import { GenerateRawSecretChannelName } from '../../common/ipc/api';
import type {
GenerateRawSecretRendererRequest,
GenerateRawSecretMainResponse,
} from '../../common/ipc/api';

export const generateRawSecretChannel: (
// IpcChannel<Incoming, Outgoing>
MainIpcChannel<GenerateRawSecretRendererRequest, GenerateRawSecretMainResponse>
) = (
new MainIpcChannel(GenerateRawSecretChannelName)
);

export const handleGenerateRawSecretRequests = () => {
generateRawSecretChannel.onReceive((request: GenerateRawSecretRendererRequest) => (
new Promise((resolve) => {
const { wallet } = request;
const rawSecret = cbor.encode(wallet.raw).toString('hex'); // EncryptedSecretKey
resolve(rawSecret);
})
));
};
@@ -7,9 +7,8 @@ import parseRedemptionCodeApi from './parse-redemption-code-from-pdf';
import resizeWindowApi from './resize-window';
import loadAsset from './load-asset';
import getGpuStatus from './get-gpu-status';
import { handleDeleteKeyFileRequests } from './deleteKeyFileChannel';
import { handleExtractWalletsRequests } from './extractWalletsChannel';
import { handleGenerateKeyFileRequests } from './generateKeyFileChannel';
import { handleGenerateRawSecretRequests } from './generateRawSecretChannel';
import { handleMatchWalletsPasswordsRequests } from './matchWalletsPasswordsChannel';
import { handleReportRequests } from './reportRequestChannel';
import { handlePaperWalletRequests } from './generatePaperWalletChannel';
@@ -23,9 +22,8 @@ export default (window: BrowserWindow) => {
resizeWindowApi(window);
loadAsset();
getGpuStatus();
handleDeleteKeyFileRequests();
handleExtractWalletsRequests();
handleGenerateKeyFileRequests();
handleGenerateRawSecretRequests();
handleMatchWalletsPasswordsRequests();
handleReportRequests();
handlePaperWalletRequests();
@@ -36,6 +36,7 @@ import { deleteWallet } from './wallets/requests/deleteWallet';
import { exportWalletAsJSON } from './wallets/requests/exportWalletAsJSON';
import { importWalletAsJSON } from './wallets/requests/importWalletAsJSON';
import { getWallets } from './wallets/requests/getWallets';
import { getWalletBalance } from './wallets/requests/getWalletBalance';
import { importWalletAsKey } from './wallets/requests/importWalletAsKey';
import { createWallet } from './wallets/requests/createWallet';
import { restoreWallet } from './wallets/requests/restoreWallet';
@@ -113,11 +114,14 @@ import type {
import type {
AdaWallet,
AdaWallets,
WalletBalance,
CreateWalletRequest,
DeleteWalletRequest,
RestoreWalletRequest,
UpdateSpendingPasswordRequest,
ExportWalletToFileRequest,
GetWalletBalanceRequest,
GetWalletBalanceResponse,
GetWalletCertificateRecoveryPhraseRequest,
GetWalletRecoveryPhraseFromCertificateRequest,
ImportWalletFromKeyRequest,
@@ -654,6 +658,26 @@ export default class AdaApi {
}
};

getWalletBalance = async (
request: GetWalletBalanceRequest
): Promise<WalletBalance> => {
Logger.debug('AdaApi::getWalletBalance called');
const { rawSecret } = request;
try {
const walletBalance: GetWalletBalanceResponse =
await getWalletBalance(this.config, rawSecret);
Logger.debug('AdaApi::getWalletBalance success', { walletBalance });
const { balance, walletId } = walletBalance;
return {
balance: new BigNumber(balance).dividedBy(LOVELACES_PER_ADA),
walletId,
};
} catch (error) {
Logger.error('AdaApi::getWalletBalance error', { error });
throw new GenericApiError();
}
};

redeemAda = async (
request: RedeemAdaParams
): Promise<WalletTransaction> => {
@@ -0,0 +1,24 @@
// @flow
import type { RequestConfig } from '../../common/types';
import type { GetWalletBalanceResponse } from '../types';
import { request } from '../../utils/request';

export const getWalletBalance = (
config: RequestConfig,
rawSecret: string, // EncryptedSecretKey
): Promise<GetWalletBalanceResponse> => (
request({
method: 'POST',
path: '/api/internal/query-balance',
...config,
}, {}, rawSecret)
);

/* eslint-disable max-len */
/*
[clever@system76:~/iohk/cardano-bittrex/wallet/states/testnet]$ time curl --cert tls/client/client.pem --cacert tls/server/ca.crt https://localhost:8090/api/internal/query-balance -X POST -d '"825880d3c1df2f6d618d1f7263ff1ead5808a9f40db72172d93933c21fcfff5e47843f9a4edcb93ad0ca5e0cba936d44d4082863e890ab5b5ba73834b5457ce61bdd6509a69c15546350d399dbfcee1a071b28ebdc290e809b8f5207af86ec16c43aa5be1d4f5bb91da36dd9f5f3081f6b047f0719a23a27f3428aea66afdf8c04fed3586031347c387c317c78374f6936465a79716830424467774f48676456367534395050747141314c5950307751447a4d7634526b3d7c5038533858316f6f5154394f594a6f446e786b2f7877545a62564251734d593174414d5666773776616e633d"' -H "Content-Type: application/json; charset=utf-8" -v
{"data":{"balance":2725394944,"walletId":"2cWKMJemoBamKb8mbQxL4we5QPZzuzp1QbsVFFEAnstGN4yMaaWz5bVyoD14EKDizvd8c"},"status":"success","meta":{"pagination":{"totalPages":1,"page":1,"perPage":1,"totalEntries":1}}}
*/
/* eslint-disable max-len */
@@ -1,4 +1,6 @@
// @flow
import BigNumber from 'bignumber.js';

export type AdaWallet = {
createdAt: string,
syncState: WalletSyncState,
@@ -36,6 +38,11 @@ export type WalletSyncState = {
tag: SyncStateTag,
};

export type WalletBalance = {
balance: BigNumber,
walletId: string,
};

// req/res Wallet types
export type CreateWalletRequest = {
name: string,
@@ -90,3 +97,12 @@ export type GetWalletRecoveryPhraseFromCertificateRequest = {
passphrase: string,
scrambledInput: string,
};

export type GetWalletBalanceRequest = {
rawSecret: string,
};

export type GetWalletBalanceResponse = {
balance: number,
walletId: string,
};

This file was deleted.

Oops, something went wrong.

This file was deleted.

Oops, something went wrong.
@@ -0,0 +1,14 @@
// @flow
import { GenerateRawSecretChannelName } from '../../../common/ipc/api';
import type {
GenerateRawSecretRendererRequest,
GenerateRawSecretMainResponse
} from '../../../common/ipc/api';
import { RendererIpcChannel } from './lib/RendererIpcChannel';

export const generateRawSecretChannel: (
// IpcChannel<Incoming, Outgoing>
RendererIpcChannel<GenerateRawSecretMainResponse, GenerateRawSecretRendererRequest>
) = (
new RendererIpcChannel(GenerateRawSecretChannelName)
);
Oops, something went wrong.

0 comments on commit 1dcd33a

Please sign in to comment.
You can’t perform that action at this time.