Skip to content

refactor: txById should return the height #249

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 39 additions & 37 deletions packages/wallet-service/src/db/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import {
TxByIdToken,
PushDeviceSettings,
FullNodeApiVersionResponse,
TxInfo,
} from '@src/types';
import {
getUnixTimestamp,
Expand Down Expand Up @@ -426,7 +427,7 @@ export const getWalletAddressDetail = async (mysql: ServerlessMysql, walletId: s
FROM \`address\`
WHERE \`wallet_id\` = ?
AND \`address\` = ?`,
[walletId, address]);
[walletId, address]);

if (results.length > 0) {
const data = results[0];
Expand Down Expand Up @@ -1160,12 +1161,12 @@ export const updateAddressLockedBalance = async (
\`unlocked_authorities\` = (unlocked_authorities | ?)
WHERE \`address\` = ?
AND \`token_id\` = ?`, [
tokenBalance.unlockedAmount,
tokenBalance.unlockedAmount,
tokenBalance.unlockedAuthorities.toInteger(),
address,
token,
],
tokenBalance.unlockedAmount,
tokenBalance.unlockedAmount,
tokenBalance.unlockedAuthorities.toInteger(),
address,
token,
],
);

// if any authority has been unlocked, we have to refresh the locked authorities
Expand Down Expand Up @@ -1201,7 +1202,7 @@ export const updateAddressLockedBalance = async (
)
WHERE \`address\` = ?
AND \`token_id\` = ?`,
[address, token, address, token]);
[address, token, address, token]);
}
}
}
Expand Down Expand Up @@ -1233,7 +1234,7 @@ export const updateWalletLockedBalance = async (
WHERE \`wallet_id\` = ?
AND \`token_id\` = ?`,
[tokenBalance.unlockedAmount, tokenBalance.unlockedAmount,
tokenBalance.unlockedAuthorities.toInteger(), walletId, token],
tokenBalance.unlockedAuthorities.toInteger(), walletId, token],
);

// if any authority has been unlocked, we have to refresh the locked authorities
Expand Down Expand Up @@ -1418,7 +1419,7 @@ export const getWalletTokens = async (
);

for (const result of results) {
tokenList.push(<string> result.token_id);
tokenList.push(<string>result.token_id);
}

return tokenList;
Expand Down Expand Up @@ -1464,7 +1465,7 @@ LEFT OUTER JOIN transaction ON transaction.tx_id = wallet_tx_history.tx_id
ORDER BY wallet_tx_history.timestamp
DESC
LIMIT ?, ?`,
[walletId, tokenId, skip, count]);
[walletId, tokenId, skip, count]);

for (const result of results) {
const tx: TxTokenBalance = {
Expand Down Expand Up @@ -2080,7 +2081,7 @@ export const markUtxosAsVoided = async (
UPDATE \`tx_output\`
SET \`voided\` = TRUE
WHERE \`tx_id\` IN (?)`,
[txIds]);
[txIds]);
};

