@@ -6,67 +6,67 @@ import { TransactionEntity, GlobalTransferCounter } from '../../generated/schema
6
6
const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000'
7
7
8
8
function 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
17
17
}
18
18
19
19
export function handleSingleTransfer ( event : TransferSingle ) : void {
20
20
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 ) )
25
25
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 ( )
29
29
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
31
31
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 ( )
45
45
}
46
46
47
47
export 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 ) )
52
52
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 ( )
56
56
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
58
58
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' ) )
60
60
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 ( )
72
72
}
0 commit comments