Handle BigNumber event params and customize Decimal (#63)

* Handle BigNumber event params in watchers

* Customize decimal according to limits of IEEE-754 decimal128

* Add definition for custom scalar BigDecimal
This commit is contained in:
prathamesh0
2021-12-28 16:08:05 +05:30
committed by nabarun
parent 238ad21189
commit 94e9182dd3
19 changed files with 232 additions and 56 deletions
@@ -14,11 +14,41 @@
"internalType": "uint8",
"name": "param2",
"type": "uint8"
},
{
"indexed": false,
"internalType": "uint256",
"name": "param3",
"type": "uint256"
}
],
"name": "Test",
"type": "event"
},
{
"inputs": [
{
"internalType": "uint128",
"name": "bidAmount1",
"type": "uint128"
},
{
"internalType": "uint128",
"name": "bidAmount2",
"type": "uint128"
}
],
"name": "addMethod",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "pure",
"type": "function"
},
{
"inputs": [],
"name": "emitEvent",
@@ -44,6 +74,42 @@
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint128",
"name": "bidAmount1",
"type": "uint128"
},
{
"internalType": "uint128",
"name": "bidAmount2",
"type": "uint128"
}
],
"name": "structMethod",
"outputs": [
{
"components": [
{
"internalType": "uint128",
"name": "bidAmount1",
"type": "uint128"
},
{
"internalType": "uint128",
"name": "bidAmount2",
"type": "uint128"
}
],
"internalType": "struct Example.Bid",
"name": "",
"type": "tuple"
}
],
"stateMutability": "pure",
"type": "function"
}
],
"storageLayout": {
@@ -27,6 +27,9 @@ export class Author {
@Column('integer')
paramInt!: number
@Column('bigint', { transformer: bigintTransformer })
paramBigInt!: number
@Column('varchar')
paramBytes!: string
+3 -2
View File
@@ -584,10 +584,11 @@ export class Indexer implements IndexerInterface {
switch (logDescription.name) {
case TEST_EVENT: {
eventName = logDescription.name;
const { param1, param2 } = logDescription.args;
const { param1, param2, param3 } = logDescription.args;
eventInfo = {
param1,
param2
param2,
param3: BigInt(param3.toString())
};
break;
@@ -5,6 +5,8 @@
import assert from 'assert';
import BigInt from 'apollo-type-bigint';
import debug from 'debug';
import Decimal from 'decimal.js';
import { GraphQLScalarType } from 'graphql';
import { ValueResult, BlockHeight } from '@vulcanize/util';
@@ -23,6 +25,19 @@ export const createResolvers = async (indexer: Indexer, eventWatcher: EventWatch
return {
BigInt: new BigInt('bigInt'),
BigDecimal: new GraphQLScalarType({
name: 'BigDecimal',
description: 'BigDecimal custom scalar type',
parseValue (value) {
// value from the client
return new Decimal(value);
},
serialize (value: Decimal) {
// value sent to the client
return value.toFixed();
}
}),
Event: {
__resolveType: (obj: any) => {
assert(obj.__typename);
@@ -62,6 +62,7 @@ union Event = TestEvent
type TestEvent {
param1: String!
param2: Int!
param3: BigInt!
}
type ResultIPLDBlock {
@@ -110,6 +111,7 @@ type Author {
name: String!
rating: BigDecimal!
paramInt: Int!
paramBigInt: BigInt!
paramBytes: Bytes!
blogs: [Blog!]!
}