Skip to content

Commit

Permalink
[be] logging instruction data of signed txs (#53)
Browse files Browse the repository at this point in the history
* claim info extraction

* decoded data logger

* simplify test

* pushing to influx

* Update address mapping (WIP)

* testing data points persistence

* remove todo

* Fix address mapping|add influx token from secrets

---------

Co-authored-by: Abhishek Rajput <abhi@qwestive.io>
  • Loading branch information
mat1asm and abhidtu2014 authored Apr 1, 2024
1 parent 613ca38 commit 412749b
Show file tree
Hide file tree
Showing 12 changed files with 2,287 additions and 705 deletions.
6 changes: 6 additions & 0 deletions backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,13 @@
"dependencies": {
"@aws-sdk/client-secrets-manager": "^3.535.0",
"@coral-xyz/anchor": "^0.29.0",
"@cosmjs/amino": "^0.32.3",
"@cosmjs/crypto": "^0.32.3",
"@cosmjs/encoding": "^0.32.3",
"@influxdata/influxdb-client": "^1.33.2",
"@solana/web3.js": "^1.91.1",
"bs58": "^5.0.0",
"hi-base32": "^0.5.1",
"tweetnacl": "^1.0.3"
},
"devDependencies": {
Expand All @@ -37,6 +42,7 @@
"jest": "^29.7.0",
"msw": "^2.2.9",
"prettier": "^2.7.1",
"testcontainers": "^10.8.0",
"typescript": "^5.4.2"
},
"jest": {
Expand Down
17 changes: 15 additions & 2 deletions backend/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default {
region: process.env.AWS_REGION ?? 'us-east-2'
},
tokenDispenserProgramId: () => process.env.TOKEN_DISPENSER_PROGRAM_ID,
keys: {
secrets: {
dispenserGuard: {
/** optional. mostly for local testing */
key: process.env.DISPENSER_WALLET_KEY,
Expand All @@ -16,11 +16,24 @@ export default {
},
funding: {
/** optional. mostly for local testing */
key: process.env.FUNDING_WALLET_KEY,
key: () => process.env.FUNDING_WALLET_KEY,
/** required. with a default value and used when when key not set */
secretName:
process.env.FUNDER_WALLET_KEY_SECRET_NAME ??
'xli-test-secret-funder-wallet'
},
influx: {
key: () => process.env.INFLUXDB_TOKEN,
/** required. with a default value */
secretName: process.env.IDB_SECRET_NAME ?? 'xl-ad-idb'
}
},
influx: {
url: () => process.env.INFLUXDB_URL ?? 'http://localhost:8086',
org: () => process.env.INFLUXDB_ORG ?? 'xl',
bucket: () => process.env.INFLUXDB_BUCKET ?? 'ad',
token: () => process.env.INFLUXDB_TOKEN,
timeout: () => parseInt(process.env.INFLUXDB_TIMEOUT_MS ?? '20500'),
isFlushEnabled: () => process.env.INFLUXDB_FLUSH_ENABLED === 'true' ?? false
}
}
18 changes: 12 additions & 6 deletions backend/src/handlers/fund-transactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@ import { APIGatewayProxyEvent, APIGatewayProxyResult } from 'aws-lambda'
import { getFundingKey } from '../utils/secrets'
import {
checkTransactions,
deserializeTransactions
deserializeTransactions,
extractCallData
} from '../utils/fund-transactions'
import { Keypair, VersionedTransaction } from '@solana/web3.js'
import bs58 from 'bs58'
import { HandlerError } from '../utils/errors'
import { asJsonResponse } from '../utils/response'
import { ClaimSignature } from '../types'
import { saveSignedTransactions } from '../utils/persistence'

export type FundTransactionRequest = Uint8Array[]

Expand All @@ -30,7 +33,8 @@ export const fundTransactions = async (
const wallet = await loadFunderWallet()

const signedTransactions = await wallet.signAllTransactions(transactions)
logSignatures(signedTransactions)
await saveSignedTransactions(getSignatures(signedTransactions))

return asJsonResponse(
200,
signedTransactions.map((tx) => Buffer.from(tx.serialize()))
Expand Down Expand Up @@ -79,10 +83,12 @@ function getSignature(tx: VersionedTransaction): string {
return 'unkown signature'
}

function logSignatures(signedTransactions: VersionedTransaction[]) {
const sigs: string[] = []
function getSignatures(signedTransactions: VersionedTransaction[]) {
const sigs: ClaimSignature[] = []
signedTransactions.forEach((tx) => {
sigs.push(getSignature(tx))
sigs.push({ sig: getSignature(tx), instruction: extractCallData(tx) })
})
console.log(`Signed transactions: ${sigs}`)
console.log(`Signed transactions: ${JSON.stringify(sigs)}`)

return sigs
}
Loading

0 comments on commit 412749b

Please sign in to comment.