Skip to content

Commit

Permalink
feat: Added supports for parsing logs from algod
Browse files Browse the repository at this point in the history
  • Loading branch information
robdmoore committed Jan 28, 2024
1 parent 9eb2fff commit 11e948e
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 9 deletions.
12 changes: 6 additions & 6 deletions examples/data-history-museum/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,21 +74,21 @@ async function saveDHMTransactions(transactions: TransactionResult[]) {
if (t['created-asset-index']) {
assets.push({
id: t['created-asset-index'],
name: t['asset-config-transaction'].params.name!,
unit: t['asset-config-transaction'].params['unit-name']!,
mediaUrl: t['asset-config-transaction'].params.url!,
name: t['asset-config-transaction']!.params!.name!,
unit: t['asset-config-transaction']!.params!['unit-name']!,
mediaUrl: t['asset-config-transaction']!.params!.url!,
metadata: getArc69Metadata(t),
created: new Date(t['round-time']! * 1000).toISOString(),
lastModified: new Date(t['round-time']! * 1000).toISOString(),
})
} else {
const asset = assets.find((a) => a.id === t['asset-config-transaction']['asset-id'])
const asset = assets.find((a) => a.id === t['asset-config-transaction']!['asset-id'])
if (!asset) {
// eslint-disable-next-line no-console
console.error(t)
throw new Error(`Unable to find existing asset data for ${t['asset-config-transaction']['asset-id']}`)
throw new Error(`Unable to find existing asset data for ${t['asset-config-transaction']!['asset-id']}`)
}
if (!t['asset-config-transaction'].params) {
if (!t['asset-config-transaction']!.params) {
// Asset was deleted, remove it
assets.splice(assets.indexOf(asset), 1)
} else {
Expand Down
6 changes: 5 additions & 1 deletion src/subscriptions.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as algokit from '@algorandfoundation/algokit-utils'
import type { TransactionResult } from '@algorandfoundation/algokit-utils/types/indexer'
import * as msgpack from 'algo-msgpack-with-bigint'
import { Algodv2, Indexer, Transaction, encodeAddress } from 'algosdk'
import type SearchForTransactions from 'algosdk/dist/types/client/v2/indexer/searchForTransactions'
import sha512 from 'js-sha512'
Expand Down Expand Up @@ -304,7 +305,10 @@ export async function getBlocksBulk(context: { startRound: number; maxRound: num
blocks.push(
...(await Promise.all(
chunk.map(async (round) => {
return (await client.block(round).do()) as { block: Block }
const response = await client.c.get(`/v2/blocks/${round}`, { format: 'msgpack' }, undefined, undefined, false)
const body = response.body as Uint8Array
const decoded = msgpack.decode(body) as { block: Block }
return decoded
}),
)),
)
Expand Down
1 change: 1 addition & 0 deletions src/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,7 @@ export function getIndexerTransactionFromAlgodTransaction(t: TransactionInBlock
: undefined,
}
: undefined,
logs: blockTransaction.dt?.lg ? blockTransaction.dt.lg.map((l) => Buffer.from(l, 'utf-8').toString('base64')) : undefined,
// todo: do we need any of these?
//"close-rewards"
//"receiver-rewards"
Expand Down
10 changes: 8 additions & 2 deletions tests/scenarios/transform-complex-txn.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ describe('Complex transaction with many nested inner transactions', () => {
"local-state-schema": undefined,
"on-completion": "update",
},
"asset-config-transaction": {},
"asset-config-transaction": undefined,
"asset-freeze-transaction": undefined,
"asset-transfer-transaction": undefined,
"auth-addr": undefined,
Expand All @@ -223,7 +223,7 @@ describe('Complex transaction with many nested inner transactions', () => {
"inner-txns": [
{
"application-transaction": undefined,
"asset-config-transaction": {},
"asset-config-transaction": undefined,
"asset-freeze-transaction": undefined,
"asset-transfer-transaction": {
"amount": 536012365,
Expand All @@ -248,6 +248,7 @@ describe('Complex transaction with many nested inner transactions', () => {
"intra-round-offset": 148,
"last-valid": 35214369,
"lease": "",
"logs": undefined,
"note": "",
"payment-transaction": undefined,
"rekey-to": undefined,
Expand All @@ -260,6 +261,11 @@ describe('Complex transaction with many nested inner transactions', () => {
"intra-round-offset": 147,
"last-valid": 35214369,
"lease": "",
"logs": [
"R2hHHwQAAAAAAAYExYAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==",
"AAAAAAAAYcKgAAAAAB/ypo2AAAAAAAAAAA==",
"PNaUw7oABCHCpmV8I9qBOd6+0ofCvhDCucm/w74lwoJqwqTdrjUCzpYNwqYAAAAAAAAAAAAAAAAABgTFgAAAAB/ypo2AAAAAAAAAAAAAAA91w7sZdAAAAAAC77+9",
],
"note": "",
"payment-transaction": undefined,
"rekey-to": undefined,
Expand Down

0 comments on commit 11e948e

Please sign in to comment.