simplify increment

This commit is contained in:
ssallam 2020-12-02 12:09:22 +01:00
parent d834f6bdfa
commit 9a74178a62

View File

@ -22,19 +22,20 @@ export function handleTransfer(event: Transfer): void {
let ZERO_ADDRESS = '0x0000000000000000000000000000000000000000' let ZERO_ADDRESS = '0x0000000000000000000000000000000000000000'
let isMint = event.params.from.toHex() == ZERO_ADDRESS
let isBurn = event.params.to.toHex() == ZERO_ADDRESS
let amount = tokenToDecimal(event.params.value.toBigDecimal(), 18) let amount = tokenToDecimal(event.params.value.toBigDecimal(), 18)
let tokenShareFrom = event.params.from.toHex() let tokenShareFrom = event.params.from.toHex()
let tokenShareTo = event.params.to.toHex() let tokenShareTo = event.params.to.toHex()
let tokenBalanceFromId = tokenId.concat('-').concat(event.params.from.toHex()) let tokenBalanceFromId = tokenId.concat('-').concat(tokenShareFrom)
let tokenBalanceToId = tokenId.concat('-').concat(event.params.to.toHex()) let tokenBalanceToId = tokenId.concat('-').concat(tokenShareTo)
let tokenBalanceFrom = TokenBalance.load(tokenBalanceFromId) let tokenBalanceFrom = TokenBalance.load(tokenBalanceFromId)
let tokenBalanceTo = TokenBalance.load(tokenBalanceToId) let tokenBalanceTo = TokenBalance.load(tokenBalanceToId)
let oldBalanceFrom = BigDecimal.fromString('0.0') let oldBalanceFrom = BigDecimal.fromString('0.0')
let oldBalanceTo = BigDecimal.fromString('0.0') let oldBalanceTo = BigDecimal.fromString('0.0')
let isMint = tokenShareFrom == ZERO_ADDRESS
let isBurn = tokenShareTo == ZERO_ADDRESS
let datatoken = Datatoken.load(tokenId) let datatoken = Datatoken.load(tokenId)
if (isMint) { if (isMint) {
@ -66,7 +67,7 @@ export function handleTransfer(event: Transfer): void {
&& tokenBalanceTo.balance.notEqual(ZERO_BD) && tokenBalanceTo.balance.notEqual(ZERO_BD)
&& oldBalanceTo.equals(ZERO_BD) && oldBalanceTo.equals(ZERO_BD)
) { ) {
datatoken.holderCount = datatoken.holderCount.plus(BigInt.fromI32(1)) datatoken.holderCount += BigInt.fromI32(1)
} }
if ( if (
@ -74,7 +75,7 @@ export function handleTransfer(event: Transfer): void {
&& tokenBalanceFrom.balance.equals(ZERO_BD) && tokenBalanceFrom.balance.equals(ZERO_BD)
&& oldBalanceFrom.notEqual(ZERO_BD) && oldBalanceFrom.notEqual(ZERO_BD)
) { ) {
datatoken.holderCount = datatoken.holderCount.minus(BigInt.fromI32(1)) datatoken.holderCount -= BigInt.fromI32(1)
} }
datatoken.save() datatoken.save()