Skip to content
This repository has been archived by the owner on Jan 21, 2022. It is now read-only.

Unit conversion: For transaction values #119

Open
jormal opened this issue Jan 11, 2019 · 0 comments
Open

Unit conversion: For transaction values #119

jormal opened this issue Jan 11, 2019 · 0 comments

Comments

@jormal
Copy link

jormal commented Jan 11, 2019

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant