-
Notifications
You must be signed in to change notification settings - Fork 3
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
Model validation #39
base: main
Are you sure you want to change the base?
Model validation #39
Changes from 12 commits
f4d4f1b
294baa6
f3c5352
651a7e4
ec0b614
efbcd0d
1480b93
435b6c8
4e762f2
b762889
5c5a725
22d44cb
d8364f0
7c9fd4f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ package account | |
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
|
||
"github.com/xyield/xrpl-go/model/client/common" | ||
"github.com/xyield/xrpl-go/model/transactions/types" | ||
|
@@ -20,6 +21,17 @@ func (*AccountLinesRequest) Method() string { | |
return "account_lines" | ||
} | ||
|
||
func (r *AccountLinesRequest) Validate() error { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Need to also run the account.Validate on the 'peer' parameter if it is present |
||
if err := r.Account.Validate(); err != nil { | ||
return fmt.Errorf("account lines request: %w", err) | ||
} | ||
|
||
if r.Limit != 0 && (r.Limit < 10 || r.Limit > 400) { | ||
return fmt.Errorf("account lines request: invalid limit, must be 10 <= limit <= 400") | ||
} | ||
|
||
return nil | ||
} | ||
func (r *AccountLinesRequest) UnmarshalJSON(data []byte) error { | ||
type alrHelper struct { | ||
Account types.Address `json:"account"` | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,3 +14,7 @@ type ShardDescriptor struct { | |
func (*DownloadShardRequest) Method() string { | ||
return "download_shard" | ||
} | ||
|
||
func (*DownloadShardRequest) Validate() error { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should we assert on shards not being nil? Bit stupid if user does send empty tho |
||
return nil | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,25 @@ | ||
package data | ||
|
||
const ( | ||
Fatal LogSeverity = "fatal" | ||
Error LogSeverity = "error" | ||
Warn LogSeverity = "warn" | ||
Info LogSeverity = "info" | ||
Debug LogSeverity = "debug" | ||
Trace LogSeverity = "trace" | ||
) | ||
|
||
type LogSeverity string | ||
|
||
type LogLevelRequest struct { | ||
Severity string `json:"severity,omitempty"` | ||
Partition string `json:"partition,omitempty"` | ||
Severity LogSeverity `json:"severity,omitempty"` | ||
Partition string `json:"partition,omitempty"` | ||
} | ||
|
||
func (*LogLevelRequest) Method() string { | ||
return "log_level" | ||
} | ||
|
||
func (*LogLevelRequest) Validate() error { | ||
return nil | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,19 @@ | ||
package data | ||
|
||
import "fmt" | ||
|
||
type NodeToShardRequest struct { | ||
Action string `json:"action"` | ||
} | ||
|
||
func (*NodeToShardRequest) Method() string { | ||
return "node_to_shard" | ||
} | ||
|
||
func (r *NodeToShardRequest) Validate() error { | ||
if r.Action != "start" && r.Action != "stop" && r.Action != "status" { | ||
return fmt.Errorf("node to shard request: invalid action '%s'", r.Action) | ||
} | ||
|
||
return nil | ||
} |
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.
in the validate method there is still a
// TODO checksum
does that need adding still?
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 have not added any intricacies for checking valid values for thinks like addresses, keys or object IDs with encoded fields