@@ -6,67 +6,67 @@ import { TransactionEntity, GlobalTransferCounter } from '../../generated/schema
66const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000'
77
88function getGlobalTransferCounter ( ) : GlobalTransferCounter {
9- // Only one entry will be kept in this entity
10- let id = 'global-transfer-counter'
11- let entity = GlobalTransferCounter . load ( id )
12- if ( entity === null ) {
13- entity = new GlobalTransferCounter ( id )
14- entity . current = BigInt . fromI32 ( 0 )
15- }
16- return entity as GlobalTransferCounter
9+ // Only one entry will be kept in this entity
10+ let id = 'global-transfer-counter'
11+ let entity = GlobalTransferCounter . load ( id )
12+ if ( entity === null ) {
13+ entity = new GlobalTransferCounter ( id )
14+ entity . current = BigInt . fromI32 ( 0 )
15+ }
16+ return entity as GlobalTransferCounter
1717}
1818
1919export function handleSingleTransfer ( event : TransferSingle ) : void {
2020
21- // Try to get what's current global counter's state
22- // when called for very first time, it'll be `0`
23- let counter = getGlobalTransferCounter ( )
24- let updated = counter . current . plus ( BigInt . fromI32 ( 1 ) )
21+ // Try to get what's current global counter's state
22+ // when called for very first time, it'll be `0`
23+ let counter = getGlobalTransferCounter ( )
24+ let updated = counter . current . plus ( BigInt . fromI32 ( 1 ) )
2525
26- // Updating global counter's state
27- counter . current = updated
28- counter . save ( )
26+ // Updating global counter's state
27+ counter . current = updated
28+ counter . save ( )
2929
30- const isWithdraw = event . params . to . toHex ( ) === ZERO_ADDRESS || event . params . to === event . address ? true : false
30+ const isWithdraw = event . params . to . toHex ( ) === ZERO_ADDRESS || event . params . to === event . address ? true : false
3131
32- let transactionEntity = new TransactionEntity ( event . transaction . hash . toHex ( ) + '-' + event . logIndex . toString ( ) + ( isWithdraw ? '-withdraw' : '-transfer' ) )
33- transactionEntity . type = isWithdraw ? 'withdraw' : 'transfer'
34- transactionEntity . from = event . params . from
35- transactionEntity . to = event . params . to
36- transactionEntity . amount = event . params . value
37- transactionEntity . tokenId = event . params . id
38- transactionEntity . block = event . block . number
39- transactionEntity . timestamp = event . block . timestamp
40- transactionEntity . transaction = event . transaction . hash
41- transactionEntity . token = event . address
42- transactionEntity . tokenType = 'ERC1155'
43- transactionEntity . isPos = true
44- transactionEntity . save ( )
32+ let transactionEntity = new TransactionEntity ( event . transaction . hash . toHex ( ) + '-' + event . logIndex . toString ( ) + ( isWithdraw ? '-withdraw' : '-transfer' ) )
33+ transactionEntity . type = isWithdraw ? 'withdraw' : 'transfer'
34+ transactionEntity . from = event . params . from
35+ transactionEntity . to = event . params . to
36+ transactionEntity . amount = event . params . value
37+ transactionEntity . tokenId = event . params . id
38+ transactionEntity . block = event . block . number
39+ transactionEntity . timestamp = event . block . timestamp
40+ transactionEntity . transaction = event . transaction . hash
41+ transactionEntity . token = event . address
42+ transactionEntity . tokenType = 'ERC1155'
43+ transactionEntity . isPos = true
44+ transactionEntity . save ( )
4545}
4646
4747export function handleBatchTransfer ( event : TransferBatch ) : void {
48- // Try to get what's current global counter's state
49- // when called for very first time, it'll be `0`
50- let counter = getGlobalTransferCounter ( )
51- let updated = counter . current . plus ( BigInt . fromI32 ( 1 ) )
48+ // Try to get what's current global counter's state
49+ // when called for very first time, it'll be `0`
50+ let counter = getGlobalTransferCounter ( )
51+ let updated = counter . current . plus ( BigInt . fromI32 ( 1 ) )
5252
53- // Updating global counter's state
54- counter . current = updated
55- counter . save ( )
53+ // Updating global counter's state
54+ counter . current = updated
55+ counter . save ( )
5656
57- const isWithdraw = event . params . to . toHex ( ) === ZERO_ADDRESS || event . params . to === event . address ? true : false
57+ const isWithdraw = event . params . to . toHex ( ) === ZERO_ADDRESS || event . params . to === event . address ? true : false
5858
59- let transactionEntity = new TransactionEntity ( event . transaction . hash . toHex ( ) + '-' + event . logIndex . toString ( ) + ( isWithdraw ? '-withdraw' : '-transfer' ) )
59+ let transactionEntity = new TransactionEntity ( event . transaction . hash . toHex ( ) + '-' + event . logIndex . toString ( ) + ( isWithdraw ? '-withdraw' : '-transfer' ) )
6060
61- transactionEntity . type = isWithdraw ? 'withdraw' : 'transfer'
62- transactionEntity . from = event . params . from
63- transactionEntity . to = event . params . to
64- transactionEntity . amounts = event . params . values
65- transactionEntity . tokenIds = event . params . ids
66- transactionEntity . timestamp = event . block . timestamp
67- transactionEntity . transaction = event . transaction . hash
68- transactionEntity . token = event . address
69- transactionEntity . tokenType = 'ERC1155'
70- transactionEntity . isPos = true
71- transactionEntity . save ( )
61+ transactionEntity . type = isWithdraw ? 'withdraw' : 'transfer'
62+ transactionEntity . from = event . params . from
63+ transactionEntity . to = event . params . to
64+ transactionEntity . amounts = event . params . values
65+ transactionEntity . tokenIds = event . params . ids
66+ transactionEntity . timestamp = event . block . timestamp
67+ transactionEntity . transaction = event . transaction . hash
68+ transactionEntity . token = event . address
69+ transactionEntity . tokenType = 'ERC1155'
70+ transactionEntity . isPos = true
71+ transactionEntity . save ( )
7272}
0 commit comments