Skip to content
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

Binary encode tx #46

Closed
wants to merge 34 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
f4d4f1b
account validation
CreatureDev Aug 21, 2023
294baa6
admin validation
CreatureDev Aug 22, 2023
f3c5352
improve error
CreatureDev Aug 22, 2023
651a7e4
channel validation
CreatureDev Aug 22, 2023
ec0b614
clio validation
CreatureDev Aug 22, 2023
efbcd0d
ledger request validation
CreatureDev Sep 7, 2023
1480b93
path/book validation
CreatureDev Sep 7, 2023
435b6c8
server request validation
CreatureDev Sep 11, 2023
4e762f2
subscribe validation
CreatureDev Sep 11, 2023
b762889
transactions validation
CreatureDev Sep 11, 2023
5c5a725
utility validation
CreatureDev Sep 11, 2023
22d44cb
addl tests
CreatureDev Sep 26, 2023
d8364f0
typo
CreatureDev Oct 21, 2023
0565c16
complete client impl
CreatureDev Oct 21, 2023
7c9fd4f
requested changes
CreatureDev Jan 18, 2024
0605fa5
Merge pull request #1 from xyield/pr/model-validation
CreatureDev Jan 30, 2024
e8e4e6d
Merge pull request #2 from xyield/pr/client-impl
CreatureDev Jan 30, 2024
95e2980
bugfixes
CreatureDev Jan 30, 2024
6a64aa5
change imports
CreatureDev Jan 30, 2024
30f5a78
fix response decoding
CreatureDev Feb 1, 2024
b847014
remainder of client
CreatureDev Feb 7, 2024
a7360f8
Update README.md
CreatureDev Feb 8, 2024
456af3b
nft history + clio client
CreatureDev Feb 8, 2024
4cd8ff2
chore: updated encode method to use transaction types
JCrawsh Sep 19, 2023
92c4967
chore: made uint a helper method to return a pointer
JCrawsh Sep 19, 2023
ce86a09
chore: added flag interface and fixed st array tests
JCrawsh Oct 23, 2023
4e84c19
chore: updated definitions.json
JCrawsh Nov 14, 2023
5187c9f
chore: added tests for uint types
JCrawsh Nov 14, 2023
6a059d5
chore: updated uint64 type and added tests
JCrawsh Nov 14, 2023
4784faf
chore: passing tests for all encode methods
JCrawsh Jan 4, 2024
88ec97d
chore: updated Encode method so don't need to include onlySigning input
JCrawsh Jan 4, 2024
7f6fe94
fix imports
CreatureDev Feb 19, 2024
57b9748
send response with error
CreatureDev Feb 19, 2024
b6876c2
have response with error
CreatureDev Feb 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
path/book validation
  • Loading branch information
CreatureDev committed Oct 5, 2023
commit 1480b93abec697c095748e6fc96c840f2a277f66
16 changes: 16 additions & 0 deletions model/client/path/book_offers_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package path

