Skip to content

Commit 95881a9

Browse files
alexloikoOleksandr Loiko
andauthored
ALL-11385 Optional filters for runOnce, by wallet and transactionIds (#115)
* ALL-11385 Optional filter parameters, filter by wallet and transactionIds * ALL-11385 Try fix a pipeline * ALL-11385 Format fixes * ALL-11385 Support for many wallets --------- Co-authored-by: Oleksandr Loiko <oleksandr.loiko@tatum.io>
1 parent c029739 commit 95881a9

File tree

5 files changed

+35
-10
lines changed

5 files changed

+35
-10
lines changed

.github/workflows/pull-request.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222

2323
- run: yarn test
2424

25-
- run: npx github-actions-ctrf summary ctrf/ctrf-report.json --pull-request
25+
- run: npx github-actions-ctrf@0.0.54 summary ctrf/ctrf-report.json --pull-request
2626
env:
2727
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2828

@@ -37,4 +37,3 @@ jobs:
3737

3838
- name: smoke test image
3939
run: docker run -i ${{secrets.DOCKER_USER}}/tatum-kms:latest --help
40-

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## [8.0.1] - April 2025
2+
3+
### Added
4+
5+
- Filtering for "run once" mode, configuration of wallets and transaction ids to fetch and sign
6+
17
## [8.0.0] - January 2025
28

39
### Updated

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@tatumio/tatum-kms",
3-
"version": "8.0.0",
3+
"version": "8.0.1",
44
"description": "Tatum KMS - Key Management System for Tatum-powered apps.",
55
"main": "dist/index.js",
66
"types": "./dist/index.d.ts",

src/index.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ const optionsConst = `
8181
--externalUrl Pass in external url to check valid transaction. This parameter is mandatory for mainnet (if testnet is false). Daemon mode only.
8282
--externalUrlMethod Determine what http method to use when calling the url passed in the --externalUrl option. Accepts GET or POST. Defaults to GET method. Daemon mode only.
8383
--runOnce Run the daemon command one time. Check for a new transactions to sign once, and then exit the process. Daemon mode only.
84+
--wallets If runOnce enabled, fetch and sign only for these wallet ids.
85+
--transactionIds If runOnce enabled, sign only transactions from defined comma-separated list.
8486
`
8587

8688
const getPasswordType = (flags: Partial<{ aws: boolean; azure: boolean; vgs: boolean }>): PasswordType => {
@@ -141,11 +143,15 @@ const startup = async () => {
141143
type: 'boolean',
142144
default: false,
143145
},
146+
wallets: {
147+
type: 'string'
148+
},
149+
transactionIds: {
150+
type: 'string',
151+
},
144152
},
145153
})
146154

147-
148-
149155
const envFilePath = (flags.envFile) ?? homedir() + '/.tatumrc/.env'
150156
if (existsSync(envFilePath)) {
151157
dotenv.config({ path: envFilePath })
@@ -170,6 +176,8 @@ const startup = async () => {
170176
flags.externalUrlMethod as ExternalUrlMethod,
171177
flags.period as number,
172178
flags.runOnce as boolean,
179+
(flags.wallets as string)?.split(','),
180+
(flags.transactionIds as string)?.split(','),
173181
)
174182
break
175183
}
@@ -232,8 +240,8 @@ const startup = async () => {
232240
case 'report':
233241
await report(
234242
utils.csvToArray(command[1]),
235-
getPasswordType(),
236-
await getPassword(getPasswordType(), axiosInstance),
243+
getPasswordType(flags),
244+
await getPassword(getPasswordType(flags), axiosInstance),
237245
flags.path,
238246
)
239247
break

src/signatures.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,8 @@ export const processSignatures = async (
589589
externalUrlMethod?: ExternalUrlMethod,
590590
period = 5,
591591
runOnce?: boolean,
592+
wallets?: string[],
593+
transactionIds?: string[],
592594
) => {
593595
let running = false
594596
const supportedChains = chains || [
@@ -617,7 +619,7 @@ export const processSignatures = async (
617619
]
618620

619621
if (runOnce) {
620-
await processPendingTransactions(supportedChains, pwd, testnet, path, axios, externalUrl, externalUrlMethod)
622+
await processPendingTransactions(supportedChains, pwd, testnet, path, axios, externalUrl, externalUrlMethod, wallets, transactionIds)
621623
return
622624
}
623625

@@ -641,19 +643,25 @@ async function processPendingTransactions(
641643
axios: AxiosInstance,
642644
externalUrl: string | undefined,
643645
externalUrlMethod: ExternalUrlMethod | undefined,
646+
wallets?: string[],
647+
transactionIds?: string[],
644648
) {
645649
const transactions = []
646650
try {
647651
for (const supportedChain of supportedChains) {
648-
const wallets = getManagedWallets(pwd, supportedChain, testnet, path)
649-
transactions.push(...(await getPendingTransactions(axios, supportedChain, wallets)))
652+
const walletsToProcess = wallets || getManagedWallets(pwd, supportedChain, testnet, path)
653+
transactions.push(...(await getPendingTransactions(axios, supportedChain, walletsToProcess)))
650654
}
651655
} catch (e) {
652656
console.error(e)
653657
}
654658
const data = []
655659
for (const transaction of transactions) {
656660
try {
661+
if (isTransactionIdExcluded(transaction, transactionIds)) {
662+
console.log(`${new Date().toISOString()} - Tx processing skipped: ${transaction.id}. Expected one of: ${transactionIds?.join(', ')}`);
663+
continue;
664+
}
657665
await processTransaction(transaction, testnet, pwd, axios, path, externalUrl, externalUrlMethod)
658666
console.log(`${new Date().toISOString()} - Tx was processed: ${transaction.id}`)
659667
} catch (e) {
@@ -675,6 +683,10 @@ async function processPendingTransactions(
675683
}
676684
}
677685

686+
function isTransactionIdExcluded(transaction: TransactionKMS, transactionIds?: string[]) {
687+
return transactionIds && !transactionIds.includes(transaction.id)
688+
}
689+
678690
function isValidNumber(value: number | undefined): boolean {
679691
return !_.isNil(value) && _.isNumber(value) && _.isFinite(value)
680692
}

0 commit comments

Comments
 (0)