-
Notifications
You must be signed in to change notification settings - Fork 5
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
Conversation
1f4aedd
to
22d44cb
Compare
Need to add the limit check (10 < L < 400) on all requests with limit as param. Could move the logic from account_lines into a helped method and call that in all places? |
Not all functions that have a limit have the same bounds, e.g. crawl shards 1<= l <= 3, account nfts 20 <= l <= 400 Functions that take a limit also explicitly state that invalid values are changed to the closest valid value. Is it really necessary to validate the values when the ledger will accept and correct invalid values? |
Ahh fairs if they will be different for others. It's just that some with the same bounds have been validated and some not (e.g. account_channels and account_lines). Unless i'm mistaken. Does account_lines not need that limit validation then? |
I don't know of any method where an invalid limit will return with an error |
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.
do we need to check for NFTokenID not empty?
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.
check for pub key not empty and potentially that it's base58 encoded?
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.
Channel id is 64 char hex string, worth checking for the validate?
XRP amount looks like a required parameter.
also a check for “The request must specify exactly one of secret, seed, seed_hex, or passphrase.”
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.
I implemented XRPAmount as an integer, so if it is not set it would be 0 which would be valid
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.
Looks like these are required:
- XRP Amount
- Channel id (64 char hex string)
- Public key (hex or base58 string)
- Signature (hex string)
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.
XRP Amount same as above, 0 is valid
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.
should we check if ledger_hash is provided that it's a 20 byte hex string?
if a.Account == "" { | ||
return errors.New("no account ID specified") | ||
func (r *AccountChannelsRequest) Validate() error { | ||
if err := r.Account.Validate(); err != 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
@@ -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 comment
The 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
|
||
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.
Do we need to add the 'amm' and 'nft_page' options too? They're not in the request struct so may have been recently added
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.
AMM does not appear to be getting approved too soon
we can do AMM support once it is reaching final stages of approval into rippled
|
||
if r.RippleState != nil { | ||
setCount++ | ||
if err := r.Offer.Validate(); err != 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.
should this be r.rippleState.Validate() ?
@@ -37,6 +118,10 @@ type DirectoryEntryReq struct { | |||
Owner string `json:"owner,omitempty"` | |||
} | |||
|
|||
func (*DirectoryEntryReq) Validate() error { | |||
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.
should this have the logic for: requires either dir_root or owner as a sub-field
type TicketEntryReq struct { | ||
Account types.Address `json:"account"` | ||
TicketSeq int `json:"ticket_seq"` | ||
} | ||
|
||
func (*TicketEntryReq) LedgerEntryRequestField() {} | ||
|
||
func (r *TicketEntryReq) Validate() error { |
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.
Number also required here I think
@@ -12,3 +12,7 @@ type TxRequest struct { | |||
func (*TxRequest) Method() string { | |||
return "tx" | |||
} | |||
|
|||
func (*TxRequest) Validate() error { | |||
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.
Think we need to validate transaction is not empty here?
@@ -38,3 +38,7 @@ func (t *TransactionEntryRequest) UnmarshalJSON(data []byte) error { | |||
t.LedgerIndex = i | |||
return nil | |||
} | |||
|
|||
func (*TransactionEntryRequest) Validate() error { | |||
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.
Again, do we not need to validate the tx_hash is not empty here?
@@ -35,3 +35,7 @@ func (r *SubmitMultisignedRequest) UnmarshalJSON(data []byte) error { | |||
|
|||
return nil | |||
} | |||
|
|||
func (*SubmitMultisignedRequest) Validate() error { | |||
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.
Need to validate on the tx_json as it's required. Think just a nil check would be ok here without getting into the json itself?
@@ -8,3 +8,7 @@ type SubmitRequest struct { | |||
func (*SubmitRequest) Method() string { | |||
return "submit" | |||
} | |||
|
|||
func (*SubmitRequest) Validate() error { | |||
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.
Need to check tx_blob as it's required
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.
Ohhhh I've just thought - are these going to be validated differently? We need to build out our submit methods but these will build out the tx_blob anyway, so won't need to validate on it?
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.
We can have this request constructed by a helper method that would validate the transaction during construction
This request should probably still validate that the blob is at least set
@@ -10,3 +10,7 @@ type WalletProposeRequest struct { | |||
func (*WalletProposeRequest) Method() string { | |||
return "wallet_propose" | |||
} | |||
|
|||
func (*WalletProposeRequest) Validate() error { | |||
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.
key_type is a required param
Need to add the logic for:
You must provide at most one of the following fields: passphrase, seed, or seed_hex
So cannot have more than one of them.
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.
Or ir does say you can run it with no params to create a random seed, so maybe don't need the required check on key_type
@@ -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 comment
The 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
@@ -8,3 +8,7 @@ type ConnectRequest struct { | |||
func (*ConnectRequest) Method() string { | |||
return "connect" | |||
} | |||
|
|||
func (*ConnectRequest) Validate() error { | |||
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.
ip is a required param
@@ -8,3 +8,7 @@ type PeerReservationAddRequest struct { | |||
func (*PeerReservationAddRequest) Method() string { | |||
return "peer_reservations_add" | |||
} | |||
|
|||
func (*PeerReservationAddRequest) Validate() error { | |||
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.
public_key is a required field. Also should be base58 encoded, so should we do a check on that? Not sure yet how will talk to Josh
@@ -7,3 +7,7 @@ type PeerReservationDelRequest struct { | |||
func (*PeerReservationDelRequest) Method() string { | |||
return "peer_reservations_del" | |||
} | |||
|
|||
func (*PeerReservationDelRequest) Validate() error { |
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.
Again need to think how we do a check on the public_key
@@ -7,3 +7,7 @@ type GetCountsRequest struct { | |||
func (*GetCountsRequest) Method() string { | |||
return "get_counts" | |||
} | |||
|
|||
func (*GetCountsRequest) Validate() error { |
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.
not sure if min_count is really required or not
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.
Does this cover these cases?:
Provide the seed in the secret field and omit the key_type field. This value can be formatted as an XRP Ledger [base58](https://xrpl.org/base58-encodings.html) seed, RFC-1751, hexadecimal, or as a string passphrase. (secp256k1 keys only) Provide a key_type value and exactly one of seed, seed_hex, or passphrase. Omit the secret field. (Not supported by the commandline syntax.)
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.
I currently don't do any validation of string format
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.
Fee and Sequence must be provided in the tx_json object and also signingpubkey must be provided with an empty string as the value. Can we do this in validate func?
Also below is similar to sign_request:
`You must provide exactly 1 field with the secret key, which can be either of the following:
Provide a secret value and omit the key_type field. This value can be formatted as an XRP Ledger base58 seed, RFC-1751, hexadecimal, or as a string passphrase. (secp256k1 keys only)
Provide a key_type value and exactly one of seed, seed_hex, or passphrase. Omit the secret field. (Not supported by the commandline syntax.)`
No description provided.