Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
PatrickDinh committed Dec 15, 2024
1 parent 37f0834 commit 936b650
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 16 deletions.
6 changes: 1 addition & 5 deletions src/block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,7 @@ function blockMapToObject(object: Map<any, any>): BlockData {
for (const [key, value] of object) {
if (key === 'r' && value instanceof Map && Array.from(value.keys()).every((k) => typeof k === 'number')) {
// State proof transactions have a property `r` with a map with numeric keys that must stay intact
const rMap = new Map()
for (const [k, v] of value) {
rMap.set(k, v instanceof Map ? blockMapToObject(v) : v)
}
result[key] = rMap
result[key] = value
} else if (value instanceof Map) {
result[key] = blockMapToObject(value)
} else if (value instanceof Uint8Array) {
Expand Down
15 changes: 4 additions & 11 deletions src/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,23 +168,16 @@ function concatArrays(...arrs: ArrayLike<number>[]) {
return c
}

// TODO: PD - review this again
const keysHaveAddressType = ['snd', 'close', 'aclose', 'rekey', 'rcv', 'arcv', 'fadd', 'asnd', 'm', 'r', 'f', 'c']

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const objectToMap = (object: Record<string, any>): Map<string, unknown> => {
return new Map(
Object.entries(object).map(([key, value]) => {
if (key === 'r' && value instanceof Map) {
// State proof transactions have a property `r` with a map with numeric keys that must stay intact
const rMap = new Map()
for (const [k, v] of value) {
rMap.set(k, objectToMap(v))
}
return [key, rMap]
if (key === 'r' && value instanceof Map && Array.from(value.keys()).every((k) => typeof k === 'number')) {
return [key, value]
}
if (value instanceof Uint8Array) {
if (keysHaveAddressType.includes(key) && value.length === 32) {
if (['snd', 'close', 'aclose', 'rekey', 'rcv', 'arcv', 'fadd', 'asnd', 'm', 'r', 'f', 'c'].includes(key) && value.length === 32) {
// fromEncodingData expects Address type
return [key, new algosdk.Address(value)]
}
return [key, value]
Expand Down

0 comments on commit 936b650

Please sign in to comment.