github.com/TrueBlocks/trueblocks-core/src/apps/chifra@v0.0.0-20241022031540-b362680128f7/pkg/articulate/events.go (about) 1 package articulate 2 3 import ( 4 "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/base" 5 "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types" 6 ) 7 8 // transferTopic is here because these three topics make up almost all of the logs in the entire history 9 // of the chain, we get significant speed-ups if we handle these items without 10 // regular processing. 11 var transferTopic = base.HexToHash( 12 "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef", 13 ) 14 var ensTransferTopic = base.HexToHash( 15 "0xd4735d920b0f87494915f556dd9b54c8f309026070caea5c737245152564d266", 16 ) 17 var approvalTopic = base.HexToHash( 18 "0x8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925", 19 ) 20 21 func parseTransferEvent(log *types.Log) (function *types.Function) { 22 if len(log.Topics) < 3 || log.Topics[0] != transferTopic { 23 // TODO: Too short topics happens (sometimes) because the ABI says that the data is not 24 // TODO: index, but it is or visa versa. In either case, we get the same topic0. We need to 25 // TODO: attempt both with and without indexed parameters. See issues/1366. 26 return nil 27 } 28 29 function = &types.Function{} 30 function.Name = "Transfer" 31 function.FunctionType = "event" 32 function.Encoding = transferTopic.Hex() 33 function.Inputs = []types.Parameter{ 34 { 35 Name: "_from", 36 ParameterType: "address", 37 Value: log.Topics[1].Hex(), 38 }, 39 { 40 Name: "_to", 41 ParameterType: "address", 42 Value: log.Topics[2].Hex(), 43 }, 44 { 45 Name: "_amount", 46 ParameterType: "uint256", 47 Value: log.Data, 48 }, 49 } 50 return 51 } 52 53 func parseEnsTransferEvent(log *types.Log) (function *types.Function) { 54 if len(log.Topics) < 2 || log.Topics[0] != ensTransferTopic { 55 // TODO: Too short topics happens (sometimes) because the ABI says that the data is not 56 // TODO: index, but it is or visa versa. In either case, we get the same topic0. We need to 57 // TODO: attempt both with and without indexed parameters. See issues/1366. 58 return nil 59 } 60 61 function = &types.Function{} 62 function.Name = "Transfer" 63 function.FunctionType = "event" 64 function.Encoding = ensTransferTopic.Hex() 65 function.Inputs = []types.Parameter{ 66 { 67 Name: "_node", 68 ParameterType: "bytes32", 69 Value: log.Topics[1].Hex(), 70 }, 71 { 72 Name: "_owner", 73 ParameterType: "address", 74 Value: log.Data, 75 }, 76 } 77 return 78 } 79 80 func parseApprovalEvent(log *types.Log) (function *types.Function) { 81 if len(log.Topics) < 3 || log.Topics[0] != approvalTopic { 82 // TODO: Too short topics happens (sometimes) because the ABI says that the data is not 83 // TODO: index, but it is or visa versa. In either case, we get the same topic0. We need to 84 // TODO: attempt both with and without indexed parameters. See issues/1366. 85 return nil 86 } 87 88 function = &types.Function{} 89 function.Name = "Approval" 90 function.FunctionType = "event" 91 function.Encoding = approvalTopic.Hex() 92 function.Inputs = []types.Parameter{ 93 { 94 Name: "_owner", 95 ParameterType: "address", 96 Value: log.Topics[1].Hex(), 97 }, 98 { 99 Name: "_spender", 100 ParameterType: "address", 101 Value: log.Topics[2].Hex(), 102 }, 103 { 104 Name: "_amount", 105 ParameterType: "uint256", 106 Value: log.Data, 107 }, 108 } 109 return 110 }