Skip to content
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

shovel-config-ts: update types to match documentation #279

Merged
merged 2 commits into from
Dec 6, 2024

Conversation

nathanhleung
Copy link
Contributor

I was attempting to use @indexsupply/shovel-config to make a shovel config in TypeScript but was running into type errors.

Upon further investigation, it appeared that the TypeScript types in the shovel-config-ts subproject were out of date with the current version of the shovel indexer in the repo. Specifically:

  • Some of the block data options in dig.go were not present in the BlockDataOptions type in Typescript (e.g. tx_contract_address, tx_max_priority_fee_per_gas):

    shovel/dig/dig.go

    Lines 896 to 962 in cb9264e

    func (lwc *logWithCtx) get(name string) any {
    switch name {
    case "src_name":
    return wctx.SrcName(lwc.ctx)
    case "ig_name":
    return wctx.IGName(lwc.ctx)
    case "chain_id":
    return wctx.ChainID(lwc.ctx)
    case "block_hash":
    return lwc.b.Hash()
    case "block_num":
    return lwc.b.Num()
    case "block_time":
    return lwc.b.Time
    case "tx_hash":
    return lwc.t.Hash()
    case "tx_idx":
    return lwc.t.Idx
    case "tx_signer":
    d, err := lwc.t.Signer()
    if err != nil {
    slog.ErrorContext(lwc.ctx, "unable to derive signer", "error", err)
    return nil
    }
    return d
    case "tx_to":
    return lwc.t.To.Bytes()
    case "tx_value":
    return &lwc.t.Value
    case "tx_input":
    return lwc.t.Data.Bytes()
    case "tx_type":
    return lwc.t.Type
    case "tx_status":
    return lwc.t.Receipt.Status
    case "log_idx":
    return lwc.l.Idx
    case "tx_gas_used":
    return lwc.t.GasUsed
    case "tx_gas_price":
    return &lwc.t.GasPrice
    case "tx_effective_gas_price":
    return &lwc.t.EffectiveGasPrice
    case "tx_contract_address":
    return lwc.t.ContractAddress.Bytes()
    case "tx_max_priority_fee_per_gas":
    return &lwc.t.MaxPriorityFeePerGas
    case "tx_max_fee_per_gas":
    return &lwc.t.MaxFeePerGas
    case "tx_nonce":
    return lwc.t.Nonce
    case "log_addr":
    return lwc.l.Address.Bytes()
    case "trace_action_call_type":
    return lwc.ta.CallType
    case "trace_action_idx":
    return lwc.ta.Idx
    case "trace_action_from":
    return lwc.ta.From.Bytes()
    case "trace_action_to":
    return lwc.ta.To.Bytes()
    case "trace_action_value":
    return &lwc.ta.Value
    default:
    return nil
    }
    }

    export type BlockDataOptions =
    | "src_name"
    | "ig_name"
    | "chain_id"
    | "block_hash"
    | "block_num"
    | "block_time"
    | "tx_hash"
    | "tx_idx"
    | "tx_signer"
    | "tx_to"
    | "tx_value"
    | "tx_input"
    | "tx_type"
    | "tx_status"
    | "log_idx"
    | "log_addr"
    | "trace_action_call_type"
    | "trace_action_idx"
    | "trace_action_from"
    | "trace_action_to"
    | "trace_action_value";

  • The FilterOp type was missing the filter ops corresponding to a config with filter_arg, as outlined in the docs under the "Filter Fields" section: https://indexsupply.com/shovel/docs/#filter-fields

    Screenshot 2024-12-06 at 15 41 48

To fix this, I added the missing options to the TypeScript types. I also added the bun install command to the build instructions, as the build was failing when I initially cloned the repo to test locally since I hadn't installed any of the dependencies.

When testing my shovel config with the updated types in this PR, the type errors were no longer present.

@ryandotsmith ryandotsmith merged commit 3286204 into indexsupply:main Dec 6, 2024
3 checks passed
@ryandotsmith
Copy link
Member

@nathanhleung thank you!

@ryandotsmith
Copy link
Member

https://www.npmjs.com/package/@indexsupply/shovel-config/v/0.0.18
https://jsr.io/@indexsupply/[email protected]

@nathanhleung nathanhleung deleted the patch-1 branch December 6, 2024 22:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants