-
Notifications
You must be signed in to change notification settings - Fork 4
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
feat: added getAddressAtIndex method and API #425
Changes from all commits
1b510ae
a02b24d
26f0138
246cbb4
a8aeaf4
79b8d38
724fde2
88e2a0d
8b3a064
f3c5018
5c9ab39
a3a71a4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
if [[ $(type -t use_flake) != function ]]; then | ||
echo "ERROR: use_flake function missing." | ||
echo "Please update direnv to v2.30.0 or later." | ||
exit 1 | ||
fi | ||
|
||
use flake |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,3 +24,5 @@ coverage | |
|
||
# fcm account config | ||
**/fcm.config.json | ||
|
||
.direnv |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
'use strict'; | ||
|
||
module.exports = { | ||
up: async (queryInterface) => { | ||
await queryInterface.addIndex( | ||
'address', | ||
['index'], { | ||
name: 'address_index_idx', | ||
fields: 'index', | ||
}, | ||
); | ||
}, | ||
|
||
down: async (queryInterface) => { | ||
await queryInterface.removeIndex('address', 'address_index_idx'); | ||
}, | ||
}; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
This flake.nix file creates a virtual environment with the desired dependencies | ||
in a reproducible way using Nix and Nix flakes (https://nixos.wiki/wiki/Flakes) | ||
|
||
Flakes are a feature in Nix that allows you to specify the dependencies of your | ||
project in a declarative and reproducible manner. It allows for better isolation, | ||
reproducibility, and more reliable upgrades. | ||
|
||
`direnv` is an environment switcher for the shell. It knows how to hook into | ||
multiple shells (like bash, zsh, fish, etc...) to load or unload environment | ||
variables depending on the current directory. This allows project-specific | ||
environment variables without cluttering the "~/.profile" file. | ||
|
||
This flake file creates a shell with nodejs v14.x installed and should work | ||
on macOs, linux and windows | ||
*/ | ||
{ | ||
description = "Flake that installs Node.js 14.x via direnv"; | ||
|
||
inputs.devshell.url = "github:numtide/devshell"; | ||
inputs.flake-utils.url = "github:numtide/flake-utils"; | ||
|
||
outputs = { self, flake-utils, devshell, nixpkgs }: | ||
|
||
flake-utils.lib.eachDefaultSystem (system: { | ||
devShell = | ||
let pkgs = import nixpkgs { | ||
inherit system; | ||
|
||
overlays = [ devshell.overlay ]; | ||
}; | ||
in | ||
pkgs.devshell.mkShell { | ||
packages = with pkgs; [ | ||
nodejs-14_x | ||
]; | ||
}; | ||
}); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3157,3 +3157,38 @@ export const getUnsentTxProposals = async ( | |
|
||
return result.map((row) => row.id); | ||
}; | ||
|
||
/** | ||
* Gets a specific address from an index and a walletId | ||
* | ||
* @param mysql - Database connection | ||
* @param walletId - The wallet id to search for | ||
* @param index - The address index to search for | ||
* | ||
* @returns An object containing the address, its index and the number of transactions | ||
*/ | ||
export const getAddressAtIndex = async ( | ||
mysql: ServerlessMysql, | ||
walletId: string, | ||
index: number, | ||
): Promise<AddressInfo | null> => { | ||
const addresses = await mysql.query<AddressInfo[]>( | ||
` | ||
SELECT \`address\`, \`index\`, \`transactions\` | ||
FROM \`address\` pd | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For an address to be available in this table, we need to have had a transaction involving the address, right? I'm asking this because, if this is true, then this new API you're building won't be able to actually derive a new address at an index, right? I don't know how this API will be used to evaluate whether this is a limitation or not There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're partially correct We also make sure that the wallet always have at least So you're correct that this API won't be able to actually derive a new address at an index, but that's the expected behavior since this is exactly what the old facade does, so this is definetly a limitation but is not a problem for our use case I added a notice in the API docs in 724fde2 |
||
WHERE \`index\` = ? | ||
AND \`wallet_id\` = ? | ||
LIMIT 1`, | ||
[walletId, index], | ||
); | ||
|
||
if (addresses.length <= 0) { | ||
return null; | ||
} | ||
|
||
return { | ||
address: addresses[0].address as string, | ||
index: addresses[0].index as number, | ||
transactions: addresses[0].transactions as number, | ||
} as AddressInfo; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this file accepts comments, I think we should explain what this is.
Maybe also mention in the README (or some other doc that we would link in the README) that we have these configs and how to use them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in 5c9ab39