diff --git a/model/client/path/ripple_path_find_request.go b/model/client/path/ripple_path_find_request.go index 3c272274..58dd35e4 100644 --- a/model/client/path/ripple_path_find_request.go +++ b/model/client/path/ripple_path_find_request.go @@ -8,13 +8,13 @@ import ( ) type RipplePathFindRequest struct { - SourceAccount types.Address `json:"source_account"` - DestinationAccount types.Address `json:"destination_account"` - DestinationAmount types.CurrencyAmount `json:"destination_amount"` - SendMax types.CurrencyAmount `json:"send_max,omitempty"` - SourceCurrencies []SourceCurrency `json:"source_currencies,omitempty"` - LedgerHash common.LedgerHash `json:"ledger_hash,omitempty"` - LedgerIndex common.LedgerSpecifier `json:"ledger_index,omitempty"` + SourceAccount types.Address `json:"source_account"` + DestinationAccount types.Address `json:"destination_account"` + DestinationAmount types.CurrencyAmount `json:"destination_amount"` + SendMax types.CurrencyAmount `json:"send_max,omitempty"` + SourceCurrencies []types.IssuedCurrencyAmount `json:"source_currencies,omitempty"` + LedgerHash common.LedgerHash `json:"ledger_hash,omitempty"` + LedgerIndex common.LedgerSpecifier `json:"ledger_index,omitempty"` } func (*RipplePathFindRequest) Method() string { @@ -23,13 +23,13 @@ func (*RipplePathFindRequest) Method() string { func (r *RipplePathFindRequest) UnmarshalJSON(data []byte) error { type rpfHelper struct { - SourceAccount types.Address `json:"source_account"` - DestinationAccount types.Address `json:"destination_account"` - DestinationAmount json.RawMessage `json:"destination_amount"` - SendMax json.RawMessage `json:"send_max,omitempty"` - SourceCurrencies []SourceCurrency `json:"source_currencies,omitempty"` - LedgerHash common.LedgerHash `json:"ledger_hash,omitempty"` - LedgerIndex json.RawMessage `json:"ledger_index,omitempty"` + SourceAccount types.Address `json:"source_account"` + DestinationAccount types.Address `json:"destination_account"` + DestinationAmount json.RawMessage `json:"destination_amount"` + SendMax json.RawMessage `json:"send_max,omitempty"` + SourceCurrencies []types.IssuedCurrencyAmount `json:"source_currencies,omitempty"` + LedgerHash common.LedgerHash `json:"ledger_hash,omitempty"` + LedgerIndex json.RawMessage `json:"ledger_index,omitempty"` } var h rpfHelper if err := json.Unmarshal(data, &h); err != nil { @@ -65,8 +65,3 @@ func (r *RipplePathFindRequest) UnmarshalJSON(data []byte) error { return nil } - -type SourceCurrency struct { - Currency string `json:"currency"` - Issuer types.Address `json:"issuer,omitempty"` -} diff --git a/model/client/path/ripple_path_find_test.go b/model/client/path/ripple_path_find_test.go new file mode 100644 index 00000000..81925620 --- /dev/null +++ b/model/client/path/ripple_path_find_test.go @@ -0,0 +1,201 @@ +package path + +import ( + "testing" + + "github.com/xyield/xrpl-go/model/transactions" + "github.com/xyield/xrpl-go/model/transactions/types" + "github.com/xyield/xrpl-go/test" +) + +func TestRipplePathFindRequest(t *testing.T) { + s := RipplePathFindRequest{ + SourceAccount: "r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59", + DestinationAccount: "r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59", + DestinationAmount: types.IssuedCurrencyAmount{ + Issuer: "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B", + Currency: "USD", + Value: "0.001", + }, + SourceCurrencies: []types.IssuedCurrencyAmount{ + { + Currency: "XRP", + }, + { + Currency: "USD", + }, + }, + } + + j := `{ + "source_account": "r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59", + "destination_account": "r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59", + "destination_amount": { + "issuer": "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B", + "currency": "USD", + "value": "0.001" + }, + "source_currencies": [ + { + "currency": "XRP" + }, + { + "currency": "USD" + } + ] +}` + if err := test.SerializeAndDeserialize(t, s, j); err != nil { + t.Error(err) + } +} + +func TestRipplePathFindResponse(t *testing.T) { + s := RipplePathFindResponse{ + Alternatives: []PathAlternative{ + { + PathsComputed: [][]transactions.PathStep{ + { + { + Currency: "USD", + Issuer: "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B", + }, + { + Account: "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B", + }, + }, + { + { + Currency: "USD", + Issuer: "rrpNnNLKrartuEqfJGpqyDwPj1AFPg9vn1", + }, + { + Account: "rrpNnNLKrartuEqfJGpqyDwPj1AFPg9vn1", + }, + { + Account: "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B", + }, + }, + { + { + Currency: "USD", + Issuer: "rrpNnNLKrartuEqfJGpqyDwPj1AFPg9vn1", + }, + { + Account: "rrpNnNLKrartuEqfJGpqyDwPj1AFPg9vn1", + }, + { + Account: "rLpq4LgabRfm1xEX5dpWfJovYBH6g7z99q", + }, + { + Account: "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B", + }, + }, + { + { + Currency: "USD", + Issuer: "rrpNnNLKrartuEqfJGpqyDwPj1AFPg9vn1", + }, + { + Account: "rrpNnNLKrartuEqfJGpqyDwPj1AFPg9vn1", + }, + { + Account: "rPuBoajMjFoDjweJBrtZEBwUMkyruxpwwV", + }, + { + Account: "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B", + }, + }, + }, + SourceAmount: types.XRPCurrencyAmount(256987), + }, + }, + DestinationAccount: "r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59", + DestinationCurrencies: []string{ + "015841551A748AD2C1F76FF6ECB0CCCD00000000", + "JOE", + "DYM", + "EUR", + "CNY", + "MXN", + "BTC", + "USD", + "XRP", + }, + } + + j := `{ + "alternatives": [ + { + "paths_computed": [ + [ + { + "currency": "USD", + "issuer": "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B" + }, + { + "account": "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B" + } + ], + [ + { + "currency": "USD", + "issuer": "rrpNnNLKrartuEqfJGpqyDwPj1AFPg9vn1" + }, + { + "account": "rrpNnNLKrartuEqfJGpqyDwPj1AFPg9vn1" + }, + { + "account": "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B" + } + ], + [ + { + "currency": "USD", + "issuer": "rrpNnNLKrartuEqfJGpqyDwPj1AFPg9vn1" + }, + { + "account": "rrpNnNLKrartuEqfJGpqyDwPj1AFPg9vn1" + }, + { + "account": "rLpq4LgabRfm1xEX5dpWfJovYBH6g7z99q" + }, + { + "account": "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B" + } + ], + [ + { + "currency": "USD", + "issuer": "rrpNnNLKrartuEqfJGpqyDwPj1AFPg9vn1" + }, + { + "account": "rrpNnNLKrartuEqfJGpqyDwPj1AFPg9vn1" + }, + { + "account": "rPuBoajMjFoDjweJBrtZEBwUMkyruxpwwV" + }, + { + "account": "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B" + } + ] + ], + "source_amount": "256987" + } + ], + "destination_account": "r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59", + "destination_currencies": [ + "015841551A748AD2C1F76FF6ECB0CCCD00000000", + "JOE", + "DYM", + "EUR", + "CNY", + "MXN", + "BTC", + "USD", + "XRP" + ] +}` + if err := test.SerializeAndDeserialize(t, s, j); err != nil { + t.Error(err) + } +}