ethql icon indicating copy to clipboard operation
ethql copied to clipboard

Unit conversion: For transaction values

Open jormal opened this issue 6 years ago • 0 comments

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.

jormal avatar Jan 11 '19 02:01 jormal