diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 044ea09..8668d34 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -22,7 +22,7 @@ jobs: - run: yarn test - - run: npx github-actions-ctrf summary ctrf/ctrf-report.json --pull-request + - run: npx github-actions-ctrf@0.0.54 summary ctrf/ctrf-report.json --pull-request env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} @@ -37,4 +37,3 @@ jobs: - name: smoke test image run: docker run -i ${{secrets.DOCKER_USER}}/tatum-kms:latest --help - \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index cee7628..71be003 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## [8.0.1] - April 2025 + +### Added + +- Filtering for "run once" mode, configuration of wallets and transaction ids to fetch and sign + ## [8.0.0] - January 2025 ### Updated diff --git a/package.json b/package.json index 6e5cabd..9a940d6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@tatumio/tatum-kms", - "version": "8.0.0", + "version": "8.0.1", "description": "Tatum KMS - Key Management System for Tatum-powered apps.", "main": "dist/index.js", "types": "./dist/index.d.ts", diff --git a/src/index.ts b/src/index.ts index 97c13d0..6a9e635 100644 --- a/src/index.ts +++ b/src/index.ts @@ -81,6 +81,8 @@ const optionsConst = ` --externalUrl Pass in external url to check valid transaction. This parameter is mandatory for mainnet (if testnet is false). Daemon mode only. --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. --runOnce Run the daemon command one time. Check for a new transactions to sign once, and then exit the process. Daemon mode only. + --wallets If runOnce enabled, fetch and sign only for these wallet ids. + --transactionIds If runOnce enabled, sign only transactions from defined comma-separated list. ` const getPasswordType = (flags: Partial<{ aws: boolean; azure: boolean; vgs: boolean }>): PasswordType => { @@ -141,11 +143,15 @@ const startup = async () => { type: 'boolean', default: false, }, + wallets: { + type: 'string' + }, + transactionIds: { + type: 'string', + }, }, }) - - const envFilePath = (flags.envFile) ?? homedir() + '/.tatumrc/.env' if (existsSync(envFilePath)) { dotenv.config({ path: envFilePath }) @@ -170,6 +176,8 @@ const startup = async () => { flags.externalUrlMethod as ExternalUrlMethod, flags.period as number, flags.runOnce as boolean, + (flags.wallets as string)?.split(','), + (flags.transactionIds as string)?.split(','), ) break } @@ -232,8 +240,8 @@ const startup = async () => { case 'report': await report( utils.csvToArray(command[1]), - getPasswordType(), - await getPassword(getPasswordType(), axiosInstance), + getPasswordType(flags), + await getPassword(getPasswordType(flags), axiosInstance), flags.path, ) break diff --git a/src/signatures.ts b/src/signatures.ts index 4015512..06935e4 100644 --- a/src/signatures.ts +++ b/src/signatures.ts @@ -589,6 +589,8 @@ export const processSignatures = async ( externalUrlMethod?: ExternalUrlMethod, period = 5, runOnce?: boolean, + wallets?: string[], + transactionIds?: string[], ) => { let running = false const supportedChains = chains || [ @@ -617,7 +619,7 @@ export const processSignatures = async ( ] if (runOnce) { - await processPendingTransactions(supportedChains, pwd, testnet, path, axios, externalUrl, externalUrlMethod) + await processPendingTransactions(supportedChains, pwd, testnet, path, axios, externalUrl, externalUrlMethod, wallets, transactionIds) return } @@ -641,12 +643,14 @@ async function processPendingTransactions( axios: AxiosInstance, externalUrl: string | undefined, externalUrlMethod: ExternalUrlMethod | undefined, + wallets?: string[], + transactionIds?: string[], ) { const transactions = [] try { for (const supportedChain of supportedChains) { - const wallets = getManagedWallets(pwd, supportedChain, testnet, path) - transactions.push(...(await getPendingTransactions(axios, supportedChain, wallets))) + const walletsToProcess = wallets || getManagedWallets(pwd, supportedChain, testnet, path) + transactions.push(...(await getPendingTransactions(axios, supportedChain, walletsToProcess))) } } catch (e) { console.error(e) @@ -654,6 +658,10 @@ async function processPendingTransactions( const data = [] for (const transaction of transactions) { try { + if (isTransactionIdExcluded(transaction, transactionIds)) { + console.log(`${new Date().toISOString()} - Tx processing skipped: ${transaction.id}. Expected one of: ${transactionIds?.join(', ')}`); + continue; + } await processTransaction(transaction, testnet, pwd, axios, path, externalUrl, externalUrlMethod) console.log(`${new Date().toISOString()} - Tx was processed: ${transaction.id}`) } catch (e) { @@ -675,6 +683,10 @@ async function processPendingTransactions( } } +function isTransactionIdExcluded(transaction: TransactionKMS, transactionIds?: string[]) { + return transactionIds && !transactionIds.includes(transaction.id) +} + function isValidNumber(value: number | undefined): boolean { return !_.isNil(value) && _.isNumber(value) && _.isFinite(value) }