Skip to content

Commit

Permalink
fix DataFrame mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
eldargab committed Dec 1, 2023
1 parent 3b8e4f4 commit ad5f69e
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 5 deletions.
7 changes: 4 additions & 3 deletions evm/evm-processor/src/ds-rpc/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import {
SMALL_QTY,
STRING,
taggedUnion,
Validator
Validator,
withDefault
} from '@subsquid/util-internal-validation'
import {Bytes, Bytes20} from '../interfaces/base'
import {FieldSelection} from '../interfaces/data'
Expand Down Expand Up @@ -114,7 +115,7 @@ function getDebugFrameValidator(fields: FieldSelection['trace']) {
gas: QTY,
input: BYTES,
gasUsed: QTY,
output: BYTES,
output: withDefault('0x', BYTES),
to: BYTES
})
})
Expand All @@ -133,7 +134,7 @@ function getDebugFrameValidator(fields: FieldSelection['trace']) {
from: BYTES,
value: option(QTY),
gas: QTY,
output: BYTES,
output: withDefault('0x', BYTES),
gasUsed: QTY
})
})
Expand Down
2 changes: 1 addition & 1 deletion evm/evm-processor/src/mapping/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export function getTxProps(fields: FieldSelection['transaction'], forArchive: bo
maxFeePerGas: option(QTY),
maxPriorityFeePerGas: option(QTY),
input: BYTES,
nonce: withSentinel('Transaction.nonce', -1, NAT),
nonce: withSentinel('Transaction.nonce', -1, natural),
value: withSentinel('Transaction.value', -1n, QTY),
v: withSentinel('Transaction.v', -1n, QTY),
r: withSentinel('Transaction.r', '0x', BYTES),
Expand Down
1 change: 0 additions & 1 deletion test/erc20-transfers/src/processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ processor.run(new TypeormDatabase({supportHotBlocks: true}), async ctx => {
let transfers: Transfer[] = []

for (let block of ctx.blocks) {
ctx.log.info(block)
for (let log of block.logs) {
if (log.address == CONTRACT && log.topics[0] === erc20.events.Transfer.topic) {
let {from, to, value} = erc20.events.Transfer.decode(log)
Expand Down
27 changes: 27 additions & 0 deletions util/util-internal-validation/src/composite/default.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import {ValidationFailure} from '../error'
import {Validator} from '../interface'


export class Default<T, S> implements Validator<T, S | undefined | null> {
constructor(
public readonly value: T,
public readonly item: Validator<T, S>
) {}

cast(value: unknown): ValidationFailure | T {
if (value == null) {
return this.value
} else {
return this.item.cast(value)
}
}

validate(value: unknown): ValidationFailure | undefined {
if (value == null) return
return this.item.validate(value)
}

phantom(): S | undefined | null {
return undefined
}
}
9 changes: 9 additions & 0 deletions util/util-internal-validation/src/dsl.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {ArrayValidator} from './composite/array'
import {ConstantValidator} from './composite/constant'
import {Default} from './composite/default'
import {GetKeyTaggedUnionCast, GetKeyTaggedUnionSrc, KeyTaggedUnionValidator} from './composite/key-tagged-union'
import {NullableValidator} from './composite/nullable'
import {GetPropsCast, GetPropsSrc, ObjectValidator} from './composite/object'
Expand Down Expand Up @@ -83,6 +84,14 @@ export function withSentinel<V extends Validator<any>>(
}


export function withDefault<V extends Validator<any>>(
value: GetCastType<V>,
validator: V
): Validator<GetCastType<V>, GetSrcType<V> | undefined | null> {
return new Default(value, validator)
}


export function ref<V extends Validator<any>>(get: () => V): Validator<GetCastType<V>, GetSrcType<V>> {
return new RefValidator(get)
}
Expand Down

0 comments on commit ad5f69e

Please sign in to comment.