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
@@ -13,6 +13,12 @@
"internalType": "uint8",
"name": "param2",
"type": "uint8"
},
{
"indexed": false,
"internalType": "uint256",
"name": "param3",
"type": "uint256"
}
],
"name": "Test",
@@ -30,6 +30,10 @@ export class Test__Params {
get param2(): i32 {
return this._event.parameters[1].value.toI32();
}
get param3(): BigInt {
return this._event.parameters[2].value.toBigInt();
}
}
export class Example1__structMethodResultValue0Struct extends ethereum.Tuple {
@@ -105,6 +105,7 @@ export class Author extends Entity {
this.set("name", Value.fromString(""));
this.set("rating", Value.fromBigDecimal(BigDecimal.zero()));
this.set("paramInt", Value.fromI32(0));
this.set("paramBigInt", Value.fromBigInt(BigInt.zero()));
this.set("paramBytes", Value.fromBytes(Bytes.empty()));
}
@@ -170,6 +171,15 @@ export class Author extends Entity {
this.set("paramInt", Value.fromI32(value));
}
get paramBigInt(): BigInt {
let value = this.get("paramBigInt");
return value!.toBigInt();
}
set paramBigInt(value: BigInt) {
this.set("paramBigInt", Value.fromBigInt(value));
}
get paramBytes(): Bytes {
let value = this.get("paramBytes");
return value!.toBytes();
@@ -18,6 +18,7 @@ type Author @entity {
name: String! # string
rating: BigDecimal!
paramInt: Int! # uint8
paramBigInt: BigInt! # uint256
paramBytes: Bytes!
blogs: [Blog!]! @derivedFrom(field: "author")
}
@@ -10,6 +10,7 @@ export function handleTest (event: Test): void {
log.debug('event.address: {}', [event.address.toHexString()]);
log.debug('event.params.param1: {}', [event.params.param1]);
log.debug('event.params.param2: {}', [event.params.param2.toString()]);
log.debug('event.params.param3: {}', [event.params.param3.toString()]);
log.debug('event.block.hash: {}', [event.block.hash.toHexString()]);
log.debug('event.block.stateRoot: {}', [event.block.stateRoot.toHexString()]);
@@ -32,8 +33,9 @@ export function handleTest (event: Test): void {
// Entity fields can be set based on event parameters
author.name = event.params.param1;
author.paramInt = event.params.param2;
author.paramBigInt = event.params.param3;
author.paramBytes = event.address;
author.rating = BigDecimal.fromString('4');
author.rating = BigDecimal.fromString('3.2132354');
// Entities can be written to the store with `.save()`
author.save();
@@ -19,7 +19,7 @@ dataSources:
- name: Example1
file: ./abis/Example1.json
eventHandlers:
- event: Test(string,uint8)
- event: Test(string,uint8,uint256)
handler: handleTest
blockHandlers:
- handler: handleBlock