8000 Unit conversion: For transaction values · Issue #119 · Consensys/ethql · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
This repository was archived by the owner on Jan 21, 2022. It is now read-only.
This repository was archived by the owner on Jan 21, 2022. It is now read-only.
Unit conversion: For transaction values #119
Open
@jormal

Description

@jormal

In issue #45, it fixed that unit conversions for balances. but, for values are still not working.

{
  transaction(hash:"0x1234...") {
    value (unit:ether)
  }
}

I think it also do conversion using web3.utils.fromWei().


I don't know is it right. but, I think it can be conversion by following this.

In, src/core/services/eth-service/index.ts

...
export interface EthService {
    ...
    fetchValue(tx: EthqlTransaction): Promise<string>;
    ...
}
...

In, src/core/services/eth-service/impl/web3-eth-service.ts

...
export class Web3EthService implements EthService {
    ...
    public async fetchValue(tx: EthqlTransaction): Promise<string> {
        return tx && tx.value;
    }
    ...
}
...

In, src/core/model/index.ts

...
export class EthqlTransaction {
    ...
    public readonly value: string;
    ...
    constructor(tx: Transaction, logs?: Log[]) {
        ...
        this.value = value;
        ...
    }
}
...

In, src/core/resolvers/transaction.ts

...
async function value(obj: EthqlTransaction, { unit } /* args */, { services }: EthqlContext): Promise<string> {
    const val = await services.ethService.fetchValue(obj);
    return unit ? Web3.utils.fromWei(val, unit) : val;
}
...

I'm Newbie and I don't know if I'm right.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0