Skip to content

Commit 0b14f58

Browse files
authored
search endpoint (#161)
Implements a search endpoint * For a numeric value, tries to fetch a block * For a hash value (length 66 with 0x) tries to fetch a block, a transaction and logs by signature. Whichever returns data first will be returned * For a hash value (length 10) fetches transactions with that function selector * For addresses, uses RPC to check for code. If not configured, looks at latest transactions and determines if it's a contract or not. For EOAs returns last 20 initiated transactions For contracts returns last 20 received transactions
2 parents 3d393c8 + acda5f8 commit 0b14f58

File tree

8 files changed

+757
-0
lines changed

8 files changed

+757
-0
lines changed

cmd/api.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ func RunApi(cmd *cobra.Command, args []string) {
8989

9090
// token holder queries
9191
root.GET("/holders/:address", handlers.GetTokenHoldersByType)
92+
93+
// search
94+
root.GET("/search/:input", handlers.Search)
9295
}
9396

9497
r.GET("/health", func(c *gin.Context) {

cmd/root.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ func init() {
100100
rootCmd.PersistentFlags().String("api-host", "localhost:3000", "API host")
101101
rootCmd.PersistentFlags().String("api-basicAuth-username", "", "API basic auth username")
102102
rootCmd.PersistentFlags().String("api-basicAuth-password", "", "API basic auth password")
103+
rootCmd.PersistentFlags().String("api-thirdweb-clientId", "", "Thirdweb client id")
103104
viper.BindPFlag("rpc.url", rootCmd.PersistentFlags().Lookup("rpc-url"))
104105
viper.BindPFlag("rpc.blocks.blocksPerRequest", rootCmd.PersistentFlags().Lookup("rpc-blocks-blocksPerRequest"))
105106
viper.BindPFlag("rpc.blocks.batchDelay", rootCmd.PersistentFlags().Lookup("rpc-blocks-batchDelay"))
@@ -164,6 +165,7 @@ func init() {
164165
viper.BindPFlag("api.host", rootCmd.PersistentFlags().Lookup("api-host"))
165166
viper.BindPFlag("api.basicAuth.username", rootCmd.PersistentFlags().Lookup("api-basicAuth-username"))
166167
viper.BindPFlag("api.basicAuth.password", rootCmd.PersistentFlags().Lookup("api-basicAuth-password"))
168+
viper.BindPFlag("api.thirdweb.clientId", rootCmd.PersistentFlags().Lookup("api-thirdweb-clientId"))
167169
rootCmd.AddCommand(orchestratorCmd)
168170
rootCmd.AddCommand(apiCmd)
169171
}

configs/config.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,16 @@ type BasicAuthConfig struct {
118118
Password string `mapstructure:"password"`
119119
}
120120

121+
type ThirdwebConfig struct {
122+
ClientId string `mapstructure:"clientId"`
123+
}
124+
121125
type APIConfig struct {
122126
Host string `mapstructure:"host"`
123127
BasicAuth BasicAuthConfig `mapstructure:"basicAuth"`
124128
ThirdwebContractApi string `mapstructure:"thirdwebContractApi"`
125129
AbiDecodingEnabled bool `mapstructure:"abiDecodingEnabled"`
130+
Thirdweb ThirdwebConfig `mapstructure:"thirdweb"`
126131
}
127132

128133
type Config struct {

configs/secrets.example.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ api:
55
basicAuth:
66
username: admin
77
password: admin
8+
thirdweb:
9+
clientId: 123abc
810

911
storage:
1012
main:

0 commit comments

Comments
 (0)