Skip to content

Commit

Permalink
requested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
CreatureDev committed Jan 18, 2024
1 parent d8364f0 commit 7c9fd4f
Show file tree
Hide file tree
Showing 19 changed files with 176 additions and 19 deletions.
8 changes: 7 additions & 1 deletion model/client/account/account_lines_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,19 @@ func (*AccountLinesRequest) Method() string {

func (r *AccountLinesRequest) Validate() error {
if err := r.Account.Validate(); err != nil {
return fmt.Errorf("account lines request: %w", err)
return fmt.Errorf("account lines request account: %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")
}

if r.Peer != "" {
if err := r.Peer.Validate(); err != nil {
return fmt.Errorf("account lines request peer: %w", err)
}
}

return nil
}
func (r *AccountLinesRequest) UnmarshalJSON(data []byte) error {
Expand Down
11 changes: 9 additions & 2 deletions model/client/admin/data/download_shard_request.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package data

import "github.com/xyield/xrpl-go/model/client/common"
import (
"fmt"

"github.com/xyield/xrpl-go/model/client/common"
)

type DownloadShardRequest struct {
Shards []ShardDescriptor `json:"shards"`
Expand All @@ -15,6 +19,9 @@ func (*DownloadShardRequest) Method() string {
return "download_shard"
}

func (*DownloadShardRequest) Validate() error {
func (d *DownloadShardRequest) Validate() error {
if len(d.Shards) == 0 {
return fmt.Errorf("download shard request: no shard descriptors provided")
}
return nil
}
17 changes: 16 additions & 1 deletion model/client/admin/key/wallet_propose_request.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package key

import "fmt"

type WalletProposeRequest struct {
KeyType string `json:"key_type,omitempty"`
Passphrase string `json:"passphrase,omitempty"`
Expand All @@ -11,6 +13,19 @@ func (*WalletProposeRequest) Method() string {
return "wallet_propose"
}

func (*WalletProposeRequest) Validate() error {
func (p *WalletProposeRequest) Validate() error {
cnt := 0
if p.Passphrase != "" {
cnt++
}
if p.Seed != "" {
cnt++
}
if p.SeedHex != "" {
cnt++
}
if cnt > 1 {
return fmt.Errorf("wallet propose request: only one of (passphrase, seed, seedhex) may be set")
}
return nil
}
7 changes: 6 additions & 1 deletion model/client/admin/peer/connect_request.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package peer

import "fmt"

type ConnectRequest struct {
IP string `json:"ip"`
Port int `json:"port,omitempty"`
Expand All @@ -9,6 +11,9 @@ func (*ConnectRequest) Method() string {
return "connect"
}

func (*ConnectRequest) Validate() error {
func (c *ConnectRequest) Validate() error {
if c.IP == "" {
return fmt.Errorf("connect request: missing ip")
}
return nil
}
7 changes: 6 additions & 1 deletion model/client/admin/peer/peer_reservations_add_request.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package peer

import "fmt"

type PeerReservationAddRequest struct {
PublicKey string `json:"public_key"`
Description string `json:"description,omitempty"`
Expand All @@ -9,6 +11,9 @@ func (*PeerReservationAddRequest) Method() string {
return "peer_reservations_add"
}

func (*PeerReservationAddRequest) Validate() error {
func (r *PeerReservationAddRequest) Validate() error {
if r.PublicKey == "" {
return fmt.Errorf("peer reservation add request: missing publickey")
}
return nil
}
7 changes: 6 additions & 1 deletion model/client/admin/peer/peer_reservations_del_request.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package peer

import "fmt"

type PeerReservationDelRequest struct {
PublicKey string `json:"public_key"`
}
Expand All @@ -8,6 +10,9 @@ func (*PeerReservationDelRequest) Method() string {
return "peer_reservations_del"
}

func (*PeerReservationDelRequest) Validate() error {
func (r *PeerReservationDelRequest) Validate() error {
if r.PublicKey == "" {
return fmt.Errorf("peer reservation del request: missing publickey")
}
return nil
}
17 changes: 17 additions & 0 deletions model/client/admin/signing/sign_for_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,23 @@ func (r *SignForRequest) Validate() error {
return fmt.Errorf("sign for request: empty tx")
}

cnt := 0
if r.Secret != "" {
cnt++
}
if r.Seed != "" {
cnt++
}
if r.SeedHex != "" {
cnt++
}
if r.Passphrase != "" {
cnt++
}
if cnt != 1 {
return fmt.Errorf("sign for request: must provide one of (secret, seed, seedhex, passphrase)")
}

return nil
}

Expand Down
20 changes: 19 additions & 1 deletion model/client/channel/channel_authorize_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,25 @@ func (r *ChannelAuthorizeRequest) Validate() error {
if r.ChannelID == "" {
return fmt.Errorf("channel authorize request: missing channel id")
}

var set []string
if r.Secret != "" {
set = append(set, "secret")
}
if r.Seed != "" {
set = append(set, "seed")
}
if r.SeedHex != "" {
set = append(set, "seed_hex")
}
if r.Passphrase != "" {
set = append(set, "passphrase")
}
if len(set) == 0 {
return fmt.Errorf("channel authorize request: at least one of (secret, seed, seed_hex, passphrase) must be set")
}
if len(set) > 1 {
return fmt.Errorf("channel authorize request: only one signing method required, currently set %v", set)
}
return nil
}

Expand Down
10 changes: 10 additions & 0 deletions model/client/channel/channel_authorize_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,15 @@ func TestChannelAuthorizeValidate(t *testing.T) {
ChannelID: "abc",
}
err = s.Validate()
assert.ErrorContains(t, err, "seed")
s = ChannelAuthorizeRequest{
ChannelID: "abc",
Seed: "123",
}
err = s.Validate()
assert.Nil(t, err)
s.Secret = "def"
err = s.Validate()
assert.ErrorContains(t, err, "seed")
assert.ErrorContains(t, err, "secret")
}
19 changes: 16 additions & 3 deletions model/client/channel/channel_verify_request.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package channel

import "github.com/xyield/xrpl-go/model/transactions/types"
import (
"fmt"

"github.com/xyield/xrpl-go/model/transactions/types"
)

type ChannelVerifyRequest struct {
Amount types.XRPCurrencyAmount `json:"amount"`
ChannelID string `json:"channel_id"`
ChannelID types.Hash256 `json:"channel_id"`
PublicKey string `json:"public_key"`
Signature string `json:"signature"`
}
Expand All @@ -13,6 +17,15 @@ func (*ChannelVerifyRequest) Method() string {
return "channel_verify"
}

func (*ChannelVerifyRequest) Validate() error {
func (r *ChannelVerifyRequest) Validate() error {
if err := r.ChannelID.Validate(); err != nil {
return fmt.Errorf("channel verify request: channel id: %w", err)
}
if r.PublicKey == "" {
return fmt.Errorf("channel verify request: public key not set")
}
if r.Signature == "" {
return fmt.Errorf("channel verify request: signature not set")
}
return nil
}
6 changes: 5 additions & 1 deletion model/client/clio/nft_info_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package clio

import (
"encoding/json"
"fmt"

"github.com/xyield/xrpl-go/model/client/common"
"github.com/xyield/xrpl-go/model/transactions/types"
Expand All @@ -17,7 +18,10 @@ func (*NFTInfoRequest) Method() string {
return "nft_info"
}

func (*NFTInfoRequest) Validate() error {
func (r *NFTInfoRequest) Validate() error {
if err := r.NFTokenID.Validate(); err != nil {
return fmt.Errorf("nft info request: %w", err)
}
return nil
}

Expand Down
7 changes: 6 additions & 1 deletion model/client/ledger/ledger_entry_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type LedgerEntryRequest struct {
PaymentChannel string `json:"payment_channel,omitempty"`
DepositPreauth EntryRequestOrString `json:"deposit_preauth,omitempty"`
Ticket EntryRequestOrString `json:"ticket,omitempty"`
NFTPage string `json:"nft_page,omitempty"`
}

func (*LedgerEntryRequest) Method() string {
Expand Down Expand Up @@ -58,7 +59,7 @@ func (r *LedgerEntryRequest) Validate() error {

if r.RippleState != nil {
setCount++
if err := r.Offer.Validate(); err != nil {
if err := r.RippleState.Validate(); err != nil {
return fmt.Errorf("ledger entry ripple state: %w", err)
}
}
Expand Down Expand Up @@ -92,6 +93,10 @@ func (r *LedgerEntryRequest) Validate() error {
}
}

if r.NFTPage != "" {
setCount++
}

if setCount != 1 {
return fmt.Errorf("ledger entry: exactly one ledger entry object may be requested, found %d", setCount)
}
Expand Down
7 changes: 6 additions & 1 deletion model/client/server/manifest_request.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package server

import "fmt"

type ManifestRequest struct {
PublicKey string `json:"public_key"`
}
Expand All @@ -8,6 +10,9 @@ func (*ManifestRequest) Method() string {
return "manifest"
}

func (*ManifestRequest) Validate() error {
func (r *ManifestRequest) Validate() error {
if r.PublicKey == "" {
return fmt.Errorf("manifest request: public key not set")
}
return nil
}
6 changes: 5 additions & 1 deletion model/client/transactions/submit_multisigned_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package transactions

import (
"encoding/json"
"fmt"

"github.com/xyield/xrpl-go/model/transactions"
)
Expand Down Expand Up @@ -36,6 +37,9 @@ func (r *SubmitMultisignedRequest) UnmarshalJSON(data []byte) error {
return nil
}

func (*SubmitMultisignedRequest) Validate() error {
func (s *SubmitMultisignedRequest) Validate() error {
if s.Tx == nil {
return fmt.Errorf("submit multisigned request: missing tx")
}
return nil
}
7 changes: 6 additions & 1 deletion model/client/transactions/submit_request.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package transactions

import "fmt"

type SubmitRequest struct {
TxBlob string `json:"tx_blob"`
FailHard bool `json:"fail_hard,omitempty"`
Expand All @@ -9,6 +11,9 @@ func (*SubmitRequest) Method() string {
return "submit"
}

func (*SubmitRequest) Validate() error {
func (s *SubmitRequest) Validate() error {
if s.TxBlob == "" {
return fmt.Errorf("submit request: missing txblob")
}
return nil
}
6 changes: 5 additions & 1 deletion model/client/transactions/transaction_entry_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package transactions

import (
"encoding/json"
"fmt"

"github.com/xyield/xrpl-go/model/client/common"
)
Expand Down Expand Up @@ -39,6 +40,9 @@ func (t *TransactionEntryRequest) UnmarshalJSON(data []byte) error {
return nil
}

func (*TransactionEntryRequest) Validate() error {
func (t *TransactionEntryRequest) Validate() error {
if t.TxHash == "" {
return fmt.Errorf("transaction entry request: missing txhash")
}
return nil
}
11 changes: 9 additions & 2 deletions model/client/transactions/tx_request.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package transactions

import "github.com/xyield/xrpl-go/model/client/common"
import (
"fmt"

"github.com/xyield/xrpl-go/model/client/common"
)

type TxRequest struct {
Transaction string `json:"transaction"`
Expand All @@ -13,6 +17,9 @@ func (*TxRequest) Method() string {
return "tx"
}

func (*TxRequest) Validate() error {
func (t *TxRequest) Validate() error {
if t.Transaction == "" {
return fmt.Errorf("transaction request: missing transaction")
}
return nil
}
12 changes: 12 additions & 0 deletions model/transactions/types/hash256.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
package types

import "fmt"

type Hash256 string

func (h Hash256) Validate() error {
if h == "" {
return fmt.Errorf("hash256 value not set")
}
if len(h) != 64 {
return fmt.Errorf("hash256 length was not expected 64 characters")
}
return nil
}
Loading

0 comments on commit 7c9fd4f

Please sign in to comment.