-
Couldn't load subscription status.
- Fork 63
LW-11425 Misc fixes #1467
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
Merged
Merged
LW-11425 Misc fixes #1467
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
39ada85
fix(cardano-services): use computed stake credential type while build…
iccicci 61d4291
feat: add script to get in chain tx cbor from tx id
iccicci 23df091
fix(cardano-services): use correct inputs and collaterals order while…
iccicci a5202ca
refactor(cardano-services): remove useless sort of collateral output …
iccicci 3166d53
fix(cardano-serices): add (partial) stake pool parameters to stake po…
iccicci 764ec3d
fix(cardano-services): don't fetch assets for collateralReturn as if …
iccicci File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| import { Pool } from 'pg'; | ||
| import { readFileSync } from 'fs'; | ||
| import { spawnSync } from 'child_process'; | ||
| import WebSocket from 'ws'; | ||
|
|
||
| interface Tx { | ||
| cbor: string; | ||
| id: string; | ||
| } | ||
|
|
||
| const txId = process.argv[2]; | ||
|
|
||
| const normalizeError = (status: number | null, stderr: string) => | ||
| [status || 1, stderr || 'Unknown error\n', ''] as const; | ||
|
|
||
| const inside = async () => { | ||
| const db = new Pool({ | ||
| database: readFileSync(process.env.POSTGRES_DB_FILE_DB_SYNC!).toString(), | ||
| host: 'postgres', | ||
| password: readFileSync(process.env.POSTGRES_PASSWORD_FILE_DB_SYNC!).toString(), | ||
| user: readFileSync(process.env.POSTGRES_USER_FILE_DB_SYNC!).toString() | ||
| }); | ||
|
|
||
| const query = `\ | ||
| SELECT ENCODE(b2.hash, 'hex') AS id, b2.slot_no::INTEGER AS slot FROM tx | ||
| JOIN block b1 ON block_id = b1.id | ||
| JOIN block b2 ON b1.previous_id = b2.id | ||
| WHERE tx.hash = $1`; | ||
|
|
||
| const { rows } = await db.query(query, [Buffer.from(txId, 'hex')]); | ||
| const [prevBlock] = rows; | ||
|
|
||
| await db.end(); | ||
|
|
||
| if (!prevBlock) return [1, `Unknown transaction id ${txId}\n`, ''] as const; | ||
|
|
||
| const cbor = await new Promise<string>((resolve) => { | ||
| const client = new WebSocket(process.env.OGMIOS_URL!); | ||
| let request = 0; | ||
|
|
||
| const rpc = (method: string, params: unknown) => | ||
| client.send(JSON.stringify({ id: ++request, jsonrpc: '2.0', method, params })); | ||
|
|
||
| client.on('open', () => rpc('findIntersection', { points: [prevBlock] })); | ||
|
|
||
| client.on('message', (msg) => { | ||
| const { result } = JSON.parse(msg.toString()) as { result: { block: { transactions: Tx[] } } }; | ||
| let tx: Tx | undefined; | ||
|
|
||
| if ( | ||
| result && | ||
| result.block && | ||
| result.block.transactions && | ||
| (tx = result.block.transactions.find((t) => t.id === txId)) | ||
| ) { | ||
| client.on('close', () => resolve(tx!.cbor)); | ||
| client.close(); | ||
| } else rpc('nextBlock', {}); | ||
| }); | ||
| }); | ||
|
|
||
| return [0, '', `${cbor}\n`] as const; | ||
| }; | ||
|
|
||
| const outside = async () => { | ||
| if (!txId) return [1, 'Missing input transaction id\n', ''] as const; | ||
|
|
||
| let { status, stderr, stdout } = spawnSync('docker', ['ps'], { encoding: 'utf-8' }); | ||
|
|
||
| if (status || stderr) return normalizeError(status, stderr); | ||
|
|
||
| const container = [ | ||
| 'cardano-services-mainnet-provider-server-1', | ||
| 'cardano-services-preprod-provider-server-1', | ||
| 'cardano-services-preview-provider-server-1', | ||
| 'cardano-services-sanchonet-provider-server-1', | ||
| 'local-network-e2e-provider-server-1' | ||
| ].find((name) => stdout.includes(name)); | ||
|
|
||
| if (!container) return [1, "Can't find any valid container\n", ''] as const; | ||
|
|
||
| ({ status, stderr, stdout } = spawnSync( | ||
| 'docker', | ||
| ['container', 'exec', '-i', container, 'bash', '-c', `cd /app ; INSIDE_THE_CONTAINER=true yarn tx-cbor ${txId}`], | ||
| { encoding: 'utf-8' } | ||
| )); | ||
|
|
||
| if (status || stderr) return normalizeError(status, stderr); | ||
|
|
||
| return [0, '', stdout] as const; | ||
| }; | ||
|
|
||
| (process.env.INSIDE_THE_CONTAINER ? inside() : outside()) | ||
| .then(([status, stderr, stdout]) => { | ||
| if (status) { | ||
| process.stderr.write(stderr); | ||
| // eslint-disable-next-line unicorn/no-process-exit | ||
| process.exit(status); | ||
| } | ||
|
|
||
| process.stdout.write(stdout); | ||
| }) | ||
| .catch((error) => { | ||
| throw error; | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.