Skip to content

Commit

Permalink
Add: URL&Protocol in cmd
Browse files Browse the repository at this point in the history
  • Loading branch information
TianyueLi1227 committed Apr 29, 2024
1 parent 387df00 commit 706d56a
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 6 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ See [Details](#preparing-configjson) of how to set up your own `config.json`.
go build

# Run the committee indexer with providing service
./modular-indexer-committee --cfg ./path/to/your/config.json --name "YourServiceName" --committee --service
./modular-indexer-committee --cfg ./path/to/your/config.json --name "YourServiceName" --url "YourServiceURL" --protocol "meta-protocol" --committee --service

# Run the committee indexer in test mode
./modular-indexer-committee --cfg ./path/to/your/config.json --name "YourServiceName" --committee --service -t --blockheight 780010
Expand All @@ -81,6 +81,10 @@ Below are the explanation for each of the command flags.

- `--name` `(-n)`: Indicate the name of the committee indexer service. This is useful for identifying different instances or configurations of the indexer.

- `--url` `(-u)`: Indicate the url of the committee indexer service. Usually this prameter is the public IP address or the domain name of your machine.

- `--protocol`: Indicate the meta protocol supported by the committee indexer. Currently, only BRC-20 is supported by committee indexer. Please name it as `brc-20` by default.

- `--committee`: This flag activates the committee functionality. When enabled, the committee indexer will publish checkpoints to the DA layer/S3.

- `--service` `(-s)`: Use this flag to activate web service from committee indexer. When enabled, the committee indexer will provide web service for incoming query.
Expand Down
8 changes: 7 additions & 1 deletion cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ type RuntimeArguments struct {
EnablePprof bool
ConfigFilePath string
CommitteeIndexerName string
CommitteeIndexerURL string
ProtocolName string
}

func NewRuntimeArguments() *RuntimeArguments {
Expand Down Expand Up @@ -54,6 +56,8 @@ leveraging Bitcoin's immutable and decentralized nature to provide a Turing-comp

log.Printf("The path of the config file is %s\n", arguments.ConfigFilePath)
log.Printf("The name of the committee indexer service is %s\n", arguments.CommitteeIndexerName)
log.Printf("The url of the committee indexer service is %s\n", arguments.CommitteeIndexerURL)
log.Printf("The meta protocol chosen is %s\n", arguments.ProtocolName)

Execution(arguments)
},
Expand All @@ -66,6 +70,8 @@ leveraging Bitcoin's immutable and decentralized nature to provide a Turing-comp
rootCmd.Flags().UintVar(&arguments.TestBlockHeightLimit, "blockheight", 0, "When -test enabled, you can set TestBlockHeightLimit as a fixed value you want")
rootCmd.Flags().BoolVar(&arguments.EnablePprof, "pprof", false, "Enable the pprof HTTP handler (at `/debug/pprof/`)")
rootCmd.Flags().StringVar(&arguments.ConfigFilePath, "cfg", "config.json", "Indicate the path of config file")
rootCmd.Flags().StringVarP(&arguments.CommitteeIndexerName, "name", "n", "default", "Indicate the name of the committee indexer service")
rootCmd.Flags().StringVarP(&arguments.CommitteeIndexerName, "name", "n", "", "Indicate the name of the committee indexer service")
rootCmd.Flags().StringVarP(&arguments.CommitteeIndexerURL, "url", "u", "", "Indicate the url of the committee indexer service")
rootCmd.Flags().StringVar(&arguments.ProtocolName, "protocol", "brc-20", "Indicate the meta protocol supported by the committee indexer")
return rootCmd
}
1 change: 1 addition & 0 deletions config.example.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
}
},
"service": {
"name": "YourServiceName",
"url": "YourCommitteeIndexerServiceURL",
"metaProtocol": "brc-20"
}
Expand Down
1 change: 1 addition & 0 deletions globals.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type Config struct {
} `json:"da"`
} `json:"report"`
Service struct {
Name string `json:"name"`
URL string `json:"url"`
MetaProtocol string `json:"metaProtocol"`
} `json:"service"`
Expand Down
24 changes: 20 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,11 @@ func ServiceStage(ordGetter getter.OrdGetter, arguments *RuntimeArguments, queue
var history = make(map[string]checkpoint.UploadRecord)

if arguments.EnableService {
log.Printf("Providing API service at: %s", GlobalConfig.Service.URL)
if arguments.CommitteeIndexerURL != "" {
log.Printf("Providing API service at: %s", arguments.CommitteeIndexerURL)
} else {
log.Printf("Providing API service at: %s", GlobalConfig.Service.URL)
}
go apis.StartService(queue, arguments.EnableCommittee, arguments.EnableTest, arguments.EnablePprof)
}

Expand Down Expand Up @@ -157,11 +161,23 @@ func ServiceStage(ordGetter getter.OrdGetter, arguments *RuntimeArguments, queue
for _, i := range hs {
key := fmt.Sprintf("%d", i.Height) + i.Hash
if curRecord, found := history[key]; !(found && curRecord.Success) {
committeeIndexerName := GlobalConfig.Service.Name
if arguments.CommitteeIndexerName != "" {
committeeIndexerName = arguments.CommitteeIndexerName
}
serviceURL := GlobalConfig.Service.URL
if arguments.CommitteeIndexerURL != "" {
serviceURL = arguments.CommitteeIndexerURL
}
metaProtocol := GlobalConfig.Service.MetaProtocol
if arguments.ProtocolName != "" {
metaProtocol = arguments.ProtocolName
}
indexerID := checkpoint.IndexerIdentification{
URL: GlobalConfig.Service.URL,
Name: arguments.CommitteeIndexerName,
URL: serviceURL,
Name: committeeIndexerName,
Version: Version,
MetaProtocol: GlobalConfig.Service.MetaProtocol,
MetaProtocol: metaProtocol,
}
commitment := base64.StdEncoding.EncodeToString(i.VerkleCommit[:])
c := checkpoint.NewCheckpoint(&indexerID, i.Height, i.Hash, commitment)
Expand Down

0 comments on commit 706d56a

Please sign in to comment.