diff --git a/README.md b/README.md index 26b67e58..b273bef5 100644 --- a/README.md +++ b/README.md @@ -21,9 +21,9 @@ Install [pre-commit](https://github.com/pre-commit/pre-commit-hooks) * Binary Codec * Address Codec * Keypairs Generation - **to finish** -* Go Models - **to finish** -* Json Rpc Client - **to finish** -* Webhook Client - **todo** +* Go Models +* Json Rpc Client +* Webhook Client ## Usage * Keys and Wallets diff --git a/binary-codec/main.go b/binary-codec/main.go index 59937275..9e440808 100644 --- a/binary-codec/main.go +++ b/binary-codec/main.go @@ -7,10 +7,9 @@ import ( "reflect" "strings" - "github.com/xyield/xrpl-go/model/transactions" - - "github.com/xyield/xrpl-go/binary-codec/serdes" - "github.com/xyield/xrpl-go/binary-codec/types" + "github.com/CreatureDev/xrpl-go/model/transactions" + "github.com/CreatureDev/xrpl-go/binary-codec/serdes" + "github.com/CreatureDev/xrpl-go/binary-codec/types" ) var ErrSigningClaimFieldNotFound = errors.New("'Channel' & 'Amount' fields are both required, but were not found") diff --git a/binary-codec/main_test.go b/binary-codec/main_test.go index 6c17cfee..39cb0db9 100644 --- a/binary-codec/main_test.go +++ b/binary-codec/main_test.go @@ -4,8 +4,8 @@ import ( "testing" "github.com/stretchr/testify/require" - "github.com/xyield/xrpl-go/model/transactions" - "github.com/xyield/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/model/transactions" + "github.com/CreatureDev/xrpl-go/model/transactions/types" ) func TestEncode(t *testing.T) { diff --git a/binary-codec/serdes/binary_parser.go b/binary-codec/serdes/binary_parser.go index 397ca664..e4edfa0c 100644 --- a/binary-codec/serdes/binary_parser.go +++ b/binary-codec/serdes/binary_parser.go @@ -3,7 +3,7 @@ package serdes import ( "errors" - "github.com/xyield/xrpl-go/binary-codec/definitions" + "github.com/CreatureDev/xrpl-go/binary-codec/definitions" ) var ( diff --git a/binary-codec/serdes/binary_serializer.go b/binary-codec/serdes/binary_serializer.go index 5d3a8fdc..9fbf55da 100644 --- a/binary-codec/serdes/binary_serializer.go +++ b/binary-codec/serdes/binary_serializer.go @@ -3,7 +3,7 @@ package serdes import ( "errors" - "github.com/xyield/xrpl-go/binary-codec/definitions" + "github.com/CreatureDev/xrpl-go/binary-codec/definitions" ) var ErrLengthPrefixTooLong = errors.New("length of value must not exceed 918744 bytes of data") diff --git a/binary-codec/serdes/field_id_codec.go b/binary-codec/serdes/field_id_codec.go index 4ef34aec..77ffda9f 100644 --- a/binary-codec/serdes/field_id_codec.go +++ b/binary-codec/serdes/field_id_codec.go @@ -3,7 +3,7 @@ package serdes import ( "encoding/hex" - "github.com/xyield/xrpl-go/binary-codec/definitions" + "github.com/CreatureDev/xrpl-go/binary-codec/definitions" ) // Returns the unique field ID for a given field name. diff --git a/binary-codec/serdes/field_id_codec_test.go b/binary-codec/serdes/field_id_codec_test.go index 41d8e880..91ea1a8e 100644 --- a/binary-codec/serdes/field_id_codec_test.go +++ b/binary-codec/serdes/field_id_codec_test.go @@ -8,7 +8,7 @@ import ( "testing" "github.com/stretchr/testify/require" - "github.com/xyield/xrpl-go/binary-codec/definitions" + "github.com/CreatureDev/xrpl-go/binary-codec/definitions" ) func TestEncodeFieldID(t *testing.T) { diff --git a/binary-codec/types/account_id.go b/binary-codec/types/account_id.go index 69d53cf6..2265acaf 100644 --- a/binary-codec/types/account_id.go +++ b/binary-codec/types/account_id.go @@ -3,9 +3,9 @@ package types import ( "errors" - addresscodec "github.com/xyield/xrpl-go/address-codec" - "github.com/xyield/xrpl-go/binary-codec/serdes" - "github.com/xyield/xrpl-go/model/transactions/types" + addresscodec "github.com/CreatureDev/xrpl-go/address-codec" + "github.com/CreatureDev/xrpl-go/binary-codec/serdes" + "github.com/CreatureDev/xrpl-go/model/transactions/types" ) var ( diff --git a/binary-codec/types/amount.go b/binary-codec/types/amount.go index 00e64532..703945f9 100644 --- a/binary-codec/types/amount.go +++ b/binary-codec/types/amount.go @@ -11,10 +11,10 @@ import ( "strconv" "strings" - addresscodec "github.com/xyield/xrpl-go/address-codec" - "github.com/xyield/xrpl-go/binary-codec/serdes" - "github.com/xyield/xrpl-go/model/transactions/types" - bigdecimal "github.com/xyield/xrpl-go/pkg/big-decimal" + addresscodec "github.com/CreatureDev/xrpl-go/address-codec" + "github.com/CreatureDev/xrpl-go/binary-codec/serdes" + "github.com/CreatureDev/xrpl-go/model/transactions/types" + bigdecimal "github.com/CreatureDev/xrpl-go/pkg/big-decimal" ) const ( diff --git a/binary-codec/types/amount_test.go b/binary-codec/types/amount_test.go index 0f9be0db..a2159e04 100644 --- a/binary-codec/types/amount_test.go +++ b/binary-codec/types/amount_test.go @@ -4,8 +4,8 @@ import ( "testing" "github.com/stretchr/testify/require" - "github.com/xyield/xrpl-go/model/transactions/types" - bigdecimal "github.com/xyield/xrpl-go/pkg/big-decimal" + "github.com/CreatureDev/xrpl-go/model/transactions/types" + bigdecimal "github.com/CreatureDev/xrpl-go/pkg/big-decimal" ) func TestVerifyXrpValue(t *testing.T) { diff --git a/binary-codec/types/blob.go b/binary-codec/types/blob.go index c7f61e76..089c1b30 100644 --- a/binary-codec/types/blob.go +++ b/binary-codec/types/blob.go @@ -5,7 +5,7 @@ import ( "errors" "strings" - "github.com/xyield/xrpl-go/binary-codec/serdes" + "github.com/CreatureDev/xrpl-go/binary-codec/serdes" ) // ErrNoLengthPrefix error is raised when no length prefix size is given. diff --git a/binary-codec/types/pathset.go b/binary-codec/types/pathset.go index 79015f2d..94e01d20 100644 --- a/binary-codec/types/pathset.go +++ b/binary-codec/types/pathset.go @@ -4,9 +4,10 @@ import ( "errors" "fmt" - addresscodec "github.com/xyield/xrpl-go/address-codec" - "github.com/xyield/xrpl-go/binary-codec/serdes" - "github.com/xyield/xrpl-go/model/transactions" + + addresscodec "github.com/CreatureDev/xrpl-go/address-codec" + "github.com/CreatureDev/xrpl-go/binary-codec/serdes" + "github.com/CreatureDev/xrpl-go/model/transactions" ) const ( diff --git a/binary-codec/types/pathset_test.go b/binary-codec/types/pathset_test.go index aa8b6284..bf342ef8 100644 --- a/binary-codec/types/pathset_test.go +++ b/binary-codec/types/pathset_test.go @@ -4,8 +4,8 @@ import ( "testing" "github.com/stretchr/testify/require" - "github.com/xyield/xrpl-go/binary-codec/serdes" - "github.com/xyield/xrpl-go/model/transactions" + "github.com/CreatureDev/xrpl-go/binary-codec/serdes" + "github.com/CreatureDev/xrpl-go/model/transactions" ) func TestIsPathStep(t *testing.T) { diff --git a/binary-codec/types/serialized_type.go b/binary-codec/types/serialized_type.go index 8d57572f..bdc6393b 100644 --- a/binary-codec/types/serialized_type.go +++ b/binary-codec/types/serialized_type.go @@ -1,6 +1,6 @@ package types -import "github.com/xyield/xrpl-go/binary-codec/serdes" +import "github.com/CreatureDev/xrpl-go/binary-codec/serdes" // SerializedType is an interface representing any type that can be serialized // and deserialized to and from JSON. diff --git a/binary-codec/types/st_array.go b/binary-codec/types/st_array.go index e62b76fd..37613bfb 100644 --- a/binary-codec/types/st_array.go +++ b/binary-codec/types/st_array.go @@ -4,7 +4,7 @@ import ( "errors" "reflect" - "github.com/xyield/xrpl-go/binary-codec/serdes" + "github.com/CreatureDev/xrpl-go/binary-codec/serdes" ) const ( diff --git a/binary-codec/types/st_object.go b/binary-codec/types/st_object.go index db3b6dc5..b5195c96 100644 --- a/binary-codec/types/st_object.go +++ b/binary-codec/types/st_object.go @@ -5,8 +5,8 @@ import ( "sort" "github.com/mitchellh/mapstructure" - "github.com/xyield/xrpl-go/binary-codec/definitions" - "github.com/xyield/xrpl-go/binary-codec/serdes" + "github.com/CreatureDev/xrpl-go/binary-codec/definitions" + "github.com/CreatureDev/xrpl-go/binary-codec/serdes" ) // FieldMutation allows values to mutated before being serialized. diff --git a/binary-codec/types/st_object_test.go b/binary-codec/types/st_object_test.go index 08042ad5..1e090abc 100644 --- a/binary-codec/types/st_object_test.go +++ b/binary-codec/types/st_object_test.go @@ -5,8 +5,8 @@ import ( "testing" "github.com/stretchr/testify/require" - "github.com/xyield/xrpl-go/binary-codec/definitions" - "github.com/xyield/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/binary-codec/definitions" + "github.com/CreatureDev/xrpl-go/model/transactions/types" ) func TestCreateFieldInstanceMapFromJson(t *testing.T) { diff --git a/binary-codec/types/uint16.go b/binary-codec/types/uint16.go index 3efb9823..352a44f8 100644 --- a/binary-codec/types/uint16.go +++ b/binary-codec/types/uint16.go @@ -4,10 +4,10 @@ import ( "bytes" "encoding/binary" - "github.com/xyield/xrpl-go/binary-codec/definitions" - "github.com/xyield/xrpl-go/binary-codec/serdes" - "github.com/xyield/xrpl-go/model/ledger" - "github.com/xyield/xrpl-go/model/transactions" + "github.com/CreatureDev/xrpl-go/binary-codec/definitions" + "github.com/CreatureDev/xrpl-go/binary-codec/serdes" + "github.com/CreatureDev/xrpl-go/model/ledger" + "github.com/CreatureDev/xrpl-go/model/transactions" ) // UInt16 represents a 16-bit unsigned integer. diff --git a/binary-codec/types/uint32.go b/binary-codec/types/uint32.go index 10b87199..e96c428f 100644 --- a/binary-codec/types/uint32.go +++ b/binary-codec/types/uint32.go @@ -5,8 +5,8 @@ import ( "encoding/binary" "errors" - "github.com/xyield/xrpl-go/binary-codec/serdes" - "github.com/xyield/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/binary-codec/serdes" + "github.com/CreatureDev/xrpl-go/model/transactions/types" ) var ErrInvalidUInt32 = errors.New("invalid type for UInt32") diff --git a/binary-codec/types/uint64.go b/binary-codec/types/uint64.go index 4285e97d..659c590a 100644 --- a/binary-codec/types/uint64.go +++ b/binary-codec/types/uint64.go @@ -8,7 +8,7 @@ import ( "regexp" "strings" - "github.com/xyield/xrpl-go/binary-codec/serdes" + "github.com/CreatureDev/xrpl-go/binary-codec/serdes" ) var UINT64_HEX_REGEX = regexp.MustCompile("^[0-9a-fA-F]{1,16}$") diff --git a/binary-codec/types/uint8.go b/binary-codec/types/uint8.go index 6b03614b..578a3988 100644 --- a/binary-codec/types/uint8.go +++ b/binary-codec/types/uint8.go @@ -4,8 +4,8 @@ import ( "bytes" "encoding/binary" - "github.com/xyield/xrpl-go/binary-codec/definitions" - "github.com/xyield/xrpl-go/binary-codec/serdes" + "github.com/CreatureDev/xrpl-go/binary-codec/definitions" + "github.com/CreatureDev/xrpl-go/binary-codec/serdes" ) // UInt8 represents an 8-bit unsigned integer. diff --git a/binary-codec/types/vector256.go b/binary-codec/types/vector256.go index a7f3d1e4..aba60bd7 100644 --- a/binary-codec/types/vector256.go +++ b/binary-codec/types/vector256.go @@ -5,8 +5,8 @@ import ( "fmt" "strings" - "github.com/xyield/xrpl-go/binary-codec/serdes" - "github.com/xyield/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/binary-codec/serdes" + "github.com/CreatureDev/xrpl-go/model/transactions/types" ) const HashLengthBytes = 32 diff --git a/client/accounts.go b/client/accounts.go index 438e8cc5..d0199789 100644 --- a/client/accounts.go +++ b/client/accounts.go @@ -1,19 +1,25 @@ package client import ( - "github.com/xyield/xrpl-go/model/client/account" + "github.com/CreatureDev/xrpl-go/model/client/account" ) type Account interface { - GetAccountChannels(req *account.AccountChannelsRequest) (*account.AccountChannelsResponse, XRPLResponse, error) - GetAccountInfo(req *account.AccountInfoRequest) (*account.AccountInfoResponse, XRPLResponse, error) + AccountChannels(req *account.AccountChannelsRequest) (*account.AccountChannelsResponse, XRPLResponse, error) + AccountCurrencies(req *account.AccountCurrenciesRequest) (*account.AccountCurrenciesResponse, XRPLResponse, error) + AccountInfo(req *account.AccountInfoRequest) (*account.AccountInfoResponse, XRPLResponse, error) + AccountLines(req *account.AccountLinesRequest) (*account.AccountLinesResponse, XRPLResponse, error) + AccountNFTs(req *account.AccountNFTsRequest) (*account.AccountNFTsResponse, XRPLResponse, error) + AccountObjects(req *account.AccountObjectsRequest) (*account.AccountObjectsResponse, XRPLResponse, error) + AccountOffers(req *account.AccountOffersRequest) (*account.AccountOffersResponse, XRPLResponse, error) + AccountTransactions(req *account.AccountTransactionsRequest) (*account.AccountTransactionsResponse, XRPLResponse, error) } type accountImpl struct { client Client } -func (a *accountImpl) GetAccountChannels(req *account.AccountChannelsRequest) (*account.AccountChannelsResponse, XRPLResponse, error) { +func (a *accountImpl) AccountChannels(req *account.AccountChannelsRequest) (*account.AccountChannelsResponse, XRPLResponse, error) { res, err := a.client.SendRequest(req) if err != nil { return nil, nil, err @@ -26,7 +32,20 @@ func (a *accountImpl) GetAccountChannels(req *account.AccountChannelsRequest) (* return &acr, res, nil } -func (a *accountImpl) GetAccountInfo(req *account.AccountInfoRequest) (*account.AccountInfoResponse, XRPLResponse, error) { +func (a *accountImpl) AccountCurrencies(req *account.AccountCurrenciesRequest) (*account.AccountCurrenciesResponse, XRPLResponse, error) { + res, err := a.client.SendRequest(req) + if err != nil { + return nil, nil, err + } + var acr account.AccountCurrenciesResponse + err = res.GetResult(&acr) + if err != nil { + return nil, nil, err + } + return &acr, res, nil +} + +func (a *accountImpl) AccountInfo(req *account.AccountInfoRequest) (*account.AccountInfoResponse, XRPLResponse, error) { res, err := a.client.SendRequest(req) if err != nil { return nil, nil, err @@ -38,3 +57,68 @@ func (a *accountImpl) GetAccountInfo(req *account.AccountInfoRequest) (*account. } return &air, res, nil } + +func (a *accountImpl) AccountLines(req *account.AccountLinesRequest) (*account.AccountLinesResponse, XRPLResponse, error) { + res, err := a.client.SendRequest(req) + if err != nil { + return nil, nil, err + } + var alr account.AccountLinesResponse + err = res.GetResult(&alr) + if err != nil { + return nil, nil, err + } + return &alr, res, nil +} + +func (a *accountImpl) AccountNFTs(req *account.AccountNFTsRequest) (*account.AccountNFTsResponse, XRPLResponse, error) { + res, err := a.client.SendRequest(req) + if err != nil { + return nil, nil, err + } + var anr account.AccountNFTsResponse + err = res.GetResult(&anr) + if err != nil { + return nil, nil, err + } + return &anr, res, nil +} + +func (a *accountImpl) AccountObjects(req *account.AccountObjectsRequest) (*account.AccountObjectsResponse, XRPLResponse, error) { + res, err := a.client.SendRequest(req) + if err != nil { + return nil, nil, err + } + var aor account.AccountObjectsResponse + err = res.GetResult(&aor) + if err != nil { + return nil, nil, err + } + return &aor, res, nil +} + +func (a *accountImpl) AccountOffers(req *account.AccountOffersRequest) (*account.AccountOffersResponse, XRPLResponse, error) { + res, err := a.client.SendRequest(req) + if err != nil { + return nil, nil, err + } + var aor account.AccountOffersResponse + err = res.GetResult(&aor) + if err != nil { + return nil, nil, err + } + return &aor, res, nil +} + +func (a *accountImpl) AccountTransactions(req *account.AccountTransactionsRequest) (*account.AccountTransactionsResponse, XRPLResponse, error) { + res, err := a.client.SendRequest(req) + if err != nil { + return nil, nil, err + } + var atr account.AccountTransactionsResponse + err = res.GetResult(&atr) + if err != nil { + return nil, nil, err + } + return &atr, res, nil +} diff --git a/client/accounts_test.go b/client/accounts_test.go index 9e18638b..acb17c64 100644 --- a/client/accounts_test.go +++ b/client/accounts_test.go @@ -4,11 +4,11 @@ import ( "errors" "testing" + "github.com/CreatureDev/xrpl-go/model/client/account" + "github.com/CreatureDev/xrpl-go/model/client/common" "github.com/mitchellh/mapstructure" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" - "github.com/xyield/xrpl-go/model/client/account" - "github.com/xyield/xrpl-go/model/client/common" ) type mockClient struct { @@ -19,6 +19,10 @@ type mockClientXrplResponse struct { Result map[string]any } +func (m *mockClientXrplResponse) GetError() error { + return nil +} + func (m *mockClientXrplResponse) GetResult(v any) error { dec, err := mapstructure.NewDecoder(&mapstructure.DecoderConfig{TagName: "json", Result: &v}) if err != nil { @@ -118,7 +122,7 @@ func TestGetAccountChannels(t *testing.T) { cl.On("SendRequest", &tc.input).Return(&tc.sendRequestResult, nil) - res, _, err := a.GetAccountChannels(&tc.input) + res, _, err := a.AccountChannels(&tc.input) if tc.expectedErr != nil { require.EqualError(t, err, tc.expectedErr.Error()) diff --git a/client/channels.go b/client/channels.go new file mode 100644 index 00000000..5bcc96fe --- /dev/null +++ b/client/channels.go @@ -0,0 +1,40 @@ +package client + +import ( + "github.com/CreatureDev/xrpl-go/model/client/channel" +) + +type Channel interface { + ChannelAuthorize(req *channel.ChannelAuthorizeRequest) (*channel.ChannelAuthorizeResponse, XRPLResponse, error) + ChannelVerify(req *channel.ChannelVerifyRequest) (*channel.ChannelVerifyResponse, XRPLResponse, error) +} + +type channelImpl struct { + client Client +} + +func (c *channelImpl) ChannelAuthorize(req *channel.ChannelAuthorizeRequest) (*channel.ChannelAuthorizeResponse, XRPLResponse, error) { + res, err := c.client.SendRequest(req) + if err != nil { + return nil, nil, err + } + var car channel.ChannelAuthorizeResponse + err = res.GetResult(&car) + if err != nil { + return nil, nil, err + } + return &car, res, nil +} + +func (c *channelImpl) ChannelVerify(req *channel.ChannelVerifyRequest) (*channel.ChannelVerifyResponse, XRPLResponse, error) { + res, err := c.client.SendRequest(req) + if err != nil { + return nil, nil, err + } + var cvr channel.ChannelVerifyResponse + err = res.GetResult(&cvr) + if err != nil { + return nil, nil, err + } + return &cvr, res, nil +} diff --git a/client/client.go b/client/client.go index 4bb48522..c766e5b0 100644 --- a/client/client.go +++ b/client/client.go @@ -5,8 +5,15 @@ type Client interface { } type XRPLClient struct { - client Client - Account Account + client Client + Account Account + Channel Channel + Ledger Ledger + Path Path + Subscription Subscription + Transaction Transaction + Server Server + Clio Clio } type XRPLRequest interface { @@ -16,6 +23,7 @@ type XRPLRequest interface { type XRPLResponse interface { GetResult(v any) error + GetError() error } type XRPLResponseWarning struct { @@ -26,8 +34,14 @@ type XRPLResponseWarning struct { func NewXRPLClient(cl Client) *XRPLClient { return &XRPLClient{ - client: cl, - Account: &accountImpl{client: cl}, + client: cl, + Account: &accountImpl{client: cl}, + Channel: &channelImpl{client: cl}, + Ledger: &ledgerImpl{client: cl}, + Path: &pathImpl{client: cl}, + Subscription: &subscriptionImpl{client: cl}, + Transaction: &transactionImpl{client: cl}, + Clio: &clioImpl{client: cl}, } } diff --git a/client/clio.go b/client/clio.go new file mode 100644 index 00000000..41d17a4d --- /dev/null +++ b/client/clio.go @@ -0,0 +1,66 @@ +package client + +import "github.com/CreatureDev/xrpl-go/model/client/clio" + +type Clio interface { + ServerInfo(*clio.ServerInfoRequest) (*clio.ServerInfoResponse, XRPLResponse, error) + Ledger(*clio.LedgerRequest) (*clio.LedgerResponse, XRPLResponse, error) + NFTHistory(*clio.NFTHistoryRequest) (*clio.NFTHistoryResponse, XRPLResponse, error) + NFTInfo(*clio.NFTInfoRequest) (*clio.NFTInfoResponse, XRPLResponse, error) +} + +type clioImpl struct { + client Client +} + +func (c *clioImpl) ServerInfo(req *clio.ServerInfoRequest) (*clio.ServerInfoResponse, XRPLResponse, error) { + res, err := c.client.SendRequest(req) + if err != nil { + return nil, nil, err + } + var sr clio.ServerInfoResponse + err = res.GetResult(&sr) + if err != nil { + return nil, nil, err + } + return &sr, res, nil +} + +func (c *clioImpl) Ledger(req *clio.LedgerRequest) (*clio.LedgerResponse, XRPLResponse, error) { + res, err := c.client.SendRequest(req) + if err != nil { + return nil, nil, err + } + var lr clio.LedgerResponse + err = res.GetResult(&lr) + if err != nil { + return nil, nil, err + } + return &lr, res, nil +} + +func (c *clioImpl) NFTHistory(req *clio.NFTHistoryRequest) (*clio.NFTHistoryResponse, XRPLResponse, error) { + res, err := c.client.SendRequest(req) + if err != nil { + return nil, nil, err + } + var nr clio.NFTHistoryResponse + err = res.GetResult(&nr) + if err != nil { + return nil, nil, err + } + return &nr, res, nil +} + +func (c *clioImpl) NFTInfo(req *clio.NFTInfoRequest) (*clio.NFTInfoResponse, XRPLResponse, error) { + res, err := c.client.SendRequest(req) + if err != nil { + return nil, nil, err + } + var nr clio.NFTInfoResponse + err = res.GetResult(&nr) + if err != nil { + return nil, nil, err + } + return &nr, res, nil +} diff --git a/client/jsonrpc/jsonrpc_client.go b/client/jsonrpc/jsonrpc_client.go index 769c1701..74e6ba52 100644 --- a/client/jsonrpc/jsonrpc_client.go +++ b/client/jsonrpc/jsonrpc_client.go @@ -11,9 +11,9 @@ import ( "strings" "time" + "github.com/CreatureDev/xrpl-go/client" + jsonrpcmodels "github.com/CreatureDev/xrpl-go/client/jsonrpc/models" jsoniter "github.com/json-iterator/go" - "github.com/xyield/xrpl-go/client" - jsonrpcmodels "github.com/xyield/xrpl-go/client/jsonrpc/models" ) type JsonRpcClient struct { @@ -52,6 +52,7 @@ func (c *JsonRpcClient) SendRequest(reqParams client.XRPLRequest) (client.XRPLRe } body, err := CreateRequest(reqParams) + fmt.Printf("sending request: %s\n", string(body)) if err != nil { return nil, err } @@ -180,8 +181,8 @@ func CheckForError(res *http.Response) (jsonrpcmodels.JsonRpcResponse, error) { } // result will have 'error' if error response - if _, ok := jr.Result["error"]; ok { - return jr, &JsonRpcClientError{ErrorString: jr.Result["error"].(string)} + if err := jr.GetError(); err != nil { + return jr, &JsonRpcClientError{ErrorString: err.Error()} } return jr, nil diff --git a/client/jsonrpc/jsonrpc_client_test.go b/client/jsonrpc/jsonrpc_client_test.go index d153a9c6..8907643b 100644 --- a/client/jsonrpc/jsonrpc_client_test.go +++ b/client/jsonrpc/jsonrpc_client_test.go @@ -9,13 +9,13 @@ import ( "testing" "time" + "github.com/CreatureDev/xrpl-go/client" + jsonrpcmodels "github.com/CreatureDev/xrpl-go/client/jsonrpc/models" + "github.com/CreatureDev/xrpl-go/model/client/account" + "github.com/CreatureDev/xrpl-go/model/client/common" + "github.com/CreatureDev/xrpl-go/model/client/utility" jsoniter "github.com/json-iterator/go" "github.com/stretchr/testify/assert" - "github.com/xyield/xrpl-go/client" - jsonrpcmodels "github.com/xyield/xrpl-go/client/jsonrpc/models" - "github.com/xyield/xrpl-go/model/client/account" - "github.com/xyield/xrpl-go/model/client/common" - "github.com/xyield/xrpl-go/model/client/utility" ) func TestJsonRpcClientCreation(t *testing.T) { @@ -78,26 +78,26 @@ func TestCheckForError(t *testing.T) { t.Run("No error Response", func(t *testing.T) { json := `{ - "result": { - "account": "rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn", - "channels": [ - { - "account": "rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn", - "amount": "1000", - "balance": "0", - "channel_id": "C7F634794B79DB40E87179A9D1BF05D05797AE7E92DF8E93FD6656E8C4BE3AE7", - "destination_account": "ra5nK24KXen9AHvsdFTKHSANinZseWnPcX", - "public_key": "aBR7mdD75Ycs8DRhMgQ4EMUEmBArF8SEh1hfjrT2V9DQTLNbJVqw", - "public_key_hex": "03CFD18E689434F032A4E84C63E2A3A6472D684EAF4FD52CA67742F3E24BAE81B2", - "settle_delay": 60 - } - ], - "ledger_hash": "27F530E5C93ED5C13994812787C1ED073C822BAEC7597964608F2C049C2ACD2D", - "ledger_index": 71766343, - "status": "success", - "validated": true + "result": { + "account": "rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn", + "channels": [ + { + "account": "rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn", + "amount": "1000", + "balance": "0", + "channel_id": "C7F634794B79DB40E87179A9D1BF05D05797AE7E92DF8E93FD6656E8C4BE3AE7", + "destination_account": "ra5nK24KXen9AHvsdFTKHSANinZseWnPcX", + "public_key": "aBR7mdD75Ycs8DRhMgQ4EMUEmBArF8SEh1hfjrT2V9DQTLNbJVqw", + "public_key_hex": "03CFD18E689434F032A4E84C63E2A3A6472D684EAF4FD52CA67742F3E24BAE81B2", + "settle_delay": 60 } - }` + ], + "ledger_hash": "27F530E5C93ED5C13994812787C1ED073C822BAEC7597964608F2C049C2ACD2D", + "ledger_index": 71766343, + "status": "success", + "validated": true + } +}` b := io.NopCloser(bytes.NewReader([]byte(json))) res := &http.Response{ @@ -210,31 +210,31 @@ func TestSendRequest(t *testing.T) { } response := `{ - "result": { - "account": "rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn", - "channels": [ - { - "account": "rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn", - "amount": "1000", - "balance": "0", - "channel_id": "C7F634794B79DB40E87179A9D1BF05D05797AE7E92DF8E93FD6656E8C4BE3AE7", - "destination_account": "ra5nK24KXen9AHvsdFTKHSANinZseWnPcX", - "public_key": "aBR7mdD75Ycs8DRhMgQ4EMUEmBArF8SEh1hfjrT2V9DQTLNbJVqw", - "public_key_hex": "03CFD18E689434F032A4E84C63E2A3A6472D684EAF4FD52CA67742F3E24BAE81B2", - "settle_delay": 60 - } - ], - "ledger_hash": "1EDBBA3C793863366DF5B31C2174B6B5E6DF6DB89A7212B86838489148E2A581", - "ledger_index": 71766314, - "validated": true - }, - "warning": "none", - "warnings": - [{ - "id": 1, - "message": "message" - }] - }` + "result": { + "account": "rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn", + "channels": [ + { + "account": "rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn", + "amount": "1000", + "balance": "0", + "channel_id": "C7F634794B79DB40E87179A9D1BF05D05797AE7E92DF8E93FD6656E8C4BE3AE7", + "destination_account": "ra5nK24KXen9AHvsdFTKHSANinZseWnPcX", + "public_key": "aBR7mdD75Ycs8DRhMgQ4EMUEmBArF8SEh1hfjrT2V9DQTLNbJVqw", + "public_key_hex": "03CFD18E689434F032A4E84C63E2A3A6472D684EAF4FD52CA67742F3E24BAE81B2", + "settle_delay": 60 + } + ], + "ledger_hash": "1EDBBA3C793863366DF5B31C2174B6B5E6DF6DB89A7212B86838489148E2A581", + "ledger_index": 71766314, + "validated": true +}, + "warning": "none", + "warnings": + [{ + "id": 1, + "message": "message" + }] +}` mc := &mockClient{} mc.DoFunc = mockResponse(response, 200, mc) @@ -247,24 +247,24 @@ func TestSendRequest(t *testing.T) { xrplResponse, err := jsonRpcClient.SendRequest(req) expectedXrplResponse := &jsonrpcmodels.JsonRpcResponse{ - Result: jsonrpcmodels.AnyJson{ + Result: json.RawMessage(`{ + "account": "rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn", + "channels": [ + { "account": "rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn", - "channels": []any{ - map[string]any{ - "account": "rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn", - "amount": "1000", - "balance": "0", - "channel_id": "C7F634794B79DB40E87179A9D1BF05D05797AE7E92DF8E93FD6656E8C4BE3AE7", - "destination_account": "ra5nK24KXen9AHvsdFTKHSANinZseWnPcX", - "public_key": "aBR7mdD75Ycs8DRhMgQ4EMUEmBArF8SEh1hfjrT2V9DQTLNbJVqw", - "public_key_hex": "03CFD18E689434F032A4E84C63E2A3A6472D684EAF4FD52CA67742F3E24BAE81B2", - "settle_delay": json.Number("60"), - }, - }, - "ledger_hash": "1EDBBA3C793863366DF5B31C2174B6B5E6DF6DB89A7212B86838489148E2A581", - "ledger_index": json.Number("71766314"), - "validated": true, - }, + "amount": "1000", + "balance": "0", + "channel_id": "C7F634794B79DB40E87179A9D1BF05D05797AE7E92DF8E93FD6656E8C4BE3AE7", + "destination_account": "ra5nK24KXen9AHvsdFTKHSANinZseWnPcX", + "public_key": "aBR7mdD75Ycs8DRhMgQ4EMUEmBArF8SEh1hfjrT2V9DQTLNbJVqw", + "public_key_hex": "03CFD18E689434F032A4E84C63E2A3A6472D684EAF4FD52CA67742F3E24BAE81B2", + "settle_delay": 60 + } + ], + "ledger_hash": "1EDBBA3C793863366DF5B31C2174B6B5E6DF6DB89A7212B86838489148E2A581", + "ledger_index": 71766314, + "validated": true +}`), Warning: "none", Warnings: []client.XRPLResponseWarning{{ Id: 1, @@ -284,6 +284,8 @@ func TestSendRequest(t *testing.T) { assert.NoError(t, err) + res := xrplResponse.(*jsonrpcmodels.JsonRpcResponse) + assert.Equal(t, string(expectedXrplResponse.Result), string(res.Result)) assert.Equal(t, expectedXrplResponse, xrplResponse) assert.Equal(t, expected.Account, channelsResponse.Account) @@ -297,17 +299,17 @@ func TestSendRequest(t *testing.T) { Account: "rLHmBn4fT92w4F6ViyYbjoizLTo83tHTHu", } response := `{ - "result": { - "error": "ledgerIndexMalformed", - "request": { - "account": "r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59", - "command": "account_info", - "ledger_index": "-", - "strict": true - }, - "status": "error" - } - }` + "result": { + "error": "ledgerIndexMalformed", + "request": { + "account": "r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59", + "command": "account_info", + "ledger_index": "-", + "strict": true + }, + "status": "error" + } +}` mc := &mockClient{} mc.DoFunc = mockResponse(response, 200, mc) diff --git a/client/jsonrpc/models/jsonrpc_response.go b/client/jsonrpc/models/jsonrpc_response.go index 03c3377a..feafcbc9 100644 --- a/client/jsonrpc/models/jsonrpc_response.go +++ b/client/jsonrpc/models/jsonrpc_response.go @@ -1,19 +1,19 @@ package jsonrpcmodels import ( - "github.com/mitchellh/mapstructure" - "github.com/xyield/xrpl-go/client" + "encoding/json" + "fmt" + + "github.com/CreatureDev/xrpl-go/client" ) type JsonRpcResponse struct { - Result AnyJson `json:"result"` + Result json.RawMessage `json:"result"` Warning string `json:"warning,omitempty"` Warnings []client.XRPLResponseWarning `json:"warnings,omitempty"` Forwarded bool `json:"forwarded,omitempty"` } -type AnyJson map[string]interface{} - type ApiWarning struct { Id int `json:"id"` Message string `json:"message"` @@ -21,15 +21,30 @@ type ApiWarning struct { } func (r JsonRpcResponse) GetResult(v any) error { - dec, err := mapstructure.NewDecoder(&mapstructure.DecoderConfig{TagName: "json", - Result: &v, DecodeHook: mapstructure.TextUnmarshallerHookFunc()}) - + if len(r.Result) == 0 { + return nil + } + err := json.Unmarshal(r.Result, v) if err != nil { return err } - err = dec.Decode(r.Result) + return nil +} + +func (r JsonRpcResponse) GetError() error { + if len(r.Result) == 0 { + return nil + } + type reqError struct { + Error string `json:"error"` + } + var errResponse reqError + err := json.Unmarshal(r.Result, &errResponse) if err != nil { return err } + if errResponse.Error != "" { + return fmt.Errorf(errResponse.Error) + } return nil } diff --git a/client/jsonrpc/models/jsonrpc_response_test.go b/client/jsonrpc/models/jsonrpc_response_test.go index de9dbbd5..c4b48ee4 100644 --- a/client/jsonrpc/models/jsonrpc_response_test.go +++ b/client/jsonrpc/models/jsonrpc_response_test.go @@ -2,23 +2,22 @@ package jsonrpcmodels import ( "encoding/json" - "strconv" "testing" + "github.com/CreatureDev/xrpl-go/client" + "github.com/CreatureDev/xrpl-go/model/client/account" "github.com/stretchr/testify/assert" - "github.com/xyield/xrpl-go/client" - "github.com/xyield/xrpl-go/model/client/account" ) func TestGetResult(t *testing.T) { t.Run("correctly decodes", func(t *testing.T) { jr := JsonRpcResponse{ - Result: AnyJson{ - "account": "rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn", - "ledger_hash": "27F530E5C93ED5C13994812787C1ED073C822BAEC7597964608F2C049C2ACD2D", - "ledger_index": json.Number(strconv.FormatInt(71766343, 10)), - }, + Result: json.RawMessage(`{ + "account": "rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn", + "ledger_hash": "27F530E5C93ED5C13994812787C1ED073C822BAEC7597964608F2C049C2ACD2D", + "ledger_index": 71766343 +}`), Warning: "none", Warnings: []client.XRPLResponseWarning{{ Id: 1, @@ -42,11 +41,11 @@ func TestGetResult(t *testing.T) { t.Run("throws error for incorrect mapping", func(t *testing.T) { jr := JsonRpcResponse{ - Result: AnyJson{ - "account": 123, - "ledger_hash": "27F530E5C93ED5C13994812787C1ED073C822BAEC7597964608F2C049C2ACD2D", - "ledger_index": json.Number(strconv.FormatInt(71766343, 10)), - }, + Result: json.RawMessage(`{ + "account": 123, + "ledger_hash": "27F530E5C93ED5C13994812787C1ED073C822BAEC7597964608F2C049C2ACD2D", + "ledger_index": json.Number(strconv.FormatInt(71766343, 10)), +}`), Warning: "none", Warnings: []client.XRPLResponseWarning{{ Id: 1, diff --git a/client/ledgers.go b/client/ledgers.go new file mode 100644 index 00000000..adeb8b68 --- /dev/null +++ b/client/ledgers.go @@ -0,0 +1,82 @@ +package client + +import ( + "github.com/CreatureDev/xrpl-go/model/client/ledger" +) + +type Ledger interface { + LedgerClosed(req *ledger.LedgerClosedRequest) (*ledger.LedgerClosedResponse, XRPLResponse, error) + LedgerCurrent(req *ledger.LedgerCurrentRequest) (*ledger.LedgerCurrentResponse, XRPLResponse, error) + LedgerData(req *ledger.LedgerDataRequest) (*ledger.LedgerDataResponse, XRPLResponse, error) + LedgerEntry(req *ledger.LedgerEntryRequest) (*ledger.LedgerEntryResponse, XRPLResponse, error) + Ledger(req *ledger.LedgerRequest) (*ledger.LedgerResponse, XRPLResponse, error) +} + +type ledgerImpl struct { + client Client +} + +func (l *ledgerImpl) LedgerClosed(req *ledger.LedgerClosedRequest) (*ledger.LedgerClosedResponse, XRPLResponse, error) { + res, err := l.client.SendRequest(req) + if err != nil { + return nil, nil, err + } + var lcr ledger.LedgerClosedResponse + err = res.GetResult(&lcr) + if err != nil { + return nil, nil, err + } + return &lcr, res, nil +} + +func (l *ledgerImpl) LedgerCurrent(req *ledger.LedgerCurrentRequest) (*ledger.LedgerCurrentResponse, XRPLResponse, error) { + res, err := l.client.SendRequest(req) + if err != nil { + return nil, nil, err + } + var lcr ledger.LedgerCurrentResponse + err = res.GetResult(&lcr) + if err != nil { + return nil, nil, err + } + return &lcr, res, nil +} + +func (l *ledgerImpl) LedgerData(req *ledger.LedgerDataRequest) (*ledger.LedgerDataResponse, XRPLResponse, error) { + res, err := l.client.SendRequest(req) + if err != nil { + return nil, nil, err + } + var ldr ledger.LedgerDataResponse + err = res.GetResult(&ldr) + if err != nil { + return nil, nil, err + } + return &ldr, res, nil +} + +func (l *ledgerImpl) LedgerEntry(req *ledger.LedgerEntryRequest) (*ledger.LedgerEntryResponse, XRPLResponse, error) { + res, err := l.client.SendRequest(req) + if err != nil { + return nil, nil, err + } + var ler ledger.LedgerEntryResponse + err = res.GetResult(&ler) + if err != nil { + return nil, nil, err + } + return &ler, res, nil +} + +func (l *ledgerImpl) Ledger(req *ledger.LedgerRequest) (*ledger.LedgerResponse, XRPLResponse, error) { + res, err := l.client.SendRequest(req) + if err != nil { + return nil, nil, err + } + var lr ledger.LedgerResponse + err = res.GetResult(&lr) + if err != nil { + return nil, nil, err + } + return &lr, res, nil +} diff --git a/client/path.go b/client/path.go new file mode 100644 index 00000000..48c79f53 --- /dev/null +++ b/client/path.go @@ -0,0 +1,94 @@ +package client + +import "github.com/CreatureDev/xrpl-go/model/client/path" + +type Path interface { + BookOffers(req *path.BookOffersRequest) (*path.BookOffersResponse, XRPLResponse, error) + DepositAuthorized(req *path.DepositAuthorizedRequest) (*path.DepositAuthorizedResponse, XRPLResponse, error) + NFTokenBuyOffers(req *path.NFTokenBuyOffersRequest) (*path.NFTokenBuyOffersResponse, XRPLResponse, error) + NFTokenSellOffers(req *path.NFTokenSellOffersRequest) (*path.NFTokenSellOffersResponse, XRPLResponse, error) + PathFind(req *path.PathFindRequest) (*path.PathFindResponse, XRPLResponse, error) + RipplePathFind(req *path.RipplePathFindRequest) (*path.RipplePathFindResponse, XRPLResponse, error) +} + +type pathImpl struct { + client Client +} + +func (p *pathImpl) BookOffers(req *path.BookOffersRequest) (*path.BookOffersResponse, XRPLResponse, error) { + res, err := p.client.SendRequest(req) + if err != nil { + return nil, nil, err + } + var bor path.BookOffersResponse + err = res.GetResult(&bor) + if err != nil { + return nil, nil, err + } + return &bor, res, nil +} + +func (p *pathImpl) DepositAuthorized(req *path.DepositAuthorizedRequest) (*path.DepositAuthorizedResponse, XRPLResponse, error) { + res, err := p.client.SendRequest(req) + if err != nil { + return nil, nil, err + } + var dar path.DepositAuthorizedResponse + err = res.GetResult(&dar) + if err != nil { + return nil, nil, err + } + return &dar, res, nil +} + +func (p *pathImpl) NFTokenBuyOffers(req *path.NFTokenBuyOffersRequest) (*path.NFTokenBuyOffersResponse, XRPLResponse, error) { + res, err := p.client.SendRequest(req) + if err != nil { + return nil, nil, err + } + var nbr path.NFTokenBuyOffersResponse + err = res.GetResult(&nbr) + if err != nil { + return nil, nil, err + } + return &nbr, res, nil +} + +func (p *pathImpl) NFTokenSellOffers(req *path.NFTokenSellOffersRequest) (*path.NFTokenSellOffersResponse, XRPLResponse, error) { + res, err := p.client.SendRequest(req) + if err != nil { + return nil, nil, err + } + var nsr path.NFTokenSellOffersResponse + err = res.GetResult(&nsr) + if err != nil { + return nil, nil, err + } + return &nsr, res, nil +} + +func (p *pathImpl) PathFind(req *path.PathFindRequest) (*path.PathFindResponse, XRPLResponse, error) { + res, err := p.client.SendRequest(req) + if err != nil { + return nil, nil, err + } + var pfr path.PathFindResponse + err = res.GetResult(&pfr) + if err != nil { + return nil, nil, err + } + return &pfr, res, nil +} + +func (p *pathImpl) RipplePathFind(req *path.RipplePathFindRequest) (*path.RipplePathFindResponse, XRPLResponse, error) { + res, err := p.client.SendRequest(req) + if err != nil { + return nil, nil, err + } + var rpfr path.RipplePathFindResponse + err = res.GetResult(&rpfr) + if err != nil { + return nil, nil, err + } + return &rpfr, res, nil +} diff --git a/client/server.go b/client/server.go new file mode 100644 index 00000000..a8817991 --- /dev/null +++ b/client/server.go @@ -0,0 +1,66 @@ +package client + +import "github.com/CreatureDev/xrpl-go/model/client/server" + +type Server interface { + Fee(*server.FeeRequest) (*server.FeeResponse, XRPLResponse, error) + Manifest(*server.ManifestRequest) (*server.ManifestResponse, XRPLResponse, error) + ServerInfo(*server.ServerInfoRequest) (*server.ServerInfoResponse, XRPLResponse, error) + ServerState(*server.ServerStateRequest) (*server.ServerStateRequest, XRPLResponse, error) +} + +type serverImpl struct { + client Client +} + +func (s *serverImpl) Fee(req *server.FeeRequest) (*server.FeeResponse, XRPLResponse, error) { + res, err := s.client.SendRequest(req) + if err != nil { + return nil, nil, err + } + var fr server.FeeResponse + err = res.GetResult(&fr) + if err != nil { + return nil, nil, err + } + return &fr, res, nil +} + +func (s *serverImpl) Manifest(req *server.ManifestRequest) (*server.ManifestResponse, XRPLResponse, error) { + res, err := s.client.SendRequest(req) + if err != nil { + return nil, nil, err + } + var mr server.ManifestResponse + err = res.GetResult(&mr) + if err != nil { + return nil, nil, err + } + return &mr, res, nil +} + +func (s *serverImpl) ServerInfo(req *server.ServerInfoRequest) (*server.ServerInfoResponse, XRPLResponse, error) { + res, err := s.client.SendRequest(req) + if err != nil { + return nil, nil, err + } + var sir server.ServerInfoResponse + err = res.GetResult(&sir) + if err != nil { + return nil, nil, err + } + return &sir, res, nil +} + +func (s *serverImpl) ServerState(req *server.ServerStateRequest) (*server.ServerStateResponse, XRPLResponse, error) { + res, err := s.client.SendRequest(req) + if err != nil { + return nil, nil, err + } + var ssr server.ServerStateResponse + err = res.GetResult(&ssr) + if err != nil { + return nil, nil, err + } + return &ssr, res, nil +} diff --git a/client/subscriptions.go b/client/subscriptions.go new file mode 100644 index 00000000..87e95b0e --- /dev/null +++ b/client/subscriptions.go @@ -0,0 +1,40 @@ +package client + +import ( + "github.com/CreatureDev/xrpl-go/model/client/subscription" +) + +type Subscription interface { + Subscribe(*subscription.SubscribeRequest) (*subscription.SubscribeResponse, XRPLResponse, error) + Unsubscribe(*subscription.UnsubscribeRequest) (*subscription.UnsubscribeResponse, XRPLResponse, error) +} + +type subscriptionImpl struct { + client Client +} + +func (s *subscriptionImpl) Subscribe(req *subscription.SubscribeRequest) (*subscription.SubscribeResponse, XRPLResponse, error) { + res, err := s.client.SendRequest(req) + if err != nil { + return nil, nil, err + } + var sr subscription.SubscribeResponse + err = res.GetResult(&sr) + if err != nil { + return nil, nil, err + } + return &sr, res, nil +} + +func (s *subscriptionImpl) Unsubscribe(req *subscription.UnsubscribeRequest) (*subscription.UnsubscribeResponse, XRPLResponse, error) { + res, err := s.client.SendRequest(req) + if err != nil { + return nil, nil, err + } + var ur subscription.UnsubscribeResponse + err = res.GetResult(&ur) + if err != nil { + return nil, nil, err + } + return &ur, res, nil +} diff --git a/client/transactions.go b/client/transactions.go new file mode 100644 index 00000000..964e535a --- /dev/null +++ b/client/transactions.go @@ -0,0 +1,68 @@ +package client + +import ( + "github.com/CreatureDev/xrpl-go/model/client/transactions" +) + +type Transaction interface { + SubmitMultisigned(*transactions.SubmitMultisignedRequest) (*transactions.SubmitMultisignedResponse, XRPLResponse, error) + Submit(*transactions.SubmitRequest) (*transactions.SubmitResponse, XRPLResponse, error) + TransactionEntry(*transactions.TransactionEntryRequest) (*transactions.TransactionEntryResponse, XRPLResponse, error) + Tx(*transactions.TxRequest) (*transactions.TxResponse, XRPLResponse, error) +} + +type transactionImpl struct { + client Client +} + +func (t *transactionImpl) SubmitMultisigned(req *transactions.SubmitMultisignedRequest) (*transactions.SubmitMultisignedResponse, XRPLResponse, error) { + res, err := t.client.SendRequest(req) + if err != nil { + return nil, nil, err + } + var smr transactions.SubmitMultisignedResponse + err = res.GetResult(&smr) + if err != nil { + return nil, nil, err + } + return &smr, res, nil +} + +func (t *transactionImpl) Submit(req *transactions.SubmitRequest) (*transactions.SubmitResponse, XRPLResponse, error) { + res, err := t.client.SendRequest(req) + if err != nil { + return nil, nil, err + } + var sr transactions.SubmitResponse + err = res.GetResult(&sr) + if err != nil { + return nil, nil, err + } + return &sr, res, nil +} + +func (t *transactionImpl) TransactionEntry(req *transactions.TransactionEntryRequest) (*transactions.TransactionEntryResponse, XRPLResponse, error) { + res, err := t.client.SendRequest(req) + if err != nil { + return nil, nil, err + } + var ter transactions.TransactionEntryResponse + err = res.GetResult(&ter) + if err != nil { + return nil, nil, err + } + return &ter, res, nil +} + +func (t *transactionImpl) Tx(req *transactions.TxRequest) (*transactions.TxResponse, XRPLResponse, error) { + res, err := t.client.SendRequest(req) + if err != nil { + return nil, nil, err + } + var tr transactions.TxResponse + err = res.GetResult(&tr) + if err != nil { + return nil, nil, err + } + return &tr, res, nil +} diff --git a/client/websocket/utils.go b/client/websocket/utils.go index d33daeef..ddba7cf9 100644 --- a/client/websocket/utils.go +++ b/client/websocket/utils.go @@ -4,7 +4,7 @@ import ( "encoding/json" "github.com/mitchellh/mapstructure" - "github.com/xyield/xrpl-go/client" + "github.com/CreatureDev/xrpl-go/client" ) func (c *WebsocketClient) formatRequest(req client.XRPLRequest, id int, marker any) ([]byte, error) { diff --git a/client/websocket/utils_test.go b/client/websocket/utils_test.go index aa89f5d7..a6e85064 100644 --- a/client/websocket/utils_test.go +++ b/client/websocket/utils_test.go @@ -4,8 +4,8 @@ import ( "testing" "github.com/stretchr/testify/require" - "github.com/xyield/xrpl-go/client" - "github.com/xyield/xrpl-go/model/client/account" + "github.com/CreatureDev/xrpl-go/client" + "github.com/CreatureDev/xrpl-go/model/client/account" ) func TestFormatRequest(t *testing.T) { diff --git a/client/websocket/websocket_client.go b/client/websocket/websocket_client.go index ae25e448..c7401d45 100644 --- a/client/websocket/websocket_client.go +++ b/client/websocket/websocket_client.go @@ -6,8 +6,8 @@ import ( "errors" "sync/atomic" + "github.com/CreatureDev/xrpl-go/client" "github.com/gorilla/websocket" - "github.com/xyield/xrpl-go/client" ) var _ client.Client = (*WebsocketClient)(nil) @@ -62,7 +62,7 @@ func (c *WebsocketClient) SendRequest(req client.XRPLRequest) (client.XRPLRespon if res.ID != int(id) { return nil, ErrIncorrectId } - if err := res.CheckError(); err != nil { + if err := res.GetError(); err != nil { return nil, err } diff --git a/client/websocket/websocket_client_response.go b/client/websocket/websocket_client_response.go index 696bb45a..f0d2ee12 100644 --- a/client/websocket/websocket_client_response.go +++ b/client/websocket/websocket_client_response.go @@ -1,8 +1,9 @@ package websocket import ( - "github.com/mitchellh/mapstructure" - "github.com/xyield/xrpl-go/client" + "encoding/json" + + "github.com/CreatureDev/xrpl-go/client" ) var _ client.XRPLResponse = (*WebSocketClientXrplResponse)(nil) @@ -21,7 +22,7 @@ type WebSocketClientXrplResponse struct { Status string `json:"status"` Type string `json:"type"` Error string `json:"error,omitempty"` - Result map[string]any `json:"result,omitempty"` + Result json.RawMessage `json:"result,omitempty"` Value map[string]any `json:"value,omitempty"` Warning string `json:"warning,omitempty"` Warnings []client.XRPLResponseWarning `json:"warnings,omitempty"` @@ -29,14 +30,10 @@ type WebSocketClientXrplResponse struct { } func (r *WebSocketClientXrplResponse) GetResult(v any) error { - dec, err := mapstructure.NewDecoder(&mapstructure.DecoderConfig{TagName: "json", Result: &v, DecodeHook: mapstructure.TextUnmarshallerHookFunc()}) - if err != nil { - return err - } - return dec.Decode(r.Result) + return json.Unmarshal(r.Result, v) } -func (r *WebSocketClientXrplResponse) CheckError() error { +func (r *WebSocketClientXrplResponse) GetError() error { if r.Error != "" { return &ErrorWebsocketClientXrplResponse{ Type: r.Error, diff --git a/client/websocket/websocket_client_test.go b/client/websocket/websocket_client_test.go index 69332175..102fa93b 100644 --- a/client/websocket/websocket_client_test.go +++ b/client/websocket/websocket_client_test.go @@ -2,13 +2,14 @@ package websocket import ( "encoding/json" + "fmt" "testing" + "github.com/CreatureDev/xrpl-go/client" + "github.com/CreatureDev/xrpl-go/model/client/account" + "github.com/CreatureDev/xrpl-go/test" "github.com/gorilla/websocket" "github.com/stretchr/testify/require" - "github.com/xyield/xrpl-go/client" - "github.com/xyield/xrpl-go/model/client/account" - "github.com/xyield/xrpl-go/test" ) func TestSendRequest(t *testing.T) { @@ -25,25 +26,8 @@ func TestSendRequest(t *testing.T) { Account: "r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59", }, res: &WebSocketClientXrplResponse{ - ID: 1, - Result: map[string]any{ - "account": "rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn", - "channels": []any{ - map[string]any{ - "account": "rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn", - "amount": "1000", - "balance": "0", - "channel_id": "C7F634794B79DB40E87179A9D1BF05D05797AE7E92DF8E93FD6656E8C4BE3AE7", - "destination_account": "ra5nK24KXen9AHvsdFTKHSANinZseWnPcX", - "public_key": "aBR7mdD75Ycs8DRhMgQ4EMUEmBArF8SEh1hfjrT2V9DQTLNbJVqw", - "public_key_hex": "03CFD18E689434F032A4E84C63E2A3A6472D684EAF4FD52CA67742F3E24BAE81B2", - "settle_delay": json.Number("60"), - }, - }, - "ledger_hash": "1EDBBA3C793863366DF5B31C2174B6B5E6DF6DB89A7212B86838489148E2A581", - "ledger_index": json.Number("71766314"), - "validated": true, - }, + ID: 1, + Result: json.RawMessage(`{"account":"rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn","channels":[{"account":"rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn","amount":"1000","balance":"0","channel_id":"C7F634794B79DB40E87179A9D1BF05D05797AE7E92DF8E93FD6656E8C4BE3AE7","destination_account":"ra5nK24KXen9AHvsdFTKHSANinZseWnPcX","public_key":"aBR7mdD75Ycs8DRhMgQ4EMUEmBArF8SEh1hfjrT2V9DQTLNbJVqw","public_key_hex":"03CFD18E689434F032A4E84C63E2A3A6472D684EAF4FD52CA67742F3E24BAE81B2","settle_delay":60}],"ledger_hash":"1EDBBA3C793863366DF5B31C2174B6B5E6DF6DB89A7212B86838489148E2A581","ledger_index":71766314,"validated":true}`), }, expectedErr: nil, serverMessages: []map[string]any{ @@ -76,24 +60,24 @@ func TestSendRequest(t *testing.T) { Account: "r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59", }, res: &WebSocketClientXrplResponse{ - Result: map[string]any{ - "account": "rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn", - "channels": []any{ - map[string]any{ - "account": "rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn", - "amount": "1000", - "balance": "0", - "channel_id": "C7F634794B79DB40E87179A9D1BF05D05797AE7E92DF8E93FD6656E8C4BE3AE7", - "destination_account": "ra5nK24KXen9AHvsdFTKHSANinZseWnPcX", - "public_key": "aBR7mdD75Ycs8DRhMgQ4EMUEmBArF8SEh1hfjrT2V9DQTLNbJVqw", - "public_key_hex": "03CFD18E689434F032A4E84C63E2A3A6472D684EAF4FD52CA67742F3E24BAE81B2", - "settle_delay": json.Number("60"), - }, - }, - "ledger_hash": "1EDBBA3C793863366DF5B31C2174B6B5E6DF6DB89A7212B86838489148E2A581", - "ledger_index": json.Number("71766314"), - "validated": true, - }, + Result: json.RawMessage(`{ + "account": "rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn", + "channels": [ + { + "account": "rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn", + "amount": "1000", + "balance": "0", + "channel_id": "C7F634794B79DB40E87179A9D1BF05D05797AE7E92DF8E93FD6656E8C4BE3AE7", + "destination_account": "ra5nK24KXen9AHvsdFTKHSANinZseWnPcX", + "public_key": "aBR7mdD75Ycs8DRhMgQ4EMUEmBArF8SEh1hfjrT2V9DQTLNbJVqw", + "public_key_hex": "03CFD18E689434F032A4E84C63E2A3A6472D684EAF4FD52CA67742F3E24BAE81B2", + "settle_delay": json.Number("60"), + } + ], + "ledger_hash": "1EDBBA3C793863366DF5B31C2174B6B5E6DF6DB89A7212B86838489148E2A581", + "ledger_index": 71766314, + "validated": true +}`), }, expectedErr: ErrIncorrectId, serverMessages: []map[string]any{ @@ -127,24 +111,24 @@ func TestSendRequest(t *testing.T) { }, res: &WebSocketClientXrplResponse{ ID: 1, - Result: map[string]any{ - "account": "rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn", - "channels": []any{ - map[string]any{ - "account": "rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn", - "amount": "1000", - "balance": "0", - "channel_id": "C7F634794B79DB40E87179A9D1BF05D05797AE7E92DF8E93FD6656E8C4BE3AE7", - "destination_account": "ra5nK24KXen9AHvsdFTKHSANinZseWnPcX", - "public_key": "aBR7mdD75Ycs8DRhMgQ4EMUEmBArF8SEh1hfjrT2V9DQTLNbJVqw", - "public_key_hex": "03CFD18E689434F032A4E84C63E2A3A6472D684EAF4FD52CA67742F3E24BAE81B2", - "settle_delay": json.Number("60"), - }, - }, - "ledger_hash": "1EDBBA3C793863366DF5B31C2174B6B5E6DF6DB89A7212B86838489148E2A581", - "ledger_index": json.Number("71766314"), - "validated": true, - }, + Result: json.RawMessage(`{ +"account": "rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn", +"channels": [ + { + "account": "rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn", + "amount": "1000", + "balance": "0", + "channel_id": "C7F634794B79DB40E87179A9D1BF05D05797AE7E92DF8E93FD6656E8C4BE3AE7", + "destination_account": "ra5nK24KXen9AHvsdFTKHSANinZseWnPcX", + "public_key": "aBR7mdD75Ycs8DRhMgQ4EMUEmBArF8SEh1hfjrT2V9DQTLNbJVqw", + "public_key_hex": "03CFD18E689434F032A4E84C63E2A3A6472D684EAF4FD52CA67742F3E24BAE81B2", + "settle_delay": json.Number("60"), + } +], +"ledger_hash": "1EDBBA3C793863366DF5B31C2174B6B5E6DF6DB89A7212B86838489148E2A581", +"ledger_index": 71766314, +"validated": true +}`), }, expectedErr: &ErrorWebsocketClientXrplResponse{ Type: "invalidParams", @@ -166,6 +150,7 @@ func TestSendRequest(t *testing.T) { for _, tc := range tt { t.Run(tc.description, func(t *testing.T) { + fmt.Println(tc.description) ws := &test.MockWebSocketServer{Msgs: tc.serverMessages} s := ws.TestWebSocketServer(func(c *websocket.Conn) { for _, m := range tc.serverMessages { diff --git a/examples/jsonrpc-client/jsonrpc_client_example.go b/examples/jsonrpc-client/jsonrpc_client_example.go index ac52bb96..44d11150 100644 --- a/examples/jsonrpc-client/jsonrpc_client_example.go +++ b/examples/jsonrpc-client/jsonrpc_client_example.go @@ -4,9 +4,9 @@ import ( "fmt" "log" - "github.com/xyield/xrpl-go/client" - jsonrpcclient "github.com/xyield/xrpl-go/client/jsonrpc" - "github.com/xyield/xrpl-go/model/client/account" + "github.com/CreatureDev/xrpl-go/client" + jsonrpcclient "github.com/CreatureDev/xrpl-go/client/jsonrpc" + "github.com/CreatureDev/xrpl-go/model/client/account" ) func main() { @@ -22,7 +22,7 @@ func main() { // call the desired method var req *account.AccountChannelsRequest - ac, xrplRes, err := client.Account.GetAccountChannels(req) + ac, xrplRes, err := client.Account.AccountChannels(req) if err != nil { fmt.Println(err.Error()) } diff --git a/examples/websocket/main.go b/examples/websocket/main.go index 2fa577ed..39bcb1de 100644 --- a/examples/websocket/main.go +++ b/examples/websocket/main.go @@ -3,14 +3,14 @@ package main import ( "fmt" - "github.com/xyield/xrpl-go/client/websocket" - "github.com/xyield/xrpl-go/model/client/account" + "github.com/CreatureDev/xrpl-go/client/websocket" + "github.com/CreatureDev/xrpl-go/model/client/account" ) func main() { client := websocket.NewClient(&websocket.WebsocketConfig{URL: "wss://s.altnet.rippletest.net"}) - acr, _, err := client.Account.GetAccountInfo(&account.AccountInfoRequest{Account: "r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59"}) + acr, _, err := client.Account.AccountInfo(&account.AccountInfoRequest{Account: "r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59"}) if err != nil { panic(err) } diff --git a/go.mod b/go.mod index 1f3c50f3..77680b75 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/xyield/xrpl-go +module github.com/CreatureDev/xrpl-go go 1.19 diff --git a/keypairs/ed25519.go b/keypairs/ed25519.go index 8f46abe0..43945949 100644 --- a/keypairs/ed25519.go +++ b/keypairs/ed25519.go @@ -5,7 +5,7 @@ import ( "crypto/ed25519" "encoding/hex" - addresscodec "github.com/xyield/xrpl-go/address-codec" + addresscodec "github.com/CreatureDev/xrpl-go/address-codec" ) type ed25519Alg struct{} diff --git a/keypairs/ed25519_test.go b/keypairs/ed25519_test.go index 6f4154c2..4b50b9db 100644 --- a/keypairs/ed25519_test.go +++ b/keypairs/ed25519_test.go @@ -4,7 +4,7 @@ import ( "testing" "github.com/stretchr/testify/require" - addresscodec "github.com/xyield/xrpl-go/address-codec" + addresscodec "github.com/CreatureDev/xrpl-go/address-codec" ) func TestED25519DeriveKeypair(t *testing.T) { diff --git a/keypairs/keypairs.go b/keypairs/keypairs.go index 281676e4..9dc2e845 100644 --- a/keypairs/keypairs.go +++ b/keypairs/keypairs.go @@ -4,7 +4,7 @@ import ( "crypto/rand" "fmt" - addresscodec "github.com/xyield/xrpl-go/address-codec" + addresscodec "github.com/CreatureDev/xrpl-go/address-codec" ) var r randomizer diff --git a/keypairs/keypairs_test.go b/keypairs/keypairs_test.go index 4d927cd7..95cee780 100644 --- a/keypairs/keypairs_test.go +++ b/keypairs/keypairs_test.go @@ -5,7 +5,7 @@ import ( "testing" "github.com/stretchr/testify/require" - addresscodec "github.com/xyield/xrpl-go/address-codec" + addresscodec "github.com/CreatureDev/xrpl-go/address-codec" ) func TestGenerateEncodeSeed(t *testing.T) { diff --git a/model/client/account/account_channels_request.go b/model/client/account/account_channels_request.go index 8c5f46d5..da6d2f1e 100644 --- a/model/client/account/account_channels_request.go +++ b/model/client/account/account_channels_request.go @@ -2,10 +2,10 @@ package account import ( "encoding/json" - "errors" + "fmt" - "github.com/xyield/xrpl-go/model/client/common" - "github.com/xyield/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/model/client/common" + "github.com/CreatureDev/xrpl-go/model/transactions/types" ) type AccountChannelsRequest struct { @@ -21,10 +21,14 @@ func (*AccountChannelsRequest) Method() string { return "account_channels" } -// Validate method to be added to each request struct -func (a *AccountChannelsRequest) Validate() error { - if a.Account == "" { - return errors.New("no account ID specified") +func (r *AccountChannelsRequest) Validate() error { + if err := r.Account.Validate(); err != nil { + return fmt.Errorf("account channels request: %w", err) + } + if len(r.DestinationAccount) > 0 { + if err := r.DestinationAccount.Validate(); err != nil { + return fmt.Errorf("account channels request: %w", err) + } } return nil diff --git a/model/client/account/account_channels_response.go b/model/client/account/account_channels_response.go index 7b865938..7d74f6cd 100644 --- a/model/client/account/account_channels_response.go +++ b/model/client/account/account_channels_response.go @@ -1,8 +1,8 @@ package account import ( - "github.com/xyield/xrpl-go/model/client/common" - "github.com/xyield/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/model/client/common" + "github.com/CreatureDev/xrpl-go/model/transactions/types" ) type AccountChannelsResponse struct { diff --git a/model/client/account/account_channels_test.go b/model/client/account/account_channels_test.go index 7fd8b9d1..8452f018 100644 --- a/model/client/account/account_channels_test.go +++ b/model/client/account/account_channels_test.go @@ -4,8 +4,8 @@ import ( "testing" "github.com/stretchr/testify/assert" - "github.com/xyield/xrpl-go/model/client/common" - "github.com/xyield/xrpl-go/test" + "github.com/CreatureDev/xrpl-go/model/client/common" + "github.com/CreatureDev/xrpl-go/test" ) func TestAccountChannelRequest(t *testing.T) { @@ -72,5 +72,5 @@ func TestValidate(t *testing.T) { err := s.Validate() - assert.EqualError(t, err, "no account ID specified") + assert.ErrorContains(t, err, "missing xrpl address") } diff --git a/model/client/account/account_currencies_request.go b/model/client/account/account_currencies_request.go index b2ab4eea..524d2cdd 100644 --- a/model/client/account/account_currencies_request.go +++ b/model/client/account/account_currencies_request.go @@ -2,9 +2,10 @@ package account import ( "encoding/json" + "fmt" - "github.com/xyield/xrpl-go/model/client/common" - "github.com/xyield/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/model/client/common" + "github.com/CreatureDev/xrpl-go/model/transactions/types" ) type AccountCurrenciesRequest struct { @@ -18,6 +19,14 @@ func (*AccountCurrenciesRequest) Method() string { return "account_currencies" } +func (r *AccountCurrenciesRequest) Validate() error { + if err := r.Account.Validate(); err != nil { + return fmt.Errorf("account currencies request: %w", err) + } + + return nil +} + func (r *AccountCurrenciesRequest) UnmarshalJSON(data []byte) error { type acrHelper struct { Account types.Address `json:"account"` diff --git a/model/client/account/account_currencies_response.go b/model/client/account/account_currencies_response.go index 4dc1fb49..99d3af2d 100644 --- a/model/client/account/account_currencies_response.go +++ b/model/client/account/account_currencies_response.go @@ -1,7 +1,7 @@ package account import ( - "github.com/xyield/xrpl-go/model/client/common" + "github.com/CreatureDev/xrpl-go/model/client/common" ) type AccountCurrenciesResponse struct { diff --git a/model/client/account/account_currencies_test.go b/model/client/account/account_currencies_test.go index 5de5d787..783e4a9b 100644 --- a/model/client/account/account_currencies_test.go +++ b/model/client/account/account_currencies_test.go @@ -3,8 +3,9 @@ package account import ( "testing" - "github.com/xyield/xrpl-go/model/client/common" - "github.com/xyield/xrpl-go/test" + "github.com/stretchr/testify/assert" + "github.com/CreatureDev/xrpl-go/model/client/common" + "github.com/CreatureDev/xrpl-go/test" ) func TestAccountCurrenciesRequest(t *testing.T) { @@ -55,3 +56,13 @@ func TestAccountCurrenciesResponse(t *testing.T) { t.Error(err) } } + +func TestAccountCurrenciesValidation(t *testing.T) { + s := AccountCurrenciesRequest{ + Account: "", + } + err := s.Validate() + + assert.ErrorContains(t, err, "missing xrpl address") + +} diff --git a/model/client/account/account_info_request.go b/model/client/account/account_info_request.go index 9506ba7d..dd951936 100644 --- a/model/client/account/account_info_request.go +++ b/model/client/account/account_info_request.go @@ -2,9 +2,10 @@ package account import ( "encoding/json" + "fmt" - "github.com/xyield/xrpl-go/model/client/common" - "github.com/xyield/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/model/client/common" + "github.com/CreatureDev/xrpl-go/model/transactions/types" ) type AccountInfoRequest struct { @@ -20,7 +21,11 @@ func (*AccountInfoRequest) Method() string { return "account_info" } -func (*AccountInfoRequest) Validate() error { +func (r *AccountInfoRequest) Validate() error { + if err := r.Account.Validate(); err != nil { + return fmt.Errorf("account info request: %w", err) + } + return nil } diff --git a/model/client/account/account_info_response.go b/model/client/account/account_info_response.go index 358e5f0c..75d32852 100644 --- a/model/client/account/account_info_response.go +++ b/model/client/account/account_info_response.go @@ -1,8 +1,8 @@ package account import ( - "github.com/xyield/xrpl-go/model/client/common" - "github.com/xyield/xrpl-go/model/ledger" + "github.com/CreatureDev/xrpl-go/model/client/common" + "github.com/CreatureDev/xrpl-go/model/ledger" ) type AccountInfoResponse struct { diff --git a/model/client/account/account_info_test.go b/model/client/account/account_info_test.go index 42f129ae..977c5702 100644 --- a/model/client/account/account_info_test.go +++ b/model/client/account/account_info_test.go @@ -3,10 +3,11 @@ package account import ( "testing" - "github.com/xyield/xrpl-go/model/client/common" - "github.com/xyield/xrpl-go/model/ledger" - "github.com/xyield/xrpl-go/model/transactions/types" - "github.com/xyield/xrpl-go/test" + "github.com/stretchr/testify/assert" + "github.com/CreatureDev/xrpl-go/model/client/common" + "github.com/CreatureDev/xrpl-go/model/ledger" + "github.com/CreatureDev/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/test" ) func TestAccountInfoRequest(t *testing.T) { @@ -110,3 +111,13 @@ func TestAccountInfoResponse(t *testing.T) { t.Error(err) } } + +func TestAccountInfoValidate(t *testing.T) { + s := AccountInfoRequest{ + Account: "", + } + + err := s.Validate() + + assert.ErrorContains(t, err, "missing xrpl address") +} diff --git a/model/client/account/account_lines_request.go b/model/client/account/account_lines_request.go index 4cd9dd61..a6897cd9 100644 --- a/model/client/account/account_lines_request.go +++ b/model/client/account/account_lines_request.go @@ -2,9 +2,10 @@ package account import ( "encoding/json" + "fmt" - "github.com/xyield/xrpl-go/model/client/common" - "github.com/xyield/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/model/client/common" + "github.com/CreatureDev/xrpl-go/model/transactions/types" ) type AccountLinesRequest struct { @@ -20,6 +21,23 @@ func (*AccountLinesRequest) Method() string { return "account_lines" } +func (r *AccountLinesRequest) Validate() error { + if err := r.Account.Validate(); err != nil { + 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 { type alrHelper struct { Account types.Address `json:"account"` diff --git a/model/client/account/account_lines_response.go b/model/client/account/account_lines_response.go index ed32acda..850fcefb 100644 --- a/model/client/account/account_lines_response.go +++ b/model/client/account/account_lines_response.go @@ -1,8 +1,8 @@ package account import ( - "github.com/xyield/xrpl-go/model/client/common" - "github.com/xyield/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/model/client/common" + "github.com/CreatureDev/xrpl-go/model/transactions/types" ) type AccountLinesResponse struct { diff --git a/model/client/account/account_lines_test.go b/model/client/account/account_lines_test.go index 5feab943..1f30ad4c 100644 --- a/model/client/account/account_lines_test.go +++ b/model/client/account/account_lines_test.go @@ -3,8 +3,9 @@ package account import ( "testing" - "github.com/xyield/xrpl-go/model/client/common" - "github.com/xyield/xrpl-go/test" + "github.com/stretchr/testify/assert" + "github.com/CreatureDev/xrpl-go/model/client/common" + "github.com/CreatureDev/xrpl-go/test" ) func TestAccountLinesRequest(t *testing.T) { @@ -74,3 +75,19 @@ func TestAccountLinesResponse(t *testing.T) { t.Error(err) } } + +func TestAccountLinesValidate(t *testing.T) { + s := AccountLinesRequest{ + Account: "", + } + + err := s.Validate() + + assert.ErrorContains(t, err, "missing xrpl address") + + s.Account = "r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59" + s.Limit = 2 + err = s.Validate() + + assert.ErrorContains(t, err, "invalid limit") +} diff --git a/model/client/account/account_nfts_request.go b/model/client/account/account_nfts_request.go index 15da7326..637f1cff 100644 --- a/model/client/account/account_nfts_request.go +++ b/model/client/account/account_nfts_request.go @@ -2,9 +2,10 @@ package account import ( "encoding/json" + "fmt" - "github.com/xyield/xrpl-go/model/client/common" - "github.com/xyield/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/model/client/common" + "github.com/CreatureDev/xrpl-go/model/transactions/types" ) type AccountNFTsRequest struct { @@ -19,6 +20,18 @@ func (*AccountNFTsRequest) Method() string { return "account_nfts" } +func (r *AccountNFTsRequest) Validate() error { + if err := r.Account.Validate(); err != nil { + return fmt.Errorf("account nfts request: %w", err) + } + + if r.Limit != 0 && (r.Limit < 20 || r.Limit > 400) { + return fmt.Errorf("account nfts request: invalid limit, must be 20 <= limit <= 400") + } + + return nil +} + func (r *AccountNFTsRequest) UnmarshalJSON(data []byte) error { type anrHelper struct { Account types.Address `json:"account"` diff --git a/model/client/account/account_nfts_response.go b/model/client/account/account_nfts_response.go index c6fe0183..5607d145 100644 --- a/model/client/account/account_nfts_response.go +++ b/model/client/account/account_nfts_response.go @@ -1,8 +1,8 @@ package account import ( - "github.com/xyield/xrpl-go/model/client/common" - "github.com/xyield/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/model/client/common" + "github.com/CreatureDev/xrpl-go/model/transactions/types" ) type AccountNFTsResponse struct { diff --git a/model/client/account/account_nfts_test.go b/model/client/account/account_nfts_test.go index 23b29496..6d392b9a 100644 --- a/model/client/account/account_nfts_test.go +++ b/model/client/account/account_nfts_test.go @@ -3,8 +3,8 @@ package account import ( "testing" - "github.com/xyield/xrpl-go/model/client/common" - "github.com/xyield/xrpl-go/test" + "github.com/CreatureDev/xrpl-go/model/client/common" + "github.com/CreatureDev/xrpl-go/test" ) func TestAccountNFTsRequest(t *testing.T) { diff --git a/model/client/account/account_objects_request.go b/model/client/account/account_objects_request.go index 9111341e..b63b7db6 100644 --- a/model/client/account/account_objects_request.go +++ b/model/client/account/account_objects_request.go @@ -2,9 +2,10 @@ package account import ( "encoding/json" + "fmt" - "github.com/xyield/xrpl-go/model/client/common" - "github.com/xyield/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/model/client/common" + "github.com/CreatureDev/xrpl-go/model/transactions/types" ) type AccountObjectType string @@ -35,6 +36,18 @@ func (*AccountObjectsRequest) Method() string { return "account_objects" } +func (r *AccountObjectsRequest) Validate() error { + if err := r.Account.Validate(); err != nil { + return fmt.Errorf("account objects request: %w", err) + } + + if r.Limit != 0 && (r.Limit < 10 || r.Limit > 400) { + return fmt.Errorf("account objects request: invalid limit, must be 10 <= limit <= 400") + } + + return nil +} + func (r *AccountObjectsRequest) UnmarshalJSON(data []byte) error { type aorHelper struct { Account types.Address `json:"account"` diff --git a/model/client/account/account_objects_response.go b/model/client/account/account_objects_response.go index 01584a21..e3a83324 100644 --- a/model/client/account/account_objects_response.go +++ b/model/client/account/account_objects_response.go @@ -4,9 +4,9 @@ import ( "encoding/json" "fmt" - "github.com/xyield/xrpl-go/model/client/common" - "github.com/xyield/xrpl-go/model/ledger" - "github.com/xyield/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/model/client/common" + "github.com/CreatureDev/xrpl-go/model/ledger" + "github.com/CreatureDev/xrpl-go/model/transactions/types" ) const ( diff --git a/model/client/account/account_objects_test.go b/model/client/account/account_objects_test.go index 3ad46b6a..d5c42ed9 100644 --- a/model/client/account/account_objects_test.go +++ b/model/client/account/account_objects_test.go @@ -3,10 +3,10 @@ package account import ( "testing" - "github.com/xyield/xrpl-go/model/client/common" - "github.com/xyield/xrpl-go/model/ledger" - "github.com/xyield/xrpl-go/model/transactions/types" - "github.com/xyield/xrpl-go/test" + "github.com/CreatureDev/xrpl-go/model/client/common" + "github.com/CreatureDev/xrpl-go/model/ledger" + "github.com/CreatureDev/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/test" ) func TestAccountObjectsRequest(t *testing.T) { diff --git a/model/client/account/account_offers_request.go b/model/client/account/account_offers_request.go index 0056cbef..366fde97 100644 --- a/model/client/account/account_offers_request.go +++ b/model/client/account/account_offers_request.go @@ -2,9 +2,10 @@ package account import ( "encoding/json" + "fmt" - "github.com/xyield/xrpl-go/model/client/common" - "github.com/xyield/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/model/client/common" + "github.com/CreatureDev/xrpl-go/model/transactions/types" ) type AccountOffersRequest struct { @@ -20,6 +21,18 @@ func (*AccountOffersRequest) Method() string { return "account_offers" } +func (r *AccountOffersRequest) Validate() error { + if err := r.Account.Validate(); err != nil { + return fmt.Errorf("account offers request: %w", err) + } + + if r.Limit != 0 && (r.Limit < 10 || r.Limit > 400) { + return fmt.Errorf("account offers request: invalid limit, must be 10 <= limit <= 400") + } + + return nil +} + func (r *AccountOffersRequest) UnmarshalJSON(data []byte) error { type aorHelper struct { Account types.Address `json:"account"` diff --git a/model/client/account/account_offers_response.go b/model/client/account/account_offers_response.go index 4efed803..16e53f38 100644 --- a/model/client/account/account_offers_response.go +++ b/model/client/account/account_offers_response.go @@ -1,8 +1,8 @@ package account import ( - "github.com/xyield/xrpl-go/model/client/common" - "github.com/xyield/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/model/client/common" + "github.com/CreatureDev/xrpl-go/model/transactions/types" ) type AccountOffersResponse struct { diff --git a/model/client/account/account_offers_test.go b/model/client/account/account_offers_test.go index 7ce5172a..4b521686 100644 --- a/model/client/account/account_offers_test.go +++ b/model/client/account/account_offers_test.go @@ -3,9 +3,9 @@ package account import ( "testing" - "github.com/xyield/xrpl-go/model/client/common" - "github.com/xyield/xrpl-go/model/transactions/types" - "github.com/xyield/xrpl-go/test" + "github.com/CreatureDev/xrpl-go/model/client/common" + "github.com/CreatureDev/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/test" ) func TestAccountOffersRequest(t *testing.T) { diff --git a/model/client/account/account_transaction.go b/model/client/account/account_transaction.go index 008b3ebe..45be41a1 100644 --- a/model/client/account/account_transaction.go +++ b/model/client/account/account_transaction.go @@ -4,7 +4,7 @@ import ( "encoding/json" "fmt" - "github.com/xyield/xrpl-go/model/transactions" + "github.com/CreatureDev/xrpl-go/model/transactions" ) const ( diff --git a/model/client/account/account_transactions_request.go b/model/client/account/account_transactions_request.go index 49c2c8c1..cfd574a3 100644 --- a/model/client/account/account_transactions_request.go +++ b/model/client/account/account_transactions_request.go @@ -2,9 +2,10 @@ package account import ( "encoding/json" + "fmt" - "github.com/xyield/xrpl-go/model/client/common" - "github.com/xyield/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/model/client/common" + "github.com/CreatureDev/xrpl-go/model/transactions/types" ) type AccountTransactionsRequest struct { @@ -23,6 +24,18 @@ func (*AccountTransactionsRequest) Method() string { return "account_tx" } +func (r *AccountTransactionsRequest) Validate() error { + if err := r.Account.Validate(); err != nil { + return fmt.Errorf("account transactions request: %w", err) + } + + if r.Limit != 0 && (r.Limit < 10 || r.Limit > 400) { + return fmt.Errorf("account transactions request: invalid limit, must be 10 <= limit <= 400") + } + + return nil +} + func (r *AccountTransactionsRequest) UnmarshalJSON(data []byte) error { type atrHelper struct { Account types.Address `json:"account"` diff --git a/model/client/account/account_transactions_response.go b/model/client/account/account_transactions_response.go index 004dcd4d..372300e1 100644 --- a/model/client/account/account_transactions_response.go +++ b/model/client/account/account_transactions_response.go @@ -1,8 +1,8 @@ package account import ( - "github.com/xyield/xrpl-go/model/client/common" - "github.com/xyield/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/model/client/common" + "github.com/CreatureDev/xrpl-go/model/transactions/types" ) type AccountTransactionsResponse struct { diff --git a/model/client/account/account_transactions_test.go b/model/client/account/account_transactions_test.go index ea13db48..44798ca8 100644 --- a/model/client/account/account_transactions_test.go +++ b/model/client/account/account_transactions_test.go @@ -3,11 +3,11 @@ package account import ( "testing" - "github.com/xyield/xrpl-go/model/client/common" - "github.com/xyield/xrpl-go/model/ledger" - tx "github.com/xyield/xrpl-go/model/transactions" - "github.com/xyield/xrpl-go/model/transactions/types" - "github.com/xyield/xrpl-go/test" + "github.com/CreatureDev/xrpl-go/model/client/common" + "github.com/CreatureDev/xrpl-go/model/ledger" + tx "github.com/CreatureDev/xrpl-go/model/transactions" + "github.com/CreatureDev/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/test" ) func TestAccountTransactionsRequest(t *testing.T) { diff --git a/model/client/account/channel_result.go b/model/client/account/channel_result.go index 5657941c..e228f947 100644 --- a/model/client/account/channel_result.go +++ b/model/client/account/channel_result.go @@ -1,7 +1,7 @@ package account import ( - "github.com/xyield/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/model/transactions/types" ) type ChannelResult struct { diff --git a/model/client/account/nft.go b/model/client/account/nft.go index 6ac3e9f8..0cfea985 100644 --- a/model/client/account/nft.go +++ b/model/client/account/nft.go @@ -1,7 +1,7 @@ package account import ( - "github.com/xyield/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/model/transactions/types" ) const ( diff --git a/model/client/account/offer_result.go b/model/client/account/offer_result.go index ed0b0055..3c1bdbec 100644 --- a/model/client/account/offer_result.go +++ b/model/client/account/offer_result.go @@ -3,7 +3,7 @@ package account import ( "encoding/json" - "github.com/xyield/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/model/transactions/types" ) type OfferResultFlags uint32 diff --git a/model/client/account/queue_data.go b/model/client/account/queue_data.go index d03f298e..123267fe 100644 --- a/model/client/account/queue_data.go +++ b/model/client/account/queue_data.go @@ -1,6 +1,6 @@ package account -import "github.com/xyield/xrpl-go/model/transactions/types" +import "github.com/CreatureDev/xrpl-go/model/transactions/types" type QueueData struct { TxnCount uint64 `json:"txn_count"` diff --git a/model/client/account/queue_transaction.go b/model/client/account/queue_transaction.go index cc177e36..20e61c8d 100644 --- a/model/client/account/queue_transaction.go +++ b/model/client/account/queue_transaction.go @@ -1,6 +1,6 @@ package account -import "github.com/xyield/xrpl-go/model/transactions/types" +import "github.com/CreatureDev/xrpl-go/model/transactions/types" type QueueTransaction struct { AuthChange bool `json:"auth_change"` diff --git a/model/client/account/trust_line.go b/model/client/account/trust_line.go index 291092b1..02505b58 100644 --- a/model/client/account/trust_line.go +++ b/model/client/account/trust_line.go @@ -1,7 +1,7 @@ package account import ( - "github.com/xyield/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/model/transactions/types" ) type TrustLine struct { diff --git a/model/client/admin/data/can_delete_request.go b/model/client/admin/data/can_delete_request.go index 9d1f615d..24add2fe 100644 --- a/model/client/admin/data/can_delete_request.go +++ b/model/client/admin/data/can_delete_request.go @@ -3,7 +3,7 @@ package data import ( "encoding/json" - "github.com/xyield/xrpl-go/model/client/common" + "github.com/CreatureDev/xrpl-go/model/client/common" ) type CanDeleteRequest struct { @@ -14,6 +14,10 @@ func (*CanDeleteRequest) Method() string { return "can_delete" } +func (*CanDeleteRequest) Validate() error { + return nil +} + func (r *CanDeleteRequest) UnmarshalJSON(data []byte) error { type cdHelper struct { CanDelete json.RawMessage `json:"can_delete"` diff --git a/model/client/admin/data/can_delete_test.go b/model/client/admin/data/can_delete_test.go index 85876da9..f9608874 100644 --- a/model/client/admin/data/can_delete_test.go +++ b/model/client/admin/data/can_delete_test.go @@ -3,8 +3,8 @@ package data import ( "testing" - "github.com/xyield/xrpl-go/model/client/common" - "github.com/xyield/xrpl-go/test" + "github.com/CreatureDev/xrpl-go/model/client/common" + "github.com/CreatureDev/xrpl-go/test" ) func TestCanDeleteRequest(t *testing.T) { diff --git a/model/client/admin/data/crawl_shards_request.go b/model/client/admin/data/crawl_shards_request.go index eb96b4d9..1ddd8760 100644 --- a/model/client/admin/data/crawl_shards_request.go +++ b/model/client/admin/data/crawl_shards_request.go @@ -1,5 +1,7 @@ package data +import "fmt" + type CrawlShardsRequest struct { PublicKey bool `json:"public_key,omitempty"` Limit int `json:"limit,omitempty"` @@ -8,3 +10,11 @@ type CrawlShardsRequest struct { func (*CrawlShardsRequest) Method() string { return "crawl_shards" } + +func (r *CrawlShardsRequest) Validate() error { + if r.Limit < 0 || r.Limit > 3 { + return fmt.Errorf("crawl shards request: invalid limit, must be 0 <= limit <= 3") + } + + return nil +} diff --git a/model/client/admin/data/crawl_shards_test.go b/model/client/admin/data/crawl_shards_test.go index 46d20ba7..995b059e 100644 --- a/model/client/admin/data/crawl_shards_test.go +++ b/model/client/admin/data/crawl_shards_test.go @@ -3,7 +3,7 @@ package data import ( "testing" - "github.com/xyield/xrpl-go/test" + "github.com/CreatureDev/xrpl-go/test" ) func TestCrawlShardsRequest(t *testing.T) { diff --git a/model/client/admin/data/download_shard_request.go b/model/client/admin/data/download_shard_request.go index ae35b5cf..f2253269 100644 --- a/model/client/admin/data/download_shard_request.go +++ b/model/client/admin/data/download_shard_request.go @@ -1,6 +1,10 @@ package data -import "github.com/xyield/xrpl-go/model/client/common" +import ( + "fmt" + + "github.com/CreatureDev/xrpl-go/model/client/common" +) type DownloadShardRequest struct { Shards []ShardDescriptor `json:"shards"` @@ -14,3 +18,10 @@ type ShardDescriptor struct { func (*DownloadShardRequest) Method() string { return "download_shard" } + +func (d *DownloadShardRequest) Validate() error { + if len(d.Shards) == 0 { + return fmt.Errorf("download shard request: no shard descriptors provided") + } + return nil +} diff --git a/model/client/admin/data/download_shard_test.go b/model/client/admin/data/download_shard_test.go index d1fefe9d..bdfb9230 100644 --- a/model/client/admin/data/download_shard_test.go +++ b/model/client/admin/data/download_shard_test.go @@ -3,7 +3,7 @@ package data import ( "testing" - "github.com/xyield/xrpl-go/test" + "github.com/CreatureDev/xrpl-go/test" ) func TestDownloadShardsRequest(t *testing.T) { diff --git a/model/client/admin/data/ledger_cleaner_request.go b/model/client/admin/data/ledger_cleaner_request.go index f7adb3e7..9badd630 100644 --- a/model/client/admin/data/ledger_cleaner_request.go +++ b/model/client/admin/data/ledger_cleaner_request.go @@ -1,6 +1,6 @@ package data -import "github.com/xyield/xrpl-go/model/client/common" +import "github.com/CreatureDev/xrpl-go/model/client/common" type LedgerCleanerRequest struct { Ledger common.LedgerIndex `json:"ledger,omitempty"` @@ -15,3 +15,7 @@ type LedgerCleanerRequest struct { func (*LedgerCleanerRequest) Method() string { return "ledger_cleaner" } + +func (*LedgerCleanerRequest) Validate() error { + return nil +} diff --git a/model/client/admin/data/ledger_cleaner_test.go b/model/client/admin/data/ledger_cleaner_test.go index 5cb5c24b..b746ea9e 100644 --- a/model/client/admin/data/ledger_cleaner_test.go +++ b/model/client/admin/data/ledger_cleaner_test.go @@ -3,7 +3,7 @@ package data import ( "testing" - "github.com/xyield/xrpl-go/test" + "github.com/CreatureDev/xrpl-go/test" ) func TestLedgerCleanerRequest(t *testing.T) { diff --git a/model/client/admin/data/ledger_request_request.go b/model/client/admin/data/ledger_request_request.go index 6c7dedfc..9346c42b 100644 --- a/model/client/admin/data/ledger_request_request.go +++ b/model/client/admin/data/ledger_request_request.go @@ -1,6 +1,6 @@ package data -import "github.com/xyield/xrpl-go/model/client/common" +import "github.com/CreatureDev/xrpl-go/model/client/common" type LedgerRequestRequest struct { LedgerIndex common.LedgerIndex `json:"ledger_index,omitempty"` @@ -10,3 +10,7 @@ type LedgerRequestRequest struct { func (*LedgerRequest) Method() string { return "ledger_request" } + +func (*LedgerRequest) Validate() error { + return nil +} diff --git a/model/client/admin/data/ledger_request_response.go b/model/client/admin/data/ledger_request_response.go index 41b72da8..baacb905 100644 --- a/model/client/admin/data/ledger_request_response.go +++ b/model/client/admin/data/ledger_request_response.go @@ -3,8 +3,8 @@ package data import ( "encoding/json" - "github.com/xyield/xrpl-go/model/client/common" - "github.com/xyield/xrpl-go/model/client/ledger" + "github.com/CreatureDev/xrpl-go/model/client/common" + "github.com/CreatureDev/xrpl-go/model/client/ledger" ) type LedgerRequestResponse struct { diff --git a/model/client/admin/data/ledger_request_test.go b/model/client/admin/data/ledger_request_test.go index b6943821..c6b0b00e 100644 --- a/model/client/admin/data/ledger_request_test.go +++ b/model/client/admin/data/ledger_request_test.go @@ -3,9 +3,9 @@ package data import ( "testing" - "github.com/xyield/xrpl-go/model/client/ledger" - "github.com/xyield/xrpl-go/model/transactions/types" - "github.com/xyield/xrpl-go/test" + "github.com/CreatureDev/xrpl-go/model/client/ledger" + "github.com/CreatureDev/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/test" ) func TestLedgerRequestRequest(t *testing.T) { diff --git a/model/client/admin/data/log_level_request.go b/model/client/admin/data/log_level_request.go index ab75171e..4e114adc 100644 --- a/model/client/admin/data/log_level_request.go +++ b/model/client/admin/data/log_level_request.go @@ -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 +} diff --git a/model/client/admin/data/logrotate_request.go b/model/client/admin/data/logrotate_request.go index 2e4cbd70..1df50e5d 100644 --- a/model/client/admin/data/logrotate_request.go +++ b/model/client/admin/data/logrotate_request.go @@ -6,3 +6,7 @@ type LogrotateRequest struct { func (*LogrotateRequest) Method() string { return "logrotate" } + +func (*LogrotateRequest) Validate() error { + return nil +} diff --git a/model/client/admin/data/node_to_shard_request.go b/model/client/admin/data/node_to_shard_request.go index 850e3167..2f37e2da 100644 --- a/model/client/admin/data/node_to_shard_request.go +++ b/model/client/admin/data/node_to_shard_request.go @@ -1,5 +1,7 @@ package data +import "fmt" + type NodeToShardRequest struct { Action string `json:"action"` } @@ -7,3 +9,11 @@ type NodeToShardRequest struct { 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 +} diff --git a/model/client/admin/key/validation_create_request.go b/model/client/admin/key/validation_create_request.go index 4f71ebfc..0a1ca127 100644 --- a/model/client/admin/key/validation_create_request.go +++ b/model/client/admin/key/validation_create_request.go @@ -7,3 +7,7 @@ type ValidationCreateRequest struct { func (*ValidationCreateRequest) Method() string { return "validation_create" } + +func (*ValidationCreateRequest) Validate() error { + return nil +} diff --git a/model/client/admin/key/validation_create_test.go b/model/client/admin/key/validation_create_test.go index af1e0cbd..4c68f754 100644 --- a/model/client/admin/key/validation_create_test.go +++ b/model/client/admin/key/validation_create_test.go @@ -3,7 +3,7 @@ package key import ( "testing" - "github.com/xyield/xrpl-go/test" + "github.com/CreatureDev/xrpl-go/test" ) func TestValidationCreateRequest(t *testing.T) { diff --git a/model/client/admin/key/wallet_propose_request.go b/model/client/admin/key/wallet_propose_request.go index 80864185..27f36e0e 100644 --- a/model/client/admin/key/wallet_propose_request.go +++ b/model/client/admin/key/wallet_propose_request.go @@ -1,5 +1,7 @@ package key +import "fmt" + type WalletProposeRequest struct { KeyType string `json:"key_type,omitempty"` Passphrase string `json:"passphrase,omitempty"` @@ -10,3 +12,20 @@ type WalletProposeRequest struct { func (*WalletProposeRequest) Method() string { return "wallet_propose" } + +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 +} diff --git a/model/client/admin/key/wallet_propose_response.go b/model/client/admin/key/wallet_propose_response.go index 3ba2241b..ca51767e 100644 --- a/model/client/admin/key/wallet_propose_response.go +++ b/model/client/admin/key/wallet_propose_response.go @@ -1,6 +1,6 @@ package key -import "github.com/xyield/xrpl-go/model/transactions/types" +import "github.com/CreatureDev/xrpl-go/model/transactions/types" type WalletProposeResponse struct { KeyType string `json:"key_type"` diff --git a/model/client/admin/key/wallet_propose_test.go b/model/client/admin/key/wallet_propose_test.go index 0971ccb2..63d90148 100644 --- a/model/client/admin/key/wallet_propose_test.go +++ b/model/client/admin/key/wallet_propose_test.go @@ -3,7 +3,7 @@ package key import ( "testing" - "github.com/xyield/xrpl-go/test" + "github.com/CreatureDev/xrpl-go/test" ) func TestWalletProposeRequest(t *testing.T) { diff --git a/model/client/admin/peer/connect_request.go b/model/client/admin/peer/connect_request.go index 334e062d..177eaf42 100644 --- a/model/client/admin/peer/connect_request.go +++ b/model/client/admin/peer/connect_request.go @@ -1,5 +1,7 @@ package peer +import "fmt" + type ConnectRequest struct { IP string `json:"ip"` Port int `json:"port,omitempty"` @@ -8,3 +10,10 @@ type ConnectRequest struct { func (*ConnectRequest) Method() string { return "connect" } + +func (c *ConnectRequest) Validate() error { + if c.IP == "" { + return fmt.Errorf("connect request: missing ip") + } + return nil +} diff --git a/model/client/admin/peer/peer_reservations_add_request.go b/model/client/admin/peer/peer_reservations_add_request.go index b0ff2111..a8da95fd 100644 --- a/model/client/admin/peer/peer_reservations_add_request.go +++ b/model/client/admin/peer/peer_reservations_add_request.go @@ -1,5 +1,7 @@ package peer +import "fmt" + type PeerReservationAddRequest struct { PublicKey string `json:"public_key"` Description string `json:"description,omitempty"` @@ -8,3 +10,10 @@ type PeerReservationAddRequest struct { func (*PeerReservationAddRequest) Method() string { return "peer_reservations_add" } + +func (r *PeerReservationAddRequest) Validate() error { + if r.PublicKey == "" { + return fmt.Errorf("peer reservation add request: missing publickey") + } + return nil +} diff --git a/model/client/admin/peer/peer_reservations_del_request.go b/model/client/admin/peer/peer_reservations_del_request.go index eefae290..34e9f49e 100644 --- a/model/client/admin/peer/peer_reservations_del_request.go +++ b/model/client/admin/peer/peer_reservations_del_request.go @@ -1,5 +1,7 @@ package peer +import "fmt" + type PeerReservationDelRequest struct { PublicKey string `json:"public_key"` } @@ -7,3 +9,10 @@ type PeerReservationDelRequest struct { func (*PeerReservationDelRequest) Method() string { return "peer_reservations_del" } + +func (r *PeerReservationDelRequest) Validate() error { + if r.PublicKey == "" { + return fmt.Errorf("peer reservation del request: missing publickey") + } + return nil +} diff --git a/model/client/admin/peer/peer_reservations_list_request.go b/model/client/admin/peer/peer_reservations_list_request.go index 54c991a2..c2af410c 100644 --- a/model/client/admin/peer/peer_reservations_list_request.go +++ b/model/client/admin/peer/peer_reservations_list_request.go @@ -6,3 +6,7 @@ type PeerReservationsListRequest struct { func (*PeerReservationsListRequest) Method() string { return "peer_reservations_list" } + +func (*PeerReservationsListRequest) Validate() error { + return nil +} diff --git a/model/client/admin/peer/peer_reservations_list_test.go b/model/client/admin/peer/peer_reservations_list_test.go index 0b68f643..f62a2fc8 100644 --- a/model/client/admin/peer/peer_reservations_list_test.go +++ b/model/client/admin/peer/peer_reservations_list_test.go @@ -3,7 +3,7 @@ package peer import ( "testing" - "github.com/xyield/xrpl-go/test" + "github.com/CreatureDev/xrpl-go/test" ) func TestPeerReservationsListResponse(t *testing.T) { diff --git a/model/client/admin/peer/peers_request.go b/model/client/admin/peer/peers_request.go index c1ceafa5..2e4ab33b 100644 --- a/model/client/admin/peer/peers_request.go +++ b/model/client/admin/peer/peers_request.go @@ -6,3 +6,7 @@ type PeersRequest struct { func (*PeersRequest) Method() string { return "peers" } + +func (*PeersRequest) Validate() error { + return nil +} diff --git a/model/client/admin/peer/peers_test.go b/model/client/admin/peer/peers_test.go index 496f3bb2..38541198 100644 --- a/model/client/admin/peer/peers_test.go +++ b/model/client/admin/peer/peers_test.go @@ -3,7 +3,7 @@ package peer import ( "testing" - "github.com/xyield/xrpl-go/test" + "github.com/CreatureDev/xrpl-go/test" ) func TestPeersResponse(t *testing.T) { diff --git a/model/client/admin/server/ledger_accept_request.go b/model/client/admin/server/ledger_accept_request.go index 550f5089..3e47223b 100644 --- a/model/client/admin/server/ledger_accept_request.go +++ b/model/client/admin/server/ledger_accept_request.go @@ -4,5 +4,9 @@ type LedgerAcceptRequest struct { } func (*LedgerAcceptRequest) Method() string { - return "leder_accept" + return "ledger_accept" +} + +func (*LedgerAcceptRequest) Validate() error { + return nil } diff --git a/model/client/admin/server/ledger_accept_response.go b/model/client/admin/server/ledger_accept_response.go index 4926a370..2bc9da05 100644 --- a/model/client/admin/server/ledger_accept_response.go +++ b/model/client/admin/server/ledger_accept_response.go @@ -1,6 +1,6 @@ package server -import "github.com/xyield/xrpl-go/model/client/common" +import "github.com/CreatureDev/xrpl-go/model/client/common" type LedgerAcceptResponse struct { LedgerCurrentIndex common.LedgerIndex `json:"ledger_current_index"` diff --git a/model/client/admin/server/stop_request.go b/model/client/admin/server/stop_request.go index 9083f4c1..dd2e3127 100644 --- a/model/client/admin/server/stop_request.go +++ b/model/client/admin/server/stop_request.go @@ -6,3 +6,7 @@ type StopRequest struct { func (*StopRequest) Method() string { return "stop" } + +func (*StopRequest) Validate() error { + return nil +} diff --git a/model/client/admin/signing/sign_for_request.go b/model/client/admin/signing/sign_for_request.go index 046f9da0..0696f664 100644 --- a/model/client/admin/signing/sign_for_request.go +++ b/model/client/admin/signing/sign_for_request.go @@ -2,9 +2,10 @@ package signing import ( "encoding/json" + "fmt" - "github.com/xyield/xrpl-go/model/transactions" - "github.com/xyield/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/model/transactions" + "github.com/CreatureDev/xrpl-go/model/transactions/types" ) type SignForRequest struct { @@ -21,6 +22,35 @@ func (*SignForRequest) Method() string { return "sign_for" } +func (r *SignForRequest) Validate() error { + if err := r.Account.Validate(); err != nil { + return fmt.Errorf("sign for request: %w", err) + } + + if r.TxJson == nil { + 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 +} + func (r *SignForRequest) UnmarshalJSON(data []byte) error { type srHelper struct { Account types.Address `json:"account"` diff --git a/model/client/admin/signing/sign_for_response.go b/model/client/admin/signing/sign_for_response.go index c4ef9ba0..881b2657 100644 --- a/model/client/admin/signing/sign_for_response.go +++ b/model/client/admin/signing/sign_for_response.go @@ -3,7 +3,7 @@ package signing import ( "encoding/json" - "github.com/xyield/xrpl-go/model/transactions" + "github.com/CreatureDev/xrpl-go/model/transactions" ) type SignForResponse struct { diff --git a/model/client/admin/signing/sign_for_test.go b/model/client/admin/signing/sign_for_test.go index 970157ed..22c50bcb 100644 --- a/model/client/admin/signing/sign_for_test.go +++ b/model/client/admin/signing/sign_for_test.go @@ -3,9 +3,9 @@ package signing import ( "testing" - "github.com/xyield/xrpl-go/model/transactions" - "github.com/xyield/xrpl-go/model/transactions/types" - "github.com/xyield/xrpl-go/test" + "github.com/CreatureDev/xrpl-go/model/transactions" + "github.com/CreatureDev/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/test" ) func TestSignForRequest(t *testing.T) { diff --git a/model/client/admin/signing/sign_request.go b/model/client/admin/signing/sign_request.go index 6a2b66eb..de64814e 100644 --- a/model/client/admin/signing/sign_request.go +++ b/model/client/admin/signing/sign_request.go @@ -2,8 +2,9 @@ package signing import ( "encoding/json" + "fmt" - "github.com/xyield/xrpl-go/model/transactions" + "github.com/CreatureDev/xrpl-go/model/transactions" ) type SignRequest struct { @@ -23,6 +24,14 @@ func (*SignRequest) Method() string { return "sign" } +func (r *SignRequest) Validate() error { + if r.TxJson == nil { + return fmt.Errorf("sign request: empty tx") + } + + return nil +} + func (r *SignRequest) UnmarshalJSON(data []byte) error { type srHelper struct { TxJson json.RawMessage `json:"tx_json"` diff --git a/model/client/admin/signing/sign_response.go b/model/client/admin/signing/sign_response.go index f9773907..9c147eb7 100644 --- a/model/client/admin/signing/sign_response.go +++ b/model/client/admin/signing/sign_response.go @@ -3,7 +3,7 @@ package signing import ( "encoding/json" - "github.com/xyield/xrpl-go/model/transactions" + "github.com/CreatureDev/xrpl-go/model/transactions" ) type SignResponse struct { diff --git a/model/client/admin/signing/sign_test.go b/model/client/admin/signing/sign_test.go index a78e556b..85d00e9c 100644 --- a/model/client/admin/signing/sign_test.go +++ b/model/client/admin/signing/sign_test.go @@ -3,9 +3,9 @@ package signing import ( "testing" - "github.com/xyield/xrpl-go/model/transactions" - "github.com/xyield/xrpl-go/model/transactions/types" - "github.com/xyield/xrpl-go/test" + "github.com/CreatureDev/xrpl-go/model/transactions" + "github.com/CreatureDev/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/test" ) func TestSignRequest(t *testing.T) { diff --git a/model/client/admin/status/consensus_info_request.go b/model/client/admin/status/consensus_info_request.go index 8b9c9677..bbaef342 100644 --- a/model/client/admin/status/consensus_info_request.go +++ b/model/client/admin/status/consensus_info_request.go @@ -6,3 +6,7 @@ type ConsensusInfoRequest struct { func (*ConsensusInfoRequest) Method() string { return "consensus_info" } + +func (*ConsensusInfoRequest) Validate() error { + return nil +} diff --git a/model/client/admin/status/consensus_info_response.go b/model/client/admin/status/consensus_info_response.go index fbea079a..7088c9c7 100644 --- a/model/client/admin/status/consensus_info_response.go +++ b/model/client/admin/status/consensus_info_response.go @@ -1,6 +1,6 @@ package status -import "github.com/xyield/xrpl-go/model/client/common" +import "github.com/CreatureDev/xrpl-go/model/client/common" type ConsensusInfoResponse struct { Info ConsensusInfo `json:"info"` diff --git a/model/client/admin/status/consensus_info_test.go b/model/client/admin/status/consensus_info_test.go index 50f0c689..54d2f319 100644 --- a/model/client/admin/status/consensus_info_test.go +++ b/model/client/admin/status/consensus_info_test.go @@ -3,7 +3,7 @@ package status import ( "testing" - "github.com/xyield/xrpl-go/test" + "github.com/CreatureDev/xrpl-go/test" ) func TestConsensusInfoResponse(t *testing.T) { diff --git a/model/client/admin/status/feature_request.go b/model/client/admin/status/feature_request.go index 4daa8148..572b17d9 100644 --- a/model/client/admin/status/feature_request.go +++ b/model/client/admin/status/feature_request.go @@ -8,3 +8,7 @@ type FeatureRequest struct { func (*FeatureRequest) Method() string { return "feature" } + +func (*FeatureRequest) Validate() error { + return nil +} diff --git a/model/client/admin/status/feature_test.go b/model/client/admin/status/feature_test.go index e10ee177..6a3486ce 100644 --- a/model/client/admin/status/feature_test.go +++ b/model/client/admin/status/feature_test.go @@ -3,7 +3,7 @@ package status import ( "testing" - "github.com/xyield/xrpl-go/test" + "github.com/CreatureDev/xrpl-go/test" ) func TestFeatureResponse(t *testing.T) { diff --git a/model/client/admin/status/fetch_info_request.go b/model/client/admin/status/fetch_info_request.go index c671a759..0ed1e245 100644 --- a/model/client/admin/status/fetch_info_request.go +++ b/model/client/admin/status/fetch_info_request.go @@ -7,3 +7,7 @@ type FetchInfoRequest struct { func (*FetchInfoRequest) Method() string { return "fetch_info" } + +func (*FetchInfoRequest) Validate() error { + return nil +} diff --git a/model/client/admin/status/fetch_info_test.go b/model/client/admin/status/fetch_info_test.go index 2ccf845e..0bed22c0 100644 --- a/model/client/admin/status/fetch_info_test.go +++ b/model/client/admin/status/fetch_info_test.go @@ -3,7 +3,7 @@ package status import ( "testing" - "github.com/xyield/xrpl-go/test" + "github.com/CreatureDev/xrpl-go/test" ) func TestFetchInfoResponse(t *testing.T) { diff --git a/model/client/admin/status/get_counts_request.go b/model/client/admin/status/get_counts_request.go index 2e72847a..59e236f0 100644 --- a/model/client/admin/status/get_counts_request.go +++ b/model/client/admin/status/get_counts_request.go @@ -7,3 +7,7 @@ type GetCountsRequest struct { func (*GetCountsRequest) Method() string { return "get_counts" } + +func (*GetCountsRequest) Validate() error { + return nil +} diff --git a/model/client/admin/status/get_counts_test.go b/model/client/admin/status/get_counts_test.go index da36da87..385f450d 100644 --- a/model/client/admin/status/get_counts_test.go +++ b/model/client/admin/status/get_counts_test.go @@ -3,7 +3,7 @@ package status import ( "testing" - "github.com/xyield/xrpl-go/test" + "github.com/CreatureDev/xrpl-go/test" ) func TestGetCountsResponse(t *testing.T) { diff --git a/model/client/admin/status/print_request.go b/model/client/admin/status/print_request.go new file mode 100644 index 00000000..5d98269e --- /dev/null +++ b/model/client/admin/status/print_request.go @@ -0,0 +1,12 @@ +package status + +type PrintRequest struct { +} + +func (*PrintRequest) Method() string { + return "print" +} + +func (*PrintRequest) Validate() error { + return nil +} diff --git a/model/client/admin/status/print_response.go b/model/client/admin/status/print_response.go new file mode 100644 index 00000000..cb7d6d91 --- /dev/null +++ b/model/client/admin/status/print_response.go @@ -0,0 +1,5 @@ +package status + +type PrintResponse struct { + App map[string]any `json:"app"` +} diff --git a/model/client/admin/status/validator_info_request.go b/model/client/admin/status/validator_info_request.go index 0ab6ad8b..6fa7ac3d 100644 --- a/model/client/admin/status/validator_info_request.go +++ b/model/client/admin/status/validator_info_request.go @@ -6,3 +6,7 @@ type ValidatorInfoRequest struct { func (*ValidatorInfoRequest) Method() string { return "validator_info" } + +func (*ValidatorInfoRequest) Validate() error { + return nil +} diff --git a/model/client/admin/status/validator_info_test.go b/model/client/admin/status/validator_info_test.go index 80a47814..0ce65e10 100644 --- a/model/client/admin/status/validator_info_test.go +++ b/model/client/admin/status/validator_info_test.go @@ -3,7 +3,7 @@ package status import ( "testing" - "github.com/xyield/xrpl-go/test" + "github.com/CreatureDev/xrpl-go/test" ) func TestValidatorInfoResponse(t *testing.T) { diff --git a/model/client/admin/status/validator_list_sites_request.go b/model/client/admin/status/validator_list_sites_request.go index 6df3a907..430cd55f 100644 --- a/model/client/admin/status/validator_list_sites_request.go +++ b/model/client/admin/status/validator_list_sites_request.go @@ -6,3 +6,7 @@ type ValidatorListSitesRequest struct { func (*ValidatorListSitesRequest) Method() string { return "validator_list_sites" } + +func (*ValidatorListSitesRequest) Validate() error { + return nil +} diff --git a/model/client/admin/status/validator_list_sites_test.go b/model/client/admin/status/validator_list_sites_test.go index bc63a412..7e5911bc 100644 --- a/model/client/admin/status/validator_list_sites_test.go +++ b/model/client/admin/status/validator_list_sites_test.go @@ -3,7 +3,7 @@ package status import ( "testing" - "github.com/xyield/xrpl-go/test" + "github.com/CreatureDev/xrpl-go/test" ) func TestValidatorListSitesResponse(t *testing.T) { diff --git a/model/client/admin/status/validators_request.go b/model/client/admin/status/validators_request.go index 354f344f..584a2fdc 100644 --- a/model/client/admin/status/validators_request.go +++ b/model/client/admin/status/validators_request.go @@ -6,3 +6,7 @@ type ValidatorsRequest struct { func (*ValidatorsRequest) Method() string { return "validators" } + +func (*ValidatorsRequest) Validate() error { + return nil +} diff --git a/model/client/admin/status/validators_test.go b/model/client/admin/status/validators_test.go index bff185c9..decd43f5 100644 --- a/model/client/admin/status/validators_test.go +++ b/model/client/admin/status/validators_test.go @@ -3,7 +3,7 @@ package status import ( "testing" - "github.com/xyield/xrpl-go/test" + "github.com/CreatureDev/xrpl-go/test" ) func TestValidatorsResponse(t *testing.T) { diff --git a/model/client/channel/channel_authorize_request.go b/model/client/channel/channel_authorize_request.go index f4af62a8..85ae1f27 100644 --- a/model/client/channel/channel_authorize_request.go +++ b/model/client/channel/channel_authorize_request.go @@ -3,7 +3,7 @@ package channel import ( "fmt" - "github.com/xyield/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/model/transactions/types" ) type ChannelAuthorizeRequest struct { @@ -20,6 +20,32 @@ func (*ChannelAuthorizeRequest) Method() string { return "channel_authorize" } +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 +} + // do not allow secrets to be printed func (c *ChannelAuthorizeRequest) Format(s fmt.State, v rune) { type fHelper struct { diff --git a/model/client/channel/channel_authorize_test.go b/model/client/channel/channel_authorize_test.go index 53e89e9c..9a4d0f02 100644 --- a/model/client/channel/channel_authorize_test.go +++ b/model/client/channel/channel_authorize_test.go @@ -3,8 +3,9 @@ package channel import ( "testing" - "github.com/xyield/xrpl-go/model/transactions/types" - "github.com/xyield/xrpl-go/test" + "github.com/stretchr/testify/assert" + "github.com/CreatureDev/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/test" ) func TestChannelAuthorizeRequest(t *testing.T) { @@ -39,3 +40,25 @@ func TestChannelAuthorizeResponse(t *testing.T) { t.Error(err) } } + +func TestChannelAuthorizeValidate(t *testing.T) { + s := ChannelAuthorizeRequest{} + err := s.Validate() + assert.ErrorContains(t, err, "missing channel id") + + s = ChannelAuthorizeRequest{ + 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") +} diff --git a/model/client/channel/channel_verify_request.go b/model/client/channel/channel_verify_request.go index d3e54eff..602f5ef3 100644 --- a/model/client/channel/channel_verify_request.go +++ b/model/client/channel/channel_verify_request.go @@ -1,10 +1,14 @@ package channel -import "github.com/xyield/xrpl-go/model/transactions/types" +import ( + "fmt" + + "github.com/CreatureDev/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"` } @@ -12,3 +16,16 @@ type ChannelVerifyRequest struct { func (*ChannelVerifyRequest) Method() string { return "channel_verify" } + +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 +} diff --git a/model/client/channel/channel_verify_test.go b/model/client/channel/channel_verify_test.go index 141d7b7c..02adaa91 100644 --- a/model/client/channel/channel_verify_test.go +++ b/model/client/channel/channel_verify_test.go @@ -3,8 +3,8 @@ package channel import ( "testing" - "github.com/xyield/xrpl-go/model/transactions/types" - "github.com/xyield/xrpl-go/test" + "github.com/CreatureDev/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/test" ) func TestChannelVerifyRequest(t *testing.T) { diff --git a/model/client/clio/ledger_request.go b/model/client/clio/ledger_request.go index e8ad6a88..32424147 100644 --- a/model/client/clio/ledger_request.go +++ b/model/client/clio/ledger_request.go @@ -3,7 +3,7 @@ package clio import ( "encoding/json" - "github.com/xyield/xrpl-go/model/client/common" + "github.com/CreatureDev/xrpl-go/model/client/common" ) type LedgerRequest struct { @@ -23,6 +23,10 @@ func (*LedgerRequest) Method() string { return "ledger" } +func (*LedgerRequest) Validate() error { + return nil +} + func (r *LedgerRequest) UnmarshalJSON(data []byte) error { type lrHelper struct { LedgerHash common.LedgerHash `json:"ledger_hash"` diff --git a/model/client/clio/ledger_response.go b/model/client/clio/ledger_response.go index 1a41f00b..fa2e57bd 100644 --- a/model/client/clio/ledger_response.go +++ b/model/client/clio/ledger_response.go @@ -3,10 +3,10 @@ package clio import ( "encoding/json" - "github.com/xyield/xrpl-go/model/client/common" - "github.com/xyield/xrpl-go/model/ledger" - "github.com/xyield/xrpl-go/model/transactions" - "github.com/xyield/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/model/client/common" + "github.com/CreatureDev/xrpl-go/model/ledger" + "github.com/CreatureDev/xrpl-go/model/transactions" + "github.com/CreatureDev/xrpl-go/model/transactions/types" ) type LedgerResponse struct { diff --git a/model/client/clio/ledger_test.go b/model/client/clio/ledger_test.go index c2c7fb30..f317f80c 100644 --- a/model/client/clio/ledger_test.go +++ b/model/client/clio/ledger_test.go @@ -3,8 +3,8 @@ package clio import ( "testing" - "github.com/xyield/xrpl-go/model/client/common" - "github.com/xyield/xrpl-go/test" + "github.com/CreatureDev/xrpl-go/model/client/common" + "github.com/CreatureDev/xrpl-go/test" ) func TestLedgerRequest(t *testing.T) { diff --git a/model/client/clio/nft_history_request.go b/model/client/clio/nft_history_request.go new file mode 100644 index 00000000..87e0be13 --- /dev/null +++ b/model/client/clio/nft_history_request.go @@ -0,0 +1,63 @@ +package clio + +import ( + "encoding/json" + "fmt" + + "github.com/CreatureDev/xrpl-go/model/client/common" + "github.com/CreatureDev/xrpl-go/model/transactions/types" +) + +type NFTHistoryRequest struct { + NFTokenID types.NFTokenID `json:"nft_id"` + LedgerIndexMin common.LedgerIndex `json:"ledger_index_min,omitempty"` + LedgerIndexMax common.LedgerIndex `json:"ledger_index_max,omitempty"` + LedgerHash common.LedgerHash `json:"ledger_hash,omitempty"` + LedgerIndex common.LedgerSpecifier `json:"ledger_index,omitempty"` + Binary bool `json:"binary,omitempty"` + Forward bool `json:"forward,omitempty"` + Limit uint32 `json:"limit,omitempty"` + Marker any `json:"marker,omitempty"` +} + +func (*NFTHistoryRequest) Method() string { + return "nft_history" +} + +func (r *NFTHistoryRequest) Validate() error { + if err := r.NFTokenID.Validate(); err != nil { + return fmt.Errorf("nft history request: %w", err) + } + return nil +} + +func (r *NFTHistoryRequest) UnmarshalJSON(data []byte) error { + type nhrHelper struct { + NFTokenID types.NFTokenID `json:"nft_id"` + LedgerIndexMin common.LedgerIndex `json:"ledger_index_min,omitempty"` + LedgerIndexMax common.LedgerIndex `json:"ledger_index_max,omitempty"` + LedgerHash common.LedgerHash `json:"ledger_hash,omitempty"` + LedgerIndex json.RawMessage `json:"ledger_index,omitempty"` + Binary bool `json:"binary,omitempty"` + Forward bool `json:"forward,omitempty"` + Limit uint32 `json:"limit,omitempty"` + Marker any `json:"marker,omitempty"` + } + var h nhrHelper + err := json.Unmarshal(data, &h) + if err != nil { + return err + } + *r = NFTHistoryRequest{ + NFTokenID: h.NFTokenID, + LedgerIndexMin: h.LedgerIndexMin, + LedgerIndexMax: h.LedgerIndexMax, + LedgerHash: h.LedgerHash, + Binary: h.Binary, + Forward: h.Forward, + Limit: h.Limit, + Marker: h.Marker, + } + r.LedgerIndex, err = common.UnmarshalLedgerSpecifier(h.LedgerIndex) + return err +} diff --git a/model/client/clio/nft_history_response.go b/model/client/clio/nft_history_response.go new file mode 100644 index 00000000..3e3ea707 --- /dev/null +++ b/model/client/clio/nft_history_response.go @@ -0,0 +1,17 @@ +package clio + +import ( + "github.com/CreatureDev/xrpl-go/model/client/account" + "github.com/CreatureDev/xrpl-go/model/client/common" + "github.com/CreatureDev/xrpl-go/model/transactions/types" +) + +type NFTHistoryResponse struct { + NFTokenID types.NFTokenID `json:"nft_id"` + LedgerIndexMin common.LedgerIndex `json:"ledger_index_min"` + LedgerIndexMax common.LedgerIndex `json:"ledger_index_max"` + Limit uint `json:"limit"` + Marker any `json:"marker"` + Transactions []account.AccountTransaction `json:"transactions"` + Validated bool `json:"validated"` +} diff --git a/model/client/clio/nft_info_request.go b/model/client/clio/nft_info_request.go index 0ada2376..24c00b31 100644 --- a/model/client/clio/nft_info_request.go +++ b/model/client/clio/nft_info_request.go @@ -2,9 +2,10 @@ package clio import ( "encoding/json" + "fmt" - "github.com/xyield/xrpl-go/model/client/common" - "github.com/xyield/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/model/client/common" + "github.com/CreatureDev/xrpl-go/model/transactions/types" ) type NFTInfoRequest struct { @@ -17,6 +18,13 @@ func (*NFTInfoRequest) Method() string { return "nft_info" } +func (r *NFTInfoRequest) Validate() error { + if err := r.NFTokenID.Validate(); err != nil { + return fmt.Errorf("nft info request: %w", err) + } + return nil +} + func (r *NFTInfoRequest) UnmarshalJSON(data []byte) error { type nirHelper struct { NFTokenID types.NFTokenID `json:"nft_id"` diff --git a/model/client/clio/nft_info_response.go b/model/client/clio/nft_info_response.go index c9ed20f4..e4a4480a 100644 --- a/model/client/clio/nft_info_response.go +++ b/model/client/clio/nft_info_response.go @@ -1,8 +1,8 @@ package clio import ( - "github.com/xyield/xrpl-go/model/client/common" - "github.com/xyield/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/model/client/common" + "github.com/CreatureDev/xrpl-go/model/transactions/types" ) type NFTInfoResponse struct { diff --git a/model/client/clio/nft_info_test.go b/model/client/clio/nft_info_test.go index 68f3a8d9..84bb2e8d 100644 --- a/model/client/clio/nft_info_test.go +++ b/model/client/clio/nft_info_test.go @@ -3,8 +3,8 @@ package clio import ( "testing" - "github.com/xyield/xrpl-go/model/client/common" - "github.com/xyield/xrpl-go/test" + "github.com/CreatureDev/xrpl-go/model/client/common" + "github.com/CreatureDev/xrpl-go/test" ) func TestNFTInfoRequest(t *testing.T) { diff --git a/model/client/clio/server_info_request.go b/model/client/clio/server_info_request.go index a285d90f..215efeca 100644 --- a/model/client/clio/server_info_request.go +++ b/model/client/clio/server_info_request.go @@ -6,3 +6,7 @@ type ServerInfoRequest struct { func (*ServerInfoRequest) Method() string { return "server_info" } + +func (*ServerInfoRequest) Validate() error { + return nil +} diff --git a/model/client/clio/server_info_response.go b/model/client/clio/server_info_response.go index d569ccc8..b872ffe0 100644 --- a/model/client/clio/server_info_response.go +++ b/model/client/clio/server_info_response.go @@ -1,6 +1,6 @@ package clio -import "github.com/xyield/xrpl-go/model/transactions/types" +import "github.com/CreatureDev/xrpl-go/model/transactions/types" type ServerInfoResponse struct { Info ClioServerInfo `json:"info"` diff --git a/model/client/clio/server_info_test.go b/model/client/clio/server_info_test.go index f261e2b0..1da7e3fa 100644 --- a/model/client/clio/server_info_test.go +++ b/model/client/clio/server_info_test.go @@ -3,7 +3,7 @@ package clio import ( "testing" - "github.com/xyield/xrpl-go/test" + "github.com/CreatureDev/xrpl-go/test" ) func TestServerInfoResponseLocalhost(t *testing.T) { diff --git a/model/client/ledger/ledger_closed_request.go b/model/client/ledger/ledger_closed_request.go index d58da25e..f8d8c456 100644 --- a/model/client/ledger/ledger_closed_request.go +++ b/model/client/ledger/ledger_closed_request.go @@ -6,3 +6,7 @@ type LedgerClosedRequest struct { func (*LedgerClosedRequest) Method() string { return "ledger_closed" } + +func (*LedgerClosedRequest) Validate() error { + return nil +} diff --git a/model/client/ledger/ledger_closed_response.go b/model/client/ledger/ledger_closed_response.go index bdeddbc1..697b7be1 100644 --- a/model/client/ledger/ledger_closed_response.go +++ b/model/client/ledger/ledger_closed_response.go @@ -1,6 +1,6 @@ package ledger -import "github.com/xyield/xrpl-go/model/client/common" +import "github.com/CreatureDev/xrpl-go/model/client/common" type LedgerClosedResponse struct { LedgerHash string `json:"ledger_hash"` diff --git a/model/client/ledger/ledger_closed_test.go b/model/client/ledger/ledger_closed_test.go index 21d51acb..cb149b75 100644 --- a/model/client/ledger/ledger_closed_test.go +++ b/model/client/ledger/ledger_closed_test.go @@ -3,7 +3,7 @@ package ledger import ( "testing" - "github.com/xyield/xrpl-go/test" + "github.com/CreatureDev/xrpl-go/test" ) // Ledger closed request does not have any fields to test diff --git a/model/client/ledger/ledger_current_request.go b/model/client/ledger/ledger_current_request.go index b9c40317..687f9682 100644 --- a/model/client/ledger/ledger_current_request.go +++ b/model/client/ledger/ledger_current_request.go @@ -6,3 +6,7 @@ type LedgerCurrentRequest struct { func (*LedgerCurrentRequest) Method() string { return "ledger_current" } + +func (*LedgerCurrentRequest) Validate() error { + return nil +} diff --git a/model/client/ledger/ledger_current_response.go b/model/client/ledger/ledger_current_response.go index b239dec0..908f12f3 100644 --- a/model/client/ledger/ledger_current_response.go +++ b/model/client/ledger/ledger_current_response.go @@ -1,6 +1,6 @@ package ledger -import "github.com/xyield/xrpl-go/model/client/common" +import "github.com/CreatureDev/xrpl-go/model/client/common" type LedgerCurrentResponse struct { LedgerCurrentIndex common.LedgerIndex `json:"ledger_current_index"` diff --git a/model/client/ledger/ledger_current_test.go b/model/client/ledger/ledger_current_test.go index bfebfb55..1302cff7 100644 --- a/model/client/ledger/ledger_current_test.go +++ b/model/client/ledger/ledger_current_test.go @@ -3,7 +3,7 @@ package ledger import ( "testing" - "github.com/xyield/xrpl-go/test" + "github.com/CreatureDev/xrpl-go/test" ) // Ledger Current request has no fields to test diff --git a/model/client/ledger/ledger_data_request.go b/model/client/ledger/ledger_data_request.go index 6fa6bc67..734aaecc 100644 --- a/model/client/ledger/ledger_data_request.go +++ b/model/client/ledger/ledger_data_request.go @@ -3,8 +3,8 @@ package ledger import ( "encoding/json" - "github.com/xyield/xrpl-go/model/client/common" - "github.com/xyield/xrpl-go/model/ledger" + "github.com/CreatureDev/xrpl-go/model/client/common" + "github.com/CreatureDev/xrpl-go/model/ledger" ) type LedgerDataRequest struct { @@ -44,3 +44,12 @@ func (r *LedgerDataRequest) UnmarshalJSON(data []byte) error { return nil } + +func (r *LedgerDataRequest) Validate() error { + // invalid limits are overwritten server-side + return nil +} + +func (r *LedgerDataRequest) Method() string { + return "ledger_data" +} diff --git a/model/client/ledger/ledger_data_response.go b/model/client/ledger/ledger_data_response.go index 5c40d6c9..e33b0407 100644 --- a/model/client/ledger/ledger_data_response.go +++ b/model/client/ledger/ledger_data_response.go @@ -3,8 +3,8 @@ package ledger import ( "encoding/json" - "github.com/xyield/xrpl-go/model/client/common" - "github.com/xyield/xrpl-go/model/ledger" + "github.com/CreatureDev/xrpl-go/model/client/common" + "github.com/CreatureDev/xrpl-go/model/ledger" ) type LedgerDataResponse struct { diff --git a/model/client/ledger/ledger_data_test.go b/model/client/ledger/ledger_data_test.go index c19a85bb..10472768 100644 --- a/model/client/ledger/ledger_data_test.go +++ b/model/client/ledger/ledger_data_test.go @@ -3,10 +3,10 @@ package ledger import ( "testing" - "github.com/xyield/xrpl-go/model/client/common" - "github.com/xyield/xrpl-go/model/ledger" - "github.com/xyield/xrpl-go/model/transactions/types" - "github.com/xyield/xrpl-go/test" + "github.com/CreatureDev/xrpl-go/model/client/common" + "github.com/CreatureDev/xrpl-go/model/ledger" + "github.com/CreatureDev/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/test" ) func TestLedgerDataRequest(t *testing.T) { diff --git a/model/client/ledger/ledger_entry_request.go b/model/client/ledger/ledger_entry_request.go index b6baaae2..e547f1de 100644 --- a/model/client/ledger/ledger_entry_request.go +++ b/model/client/ledger/ledger_entry_request.go @@ -2,9 +2,10 @@ package ledger import ( "encoding/json" + "fmt" - "github.com/xyield/xrpl-go/model/client/common" - "github.com/xyield/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/model/client/common" + "github.com/CreatureDev/xrpl-go/model/transactions/types" ) type LedgerEntryRequest struct { @@ -15,20 +16,105 @@ type LedgerEntryRequest struct { AccountRoot types.Address `json:"account_root,omitempty"` Directory EntryRequestOrString `json:"directory,omitempty"` Offer EntryRequestOrString `json:"offer,omitempty"` - RippleState EntryRequestOrString `json:"ripple_state,omitempty"` + RippleState *RippleStateEntryReq `json:"ripple_state,omitempty"` Check string `json:"check,omitempty"` Escrow EntryRequestOrString `json:"escrow,omitempty"` 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 { + return "ledger_entry" +} + +func (r *LedgerEntryRequest) Validate() error { + setCount := 0 + + if r.Index != "" { + setCount++ + } + + if r.AccountRoot != "" { + setCount++ + if err := r.AccountRoot.Validate(); err != nil { + return fmt.Errorf("ledger entry account root: %w", err) + } + } + + if r.Directory != nil { + setCount++ + if err := r.Directory.Validate(); err != nil { + return fmt.Errorf("ledger entry directory: %w", err) + } + } + + if r.Offer != nil { + setCount++ + if err := r.Offer.Validate(); err != nil { + return fmt.Errorf("ledger entry offer: %w", err) + } + } + + if r.RippleState != nil { + setCount++ + if err := r.RippleState.Validate(); err != nil { + return fmt.Errorf("ledger entry ripple state: %w", err) + } + } + + if r.Check != "" { + setCount++ + } + + if r.Escrow != nil { + setCount++ + if err := r.Escrow.Validate(); err != nil { + return fmt.Errorf("ledger entry escrow: %w", err) + } + } + + if r.PaymentChannel != "" { + setCount++ + } + + if r.DepositPreauth != nil { + setCount++ + if err := r.DepositPreauth.Validate(); err != nil { + return fmt.Errorf("ledger entry deposit preauth: %w", err) + } + } + + if r.Ticket != nil { + setCount++ + if err := r.Ticket.Validate(); err != nil { + return fmt.Errorf("ledger entry ticket: %w", err) + } + } + + if r.NFTPage != "" { + setCount++ + } + + if setCount != 1 { + return fmt.Errorf("ledger entry: exactly one ledger entry object may be requested, found %d", setCount) + } + + return nil } type EntryRequestOrString interface { LedgerEntryRequestField() + Validate() error } type EntryString string +func (EntryString) Validate() error { + return nil +} + func (EntryString) LedgerEntryRequestField() {} type DirectoryEntryReq struct { @@ -37,6 +123,10 @@ type DirectoryEntryReq struct { Owner string `json:"owner,omitempty"` } +func (*DirectoryEntryReq) Validate() error { + return nil +} + func (*DirectoryEntryReq) LedgerEntryRequestField() {} type OfferEntryReq struct { @@ -46,6 +136,13 @@ type OfferEntryReq struct { func (*OfferEntryReq) LedgerEntryRequestField() {} +func (r *OfferEntryReq) Validate() error { + if err := r.Account.Validate(); err != nil { + return fmt.Errorf("offer entry account: %w", err) + } + return nil +} + type RippleStateEntryReq struct { Accounts []types.Address `json:"accounts"` Currency string `json:"currency"` @@ -53,6 +150,18 @@ type RippleStateEntryReq struct { func (*RippleStateEntryReq) LedgerEntryRequestField() {} +func (r *RippleStateEntryReq) Validate() error { + if len(r.Accounts) != 2 { + return fmt.Errorf("ripple state entry requires two accounts") + } + for i, a := range r.Accounts { + if err := a.Validate(); err != nil { + return fmt.Errorf("ripple state entry account %d: %w", i+1, err) + } + } + return nil +} + type EscrowEntryReq struct { Owner types.Address `json:"owner"` Seq uint `json:"seq"` @@ -60,6 +169,13 @@ type EscrowEntryReq struct { func (*EscrowEntryReq) LedgerEntryRequestField() {} +func (r *EscrowEntryReq) Validate() error { + if err := r.Owner.Validate(); err != nil { + return fmt.Errorf("escrow entry owner: %w", err) + } + return nil +} + type DepositPreauthEntryReq struct { Owner types.Address `json:"owner"` Authorized types.Address `json:"authorized"` @@ -67,6 +183,16 @@ type DepositPreauthEntryReq struct { func (*DepositPreauthEntryReq) LedgerEntryRequestField() {} +func (r *DepositPreauthEntryReq) Validate() error { + if err := r.Owner.Validate(); err != nil { + return fmt.Errorf("deposit preauth entry owner: %w", err) + } + if err := r.Authorized.Validate(); err != nil { + return fmt.Errorf("deposit preauth entry authorized: %w", err) + } + return nil +} + type TicketEntryReq struct { Account types.Address `json:"account"` TicketSeq int `json:"ticket_seq"` @@ -74,6 +200,13 @@ type TicketEntryReq struct { func (*TicketEntryReq) LedgerEntryRequestField() {} +func (r *TicketEntryReq) Validate() error { + if err := r.Account.Validate(); err != nil { + return fmt.Errorf("ticket entry account: %w", err) + } + return nil +} + func parseEntryRequestField(data []byte, target EntryRequestOrString) (EntryRequestOrString, error) { if len(data) == 0 { return nil, nil @@ -89,19 +222,19 @@ func parseEntryRequestField(data []byte, target EntryRequestOrString) (EntryRequ func (r *LedgerEntryRequest) UnmarshalJSON(data []byte) error { type lerHelper struct { - Binary bool `json:"binary,omitempty"` - LedgerHash common.LedgerHash `json:"ledger_hash,omitempty"` - LedgerIndex json.RawMessage `json:"ledger_index,omitempty"` - Index string `json:"index,omitempty"` - AccountRoot types.Address `json:"account_root,omitempty"` - Directory json.RawMessage `json:"directory,omitempty"` - Offer json.RawMessage `json:"offer,omitempty"` - RippleState json.RawMessage `json:"ripple_state,omitempty"` - Check string `json:"check,omitempty"` - Escrow json.RawMessage `json:"escrow,omitempty"` - PaymentChannel string `json:"payment_channel,omitempty"` - DepositPreauth json.RawMessage `json:"deposit_preauth,omitempty"` - Ticket json.RawMessage `json:"ticket,omitempty"` + Binary bool `json:"binary,omitempty"` + LedgerHash common.LedgerHash `json:"ledger_hash,omitempty"` + LedgerIndex json.RawMessage `json:"ledger_index,omitempty"` + Index string `json:"index,omitempty"` + AccountRoot types.Address `json:"account_root,omitempty"` + Directory json.RawMessage `json:"directory,omitempty"` + Offer json.RawMessage `json:"offer,omitempty"` + RippleState *RippleStateEntryReq `json:"ripple_state,omitempty"` + Check string `json:"check,omitempty"` + Escrow json.RawMessage `json:"escrow,omitempty"` + PaymentChannel string `json:"payment_channel,omitempty"` + DepositPreauth json.RawMessage `json:"deposit_preauth,omitempty"` + Ticket json.RawMessage `json:"ticket,omitempty"` } var h lerHelper err := json.Unmarshal(data, &h) @@ -115,6 +248,7 @@ func (r *LedgerEntryRequest) UnmarshalJSON(data []byte) error { AccountRoot: h.AccountRoot, Check: h.Check, PaymentChannel: h.PaymentChannel, + RippleState: h.RippleState, } r.LedgerIndex, err = common.UnmarshalLedgerSpecifier(h.LedgerIndex) if err != nil { @@ -128,10 +262,6 @@ func (r *LedgerEntryRequest) UnmarshalJSON(data []byte) error { if err != nil { return err } - r.RippleState, err = parseEntryRequestField(h.RippleState, &RippleStateEntryReq{}) - if err != nil { - return err - } r.Escrow, err = parseEntryRequestField(h.Escrow, &EscrowEntryReq{}) if err != nil { return err diff --git a/model/client/ledger/ledger_entry_response.go b/model/client/ledger/ledger_entry_response.go index 58b1e925..e5657462 100644 --- a/model/client/ledger/ledger_entry_response.go +++ b/model/client/ledger/ledger_entry_response.go @@ -3,8 +3,8 @@ package ledger import ( "encoding/json" - "github.com/xyield/xrpl-go/model/client/common" - "github.com/xyield/xrpl-go/model/ledger" + "github.com/CreatureDev/xrpl-go/model/client/common" + "github.com/CreatureDev/xrpl-go/model/ledger" ) type LedgerEntryResponse struct { diff --git a/model/client/ledger/ledger_entry_test.go b/model/client/ledger/ledger_entry_test.go index d4549847..679b1a90 100644 --- a/model/client/ledger/ledger_entry_test.go +++ b/model/client/ledger/ledger_entry_test.go @@ -3,10 +3,11 @@ package ledger import ( "testing" - "github.com/xyield/xrpl-go/model/client/common" - "github.com/xyield/xrpl-go/model/ledger" - "github.com/xyield/xrpl-go/model/transactions/types" - "github.com/xyield/xrpl-go/test" + "github.com/stretchr/testify/assert" + "github.com/CreatureDev/xrpl-go/model/client/common" + "github.com/CreatureDev/xrpl-go/model/ledger" + "github.com/CreatureDev/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/test" ) func TestLedgerEntryRequest(t *testing.T) { @@ -72,3 +73,60 @@ func TestLedgerEntryResponse(t *testing.T) { t.Error(err) } } + +func TestLedgerEntryValidate(t *testing.T) { + off := &OfferEntryReq{} + err := off.Validate() + assert.ErrorContains(t, err, "offer") + off.Account = "rG1QQv2nh2gr7RCZ1P8YYcBUKCCN633jCn" + err = off.Validate() + assert.Nil(t, err) + + rs := RippleStateEntryReq{} + err = rs.Validate() + assert.ErrorContains(t, err, "requires two accounts") + rs.Accounts = []types.Address{"rG1QQv2nh2gr7RCZ1P8YYcBUKCCN633jCn", ""} + err = rs.Validate() + assert.ErrorContains(t, err, "account 2") + rs.Accounts[1] = "rG1QQv2nh2gr7RCZ1P8YYcBUKCCN633jCc" + err = rs.Validate() + assert.Nil(t, err) + + esc := EscrowEntryReq{} + err = esc.Validate() + assert.ErrorContains(t, err, "escrow entry owner") + esc.Owner = "rG1QQv2nh2gr7RCZ1P8YYcBUKCCN633jCn" + err = esc.Validate() + assert.Nil(t, err) + + dep := DepositPreauthEntryReq{} + err = dep.Validate() + assert.ErrorContains(t, err, "deposit preauth") + dep.Owner = "rG1QQv2nh2gr7RCZ1P8YYcBUKCCN633jCn" + err = dep.Validate() + assert.ErrorContains(t, err, "authorized") + dep.Authorized = "rG1QQv2nh2gr7RCZ1P8YYcBUKCCN633jCC" + err = dep.Validate() + assert.Nil(t, err) + + tick := TicketEntryReq{} + err = tick.Validate() + assert.ErrorContains(t, err, "ticket") + tick.Account = "rG1QQv2nh2gr7RCZ1P8YYcBUKCCN633jCn" + err = tick.Validate() + assert.Nil(t, err) + + s := LedgerEntryRequest{} + err = s.Validate() + assert.ErrorContains(t, err, "0") + s.AccountRoot = "rG1QQv2nh2gr7RCZ1P8YYcBUKCCN633jCn" + err = s.Validate() + assert.Nil(t, err) + s.Offer = off + err = s.Validate() + assert.ErrorContains(t, err, "2") + s.AccountRoot = "" + s.Offer = &OfferEntryReq{} + err = s.Validate() + assert.ErrorContains(t, err, "ledger entry offer") +} diff --git a/model/client/ledger/ledger_request.go b/model/client/ledger/ledger_request.go index 0f004783..7329b25d 100644 --- a/model/client/ledger/ledger_request.go +++ b/model/client/ledger/ledger_request.go @@ -3,8 +3,8 @@ package ledger import ( "encoding/json" - "github.com/xyield/xrpl-go/model/client/common" - "github.com/xyield/xrpl-go/model/ledger" + "github.com/CreatureDev/xrpl-go/model/client/common" + "github.com/CreatureDev/xrpl-go/model/ledger" ) type LedgerRequest struct { @@ -23,6 +23,10 @@ func (*LedgerRequest) Method() string { return "ledger" } +func (*LedgerRequest) Validate() error { + return nil +} + func (r *LedgerRequest) UnmarshalJSON(data []byte) error { type lrHelper struct { LedgerHash common.LedgerHash `json:"ledger_hash,omitempty"` diff --git a/model/client/ledger/ledger_response.go b/model/client/ledger/ledger_response.go index fab5b263..255c7dc1 100644 --- a/model/client/ledger/ledger_response.go +++ b/model/client/ledger/ledger_response.go @@ -3,10 +3,10 @@ package ledger import ( "encoding/json" - "github.com/xyield/xrpl-go/model/client/common" - "github.com/xyield/xrpl-go/model/ledger" - "github.com/xyield/xrpl-go/model/transactions" - "github.com/xyield/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/model/client/common" + "github.com/CreatureDev/xrpl-go/model/ledger" + "github.com/CreatureDev/xrpl-go/model/transactions" + "github.com/CreatureDev/xrpl-go/model/transactions/types" ) type LedgerResponse struct { diff --git a/model/client/ledger/ledger_test.go b/model/client/ledger/ledger_test.go index 772ee3f5..c0c7bb6d 100644 --- a/model/client/ledger/ledger_test.go +++ b/model/client/ledger/ledger_test.go @@ -3,9 +3,9 @@ package ledger import ( "testing" - "github.com/xyield/xrpl-go/model/client/common" - "github.com/xyield/xrpl-go/model/transactions/types" - "github.com/xyield/xrpl-go/test" + "github.com/CreatureDev/xrpl-go/model/client/common" + "github.com/CreatureDev/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/test" ) func TestLedgerRequest(t *testing.T) { diff --git a/model/client/path/book_offers_request.go b/model/client/path/book_offers_request.go index f33492f7..1bf24043 100644 --- a/model/client/path/book_offers_request.go +++ b/model/client/path/book_offers_request.go @@ -2,9 +2,10 @@ package path import ( "encoding/json" + "fmt" - "github.com/xyield/xrpl-go/model/client/common" - "github.com/xyield/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/model/client/common" + "github.com/CreatureDev/xrpl-go/model/transactions/types" ) type BookOffersRequest struct { @@ -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"` diff --git a/model/client/path/book_offers_response.go b/model/client/path/book_offers_response.go index e99e1ae6..cee7ccb9 100644 --- a/model/client/path/book_offers_response.go +++ b/model/client/path/book_offers_response.go @@ -3,9 +3,9 @@ package path import ( "encoding/json" - "github.com/xyield/xrpl-go/model/client/common" - "github.com/xyield/xrpl-go/model/ledger" - "github.com/xyield/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/model/client/common" + "github.com/CreatureDev/xrpl-go/model/ledger" + "github.com/CreatureDev/xrpl-go/model/transactions/types" ) type BookOffersResponse struct { diff --git a/model/client/path/book_offers_test.go b/model/client/path/book_offers_test.go index f48d797a..e664411f 100644 --- a/model/client/path/book_offers_test.go +++ b/model/client/path/book_offers_test.go @@ -3,9 +3,9 @@ package path import ( "testing" - "github.com/xyield/xrpl-go/model/ledger" - "github.com/xyield/xrpl-go/model/transactions/types" - "github.com/xyield/xrpl-go/test" + "github.com/CreatureDev/xrpl-go/model/ledger" + "github.com/CreatureDev/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/test" ) func TestBookOffersRequest(t *testing.T) { diff --git a/model/client/path/deposit_authorized_request.go b/model/client/path/deposit_authorized_request.go index ccb15c9a..7f3fd3b3 100644 --- a/model/client/path/deposit_authorized_request.go +++ b/model/client/path/deposit_authorized_request.go @@ -2,9 +2,10 @@ package path import ( "encoding/json" + "fmt" - "github.com/xyield/xrpl-go/model/client/common" - "github.com/xyield/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/model/client/common" + "github.com/CreatureDev/xrpl-go/model/transactions/types" ) type DepositAuthorizedRequest struct { @@ -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"` diff --git a/model/client/path/deposit_authorized_response.go b/model/client/path/deposit_authorized_response.go index 985bea81..1e5b57d6 100644 --- a/model/client/path/deposit_authorized_response.go +++ b/model/client/path/deposit_authorized_response.go @@ -1,8 +1,8 @@ package path import ( - "github.com/xyield/xrpl-go/model/client/common" - "github.com/xyield/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/model/client/common" + "github.com/CreatureDev/xrpl-go/model/transactions/types" ) type DepositAuthorizedResponse struct { diff --git a/model/client/path/deposit_authorized_test.go b/model/client/path/deposit_authorized_test.go index d331df7f..3839c1de 100644 --- a/model/client/path/deposit_authorized_test.go +++ b/model/client/path/deposit_authorized_test.go @@ -3,8 +3,8 @@ package path import ( "testing" - "github.com/xyield/xrpl-go/model/client/common" - "github.com/xyield/xrpl-go/test" + "github.com/CreatureDev/xrpl-go/model/client/common" + "github.com/CreatureDev/xrpl-go/test" ) func TestDepositAuthorizedRequest(t *testing.T) { diff --git a/model/client/path/nftoken_buy_offers_request.go b/model/client/path/nftoken_buy_offers_request.go index caf65176..4268e45e 100644 --- a/model/client/path/nftoken_buy_offers_request.go +++ b/model/client/path/nftoken_buy_offers_request.go @@ -2,9 +2,10 @@ package path import ( "encoding/json" + "fmt" - "github.com/xyield/xrpl-go/model/client/common" - "github.com/xyield/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/model/client/common" + "github.com/CreatureDev/xrpl-go/model/transactions/types" ) type NFTokenBuyOffersRequest struct { @@ -19,6 +20,13 @@ func (*NFTokenBuyOffersRequest) Method() string { return "nft_buy_offers" } +func (r *NFTokenBuyOffersRequest) Validate() 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"` diff --git a/model/client/path/nftoken_buy_offers_response.go b/model/client/path/nftoken_buy_offers_response.go index 9606f52d..f95c88a3 100644 --- a/model/client/path/nftoken_buy_offers_response.go +++ b/model/client/path/nftoken_buy_offers_response.go @@ -1,7 +1,7 @@ package path import ( - "github.com/xyield/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/model/transactions/types" ) type NFTokenBuyOffersResponse struct { diff --git a/model/client/path/nftoken_buy_offers_test.go b/model/client/path/nftoken_buy_offers_test.go index eba997e1..1b452fcc 100644 --- a/model/client/path/nftoken_buy_offers_test.go +++ b/model/client/path/nftoken_buy_offers_test.go @@ -3,9 +3,9 @@ package path import ( "testing" - "github.com/xyield/xrpl-go/model/client/common" - "github.com/xyield/xrpl-go/model/transactions/types" - "github.com/xyield/xrpl-go/test" + "github.com/CreatureDev/xrpl-go/model/client/common" + "github.com/CreatureDev/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/test" ) func TestNFTokenBuyOffersRequest(t *testing.T) { diff --git a/model/client/path/nftoken_offer.go b/model/client/path/nftoken_offer.go index a74065c8..071a4a43 100644 --- a/model/client/path/nftoken_offer.go +++ b/model/client/path/nftoken_offer.go @@ -3,7 +3,7 @@ package path import ( "encoding/json" - "github.com/xyield/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/model/transactions/types" ) type NFTokenOffer struct { diff --git a/model/client/path/nftoken_sell_offers_request.go b/model/client/path/nftoken_sell_offers_request.go index 38393581..d8858e80 100644 --- a/model/client/path/nftoken_sell_offers_request.go +++ b/model/client/path/nftoken_sell_offers_request.go @@ -2,9 +2,10 @@ package path import ( "encoding/json" + "fmt" - "github.com/xyield/xrpl-go/model/client/common" - "github.com/xyield/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/model/client/common" + "github.com/CreatureDev/xrpl-go/model/transactions/types" ) type NFTokenSellOffersRequest struct { @@ -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"` diff --git a/model/client/path/nftoken_sell_offers_response.go b/model/client/path/nftoken_sell_offers_response.go index 3d06c18c..d686a967 100644 --- a/model/client/path/nftoken_sell_offers_response.go +++ b/model/client/path/nftoken_sell_offers_response.go @@ -1,7 +1,7 @@ package path import ( - "github.com/xyield/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/model/transactions/types" ) type NFTokenSellOffersResponse struct { diff --git a/model/client/path/nftoken_sell_offers_test.go b/model/client/path/nftoken_sell_offers_test.go index 024b6aa7..83943fbd 100644 --- a/model/client/path/nftoken_sell_offers_test.go +++ b/model/client/path/nftoken_sell_offers_test.go @@ -3,9 +3,9 @@ package path import ( "testing" - "github.com/xyield/xrpl-go/model/client/common" - "github.com/xyield/xrpl-go/model/transactions/types" - "github.com/xyield/xrpl-go/test" + "github.com/CreatureDev/xrpl-go/model/client/common" + "github.com/CreatureDev/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/test" ) func TestNFTokenSellOffersRequest(t *testing.T) { diff --git a/model/client/path/path_find_request.go b/model/client/path/path_find_request.go index 13545f9d..729cc916 100644 --- a/model/client/path/path_find_request.go +++ b/model/client/path/path_find_request.go @@ -2,9 +2,10 @@ package path import ( "encoding/json" + "fmt" - "github.com/xyield/xrpl-go/model/transactions" - "github.com/xyield/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/model/transactions" + "github.com/CreatureDev/xrpl-go/model/transactions/types" ) type PathSubCommand string @@ -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"` diff --git a/model/client/path/path_find_response.go b/model/client/path/path_find_response.go index 33c993f9..effb2e84 100644 --- a/model/client/path/path_find_response.go +++ b/model/client/path/path_find_response.go @@ -3,8 +3,8 @@ package path import ( "encoding/json" - "github.com/xyield/xrpl-go/model/transactions" - "github.com/xyield/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/model/transactions" + "github.com/CreatureDev/xrpl-go/model/transactions/types" ) type PathFindResponse struct { diff --git a/model/client/path/path_find_test.go b/model/client/path/path_find_test.go index e9ce0f81..9180ef4d 100644 --- a/model/client/path/path_find_test.go +++ b/model/client/path/path_find_test.go @@ -3,9 +3,9 @@ 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" + "github.com/CreatureDev/xrpl-go/model/transactions" + "github.com/CreatureDev/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/test" ) func TestPathFindRequest(t *testing.T) { diff --git a/model/client/path/ripple_path_find_request.go b/model/client/path/ripple_path_find_request.go index 58dd35e4..abdcad65 100644 --- a/model/client/path/ripple_path_find_request.go +++ b/model/client/path/ripple_path_find_request.go @@ -2,9 +2,10 @@ package path import ( "encoding/json" + "fmt" - "github.com/xyield/xrpl-go/model/client/common" - "github.com/xyield/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/model/client/common" + "github.com/CreatureDev/xrpl-go/model/transactions/types" ) type RipplePathFindRequest struct { @@ -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"` diff --git a/model/client/path/ripple_path_find_response.go b/model/client/path/ripple_path_find_response.go index c02e20ef..90983d21 100644 --- a/model/client/path/ripple_path_find_response.go +++ b/model/client/path/ripple_path_find_response.go @@ -1,7 +1,7 @@ package path import ( - "github.com/xyield/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/model/transactions/types" ) type RipplePathFindResponse struct { diff --git a/model/client/path/ripple_path_find_test.go b/model/client/path/ripple_path_find_test.go index 81925620..0f6c54db 100644 --- a/model/client/path/ripple_path_find_test.go +++ b/model/client/path/ripple_path_find_test.go @@ -3,9 +3,9 @@ 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" + "github.com/CreatureDev/xrpl-go/model/transactions" + "github.com/CreatureDev/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/test" ) func TestRipplePathFindRequest(t *testing.T) { diff --git a/model/client/server/fee_request.go b/model/client/server/fee_request.go index a90db311..25a08e39 100644 --- a/model/client/server/fee_request.go +++ b/model/client/server/fee_request.go @@ -6,3 +6,7 @@ type FeeRequest struct { func (*FeeRequest) Method() string { return "fee" } + +func (*FeeRequest) Validate() error { + return nil +} diff --git a/model/client/server/fee_response.go b/model/client/server/fee_response.go index d1d96b16..5c839a36 100644 --- a/model/client/server/fee_response.go +++ b/model/client/server/fee_response.go @@ -1,8 +1,8 @@ package server import ( - "github.com/xyield/xrpl-go/model/client/common" - "github.com/xyield/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/model/client/common" + "github.com/CreatureDev/xrpl-go/model/transactions/types" ) type FeeResponse struct { diff --git a/model/client/server/fee_test.go b/model/client/server/fee_test.go index e7d707e4..217a5a07 100644 --- a/model/client/server/fee_test.go +++ b/model/client/server/fee_test.go @@ -3,7 +3,7 @@ package server import ( "testing" - "github.com/xyield/xrpl-go/test" + "github.com/CreatureDev/xrpl-go/test" ) func TestFeeResponse(t *testing.T) { diff --git a/model/client/server/manifest_request.go b/model/client/server/manifest_request.go index b48b0ca1..a2da5ad5 100644 --- a/model/client/server/manifest_request.go +++ b/model/client/server/manifest_request.go @@ -1,5 +1,7 @@ package server +import "fmt" + type ManifestRequest struct { PublicKey string `json:"public_key"` } @@ -7,3 +9,10 @@ type ManifestRequest struct { func (*ManifestRequest) Method() string { return "manifest" } + +func (r *ManifestRequest) Validate() error { + if r.PublicKey == "" { + return fmt.Errorf("manifest request: public key not set") + } + return nil +} diff --git a/model/client/server/manifest_test.go b/model/client/server/manifest_test.go index 1a852330..3bce11ec 100644 --- a/model/client/server/manifest_test.go +++ b/model/client/server/manifest_test.go @@ -3,7 +3,7 @@ package server import ( "testing" - "github.com/xyield/xrpl-go/test" + "github.com/CreatureDev/xrpl-go/test" ) func TestManifestRequest(t *testing.T) { diff --git a/model/client/server/server_info_request.go b/model/client/server/server_info_request.go index 398bb383..fdb8c582 100644 --- a/model/client/server/server_info_request.go +++ b/model/client/server/server_info_request.go @@ -6,3 +6,7 @@ type ServerInfoRequest struct { func (*ServerInfoRequest) Method() string { return "server_info" } + +func (*ServerInfoRequest) Validate() error { + return nil +} diff --git a/model/client/server/server_info_response.go b/model/client/server/server_info_response.go index bef65d1d..696973d6 100644 --- a/model/client/server/server_info_response.go +++ b/model/client/server/server_info_response.go @@ -1,6 +1,6 @@ package server -import "github.com/xyield/xrpl-go/model/transactions/types" +import "github.com/CreatureDev/xrpl-go/model/transactions/types" type ServerInfoResponse struct { Info ServerInfo `json:"info"` diff --git a/model/client/server/server_info_test.go b/model/client/server/server_info_test.go index 089548e4..eb078a04 100644 --- a/model/client/server/server_info_test.go +++ b/model/client/server/server_info_test.go @@ -3,7 +3,7 @@ package server import ( "testing" - "github.com/xyield/xrpl-go/test" + "github.com/CreatureDev/xrpl-go/test" ) func TestServerInfoResponse(t *testing.T) { diff --git a/model/client/server/server_state_request.go b/model/client/server/server_state_request.go index ed9f628b..8c9e646a 100644 --- a/model/client/server/server_state_request.go +++ b/model/client/server/server_state_request.go @@ -6,3 +6,7 @@ type ServerStateRequest struct { func (*ServerStateRequest) Method() string { return "server_state" } + +func (*ServerStateRequest) Validate() error { + return nil +} diff --git a/model/client/server/server_state_test.go b/model/client/server/server_state_test.go index 4aae2910..b08ece42 100644 --- a/model/client/server/server_state_test.go +++ b/model/client/server/server_state_test.go @@ -3,7 +3,7 @@ package server import ( "testing" - "github.com/xyield/xrpl-go/test" + "github.com/CreatureDev/xrpl-go/test" ) func TestServerStateResponse(t *testing.T) { diff --git a/model/client/subscription/stream/ledger.go b/model/client/subscription/stream/ledger.go index 5136ebef..0e161a33 100644 --- a/model/client/subscription/stream/ledger.go +++ b/model/client/subscription/stream/ledger.go @@ -1,6 +1,6 @@ package stream -import "github.com/xyield/xrpl-go/model/client/common" +import "github.com/CreatureDev/xrpl-go/model/client/common" type LedgerStream struct { Type StreamType `json:"type"` diff --git a/model/client/subscription/stream/peer.go b/model/client/subscription/stream/peer.go index d0ab062d..bdcc79c4 100644 --- a/model/client/subscription/stream/peer.go +++ b/model/client/subscription/stream/peer.go @@ -1,6 +1,6 @@ package stream -import "github.com/xyield/xrpl-go/model/client/common" +import "github.com/CreatureDev/xrpl-go/model/client/common" type PeerStatusStream struct { Type StreamType `json:"type"` diff --git a/model/client/subscription/stream/transaction.go b/model/client/subscription/stream/transaction.go index 1a789213..e90af45a 100644 --- a/model/client/subscription/stream/transaction.go +++ b/model/client/subscription/stream/transaction.go @@ -3,8 +3,8 @@ package stream import ( "encoding/json" - "github.com/xyield/xrpl-go/model/client/common" - "github.com/xyield/xrpl-go/model/transactions" + "github.com/CreatureDev/xrpl-go/model/client/common" + "github.com/CreatureDev/xrpl-go/model/transactions" ) type TransactionStream struct { diff --git a/model/client/subscription/stream/validation.go b/model/client/subscription/stream/validation.go index 12789ec9..1ad51aaa 100644 --- a/model/client/subscription/stream/validation.go +++ b/model/client/subscription/stream/validation.go @@ -1,7 +1,7 @@ package stream import ( - "github.com/xyield/xrpl-go/model/client/common" + "github.com/CreatureDev/xrpl-go/model/client/common" ) type ValidationStream struct { diff --git a/model/client/subscription/subscribe_request.go b/model/client/subscription/subscribe_request.go index 407723fa..98173732 100644 --- a/model/client/subscription/subscribe_request.go +++ b/model/client/subscription/subscribe_request.go @@ -1,6 +1,10 @@ -package subscribe +package subscription -import "github.com/xyield/xrpl-go/model/transactions/types" +import ( + "fmt" + + "github.com/CreatureDev/xrpl-go/model/transactions/types" +) type SubscribeRequest struct { Streams []string `json:"streams,omitempty"` @@ -23,3 +27,19 @@ type SubscribeOrderBook struct { Snapshot bool `json:"snapshot,omitempty"` Both bool `json:"both,omitempty"` } + +func (r *SubscribeRequest) Validate() error { + for _, a := range r.Accounts { + if err := a.Validate(); err != nil { + return fmt.Errorf("subscribe request accounts: %w", err) + } + } + + for _, a := range r.AccountsProposed { + if err := a.Validate(); err != nil { + return fmt.Errorf("subscribe request accounts proposed: %w", err) + } + } + + return nil +} diff --git a/model/client/subscription/subscribe_response.go b/model/client/subscription/subscribe_response.go index 43905fce..7908b506 100644 --- a/model/client/subscription/subscribe_response.go +++ b/model/client/subscription/subscribe_response.go @@ -1,8 +1,8 @@ -package subscribe +package subscription import ( - "github.com/xyield/xrpl-go/model/client/common" - "github.com/xyield/xrpl-go/model/ledger" + "github.com/CreatureDev/xrpl-go/model/client/common" + "github.com/CreatureDev/xrpl-go/model/ledger" ) type SubscribeResponse struct { diff --git a/model/client/subscription/subscribe_test.go b/model/client/subscription/subscribe_test.go index 04944560..0e9158d7 100644 --- a/model/client/subscription/subscribe_test.go +++ b/model/client/subscription/subscribe_test.go @@ -1,10 +1,10 @@ -package subscribe +package subscription import ( "testing" - "github.com/xyield/xrpl-go/model/transactions/types" - "github.com/xyield/xrpl-go/test" + "github.com/CreatureDev/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/test" ) func TestSubscribeRequest(t *testing.T) { diff --git a/model/client/subscription/unsubscribe_request.go b/model/client/subscription/unsubscribe_request.go index 2339a9d8..1ba1d534 100644 --- a/model/client/subscription/unsubscribe_request.go +++ b/model/client/subscription/unsubscribe_request.go @@ -1,6 +1,10 @@ -package subscribe +package subscription -import "github.com/xyield/xrpl-go/model/transactions/types" +import ( + "fmt" + + "github.com/CreatureDev/xrpl-go/model/transactions/types" +) type UnsubscribeRequest struct { Streams []string `json:"streams,omitempty"` @@ -18,3 +22,19 @@ type UnsubscribeOrderBook struct { TakerPays types.IssuedCurrencyAmount `json:"taker_pays"` Both bool `json:"both,omitempty"` } + +func (r *UnsubscribeRequest) Validate() error { + for _, a := range r.Accounts { + if err := a.Validate(); err != nil { + return fmt.Errorf("unsubscribe request accounts: %w", err) + } + } + + for _, a := range r.AccountsProposed { + if err := a.Validate(); err != nil { + return fmt.Errorf("unsubscribe request accounts proposed: %w", err) + } + } + + return nil +} diff --git a/model/client/subscription/unsubscribe_response.go b/model/client/subscription/unsubscribe_response.go index e3583a4b..b52c0706 100644 --- a/model/client/subscription/unsubscribe_response.go +++ b/model/client/subscription/unsubscribe_response.go @@ -1,4 +1,4 @@ -package subscribe +package subscription type UnsubscribeResponse struct { } diff --git a/model/client/subscription/unsubscribe_test.go b/model/client/subscription/unsubscribe_test.go index b0576cdf..78fd6c8c 100644 --- a/model/client/subscription/unsubscribe_test.go +++ b/model/client/subscription/unsubscribe_test.go @@ -1,10 +1,10 @@ -package subscribe +package subscription import ( "testing" - "github.com/xyield/xrpl-go/model/transactions/types" - "github.com/xyield/xrpl-go/test" + "github.com/CreatureDev/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/test" ) func TestUnsubscribeRequest(t *testing.T) { diff --git a/model/client/transactions/submit_multisigned_request.go b/model/client/transactions/submit_multisigned_request.go index 72259b68..d729f4ba 100644 --- a/model/client/transactions/submit_multisigned_request.go +++ b/model/client/transactions/submit_multisigned_request.go @@ -2,8 +2,9 @@ package transactions import ( "encoding/json" + "fmt" - "github.com/xyield/xrpl-go/model/transactions" + "github.com/CreatureDev/xrpl-go/model/transactions" ) type SubmitMultisignedRequest struct { @@ -35,3 +36,10 @@ func (r *SubmitMultisignedRequest) UnmarshalJSON(data []byte) error { return nil } + +func (s *SubmitMultisignedRequest) Validate() error { + if s.Tx == nil { + return fmt.Errorf("submit multisigned request: missing tx") + } + return nil +} diff --git a/model/client/transactions/submit_multisigned_response.go b/model/client/transactions/submit_multisigned_response.go index 01e4902a..1bc8eaef 100644 --- a/model/client/transactions/submit_multisigned_response.go +++ b/model/client/transactions/submit_multisigned_response.go @@ -3,7 +3,7 @@ package transactions import ( "encoding/json" - "github.com/xyield/xrpl-go/model/transactions" + "github.com/CreatureDev/xrpl-go/model/transactions" ) type SubmitMultisignedResponse struct { diff --git a/model/client/transactions/submit_multisigned_test.go b/model/client/transactions/submit_multisigned_test.go index 02e45c75..5f6fcf86 100644 --- a/model/client/transactions/submit_multisigned_test.go +++ b/model/client/transactions/submit_multisigned_test.go @@ -3,9 +3,9 @@ package transactions import ( "testing" - "github.com/xyield/xrpl-go/model/transactions" - "github.com/xyield/xrpl-go/model/transactions/types" - "github.com/xyield/xrpl-go/test" + "github.com/CreatureDev/xrpl-go/model/transactions" + "github.com/CreatureDev/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/test" ) func TestSubmitMultisignedRequest(t *testing.T) { diff --git a/model/client/transactions/submit_request.go b/model/client/transactions/submit_request.go index b67ff4bc..c3fc30fd 100644 --- a/model/client/transactions/submit_request.go +++ b/model/client/transactions/submit_request.go @@ -1,5 +1,7 @@ package transactions +import "fmt" + type SubmitRequest struct { TxBlob string `json:"tx_blob"` FailHard bool `json:"fail_hard,omitempty"` @@ -8,3 +10,10 @@ type SubmitRequest struct { func (*SubmitRequest) Method() string { return "submit" } + +func (s *SubmitRequest) Validate() error { + if s.TxBlob == "" { + return fmt.Errorf("submit request: missing txblob") + } + return nil +} diff --git a/model/client/transactions/submit_response.go b/model/client/transactions/submit_response.go index 6ed284b9..ee653d71 100644 --- a/model/client/transactions/submit_response.go +++ b/model/client/transactions/submit_response.go @@ -3,8 +3,8 @@ package transactions import ( "encoding/json" - "github.com/xyield/xrpl-go/model/client/common" - "github.com/xyield/xrpl-go/model/transactions" + "github.com/CreatureDev/xrpl-go/model/client/common" + "github.com/CreatureDev/xrpl-go/model/transactions" ) type SubmitResponse struct { diff --git a/model/client/transactions/submit_test.go b/model/client/transactions/submit_test.go index 182b0d83..7d744323 100644 --- a/model/client/transactions/submit_test.go +++ b/model/client/transactions/submit_test.go @@ -3,9 +3,9 @@ package transactions import ( "testing" - "github.com/xyield/xrpl-go/model/transactions" - "github.com/xyield/xrpl-go/model/transactions/types" - "github.com/xyield/xrpl-go/test" + "github.com/CreatureDev/xrpl-go/model/transactions" + "github.com/CreatureDev/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/test" ) func TestSubmitRequest(t *testing.T) { diff --git a/model/client/transactions/transaction_entry_request.go b/model/client/transactions/transaction_entry_request.go index b56262e0..59729247 100644 --- a/model/client/transactions/transaction_entry_request.go +++ b/model/client/transactions/transaction_entry_request.go @@ -2,8 +2,9 @@ package transactions import ( "encoding/json" + "fmt" - "github.com/xyield/xrpl-go/model/client/common" + "github.com/CreatureDev/xrpl-go/model/client/common" ) type TransactionEntryRequest struct { @@ -38,3 +39,10 @@ func (t *TransactionEntryRequest) UnmarshalJSON(data []byte) error { t.LedgerIndex = i return nil } + +func (t *TransactionEntryRequest) Validate() error { + if t.TxHash == "" { + return fmt.Errorf("transaction entry request: missing txhash") + } + return nil +} diff --git a/model/client/transactions/transaction_entry_response.go b/model/client/transactions/transaction_entry_response.go index 446b6362..fce05657 100644 --- a/model/client/transactions/transaction_entry_response.go +++ b/model/client/transactions/transaction_entry_response.go @@ -3,8 +3,8 @@ package transactions import ( "encoding/json" - "github.com/xyield/xrpl-go/model/client/common" - "github.com/xyield/xrpl-go/model/transactions" + "github.com/CreatureDev/xrpl-go/model/client/common" + "github.com/CreatureDev/xrpl-go/model/transactions" ) type TransactionEntryResponse struct { diff --git a/model/client/transactions/transaction_entry_test.go b/model/client/transactions/transaction_entry_test.go index eb4a7502..1e52cc70 100644 --- a/model/client/transactions/transaction_entry_test.go +++ b/model/client/transactions/transaction_entry_test.go @@ -3,11 +3,11 @@ package transactions import ( "testing" - "github.com/xyield/xrpl-go/model/client/common" - "github.com/xyield/xrpl-go/model/ledger" - "github.com/xyield/xrpl-go/model/transactions" - "github.com/xyield/xrpl-go/model/transactions/types" - "github.com/xyield/xrpl-go/test" + "github.com/CreatureDev/xrpl-go/model/client/common" + "github.com/CreatureDev/xrpl-go/model/ledger" + "github.com/CreatureDev/xrpl-go/model/transactions" + "github.com/CreatureDev/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/test" ) func TestTransactionEntryRequest(t *testing.T) { diff --git a/model/client/transactions/tx_request.go b/model/client/transactions/tx_request.go index 79103d15..533c7d5d 100644 --- a/model/client/transactions/tx_request.go +++ b/model/client/transactions/tx_request.go @@ -1,6 +1,10 @@ package transactions -import "github.com/xyield/xrpl-go/model/client/common" +import ( + "fmt" + + "github.com/CreatureDev/xrpl-go/model/client/common" +) type TxRequest struct { Transaction string `json:"transaction"` @@ -12,3 +16,10 @@ type TxRequest struct { func (*TxRequest) Method() string { return "tx" } + +func (t *TxRequest) Validate() error { + if t.Transaction == "" { + return fmt.Errorf("transaction request: missing transaction") + } + return nil +} diff --git a/model/client/transactions/tx_response.go b/model/client/transactions/tx_response.go index f4982685..21fdadb3 100644 --- a/model/client/transactions/tx_response.go +++ b/model/client/transactions/tx_response.go @@ -3,9 +3,9 @@ package transactions import ( "encoding/json" - "github.com/xyield/xrpl-go/model/client/common" - "github.com/xyield/xrpl-go/model/transactions" - "github.com/xyield/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/model/client/common" + "github.com/CreatureDev/xrpl-go/model/transactions" + "github.com/CreatureDev/xrpl-go/model/transactions/types" ) type TxResponse struct { diff --git a/model/client/transactions/tx_test.go b/model/client/transactions/tx_test.go index 0c422c33..673ce041 100644 --- a/model/client/transactions/tx_test.go +++ b/model/client/transactions/tx_test.go @@ -6,9 +6,9 @@ import ( "reflect" "testing" - "github.com/xyield/xrpl-go/model/ledger" - "github.com/xyield/xrpl-go/model/transactions" - "github.com/xyield/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/model/ledger" + "github.com/CreatureDev/xrpl-go/model/transactions" + "github.com/CreatureDev/xrpl-go/model/transactions/types" ) func TestTxResponse(t *testing.T) { diff --git a/model/client/utility/random_request.go b/model/client/utility/random_request.go index d0234240..9b85d6d2 100644 --- a/model/client/utility/random_request.go +++ b/model/client/utility/random_request.go @@ -5,3 +5,7 @@ type RandomRequest struct{} func (*RandomRequest) Method() string { return "random" } + +func (*RandomRequest) Validate() error { + return nil +} diff --git a/model/client/utility/random_response.go b/model/client/utility/random_response.go index 9d4378e9..fb8ba6de 100644 --- a/model/client/utility/random_response.go +++ b/model/client/utility/random_response.go @@ -1,6 +1,6 @@ package utility -import "github.com/xyield/xrpl-go/model/transactions/types" +import "github.com/CreatureDev/xrpl-go/model/transactions/types" type RandomResponse struct { Random types.Hash256 `json:"random"` diff --git a/model/client/utility/random_test.go b/model/client/utility/random_test.go index 608a36e3..6c7c865d 100644 --- a/model/client/utility/random_test.go +++ b/model/client/utility/random_test.go @@ -3,7 +3,7 @@ package utility import ( "testing" - "github.com/xyield/xrpl-go/test" + "github.com/CreatureDev/xrpl-go/test" ) func TestRandomResponse(t *testing.T) { diff --git a/model/ledger/account_root.go b/model/ledger/account_root.go index 3e0aa3aa..e41a8439 100644 --- a/model/ledger/account_root.go +++ b/model/ledger/account_root.go @@ -1,7 +1,7 @@ package ledger import ( - "github.com/xyield/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/model/transactions/types" ) type AccountRoot struct { diff --git a/model/ledger/account_root_test.go b/model/ledger/account_root_test.go index f3f7018c..98877fde 100644 --- a/model/ledger/account_root_test.go +++ b/model/ledger/account_root_test.go @@ -3,8 +3,8 @@ package ledger import ( "testing" - "github.com/xyield/xrpl-go/model/transactions/types" - "github.com/xyield/xrpl-go/test" + "github.com/CreatureDev/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/test" ) func TestAccountRoot(t *testing.T) { diff --git a/model/ledger/amendments.go b/model/ledger/amendments.go index 449139d5..62779b2b 100644 --- a/model/ledger/amendments.go +++ b/model/ledger/amendments.go @@ -1,7 +1,7 @@ package ledger import ( - "github.com/xyield/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/model/transactions/types" ) type Amendments struct { diff --git a/model/ledger/amendments_test.go b/model/ledger/amendments_test.go index 9cb0d411..95975bc0 100644 --- a/model/ledger/amendments_test.go +++ b/model/ledger/amendments_test.go @@ -3,8 +3,8 @@ package ledger import ( "testing" - "github.com/xyield/xrpl-go/model/transactions/types" - "github.com/xyield/xrpl-go/test" + "github.com/CreatureDev/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/test" ) func TestAmmendments(t *testing.T) { diff --git a/model/ledger/amm.go b/model/ledger/amm.go index 959af047..c531b64a 100644 --- a/model/ledger/amm.go +++ b/model/ledger/amm.go @@ -3,7 +3,7 @@ package ledger import ( "encoding/json" - "github.com/xyield/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/model/transactions/types" ) type AMM struct { diff --git a/model/ledger/check.go b/model/ledger/check.go index 505ffa4d..d2cd35f9 100644 --- a/model/ledger/check.go +++ b/model/ledger/check.go @@ -1,6 +1,6 @@ package ledger -import "github.com/xyield/xrpl-go/model/transactions/types" +import "github.com/CreatureDev/xrpl-go/model/transactions/types" // TODO verify format of SendMax type Check struct { diff --git a/model/ledger/check_test.go b/model/ledger/check_test.go index d172a2be..c0bff572 100644 --- a/model/ledger/check_test.go +++ b/model/ledger/check_test.go @@ -3,7 +3,7 @@ package ledger import ( "testing" - "github.com/xyield/xrpl-go/test" + "github.com/CreatureDev/xrpl-go/test" ) func TestCheck(t *testing.T) { diff --git a/model/ledger/deposit_preauth.go b/model/ledger/deposit_preauth.go index a9aa4bf9..45f9e22d 100644 --- a/model/ledger/deposit_preauth.go +++ b/model/ledger/deposit_preauth.go @@ -1,7 +1,7 @@ package ledger import ( - "github.com/xyield/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/model/transactions/types" ) type DepositPreauthObj struct { diff --git a/model/ledger/deposit_preauth_test.go b/model/ledger/deposit_preauth_test.go index 987341ec..26a4dceb 100644 --- a/model/ledger/deposit_preauth_test.go +++ b/model/ledger/deposit_preauth_test.go @@ -3,7 +3,7 @@ package ledger import ( "testing" - "github.com/xyield/xrpl-go/test" + "github.com/CreatureDev/xrpl-go/test" ) func TestDepositPreauth(t *testing.T) { diff --git a/model/ledger/directory_node.go b/model/ledger/directory_node.go index beb8df60..bfc7d1d9 100644 --- a/model/ledger/directory_node.go +++ b/model/ledger/directory_node.go @@ -1,7 +1,7 @@ package ledger import ( - "github.com/xyield/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/model/transactions/types" ) type DirectoryNode struct { diff --git a/model/ledger/directory_node_test.go b/model/ledger/directory_node_test.go index 7457c7a3..a2d96314 100644 --- a/model/ledger/directory_node_test.go +++ b/model/ledger/directory_node_test.go @@ -3,8 +3,8 @@ package ledger import ( "testing" - "github.com/xyield/xrpl-go/model/transactions/types" - "github.com/xyield/xrpl-go/test" + "github.com/CreatureDev/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/test" ) func TestOfferDirectoryNode(t *testing.T) { diff --git a/model/ledger/escrow.go b/model/ledger/escrow.go index f0a578fd..1e7dc635 100644 --- a/model/ledger/escrow.go +++ b/model/ledger/escrow.go @@ -1,7 +1,7 @@ package ledger import ( - "github.com/xyield/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/model/transactions/types" ) type Escrow struct { diff --git a/model/ledger/escrow_test.go b/model/ledger/escrow_test.go index 77d2395f..f17651f1 100644 --- a/model/ledger/escrow_test.go +++ b/model/ledger/escrow_test.go @@ -3,8 +3,8 @@ package ledger import ( "testing" - "github.com/xyield/xrpl-go/model/transactions/types" - "github.com/xyield/xrpl-go/test" + "github.com/CreatureDev/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/test" ) func TestEscrow(t *testing.T) { diff --git a/model/ledger/fee_settings_test.go b/model/ledger/fee_settings_test.go index 923bc03c..d8a71eed 100644 --- a/model/ledger/fee_settings_test.go +++ b/model/ledger/fee_settings_test.go @@ -3,7 +3,7 @@ package ledger import ( "testing" - "github.com/xyield/xrpl-go/test" + "github.com/CreatureDev/xrpl-go/test" ) func TestFeeSettings(t *testing.T) { diff --git a/model/ledger/ledger_hashes.go b/model/ledger/ledger_hashes.go index dfa83353..c00dd264 100644 --- a/model/ledger/ledger_hashes.go +++ b/model/ledger/ledger_hashes.go @@ -1,6 +1,6 @@ package ledger -import "github.com/xyield/xrpl-go/model/transactions/types" +import "github.com/CreatureDev/xrpl-go/model/transactions/types" type LedgerHashes struct { FirstLedgerSequence uint32 diff --git a/model/ledger/ledger_hashes_test.go b/model/ledger/ledger_hashes_test.go index bcdcc08c..5d29ce58 100644 --- a/model/ledger/ledger_hashes_test.go +++ b/model/ledger/ledger_hashes_test.go @@ -3,8 +3,8 @@ package ledger import ( "testing" - "github.com/xyield/xrpl-go/model/transactions/types" - "github.com/xyield/xrpl-go/test" + "github.com/CreatureDev/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/test" ) func TestLedgerHashes(t *testing.T) { diff --git a/model/ledger/negative_unl_test.go b/model/ledger/negative_unl_test.go index 3c9bed72..8c1cc31c 100644 --- a/model/ledger/negative_unl_test.go +++ b/model/ledger/negative_unl_test.go @@ -3,7 +3,7 @@ package ledger import ( "testing" - "github.com/xyield/xrpl-go/test" + "github.com/CreatureDev/xrpl-go/test" ) func TestNegativeUNL(t *testing.T) { diff --git a/model/ledger/nftoken_offer.go b/model/ledger/nftoken_offer.go index 8f1d8f73..fbb8bfcf 100644 --- a/model/ledger/nftoken_offer.go +++ b/model/ledger/nftoken_offer.go @@ -3,7 +3,7 @@ package ledger import ( "encoding/json" - "github.com/xyield/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/model/transactions/types" ) type NFTokenOffer struct { diff --git a/model/ledger/nftoken_offer_test.go b/model/ledger/nftoken_offer_test.go index 03d1ec15..eece8448 100644 --- a/model/ledger/nftoken_offer_test.go +++ b/model/ledger/nftoken_offer_test.go @@ -3,8 +3,8 @@ package ledger import ( "testing" - "github.com/xyield/xrpl-go/model/transactions/types" - "github.com/xyield/xrpl-go/test" + "github.com/CreatureDev/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/test" ) func TestNFTokenOffer(t *testing.T) { diff --git a/model/ledger/nftoken_page.go b/model/ledger/nftoken_page.go index 17dcbf12..ea603dc4 100644 --- a/model/ledger/nftoken_page.go +++ b/model/ledger/nftoken_page.go @@ -1,6 +1,6 @@ package ledger -import "github.com/xyield/xrpl-go/model/transactions/types" +import "github.com/CreatureDev/xrpl-go/model/transactions/types" type NFTokenPage struct { LedgerEntryType LedgerEntryType diff --git a/model/ledger/nftoken_page_test.go b/model/ledger/nftoken_page_test.go index 1da49725..ad262273 100644 --- a/model/ledger/nftoken_page_test.go +++ b/model/ledger/nftoken_page_test.go @@ -3,8 +3,8 @@ package ledger import ( "testing" - "github.com/xyield/xrpl-go/model/transactions/types" - "github.com/xyield/xrpl-go/test" + "github.com/CreatureDev/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/test" ) func TestNFTokenPage(t *testing.T) { diff --git a/model/ledger/offer.go b/model/ledger/offer.go index 33e0abbb..7c068f89 100644 --- a/model/ledger/offer.go +++ b/model/ledger/offer.go @@ -3,7 +3,7 @@ package ledger import ( "encoding/json" - "github.com/xyield/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/model/transactions/types" ) type OfferFlags uint32 diff --git a/model/ledger/offer_test.go b/model/ledger/offer_test.go index 65f4ef6f..ea1541f0 100644 --- a/model/ledger/offer_test.go +++ b/model/ledger/offer_test.go @@ -3,8 +3,8 @@ package ledger import ( "testing" - "github.com/xyield/xrpl-go/model/transactions/types" - "github.com/xyield/xrpl-go/test" + "github.com/CreatureDev/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/test" ) func TestOffer(t *testing.T) { diff --git a/model/ledger/pay_channel.go b/model/ledger/pay_channel.go index 2cb9cadc..122259a1 100644 --- a/model/ledger/pay_channel.go +++ b/model/ledger/pay_channel.go @@ -1,6 +1,6 @@ package ledger -import "github.com/xyield/xrpl-go/model/transactions/types" +import "github.com/CreatureDev/xrpl-go/model/transactions/types" type PayChannel struct { Account types.Address diff --git a/model/ledger/pay_channel_test.go b/model/ledger/pay_channel_test.go index ea907200..a2ba8ec8 100644 --- a/model/ledger/pay_channel_test.go +++ b/model/ledger/pay_channel_test.go @@ -3,8 +3,8 @@ package ledger import ( "testing" - "github.com/xyield/xrpl-go/model/transactions/types" - "github.com/xyield/xrpl-go/test" + "github.com/CreatureDev/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/test" ) func TestPayChannel(t *testing.T) { diff --git a/model/ledger/ripple_state.go b/model/ledger/ripple_state.go index 92350a77..f4f90c58 100644 --- a/model/ledger/ripple_state.go +++ b/model/ledger/ripple_state.go @@ -1,6 +1,6 @@ package ledger -import "github.com/xyield/xrpl-go/model/transactions/types" +import "github.com/CreatureDev/xrpl-go/model/transactions/types" // TODO flags diff --git a/model/ledger/ripple_state_test.go b/model/ledger/ripple_state_test.go index 509b01f4..19080d36 100644 --- a/model/ledger/ripple_state_test.go +++ b/model/ledger/ripple_state_test.go @@ -3,8 +3,8 @@ package ledger import ( "testing" - "github.com/xyield/xrpl-go/model/transactions/types" - "github.com/xyield/xrpl-go/test" + "github.com/CreatureDev/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/test" ) func TestRippleState(t *testing.T) { diff --git a/model/ledger/signer_list.go b/model/ledger/signer_list.go index 9745057b..c59efe83 100644 --- a/model/ledger/signer_list.go +++ b/model/ledger/signer_list.go @@ -1,6 +1,6 @@ package ledger -import "github.com/xyield/xrpl-go/model/transactions/types" +import "github.com/CreatureDev/xrpl-go/model/transactions/types" type SignerListFlags uint32 diff --git a/model/ledger/signer_list_test.go b/model/ledger/signer_list_test.go index 41a3b809..859119f4 100644 --- a/model/ledger/signer_list_test.go +++ b/model/ledger/signer_list_test.go @@ -3,7 +3,7 @@ package ledger import ( "testing" - "github.com/xyield/xrpl-go/test" + "github.com/CreatureDev/xrpl-go/test" ) func TestSignerList(t *testing.T) { diff --git a/model/ledger/ticket.go b/model/ledger/ticket.go index c76fe2d5..770515c4 100644 --- a/model/ledger/ticket.go +++ b/model/ledger/ticket.go @@ -1,6 +1,6 @@ package ledger -import "github.com/xyield/xrpl-go/model/transactions/types" +import "github.com/CreatureDev/xrpl-go/model/transactions/types" type Ticket struct { Account types.Address diff --git a/model/ledger/ticket_test.go b/model/ledger/ticket_test.go index adb6dfc1..8341ddcc 100644 --- a/model/ledger/ticket_test.go +++ b/model/ledger/ticket_test.go @@ -3,7 +3,7 @@ package ledger import ( "testing" - "github.com/xyield/xrpl-go/test" + "github.com/CreatureDev/xrpl-go/test" ) func TestTicket(t *testing.T) { diff --git a/model/transactions/account_delete.go b/model/transactions/account_delete.go index bf99baba..0d638d32 100644 --- a/model/transactions/account_delete.go +++ b/model/transactions/account_delete.go @@ -1,7 +1,7 @@ package transactions import ( - "github.com/xyield/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/model/transactions/types" ) type AccountDelete struct { diff --git a/model/transactions/account_delete_test.go b/model/transactions/account_delete_test.go index 1b01282b..2e876fb3 100644 --- a/model/transactions/account_delete_test.go +++ b/model/transactions/account_delete_test.go @@ -5,8 +5,8 @@ import ( "reflect" "testing" - "github.com/xyield/xrpl-go/model/transactions/types" - "github.com/xyield/xrpl-go/test" + "github.com/CreatureDev/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/test" ) func TestAccountDeleteTransaction(t *testing.T) { diff --git a/model/transactions/account_set.go b/model/transactions/account_set.go index 756f9bb2..91ef1afe 100644 --- a/model/transactions/account_set.go +++ b/model/transactions/account_set.go @@ -1,7 +1,7 @@ package transactions import ( - "github.com/xyield/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/model/transactions/types" ) type AccountSet struct { diff --git a/model/transactions/account_set_test.go b/model/transactions/account_set_test.go index dd16eec4..de22b700 100644 --- a/model/transactions/account_set_test.go +++ b/model/transactions/account_set_test.go @@ -5,8 +5,8 @@ import ( "reflect" "testing" - "github.com/xyield/xrpl-go/model/transactions/types" - "github.com/xyield/xrpl-go/test" + "github.com/CreatureDev/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/test" ) func TestAccountSetTransaction(t *testing.T) { diff --git a/model/transactions/check_cancel.go b/model/transactions/check_cancel.go index e4d2279a..b1f3ffce 100644 --- a/model/transactions/check_cancel.go +++ b/model/transactions/check_cancel.go @@ -1,7 +1,7 @@ package transactions import ( - "github.com/xyield/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/model/transactions/types" ) type CheckCancel struct { diff --git a/model/transactions/check_cancel_test.go b/model/transactions/check_cancel_test.go index 1f864236..e4b41b46 100644 --- a/model/transactions/check_cancel_test.go +++ b/model/transactions/check_cancel_test.go @@ -5,8 +5,8 @@ import ( "reflect" "testing" - "github.com/xyield/xrpl-go/model/transactions/types" - "github.com/xyield/xrpl-go/test" + "github.com/CreatureDev/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/test" ) func TestCheckCancelTransaction(t *testing.T) { diff --git a/model/transactions/check_cash.go b/model/transactions/check_cash.go index de67937f..bfcb69b8 100644 --- a/model/transactions/check_cash.go +++ b/model/transactions/check_cash.go @@ -3,7 +3,7 @@ package transactions import ( "encoding/json" - "github.com/xyield/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/model/transactions/types" ) type CheckCash struct { diff --git a/model/transactions/check_cash_test.go b/model/transactions/check_cash_test.go index f41ee5d4..f470d75a 100644 --- a/model/transactions/check_cash_test.go +++ b/model/transactions/check_cash_test.go @@ -5,8 +5,8 @@ import ( "reflect" "testing" - "github.com/xyield/xrpl-go/model/transactions/types" - "github.com/xyield/xrpl-go/test" + "github.com/CreatureDev/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/test" ) func TestCheckCashTransaction(t *testing.T) { diff --git a/model/transactions/check_create.go b/model/transactions/check_create.go index 59bef541..19a119b4 100644 --- a/model/transactions/check_create.go +++ b/model/transactions/check_create.go @@ -3,7 +3,7 @@ package transactions import ( "encoding/json" - "github.com/xyield/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/model/transactions/types" ) type CheckCreate struct { diff --git a/model/transactions/check_create_test.go b/model/transactions/check_create_test.go index 2708e46c..83d42332 100644 --- a/model/transactions/check_create_test.go +++ b/model/transactions/check_create_test.go @@ -5,8 +5,8 @@ import ( "reflect" "testing" - "github.com/xyield/xrpl-go/model/transactions/types" - "github.com/xyield/xrpl-go/test" + "github.com/CreatureDev/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/test" ) func TestCheckCreateTransaction(t *testing.T) { diff --git a/model/transactions/deposit_preauth.go b/model/transactions/deposit_preauth.go index d7118ab4..c8a450f2 100644 --- a/model/transactions/deposit_preauth.go +++ b/model/transactions/deposit_preauth.go @@ -1,7 +1,7 @@ package transactions import ( - "github.com/xyield/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/model/transactions/types" ) type DepositPreauth struct { diff --git a/model/transactions/deposit_preauth_test.go b/model/transactions/deposit_preauth_test.go index 432d15a0..71dfd119 100644 --- a/model/transactions/deposit_preauth_test.go +++ b/model/transactions/deposit_preauth_test.go @@ -5,8 +5,8 @@ import ( "reflect" "testing" - "github.com/xyield/xrpl-go/model/transactions/types" - "github.com/xyield/xrpl-go/test" + "github.com/CreatureDev/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/test" ) func TestDepositPreauthTransaction(t *testing.T) { diff --git a/model/transactions/escrow_cancel.go b/model/transactions/escrow_cancel.go index 01149446..bc37de93 100644 --- a/model/transactions/escrow_cancel.go +++ b/model/transactions/escrow_cancel.go @@ -1,7 +1,7 @@ package transactions import ( - "github.com/xyield/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/model/transactions/types" ) type EscrowCancel struct { diff --git a/model/transactions/escrow_cancel_test.go b/model/transactions/escrow_cancel_test.go index a5bf5133..cb251687 100644 --- a/model/transactions/escrow_cancel_test.go +++ b/model/transactions/escrow_cancel_test.go @@ -5,8 +5,8 @@ import ( "reflect" "testing" - "github.com/xyield/xrpl-go/model/transactions/types" - "github.com/xyield/xrpl-go/test" + "github.com/CreatureDev/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/test" ) func TestEscrowCancelTransaction(t *testing.T) { diff --git a/model/transactions/escrow_create.go b/model/transactions/escrow_create.go index 113148fb..27bab953 100644 --- a/model/transactions/escrow_create.go +++ b/model/transactions/escrow_create.go @@ -1,7 +1,7 @@ package transactions import ( - "github.com/xyield/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/model/transactions/types" ) type EscrowCreate struct { diff --git a/model/transactions/escrow_create_test.go b/model/transactions/escrow_create_test.go index daa385d7..e047849f 100644 --- a/model/transactions/escrow_create_test.go +++ b/model/transactions/escrow_create_test.go @@ -5,8 +5,8 @@ import ( "reflect" "testing" - "github.com/xyield/xrpl-go/model/transactions/types" - "github.com/xyield/xrpl-go/test" + "github.com/CreatureDev/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/test" ) func TestEscrowCreateTransaction(t *testing.T) { diff --git a/model/transactions/escrow_finish.go b/model/transactions/escrow_finish.go index 8a69d78b..720d2b29 100644 --- a/model/transactions/escrow_finish.go +++ b/model/transactions/escrow_finish.go @@ -1,7 +1,7 @@ package transactions import ( - "github.com/xyield/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/model/transactions/types" ) type EscrowFinish struct { diff --git a/model/transactions/escrow_finish_test.go b/model/transactions/escrow_finish_test.go index 6d8b3c8c..ff189d65 100644 --- a/model/transactions/escrow_finish_test.go +++ b/model/transactions/escrow_finish_test.go @@ -5,8 +5,8 @@ import ( "reflect" "testing" - "github.com/xyield/xrpl-go/model/transactions/types" - "github.com/xyield/xrpl-go/test" + "github.com/CreatureDev/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/test" ) func TestEscrowFinishTransaction(t *testing.T) { diff --git a/model/transactions/nftoken_accept_offer.go b/model/transactions/nftoken_accept_offer.go index 3f94ed41..eda10ce6 100644 --- a/model/transactions/nftoken_accept_offer.go +++ b/model/transactions/nftoken_accept_offer.go @@ -3,7 +3,7 @@ package transactions import ( "encoding/json" - "github.com/xyield/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/model/transactions/types" ) type NFTokenAcceptOffer struct { diff --git a/model/transactions/nftoken_accept_offer_test.go b/model/transactions/nftoken_accept_offer_test.go index 83a9c604..7dd91187 100644 --- a/model/transactions/nftoken_accept_offer_test.go +++ b/model/transactions/nftoken_accept_offer_test.go @@ -5,8 +5,8 @@ import ( "reflect" "testing" - "github.com/xyield/xrpl-go/model/transactions/types" - "github.com/xyield/xrpl-go/test" + "github.com/CreatureDev/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/test" ) func TestNFTokenAcceptOfferTransaction(t *testing.T) { diff --git a/model/transactions/nftoken_burn.go b/model/transactions/nftoken_burn.go index 70c213ec..2b2663d1 100644 --- a/model/transactions/nftoken_burn.go +++ b/model/transactions/nftoken_burn.go @@ -1,7 +1,7 @@ package transactions import ( - "github.com/xyield/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/model/transactions/types" ) type NFTokenBurn struct { diff --git a/model/transactions/nftoken_burn_test.go b/model/transactions/nftoken_burn_test.go index 2b9d97e1..15637a8b 100644 --- a/model/transactions/nftoken_burn_test.go +++ b/model/transactions/nftoken_burn_test.go @@ -5,8 +5,8 @@ import ( "reflect" "testing" - "github.com/xyield/xrpl-go/model/transactions/types" - "github.com/xyield/xrpl-go/test" + "github.com/CreatureDev/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/test" ) func TestNFTokenBurnTransaction(t *testing.T) { diff --git a/model/transactions/nftoken_cancel_offer.go b/model/transactions/nftoken_cancel_offer.go index 094b3acf..fb5058e7 100644 --- a/model/transactions/nftoken_cancel_offer.go +++ b/model/transactions/nftoken_cancel_offer.go @@ -1,7 +1,7 @@ package transactions import ( - "github.com/xyield/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/model/transactions/types" ) type NFTokenCancelOffer struct { diff --git a/model/transactions/nftoken_cancel_offer_test.go b/model/transactions/nftoken_cancel_offer_test.go index 7941a8f4..5d37edac 100644 --- a/model/transactions/nftoken_cancel_offer_test.go +++ b/model/transactions/nftoken_cancel_offer_test.go @@ -5,8 +5,8 @@ import ( "reflect" "testing" - "github.com/xyield/xrpl-go/model/transactions/types" - "github.com/xyield/xrpl-go/test" + "github.com/CreatureDev/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/test" ) func TestNFTokenCancelOfferTx(t *testing.T) { diff --git a/model/transactions/nftoken_create_offer.go b/model/transactions/nftoken_create_offer.go index 7964f718..4c0f2c5b 100644 --- a/model/transactions/nftoken_create_offer.go +++ b/model/transactions/nftoken_create_offer.go @@ -3,7 +3,7 @@ package transactions import ( "encoding/json" - "github.com/xyield/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/model/transactions/types" ) type NFTokenCreateOffer struct { diff --git a/model/transactions/nftoken_create_offer_test.go b/model/transactions/nftoken_create_offer_test.go index 55623027..1e7b0a1d 100644 --- a/model/transactions/nftoken_create_offer_test.go +++ b/model/transactions/nftoken_create_offer_test.go @@ -5,8 +5,8 @@ import ( "reflect" "testing" - "github.com/xyield/xrpl-go/model/transactions/types" - "github.com/xyield/xrpl-go/test" + "github.com/CreatureDev/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/test" ) func TestNFTokenCreateOfferTx(t *testing.T) { diff --git a/model/transactions/nftoken_mint.go b/model/transactions/nftoken_mint.go index cbb12c6a..1070b1c0 100644 --- a/model/transactions/nftoken_mint.go +++ b/model/transactions/nftoken_mint.go @@ -1,7 +1,7 @@ package transactions import ( - "github.com/xyield/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/model/transactions/types" ) type NFTokenMint struct { diff --git a/model/transactions/nftoken_mint_test.go b/model/transactions/nftoken_mint_test.go index 706947aa..6b8ee032 100644 --- a/model/transactions/nftoken_mint_test.go +++ b/model/transactions/nftoken_mint_test.go @@ -5,8 +5,8 @@ import ( "reflect" "testing" - "github.com/xyield/xrpl-go/model/transactions/types" - "github.com/xyield/xrpl-go/test" + "github.com/CreatureDev/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/test" ) func TestNFTokenMintTx(t *testing.T) { diff --git a/model/transactions/offer_cancel_test.go b/model/transactions/offer_cancel_test.go index 304a013b..8d08f735 100644 --- a/model/transactions/offer_cancel_test.go +++ b/model/transactions/offer_cancel_test.go @@ -5,8 +5,8 @@ import ( "reflect" "testing" - "github.com/xyield/xrpl-go/model/transactions/types" - "github.com/xyield/xrpl-go/test" + "github.com/CreatureDev/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/test" ) func TestOfferCancelTx(t *testing.T) { diff --git a/model/transactions/offer_create.go b/model/transactions/offer_create.go index 8bd4871c..81edfa39 100644 --- a/model/transactions/offer_create.go +++ b/model/transactions/offer_create.go @@ -3,7 +3,7 @@ package transactions import ( "encoding/json" - "github.com/xyield/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/model/transactions/types" ) type OfferCreate struct { diff --git a/model/transactions/offer_create_test.go b/model/transactions/offer_create_test.go index b91717ff..e6ce9901 100644 --- a/model/transactions/offer_create_test.go +++ b/model/transactions/offer_create_test.go @@ -5,8 +5,8 @@ import ( "reflect" "testing" - "github.com/xyield/xrpl-go/model/transactions/types" - "github.com/xyield/xrpl-go/test" + "github.com/CreatureDev/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/test" ) func TestOfferCreateTx(t *testing.T) { diff --git a/model/transactions/path_step.go b/model/transactions/path_step.go index 12520db9..a1a3f637 100644 --- a/model/transactions/path_step.go +++ b/model/transactions/path_step.go @@ -1,7 +1,7 @@ package transactions import ( - "github.com/xyield/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/model/transactions/types" ) type PathStep struct { diff --git a/model/transactions/payment.go b/model/transactions/payment.go index 825a64fd..a029e62c 100644 --- a/model/transactions/payment.go +++ b/model/transactions/payment.go @@ -3,7 +3,7 @@ package transactions import ( "encoding/json" - "github.com/xyield/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/model/transactions/types" ) type Payment struct { diff --git a/model/transactions/payment_channel_claim.go b/model/transactions/payment_channel_claim.go index 48bc68b1..4fb63b3a 100644 --- a/model/transactions/payment_channel_claim.go +++ b/model/transactions/payment_channel_claim.go @@ -1,7 +1,7 @@ package transactions import ( - "github.com/xyield/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/model/transactions/types" ) type PaymentChannelClaim struct { diff --git a/model/transactions/payment_channel_claim_test.go b/model/transactions/payment_channel_claim_test.go index cb04594d..99b85b24 100644 --- a/model/transactions/payment_channel_claim_test.go +++ b/model/transactions/payment_channel_claim_test.go @@ -5,8 +5,8 @@ import ( "reflect" "testing" - "github.com/xyield/xrpl-go/model/transactions/types" - "github.com/xyield/xrpl-go/test" + "github.com/CreatureDev/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/test" ) func TestPaymentChannelClaimTx(t *testing.T) { diff --git a/model/transactions/payment_channel_create.go b/model/transactions/payment_channel_create.go index 39e1b708..09753f1d 100644 --- a/model/transactions/payment_channel_create.go +++ b/model/transactions/payment_channel_create.go @@ -1,7 +1,7 @@ package transactions import ( - "github.com/xyield/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/model/transactions/types" ) type PaymentChannelCreate struct { diff --git a/model/transactions/payment_channel_create_test.go b/model/transactions/payment_channel_create_test.go index 4729bf5d..92894dea 100644 --- a/model/transactions/payment_channel_create_test.go +++ b/model/transactions/payment_channel_create_test.go @@ -5,8 +5,8 @@ import ( "reflect" "testing" - "github.com/xyield/xrpl-go/model/transactions/types" - "github.com/xyield/xrpl-go/test" + "github.com/CreatureDev/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/test" ) func TestPaymentChannelCreate(t *testing.T) { diff --git a/model/transactions/payment_channel_fund.go b/model/transactions/payment_channel_fund.go index adf1d7d1..1a0687a9 100644 --- a/model/transactions/payment_channel_fund.go +++ b/model/transactions/payment_channel_fund.go @@ -1,7 +1,7 @@ package transactions import ( - "github.com/xyield/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/model/transactions/types" ) type PaymentChannelFund struct { diff --git a/model/transactions/payment_channel_fund_test.go b/model/transactions/payment_channel_fund_test.go index f07f5fad..9fce42a0 100644 --- a/model/transactions/payment_channel_fund_test.go +++ b/model/transactions/payment_channel_fund_test.go @@ -5,8 +5,8 @@ import ( "reflect" "testing" - "github.com/xyield/xrpl-go/model/transactions/types" - "github.com/xyield/xrpl-go/test" + "github.com/CreatureDev/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/test" ) func TestPaymentChannelFund(t *testing.T) { diff --git a/model/transactions/payment_test.go b/model/transactions/payment_test.go index 08037e96..0bdaa504 100644 --- a/model/transactions/payment_test.go +++ b/model/transactions/payment_test.go @@ -5,8 +5,8 @@ import ( "reflect" "testing" - "github.com/xyield/xrpl-go/model/transactions/types" - "github.com/xyield/xrpl-go/test" + "github.com/CreatureDev/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/test" ) func TestPaymentTx(t *testing.T) { diff --git a/model/transactions/set_regular_key.go b/model/transactions/set_regular_key.go index 6b88c328..58d39824 100644 --- a/model/transactions/set_regular_key.go +++ b/model/transactions/set_regular_key.go @@ -1,7 +1,7 @@ package transactions import ( - "github.com/xyield/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/model/transactions/types" ) type SetRegularKey struct { diff --git a/model/transactions/set_regular_key_test.go b/model/transactions/set_regular_key_test.go index ab77c4db..6737e9a1 100644 --- a/model/transactions/set_regular_key_test.go +++ b/model/transactions/set_regular_key_test.go @@ -5,8 +5,8 @@ import ( "reflect" "testing" - "github.com/xyield/xrpl-go/model/transactions/types" - "github.com/xyield/xrpl-go/test" + "github.com/CreatureDev/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/test" ) func TestSetRegularKeyTx(t *testing.T) { diff --git a/model/transactions/signer.go b/model/transactions/signer.go index 08495b3e..7889f0e8 100644 --- a/model/transactions/signer.go +++ b/model/transactions/signer.go @@ -1,7 +1,7 @@ package transactions import ( - "github.com/xyield/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/model/transactions/types" ) type Signer struct { diff --git a/model/transactions/signer_list_set.go b/model/transactions/signer_list_set.go index e37b8a8d..f9f21d49 100644 --- a/model/transactions/signer_list_set.go +++ b/model/transactions/signer_list_set.go @@ -1,7 +1,7 @@ package transactions import ( - "github.com/xyield/xrpl-go/model/ledger" + "github.com/CreatureDev/xrpl-go/model/ledger" ) type SignerListSet struct { diff --git a/model/transactions/signer_list_set_test.go b/model/transactions/signer_list_set_test.go index b5a61cef..c2652eb3 100644 --- a/model/transactions/signer_list_set_test.go +++ b/model/transactions/signer_list_set_test.go @@ -5,9 +5,9 @@ import ( "reflect" "testing" - "github.com/xyield/xrpl-go/model/ledger" - "github.com/xyield/xrpl-go/model/transactions/types" - "github.com/xyield/xrpl-go/test" + "github.com/CreatureDev/xrpl-go/model/ledger" + "github.com/CreatureDev/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/test" ) func TestSignerListSetTx(t *testing.T) { diff --git a/model/transactions/ticket_create_test.go b/model/transactions/ticket_create_test.go index 06614d9c..ab1de015 100644 --- a/model/transactions/ticket_create_test.go +++ b/model/transactions/ticket_create_test.go @@ -5,8 +5,8 @@ import ( "reflect" "testing" - "github.com/xyield/xrpl-go/model/transactions/types" - "github.com/xyield/xrpl-go/test" + "github.com/CreatureDev/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/test" ) func TestTicketCreateTx(t *testing.T) { diff --git a/model/transactions/transaction_metadata.go b/model/transactions/transaction_metadata.go index 9bf4d1cb..abc3f2ef 100644 --- a/model/transactions/transaction_metadata.go +++ b/model/transactions/transaction_metadata.go @@ -4,8 +4,8 @@ import ( "encoding/json" "fmt" - "github.com/xyield/xrpl-go/model/ledger" - "github.com/xyield/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/model/ledger" + "github.com/CreatureDev/xrpl-go/model/transactions/types" ) type TxMeta interface { diff --git a/model/transactions/trust_set.go b/model/transactions/trust_set.go index 25ecccfc..51bd221d 100644 --- a/model/transactions/trust_set.go +++ b/model/transactions/trust_set.go @@ -3,7 +3,7 @@ package transactions import ( "encoding/json" - "github.com/xyield/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/model/transactions/types" ) type TrustSet struct { diff --git a/model/transactions/trust_set_test.go b/model/transactions/trust_set_test.go index e11e79e6..5e535670 100644 --- a/model/transactions/trust_set_test.go +++ b/model/transactions/trust_set_test.go @@ -5,8 +5,8 @@ import ( "reflect" "testing" - "github.com/xyield/xrpl-go/model/transactions/types" - "github.com/xyield/xrpl-go/test" + "github.com/CreatureDev/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/test" ) func TestTrustSetTx(t *testing.T) { diff --git a/model/transactions/tx.go b/model/transactions/tx.go index ebbd3171..27a65106 100644 --- a/model/transactions/tx.go +++ b/model/transactions/tx.go @@ -4,7 +4,7 @@ import ( "encoding/json" "fmt" - "github.com/xyield/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/model/transactions/types" ) type Tx interface { diff --git a/model/transactions/types/address.go b/model/transactions/types/address.go index 1337a228..1e183804 100644 --- a/model/transactions/types/address.go +++ b/model/transactions/types/address.go @@ -1,3 +1,28 @@ package types +import ( + "fmt" + "strings" +) + type Address string + +func (a Address) Validate() error { + characters := []string{"0", "O", "I", "l"} + if len(a) == 0 { + return fmt.Errorf("missing xrpl address") + } + if len(a) < 25 || len(a) > 35 { + return fmt.Errorf("invalid xrpl address length") + } + if a[0] != 'r' { + return fmt.Errorf("invalid xrpl address prefix '%c'", a[0]) + } + for _, c := range characters { + if strings.Contains(string(a), c) { + return fmt.Errorf("xrpl address contains invalid character '%s'", c) + } + } + // TODO checksum + return nil +} diff --git a/model/transactions/types/currency_amount.go b/model/transactions/types/currency_amount.go index dd87f30d..050678f4 100644 --- a/model/transactions/types/currency_amount.go +++ b/model/transactions/types/currency_amount.go @@ -2,6 +2,7 @@ package types import ( "encoding/json" + "fmt" "strconv" ) @@ -14,6 +15,7 @@ const ( type CurrencyAmount interface { Kind() CurrencyKind + Validate() error } func UnmarshalCurrencyAmount(data []byte) (CurrencyAmount, error) { @@ -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 } @@ -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) diff --git a/model/transactions/types/hash256.go b/model/transactions/types/hash256.go index df068aa3..e63df929 100644 --- a/model/transactions/types/hash256.go +++ b/model/transactions/types/hash256.go @@ -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 +} diff --git a/model/transactions/types/nftoken_id.go b/model/transactions/types/nftoken_id.go index 438a0a42..c682b473 100644 --- a/model/transactions/types/nftoken_id.go +++ b/model/transactions/types/nftoken_id.go @@ -1,3 +1,13 @@ package types +import "fmt" + type NFTokenID Hash256 + +func (id NFTokenID) Validate() error { + h := Hash256(id) + if err := h.Validate(); err != nil { + return fmt.Errorf("nftoken id: %w", err) + } + return nil +}