-
Notifications
You must be signed in to change notification settings - Fork 69
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: fixed namespaceID parsing from toml #373
Merged
mtsitrin
merged 2 commits into
main
from
mtsitrin/372-error-parsing-namespaceid-from-toml-file
Jun 27, 2023
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package celestia | ||
|
||
import ( | ||
"encoding/hex" | ||
"encoding/json" | ||
"time" | ||
) | ||
|
||
const ( | ||
defaultTxPollingRetryDelay = 20 * time.Second | ||
defaultSubmitRetryDelay = 10 * time.Second | ||
defaultTxPollingAttempts = 5 | ||
) | ||
|
||
// Config stores Celestia DALC configuration parameters. | ||
type Config struct { | ||
BaseURL string `json:"base_url"` | ||
AppNodeURL string `json:"app_node_url"` | ||
Timeout time.Duration `json:"timeout"` | ||
Fee int64 `json:"fee"` | ||
GasLimit uint64 `json:"gas_limit"` | ||
NamespaceID [8]byte //`json:"namespace_id"` | ||
} | ||
|
||
// Define an auxiliary type to prevent infinite recursion in UnmarshalJSON | ||
type auxConfig struct { | ||
BaseURL string `json:"base_url"` | ||
AppNodeURL string `json:"app_node_url"` | ||
Timeout time.Duration `json:"timeout"` | ||
Fee int64 `json:"fee"` | ||
GasLimit uint64 `json:"gas_limit"` | ||
NamespaceID string `json:"namespace_id"` // In the auxiliary type, NamespaceID is a string | ||
} | ||
|
||
var CelestiaDefaultConfig = Config{ | ||
BaseURL: "http://127.0.0.1:26659", | ||
AppNodeURL: "", | ||
Timeout: 30 * time.Second, | ||
Fee: 20000, | ||
GasLimit: 20000000, | ||
NamespaceID: [8]byte{0, 0, 0, 0, 0, 0, 255, 255}, | ||
} | ||
|
||
// UnmarshalJSON on Config type | ||
func (c *Config) UnmarshalJSON(data []byte) error { | ||
var aux auxConfig | ||
if err := json.Unmarshal(data, &aux); err != nil { | ||
return err | ||
} | ||
|
||
// Decode NamespaceID from string to byte array | ||
namespaceBytes, err := hex.DecodeString(aux.NamespaceID) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// Copy the decoded bytes into NamespaceID | ||
copy(c.NamespaceID[:], namespaceBytes) | ||
|
||
// Copy other fields | ||
c.BaseURL = aux.BaseURL | ||
c.AppNodeURL = aux.AppNodeURL | ||
c.Timeout = aux.Timeout | ||
c.Fee = aux.Fee | ||
c.GasLimit = aux.GasLimit | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't really like the duplication here. if I understand correctly the goal is to parse namespace id from string to bytes. I believe previously it has been done in the config file.
why do you think using AuxConfig is preferred?
Another option is possibly to add a field to the main config.
Creating 2 config which are basically the same but one field seems very confusing to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I'll figure out better way