/**
Expand Down Expand Up @@ -2818,15 +2819,15 @@ export const existsPushDevice = async (
mysql: ServerlessMysql,
deviceId: string,
walletId: string,
) : Promise<boolean> => {
): Promise<boolean> => {
const [{ count }] = await mysql.query(
`
SELECT COUNT(1) as \`count\`
FROM \`push_devices\` pd
WHERE device_id = ?
AND wallet_id = ?`,
[deviceId, walletId],
) as unknown as Array<{count}>;
) as unknown as Array<{ count }>;

return count > 0;
};
Expand All @@ -2846,7 +2847,7 @@ export const registerPushDevice = async (
enablePush: boolean,
enableShowAmounts: boolean,
},
) : Promise<void> => {
): Promise<void> => {
await mysql.query(
`
INSERT
Expand Down Expand Up @@ -2895,7 +2896,7 @@ export const updatePushDevice = async (
enablePush: boolean,
enableShowAmounts: boolean,
},
) : Promise<void> => {
): Promise<void> => {
await mysql.query(
`
UPDATE \`push_devices\`
Expand All @@ -2918,7 +2919,7 @@ export const unregisterPushDevice = async (
mysql: ServerlessMysql,
deviceId: string,
walletId?: string,
) : Promise<void> => {
): Promise<void> => {
if (walletId) {
await mysql.query(
`
Expand Down Expand Up @@ -2952,39 +2953,40 @@ export const getTransactionById = async (
txId: string,
walletId: string,
): Promise<TxByIdToken[]> => {
const result = await mysql.query(`
const result = await mysql.query<TxByIdToken[]>(`
SELECT
transaction.tx_id AS tx_id
transaction.tx_id AS txId
, transaction.timestamp AS timestamp
, transaction.version AS version
, transaction.voided AS voided
, transaction.height AS height
, transaction.weight AS weight
, wallet_tx_history.balance AS balance
, wallet_tx_history.token_id AS token_id
, token.name AS name
, token.symbol AS symbol
, wallet_tx_history.token_id AS tokenId
, token.name AS tokenName
, token.symbol AS tokenSymbol
FROM wallet_tx_history
INNER JOIN transaction ON transaction.tx_id = wallet_tx_history.tx_id
INNER JOIN transaction ON transaction.tx_id = wallet_tx_history.txId
INNER JOIN token ON wallet_tx_history.token_id = token.id
WHERE transaction.tx_id = ?
AND transaction.voided = FALSE
AND wallet_tx_history.wallet_id = ?`,
// eslint-disable-next-line camelcase
[txId, walletId]) as Array<{tx_id, timestamp, version, voided, weight, balance, token_id, name, symbol }>;
// eslint-disable-next-line camelcase
[txId, walletId]);

const txTokens = [];
result.forEach((eachTxToken) => {
const txToken = {
txId: eachTxToken.tx_id,
txId: eachTxToken.txId,
timestamp: eachTxToken.timestamp,
version: eachTxToken.version,
voided: !!eachTxToken.voided,
weight: eachTxToken.weight,
height: eachTxToken.height,
balance: eachTxToken.balance,
tokenId: eachTxToken.token_id,
tokenName: eachTxToken.name,
tokenSymbol: eachTxToken.symbol,
tokenId: eachTxToken.tokenId,
tokenName: eachTxToken.tokenName,
tokenSymbol: eachTxToken.tokenSymbol,
} as TxByIdToken;
txTokens.push(txToken);
});
Expand All @@ -3001,7 +3003,7 @@ export const getTransactionById = async (
export const existsWallet = async (
mysql: ServerlessMysql,
walletId: string,
) : Promise<boolean> => {
): Promise<boolean> => {
const [{ count }] = (await mysql.query(
`
SELECT COUNT(1) as \`count\`
Expand All @@ -3022,15 +3024,15 @@ export const existsWallet = async (
export const getPushDevice = async (
mysql: ServerlessMysql,
deviceId: string,
) : Promise<PushDevice|null> => {
): Promise<PushDevice | null> => {
const [pushDevice] = await mysql.query(
`
SELECT *
FROM \`push_devices\`
WHERE device_id = ?`,
[deviceId],
// eslint-disable-next-line camelcase
) as Array<{wallet_id, device_id, push_provider, enable_push, enable_show_amounts}>;
// eslint-disable-next-line camelcase
) as Array<{ wallet_id, device_id, push_provider, enable_push, enable_show_amounts }>;

if (!pushDevice) {
return null;
Expand All @@ -3055,7 +3057,7 @@ export const getPushDevice = async (
export const getPushDeviceSettingsList = async (
mysql: ServerlessMysql,
walletIdList: string[],
) : Promise<PushDeviceSettings[]> => {
): Promise<PushDeviceSettings[]> => {
const pushDeviceSettingsResult = await mysql.query(
`
SELECT wallet_id
Expand All @@ -3065,8 +3067,8 @@ export const getPushDeviceSettingsList = async (
FROM \`push_devices\`
WHERE wallet_id in (?)`,
[walletIdList],
// eslint-disable-next-line camelcase
) as Array<{wallet_id, device_id, enable_push, enable_show_amounts}>;
// eslint-disable-next-line camelcase
) as Array<{ wallet_id, device_id, enable_push, enable_show_amounts }>;

const pushDeviceSettignsList = pushDeviceSettingsResult.map((each) => ({
walletId: each.wallet_id,
Expand Down Expand Up @@ -3127,7 +3129,7 @@ export const getTokenSymbols = async (
);

if (results.length === 0) return null;
return results.reduce((prev: Record<string, string>, token: { id: string, symbol: string}) => {
return results.reduce((prev: Record<string, string>, token: { id: string, symbol: string }) => {
// eslint-disable-next-line no-param-reassign
prev[token.id] = token.symbol;
return prev;
Expand Down
7 changes: 4 additions & 3 deletions packages/wallet-service/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,12 @@ export interface EnvironmentConfig {
firebaseTokenUri: string;
firebaseAuthProviderX509CertUrl: string;
firebaseClientX509CertUrl: string;
firebasePrivateKey: string|null;
firebasePrivateKey: string | null;
maxLoadWalletRetries: number;
logLevel: string;
createNftMaxRetries: number;
warnMaxReorgSize: number;
};
}

/**
* Fullnode converted version data.
Expand Down Expand Up @@ -118,7 +118,7 @@ export interface FullNodeApiVersionResponse {
genesis_block_hash: string,
genesis_tx1_hash: string,
genesis_tx2_hash: string,
native_token: { name: string, symbol: string};
native_token: { name: string, symbol: string };
}

export interface TxProposal {
Expand Down Expand Up @@ -744,6 +744,7 @@ export interface TxByIdToken {
timestamp: number;
version: number;
voided: boolean;
height: number | null;
weight: number;
balance: Balance;
tokenId: string;
Expand Down
Loading