import (
"encoding/json"
"fmt"

"github.com/xyield/xrpl-go/model/client/common"
"github.com/xyield/xrpl-go/model/transactions/types"
Expand All @@ -20,6 +21,21 @@ func (*BookOffersRequest) Method() string {
return "book_offers"
}

func (r *BookOffersRequest) Validate() error {
if err := r.TakerGets.Validate(); err != nil {
return fmt.Errorf("book offers taker gets: %w", err)
}
if err := r.TakerPays.Validate(); err != nil {
return fmt.Errorf("book offers taker pays: %w", err)
}

if err := r.Taker.Validate(); r.Taker != "" && err != nil {
return fmt.Errorf("book offers taker: %w", err)
}

return nil
}

func (r *BookOffersRequest) UnmarshalJSON(data []byte) error {
type borHelper struct {
TakerGets types.IssuedCurrencyAmount `json:"taker_gets"`
Expand Down
12 changes: 12 additions & 0 deletions model/client/path/deposit_authorized_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package path

import (
"encoding/json"
"fmt"

"github.com/xyield/xrpl-go/model/client/common"
"github.com/xyield/xrpl-go/model/transactions/types"
Expand All @@ -18,6 +19,17 @@ func (*DepositAuthorizedRequest) Method() string {
return "deposit_authorized"
}

func (r *DepositAuthorizedRequest) Validate() error {
if err := r.SourceAccount.Validate(); err != nil {
return fmt.Errorf("deposit authorized source: %w", err)
}
if err := r.DestinationAccount.Validate(); err != nil {
return fmt.Errorf("deposit authorized destination: %w", err)
}

return nil
}

func (r *DepositAuthorizedRequest) UnmarshalJSON(data []byte) error {
type darHelper struct {
SourceAccount types.Address `json:"source_account"`
Expand Down
8 changes: 8 additions & 0 deletions model/client/path/nftoken_buy_offers_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package path

import (
"encoding/json"
"fmt"

"github.com/xyield/xrpl-go/model/client/common"
"github.com/xyield/xrpl-go/model/transactions/types"
Expand All @@ -19,6 +20,13 @@ func (*NFTokenBuyOffersRequest) Method() string {
return "nft_buy_offers"
}

func (r *NFTokenBuyOffersRequest) Validat() error {
if r.NFTokenID == "" {
return fmt.Errorf("nft buy offer missing token id")
}
return nil
}

func (r *NFTokenBuyOffersRequest) UnmarshalJSON(data []byte) error {
type borHelper struct {
NFTokenID types.NFTokenID `json:"nft_id"`
Expand Down
8 changes: 8 additions & 0 deletions model/client/path/nftoken_sell_offers_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package path

import (
"encoding/json"
"fmt"

"github.com/xyield/xrpl-go/model/client/common"
"github.com/xyield/xrpl-go/model/transactions/types"
Expand All @@ -19,6 +20,13 @@ func (*NFTokenSellOffersRequest) Method() string {
return "nft_sell_offers"
}

func (r *NFTokenSellOffersRequest) Validate() error {
if r.NFTokenID == "" {
return fmt.Errorf("nft sell offer missing token id")
}
return nil
}

func (r *NFTokenSellOffersRequest) UnmarshalJSON(data []byte) error {
type borHelper struct {
NFTokenID types.NFTokenID `json:"nft_id"`
Expand Down
26 changes: 26 additions & 0 deletions model/client/path/path_find_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package path

import (
"encoding/json"
"fmt"

"github.com/xyield/xrpl-go/model/transactions"
"github.com/xyield/xrpl-go/model/transactions/types"
Expand All @@ -28,6 +29,31 @@ func (*PathFindRequest) Method() string {
return "path_find"
}

func (r *PathFindRequest) Validate() error {
switch r.Subcommand {
case CREATE:
if err := r.SourceAccount.Validate(); err != nil {
return fmt.Errorf("path find create source: %w", err)
}
if err := r.DestinationAccount.Validate(); err != nil {
return fmt.Errorf("path find create destination: %w", err)
}
if err := r.DestinationAmount.Validate(); err != nil {
return fmt.Errorf("path find create destination amount: %w", err)
}
if r.SendMax != nil {
if err := r.SendMax.Validate(); err != nil {
return fmt.Errorf("path find create send max: %w", err)
}
}
return nil
case CLOSE, STATUS:
return nil
default:
return fmt.Errorf("path find: invalid subcommand")
}
}

func (r *PathFindRequest) UnmarshalJSON(data []byte) error {
type pfrHelper struct {
Subcommand PathSubCommand `json:"subcommand"`
Expand Down
29 changes: 29 additions & 0 deletions model/client/path/ripple_path_find_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package path

import (
"encoding/json"
"fmt"

"github.com/xyield/xrpl-go/model/client/common"
"github.com/xyield/xrpl-go/model/transactions/types"
Expand All @@ -21,6 +22,34 @@ func (*RipplePathFindRequest) Method() string {
return "ripple_path_find"
}

func (r *RipplePathFindRequest) Validate() error {
if err := r.SourceAccount.Validate(); err != nil {
return fmt.Errorf("ripple path find source: %w", err)
}
if err := r.DestinationAccount.Validate(); err != nil {
return fmt.Errorf("ripple path find destination: %w", err)
}
if err := r.DestinationAmount.Validate(); err != nil {
return fmt.Errorf("ripple path find destination amount: %w", err)
}
if r.SendMax != nil && len(r.SourceCurrencies) != 0 {
return fmt.Errorf("ripple path find cannot have send max and source currencies set simultaneously")
}
if r.SendMax != nil {
if err := r.SendMax.Validate(); err != nil {
return fmt.Errorf("ripple path find send max: %w", err)
}
}
if len(r.SourceCurrencies) != 0 {
for _, c := range r.SourceCurrencies {
if err := c.Validate(); err != nil {
return fmt.Errorf("ripple path find source currencies: %w", err)
}
}
}
return nil
}

func (r *RipplePathFindRequest) UnmarshalJSON(data []byte) error {
type rpfHelper struct {
SourceAccount types.Address `json:"source_account"`
Expand Down
26 changes: 26 additions & 0 deletions model/transactions/types/currency_amount.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package types

import (
"encoding/json"
"fmt"
"strconv"
)

Expand All @@ -14,6 +15,7 @@ const (

type CurrencyAmount interface {
Kind() CurrencyKind
Validate() error
}

func UnmarshalCurrencyAmount(data []byte) (CurrencyAmount, error) {
Expand Down Expand Up @@ -42,6 +44,26 @@ type IssuedCurrencyAmount struct {
Value string `json:"value,omitempty"`
}

func (i IssuedCurrencyAmount) Validate() error {
if i.Currency == "" {
return fmt.Errorf("issued currency: missing currency code")
}
if i.Currency == "XRP" && i.Issuer != "" {
return fmt.Errorf("issued currency: xrp cannot be issued")

}
/*
// Issuer not required for source currencies field (path find request)
if i.Currency != "XRP" && i.Issuer == "" {
return fmt.Errorf("issued currency: non-xrp currencies require and issuer")
}
*/
if err := i.Issuer.Validate(); i.Issuer != "" && err != nil {
return fmt.Errorf("issued currency: %w", err)
}
return nil
}

func (IssuedCurrencyAmount) Kind() CurrencyKind {
return ISSUED
}
Expand All @@ -52,6 +74,10 @@ func (XRPCurrencyAmount) Kind() CurrencyKind {
return XRP
}

func (XRPCurrencyAmount) Validate() error {
return nil
}

func (a XRPCurrencyAmount) MarshalJSON() ([]byte, error) {
s := strconv.FormatUint(uint64(a), 10)
return json.Marshal(s)
Expand Down