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/definitions/definitions.json b/binary-codec/definitions/definitions.json index f3d92f77..b6b48f44 100644 --- a/binary-codec/definitions/definitions.json +++ b/binary-codec/definitions/definitions.json @@ -1,29 +1,34 @@ { "TYPES": { - "Validation": 10003, "Done": -1, + "Unknown": -2, + "NotPresent": 0, + "UInt16": 1, + "UInt32": 2, + "UInt64": 3, "Hash128": 4, + "Hash256": 5, + "Amount": 6, "Blob": 7, "AccountID": 8, - "Amount": 6, - "Hash256": 5, - "UInt8": 16, - "Vector256": 19, "STObject": 14, - "Unknown": -2, - "Transaction": 10001, + "STArray": 15, + "UInt8": 16, "Hash160": 17, "PathSet": 18, + "Vector256": 19, + "UInt96": 20, + "UInt192": 21, + "UInt384": 22, + "UInt512": 23, + "Issue": 24, + "XChainBridge": 25, + "Transaction": 10001, "LedgerEntry": 10002, - "UInt16": 1, - "NotPresent": 0, - "UInt64": 3, - "UInt32": 2, - "STArray": 15 + "Validation": 10003, + "Metadata": 10004 }, "LEDGER_ENTRY_TYPES": { - "Any": -3, - "Child": -2, "Invalid": -1, "AccountRoot": 97, "DirectoryNode": 100, @@ -31,18 +36,25 @@ "Ticket": 84, "SignerList": 83, "Offer": 111, + "Bridge": 105, "LedgerHashes": 104, "Amendments": 102, + "XChainOwnedClaimID": 113, + "XChainOwnedCreateAccountClaimID": 116, "FeeSettings": 115, "Escrow": 117, "PayChannel": 120, - "DepositPreauth": 112, "Check": 67, - "Nickname": 110, - "Contract": 99, + "DepositPreauth": 112, + "NegativeUNL": 78, "NFTokenPage": 80, "NFTokenOffer": 55, - "NegativeUNL": 78 + "AMM": 121, + "Any": -3, + "Child": -2, + "Nickname": 110, + "Contract": 99, + "GeneratorMap": 103 }, "FIELDS": [ [ @@ -65,6 +77,176 @@ "type": "Unknown" } ], + [ + "ObjectEndMarker", + { + "nth": 1, + "isVLEncoded": false, + "isSerialized": true, + "isSigningField": true, + "type": "STObject" + } + ], + [ + "ArrayEndMarker", + { + "nth": 1, + "isVLEncoded": false, + "isSerialized": true, + "isSigningField": true, + "type": "STArray" + } + ], + [ + "hash", + { + "nth": 257, + "isVLEncoded": false, + "isSerialized": false, + "isSigningField": false, + "type": "Hash256" + } + ], + [ + "index", + { + "nth": 258, + "isVLEncoded": false, + "isSerialized": false, + "isSigningField": false, + "type": "Hash256" + } + ], + [ + "taker_gets_funded", + { + "nth": 258, + "isVLEncoded": false, + "isSerialized": false, + "isSigningField": false, + "type": "Amount" + } + ], + [ + "taker_pays_funded", + { + "nth": 259, + "isVLEncoded": false, + "isSerialized": false, + "isSigningField": false, + "type": "Amount" + } + ], + [ + "LedgerEntry", + { + "nth": 1, + "isVLEncoded": false, + "isSerialized": false, + "isSigningField": true, + "type": "LedgerEntry" + } + ], + [ + "Transaction", + { + "nth": 1, + "isVLEncoded": false, + "isSerialized": false, + "isSigningField": true, + "type": "Transaction" + } + ], + [ + "Validation", + { + "nth": 1, + "isVLEncoded": false, + "isSerialized": false, + "isSigningField": true, + "type": "Validation" + } + ], + [ + "Metadata", + { + "nth": 1, + "isVLEncoded": false, + "isSerialized": true, + "isSigningField": true, + "type": "Metadata" + } + ], + [ + "CloseResolution", + { + "nth": 1, + "isVLEncoded": false, + "isSerialized": true, + "isSigningField": true, + "type": "UInt8" + } + ], + [ + "Method", + { + "nth": 2, + "isVLEncoded": false, + "isSerialized": true, + "isSigningField": true, + "type": "UInt8" + } + ], + [ + "TransactionResult", + { + "nth": 3, + "isVLEncoded": false, + "isSerialized": true, + "isSigningField": true, + "type": "UInt8" + } + ], + [ + "TickSize", + { + "nth": 16, + "isVLEncoded": false, + "isSerialized": true, + "isSigningField": true, + "type": "UInt8" + } + ], + [ + "UNLModifyDisabling", + { + "nth": 17, + "isVLEncoded": false, + "isSerialized": true, + "isSigningField": true, + "type": "UInt8" + } + ], + [ + "HookResult", + { + "nth": 18, + "isVLEncoded": false, + "isSerialized": true, + "isSigningField": true, + "type": "UInt8" + } + ], + [ + "WasLockingChainSend", + { + "nth": 19, + "isVLEncoded": false, + "isSerialized": true, + "isSigningField": true, + "type": "UInt8" + } + ], [ "LedgerEntryType", { @@ -106,79 +288,79 @@ } ], [ - "Flags", + "TradingFee", { - "nth": 2, + "nth": 5, "isVLEncoded": false, "isSerialized": true, "isSigningField": true, - "type": "UInt32" + "type": "UInt16" } ], [ - "SourceTag", + "DiscountedFee", { - "nth": 3, + "nth": 6, "isVLEncoded": false, "isSerialized": true, "isSigningField": true, - "type": "UInt32" + "type": "UInt16" } ], [ - "Sequence", + "Version", { - "nth": 4, + "nth": 16, "isVLEncoded": false, "isSerialized": true, "isSigningField": true, - "type": "UInt32" + "type": "UInt16" } ], [ - "PreviousTxnLgrSeq", + "HookStateChangeCount", { - "nth": 5, + "nth": 17, "isVLEncoded": false, "isSerialized": true, "isSigningField": true, - "type": "UInt32" + "type": "UInt16" } ], [ - "LedgerSequence", + "HookEmitCount", { - "nth": 6, + "nth": 18, "isVLEncoded": false, "isSerialized": true, "isSigningField": true, - "type": "UInt32" + "type": "UInt16" } ], [ - "CloseTime", + "HookExecutionIndex", { - "nth": 7, + "nth": 19, "isVLEncoded": false, "isSerialized": true, "isSigningField": true, - "type": "UInt32" + "type": "UInt16" } ], [ - "ParentCloseTime", + "HookApiVersion", { - "nth": 8, + "nth": 20, "isVLEncoded": false, "isSerialized": true, "isSigningField": true, - "type": "UInt32" + "type": "UInt16" } ], [ - "SigningTime", + "NetworkID", { - "nth": 9, + "nth": 1, "isVLEncoded": false, "isSerialized": true, "isSigningField": true, @@ -186,9 +368,9 @@ } ], [ - "Expiration", + "Flags", { - "nth": 10, + "nth": 2, "isVLEncoded": false, "isSerialized": true, "isSigningField": true, @@ -196,9 +378,9 @@ } ], [ - "TransferRate", + "SourceTag", { - "nth": 11, + "nth": 3, "isVLEncoded": false, "isSerialized": true, "isSigningField": true, @@ -206,9 +388,9 @@ } ], [ - "WalletSize", + "Sequence", { - "nth": 12, + "nth": 4, "isVLEncoded": false, "isSerialized": true, "isSigningField": true, @@ -216,9 +398,9 @@ } ], [ - "OwnerCount", + "PreviousTxnLgrSeq", { - "nth": 13, + "nth": 5, "isVLEncoded": false, "isSerialized": true, "isSigningField": true, @@ -226,329 +408,919 @@ } ], [ - "DestinationTag", + "LedgerSequence", + { + "nth": 6, + "isVLEncoded": false, + "isSerialized": true, + "isSigningField": true, + "type": "UInt32" + } + ], + [ + "CloseTime", + { + "nth": 7, + "isVLEncoded": false, + "isSerialized": true, + "isSigningField": true, + "type": "UInt32" + } + ], + [ + "ParentCloseTime", + { + "nth": 8, + "isVLEncoded": false, + "isSerialized": true, + "isSigningField": true, + "type": "UInt32" + } + ], + [ + "SigningTime", + { + "nth": 9, + "isVLEncoded": false, + "isSerialized": true, + "isSigningField": true, + "type": "UInt32" + } + ], + [ + "Expiration", + { + "nth": 10, + "isVLEncoded": false, + "isSerialized": true, + "isSigningField": true, + "type": "UInt32" + } + ], + [ + "TransferRate", + { + "nth": 11, + "isVLEncoded": false, + "isSerialized": true, + "isSigningField": true, + "type": "UInt32" + } + ], + [ + "WalletSize", + { + "nth": 12, + "isVLEncoded": false, + "isSerialized": true, + "isSigningField": true, + "type": "UInt32" + } + ], + [ + "OwnerCount", + { + "nth": 13, + "isVLEncoded": false, + "isSerialized": true, + "isSigningField": true, + "type": "UInt32" + } + ], + [ + "DestinationTag", + { + "nth": 14, + "isVLEncoded": false, + "isSerialized": true, + "isSigningField": true, + "type": "UInt32" + } + ], + [ + "HighQualityIn", + { + "nth": 16, + "isVLEncoded": false, + "isSerialized": true, + "isSigningField": true, + "type": "UInt32" + } + ], + [ + "HighQualityOut", + { + "nth": 17, + "isVLEncoded": false, + "isSerialized": true, + "isSigningField": true, + "type": "UInt32" + } + ], + [ + "LowQualityIn", + { + "nth": 18, + "isVLEncoded": false, + "isSerialized": true, + "isSigningField": true, + "type": "UInt32" + } + ], + [ + "LowQualityOut", + { + "nth": 19, + "isVLEncoded": false, + "isSerialized": true, + "isSigningField": true, + "type": "UInt32" + } + ], + [ + "QualityIn", + { + "nth": 20, + "isVLEncoded": false, + "isSerialized": true, + "isSigningField": true, + "type": "UInt32" + } + ], + [ + "QualityOut", + { + "nth": 21, + "isVLEncoded": false, + "isSerialized": true, + "isSigningField": true, + "type": "UInt32" + } + ], + [ + "StampEscrow", + { + "nth": 22, + "isVLEncoded": false, + "isSerialized": true, + "isSigningField": true, + "type": "UInt32" + } + ], + [ + "BondAmount", + { + "nth": 23, + "isVLEncoded": false, + "isSerialized": true, + "isSigningField": true, + "type": "UInt32" + } + ], + [ + "LoadFee", + { + "nth": 24, + "isVLEncoded": false, + "isSerialized": true, + "isSigningField": true, + "type": "UInt32" + } + ], + [ + "OfferSequence", + { + "nth": 25, + "isVLEncoded": false, + "isSerialized": true, + "isSigningField": true, + "type": "UInt32" + } + ], + [ + "FirstLedgerSequence", + { + "nth": 26, + "isVLEncoded": false, + "isSerialized": true, + "isSigningField": true, + "type": "UInt32" + } + ], + [ + "LastLedgerSequence", + { + "nth": 27, + "isVLEncoded": false, + "isSerialized": true, + "isSigningField": true, + "type": "UInt32" + } + ], + [ + "TransactionIndex", + { + "nth": 28, + "isVLEncoded": false, + "isSerialized": true, + "isSigningField": true, + "type": "UInt32" + } + ], + [ + "OperationLimit", + { + "nth": 29, + "isVLEncoded": false, + "isSerialized": true, + "isSigningField": true, + "type": "UInt32" + } + ], + [ + "ReferenceFeeUnits", + { + "nth": 30, + "isVLEncoded": false, + "isSerialized": true, + "isSigningField": true, + "type": "UInt32" + } + ], + [ + "ReserveBase", + { + "nth": 31, + "isVLEncoded": false, + "isSerialized": true, + "isSigningField": true, + "type": "UInt32" + } + ], + [ + "ReserveIncrement", + { + "nth": 32, + "isVLEncoded": false, + "isSerialized": true, + "isSigningField": true, + "type": "UInt32" + } + ], + [ + "SetFlag", + { + "nth": 33, + "isVLEncoded": false, + "isSerialized": true, + "isSigningField": true, + "type": "UInt32" + } + ], + [ + "ClearFlag", + { + "nth": 34, + "isVLEncoded": false, + "isSerialized": true, + "isSigningField": true, + "type": "UInt32" + } + ], + [ + "SignerQuorum", + { + "nth": 35, + "isVLEncoded": false, + "isSerialized": true, + "isSigningField": true, + "type": "UInt32" + } + ], + [ + "CancelAfter", + { + "nth": 36, + "isVLEncoded": false, + "isSerialized": true, + "isSigningField": true, + "type": "UInt32" + } + ], + [ + "FinishAfter", + { + "nth": 37, + "isVLEncoded": false, + "isSerialized": true, + "isSigningField": true, + "type": "UInt32" + } + ], + [ + "SignerListID", + { + "nth": 38, + "isVLEncoded": false, + "isSerialized": true, + "isSigningField": true, + "type": "UInt32" + } + ], + [ + "SettleDelay", + { + "nth": 39, + "isVLEncoded": false, + "isSerialized": true, + "isSigningField": true, + "type": "UInt32" + } + ], + [ + "TicketCount", + { + "nth": 40, + "isVLEncoded": false, + "isSerialized": true, + "isSigningField": true, + "type": "UInt32" + } + ], + [ + "TicketSequence", + { + "nth": 41, + "isVLEncoded": false, + "isSerialized": true, + "isSigningField": true, + "type": "UInt32" + } + ], + [ + "NFTokenTaxon", + { + "nth": 42, + "isVLEncoded": false, + "isSerialized": true, + "isSigningField": true, + "type": "UInt32" + } + ], + [ + "MintedNFTokens", + { + "nth": 43, + "isVLEncoded": false, + "isSerialized": true, + "isSigningField": true, + "type": "UInt32" + } + ], + [ + "BurnedNFTokens", + { + "nth": 44, + "isVLEncoded": false, + "isSerialized": true, + "isSigningField": true, + "type": "UInt32" + } + ], + [ + "HookStateCount", + { + "nth": 45, + "isVLEncoded": false, + "isSerialized": true, + "isSigningField": true, + "type": "UInt32" + } + ], + [ + "EmitGeneration", + { + "nth": 46, + "isVLEncoded": false, + "isSerialized": true, + "isSigningField": true, + "type": "UInt32" + } + ], + [ + "VoteWeight", + { + "nth": 48, + "isVLEncoded": false, + "isSerialized": true, + "isSigningField": true, + "type": "UInt32" + } + ], + [ + "FirstNFTokenSequence", + { + "nth": 50, + "isVLEncoded": false, + "isSerialized": true, + "isSigningField": true, + "type": "UInt32" + } + ], + [ + "IndexNext", + { + "nth": 1, + "isVLEncoded": false, + "isSerialized": true, + "isSigningField": true, + "type": "UInt64" + } + ], + [ + "IndexPrevious", + { + "nth": 2, + "isVLEncoded": false, + "isSerialized": true, + "isSigningField": true, + "type": "UInt64" + } + ], + [ + "BookNode", + { + "nth": 3, + "isVLEncoded": false, + "isSerialized": true, + "isSigningField": true, + "type": "UInt64" + } + ], + [ + "OwnerNode", + { + "nth": 4, + "isVLEncoded": false, + "isSerialized": true, + "isSigningField": true, + "type": "UInt64" + } + ], + [ + "BaseFee", + { + "nth": 5, + "isVLEncoded": false, + "isSerialized": true, + "isSigningField": true, + "type": "UInt64" + } + ], + [ + "ExchangeRate", + { + "nth": 6, + "isVLEncoded": false, + "isSerialized": true, + "isSigningField": true, + "type": "UInt64" + } + ], + [ + "LowNode", + { + "nth": 7, + "isVLEncoded": false, + "isSerialized": true, + "isSigningField": true, + "type": "UInt64" + } + ], + [ + "HighNode", + { + "nth": 8, + "isVLEncoded": false, + "isSerialized": true, + "isSigningField": true, + "type": "UInt64" + } + ], + [ + "DestinationNode", + { + "nth": 9, + "isVLEncoded": false, + "isSerialized": true, + "isSigningField": true, + "type": "UInt64" + } + ], + [ + "Cookie", + { + "nth": 10, + "isVLEncoded": false, + "isSerialized": true, + "isSigningField": true, + "type": "UInt64" + } + ], + [ + "ServerVersion", + { + "nth": 11, + "isVLEncoded": false, + "isSerialized": true, + "isSigningField": true, + "type": "UInt64" + } + ], + [ + "NFTokenOfferNode", + { + "nth": 12, + "isVLEncoded": false, + "isSerialized": true, + "isSigningField": true, + "type": "UInt64" + } + ], + [ + "EmitBurden", + { + "nth": 13, + "isVLEncoded": false, + "isSerialized": true, + "isSigningField": true, + "type": "UInt64" + } + ], + [ + "HookOn", + { + "nth": 16, + "isVLEncoded": false, + "isSerialized": true, + "isSigningField": true, + "type": "UInt64" + } + ], + [ + "HookInstructionCount", + { + "nth": 17, + "isVLEncoded": false, + "isSerialized": true, + "isSigningField": true, + "type": "UInt64" + } + ], + [ + "HookReturnCode", + { + "nth": 18, + "isVLEncoded": false, + "isSerialized": true, + "isSigningField": true, + "type": "UInt64" + } + ], + [ + "ReferenceCount", + { + "nth": 19, + "isVLEncoded": false, + "isSerialized": true, + "isSigningField": true, + "type": "UInt64" + } + ], + [ + "XChainClaimID", { - "nth": 14, + "nth": 20, "isVLEncoded": false, "isSerialized": true, "isSigningField": true, - "type": "UInt32" + "type": "UInt64" } ], [ - "HighQualityIn", + "XChainAccountCreateCount", { - "nth": 16, + "nth": 21, "isVLEncoded": false, "isSerialized": true, "isSigningField": true, - "type": "UInt32" + "type": "UInt64" } ], [ - "HighQualityOut", + "XChainAccountClaimCount", { - "nth": 17, + "nth": 22, "isVLEncoded": false, "isSerialized": true, "isSigningField": true, - "type": "UInt32" + "type": "UInt64" } ], [ - "LowQualityIn", + "EmailHash", { - "nth": 18, + "nth": 1, "isVLEncoded": false, "isSerialized": true, "isSigningField": true, - "type": "UInt32" + "type": "Hash128" } ], [ - "LowQualityOut", + "TakerPaysCurrency", { - "nth": 19, + "nth": 1, "isVLEncoded": false, "isSerialized": true, "isSigningField": true, - "type": "UInt32" + "type": "Hash160" } ], [ - "QualityIn", + "TakerPaysIssuer", { - "nth": 20, + "nth": 2, "isVLEncoded": false, "isSerialized": true, "isSigningField": true, - "type": "UInt32" + "type": "Hash160" } ], [ - "QualityOut", + "TakerGetsCurrency", { - "nth": 21, + "nth": 3, "isVLEncoded": false, "isSerialized": true, "isSigningField": true, - "type": "UInt32" + "type": "Hash160" } ], [ - "StampEscrow", + "TakerGetsIssuer", { - "nth": 22, + "nth": 4, "isVLEncoded": false, "isSerialized": true, "isSigningField": true, - "type": "UInt32" + "type": "Hash160" } ], [ - "BondAmount", + "LedgerHash", { - "nth": 23, + "nth": 1, "isVLEncoded": false, "isSerialized": true, "isSigningField": true, - "type": "UInt32" + "type": "Hash256" } ], [ - "LoadFee", + "ParentHash", { - "nth": 24, + "nth": 2, "isVLEncoded": false, "isSerialized": true, "isSigningField": true, - "type": "UInt32" + "type": "Hash256" } ], [ - "OfferSequence", + "TransactionHash", { - "nth": 25, + "nth": 3, "isVLEncoded": false, "isSerialized": true, "isSigningField": true, - "type": "UInt32" + "type": "Hash256" } ], [ - "FirstLedgerSequence", + "AccountHash", { - "nth": 26, + "nth": 4, "isVLEncoded": false, "isSerialized": true, "isSigningField": true, - "type": "UInt32" + "type": "Hash256" } ], [ - "LastLedgerSequence", + "PreviousTxnID", { - "nth": 27, + "nth": 5, "isVLEncoded": false, "isSerialized": true, "isSigningField": true, - "type": "UInt32" + "type": "Hash256" } ], [ - "TransactionIndex", + "LedgerIndex", { - "nth": 28, + "nth": 6, "isVLEncoded": false, "isSerialized": true, "isSigningField": true, - "type": "UInt32" + "type": "Hash256" } ], [ - "OperationLimit", + "WalletLocator", { - "nth": 29, + "nth": 7, "isVLEncoded": false, "isSerialized": true, "isSigningField": true, - "type": "UInt32" + "type": "Hash256" } ], [ - "ReferenceFeeUnits", + "RootIndex", { - "nth": 30, + "nth": 8, "isVLEncoded": false, "isSerialized": true, "isSigningField": true, - "type": "UInt32" + "type": "Hash256" } ], [ - "ReserveBase", + "AccountTxnID", { - "nth": 31, + "nth": 9, "isVLEncoded": false, "isSerialized": true, "isSigningField": true, - "type": "UInt32" + "type": "Hash256" } ], [ - "ReserveIncrement", + "NFTokenID", { - "nth": 32, + "nth": 10, "isVLEncoded": false, "isSerialized": true, "isSigningField": true, - "type": "UInt32" + "type": "Hash256" } ], [ - "SetFlag", + "EmitParentTxnID", { - "nth": 33, + "nth": 11, "isVLEncoded": false, "isSerialized": true, "isSigningField": true, - "type": "UInt32" + "type": "Hash256" } ], [ - "ClearFlag", + "EmitNonce", { - "nth": 34, + "nth": 12, "isVLEncoded": false, "isSerialized": true, "isSigningField": true, - "type": "UInt32" + "type": "Hash256" } ], [ - "SignerQuorum", + "EmitHookHash", { - "nth": 35, + "nth": 13, "isVLEncoded": false, "isSerialized": true, "isSigningField": true, - "type": "UInt32" + "type": "Hash256" } ], [ - "CancelAfter", + "AMMID", { - "nth": 36, + "nth": 14, "isVLEncoded": false, "isSerialized": true, "isSigningField": true, - "type": "UInt32" + "type": "Hash256" } ], [ - "FinishAfter", + "BookDirectory", { - "nth": 37, + "nth": 16, "isVLEncoded": false, "isSerialized": true, "isSigningField": true, - "type": "UInt32" + "type": "Hash256" } ], [ - "IndexNext", + "InvoiceID", { - "nth": 1, + "nth": 17, "isVLEncoded": false, "isSerialized": true, "isSigningField": true, - "type": "UInt64" + "type": "Hash256" } ], [ - "IndexPrevious", + "Nickname", { - "nth": 2, + "nth": 18, "isVLEncoded": false, "isSerialized": true, "isSigningField": true, - "type": "UInt64" + "type": "Hash256" } ], [ - "BookNode", + "Amendment", { - "nth": 3, + "nth": 19, "isVLEncoded": false, "isSerialized": true, "isSigningField": true, - "type": "UInt64" + "type": "Hash256" } ], [ - "OwnerNode", + "Digest", { - "nth": 4, + "nth": 21, "isVLEncoded": false, "isSerialized": true, "isSigningField": true, - "type": "UInt64" + "type": "Hash256" } ], [ - "BaseFee", + "Channel", { - "nth": 5, + "nth": 22, "isVLEncoded": false, "isSerialized": true, "isSigningField": true, - "type": "UInt64" + "type": "Hash256" } ], [ - "ExchangeRate", + "ConsensusHash", { - "nth": 6, + "nth": 23, "isVLEncoded": false, "isSerialized": true, "isSigningField": true, - "type": "UInt64" + "type": "Hash256" } ], [ - "LowNode", + "CheckID", { - "nth": 7, + "nth": 24, "isVLEncoded": false, "isSerialized": true, "isSigningField": true, - "type": "UInt64" + "type": "Hash256" } ], [ - "HighNode", + "ValidatedHash", { - "nth": 8, + "nth": 25, "isVLEncoded": false, "isSerialized": true, "isSigningField": true, - "type": "UInt64" + "type": "Hash256" } ], [ - "EmailHash", + "PreviousPageMin", { - "nth": 1, + "nth": 26, "isVLEncoded": false, "isSerialized": true, "isSigningField": true, - "type": "Hash128" + "type": "Hash256" } ], [ - "LedgerHash", + "NextPageMin", { - "nth": 1, + "nth": 27, "isVLEncoded": false, "isSerialized": true, "isSigningField": true, @@ -556,9 +1328,9 @@ } ], [ - "ParentHash", + "NFTokenBuyOffer", { - "nth": 2, + "nth": 28, "isVLEncoded": false, "isSerialized": true, "isSigningField": true, @@ -566,9 +1338,9 @@ } ], [ - "TransactionHash", + "NFTokenSellOffer", { - "nth": 3, + "nth": 29, "isVLEncoded": false, "isSerialized": true, "isSigningField": true, @@ -576,9 +1348,9 @@ } ], [ - "AccountHash", + "HookStateKey", { - "nth": 4, + "nth": 30, "isVLEncoded": false, "isSerialized": true, "isSigningField": true, @@ -586,9 +1358,9 @@ } ], [ - "PreviousTxnID", + "HookHash", { - "nth": 5, + "nth": 31, "isVLEncoded": false, "isSerialized": true, "isSigningField": true, @@ -596,9 +1368,9 @@ } ], [ - "LedgerIndex", + "HookNamespace", { - "nth": 6, + "nth": 32, "isVLEncoded": false, "isSerialized": true, "isSigningField": true, @@ -606,9 +1378,9 @@ } ], [ - "WalletLocator", + "HookSetTxnID", { - "nth": 7, + "nth": 33, "isVLEncoded": false, "isSerialized": true, "isSigningField": true, @@ -616,119 +1388,119 @@ } ], [ - "RootIndex", + "Amount", { - "nth": 8, + "nth": 1, "isVLEncoded": false, "isSerialized": true, "isSigningField": true, - "type": "Hash256" + "type": "Amount" } ], [ - "AccountTxnID", + "Balance", { - "nth": 9, + "nth": 2, "isVLEncoded": false, "isSerialized": true, "isSigningField": true, - "type": "Hash256" + "type": "Amount" } ], [ - "NFTokenID", + "LimitAmount", { - "nth": 10, + "nth": 3, "isVLEncoded": false, "isSerialized": true, "isSigningField": true, - "type": "Hash256" + "type": "Amount" } ], [ - "BookDirectory", + "TakerPays", { - "nth": 16, + "nth": 4, "isVLEncoded": false, "isSerialized": true, "isSigningField": true, - "type": "Hash256" + "type": "Amount" } ], [ - "InvoiceID", + "TakerGets", { - "nth": 17, + "nth": 5, "isVLEncoded": false, "isSerialized": true, "isSigningField": true, - "type": "Hash256" + "type": "Amount" } ], [ - "Nickname", + "LowLimit", { - "nth": 18, + "nth": 6, "isVLEncoded": false, "isSerialized": true, "isSigningField": true, - "type": "Hash256" + "type": "Amount" } ], [ - "Amendment", + "HighLimit", { - "nth": 19, + "nth": 7, "isVLEncoded": false, "isSerialized": true, "isSigningField": true, - "type": "Hash256" + "type": "Amount" } ], [ - "TicketID", + "Fee", { - "nth": 20, + "nth": 8, "isVLEncoded": false, "isSerialized": true, "isSigningField": true, - "type": "Hash256" + "type": "Amount" } ], [ - "Digest", + "SendMax", { - "nth": 21, + "nth": 9, "isVLEncoded": false, "isSerialized": true, "isSigningField": true, - "type": "Hash256" + "type": "Amount" } ], [ - "hash", + "DeliverMin", { - "nth": 257, + "nth": 10, "isVLEncoded": false, - "isSerialized": false, - "isSigningField": false, - "type": "Hash256" + "isSerialized": true, + "isSigningField": true, + "type": "Amount" } ], [ - "index", + "Amount2", { - "nth": 258, + "nth": 11, "isVLEncoded": false, - "isSerialized": false, - "isSigningField": false, - "type": "Hash256" + "isSerialized": true, + "isSigningField": true, + "type": "Amount" } ], [ - "Amount", + "BidMin", { - "nth": 1, + "nth": 12, "isVLEncoded": false, "isSerialized": true, "isSigningField": true, @@ -736,9 +1508,9 @@ } ], [ - "Balance", + "BidMax", { - "nth": 2, + "nth": 13, "isVLEncoded": false, "isSerialized": true, "isSigningField": true, @@ -746,9 +1518,9 @@ } ], [ - "LimitAmount", + "MinimumOffer", { - "nth": 3, + "nth": 16, "isVLEncoded": false, "isSerialized": true, "isSigningField": true, @@ -756,9 +1528,9 @@ } ], [ - "TakerPays", + "RippleEscrow", { - "nth": 4, + "nth": 17, "isVLEncoded": false, "isSerialized": true, "isSigningField": true, @@ -766,9 +1538,9 @@ } ], [ - "TakerGets", + "DeliveredAmount", { - "nth": 5, + "nth": 18, "isVLEncoded": false, "isSerialized": true, "isSigningField": true, @@ -776,9 +1548,9 @@ } ], [ - "LowLimit", + "NFTokenBrokerFee", { - "nth": 6, + "nth": 19, "isVLEncoded": false, "isSerialized": true, "isSigningField": true, @@ -786,9 +1558,9 @@ } ], [ - "HighLimit", + "BaseFeeDrops", { - "nth": 7, + "nth": 22, "isVLEncoded": false, "isSerialized": true, "isSigningField": true, @@ -796,9 +1568,9 @@ } ], [ - "Fee", + "ReserveBaseDrops", { - "nth": 8, + "nth": 23, "isVLEncoded": false, "isSerialized": true, "isSigningField": true, @@ -806,9 +1578,9 @@ } ], [ - "SendMax", + "ReserveIncrementDrops", { - "nth": 9, + "nth": 24, "isVLEncoded": false, "isSerialized": true, "isSigningField": true, @@ -816,9 +1588,9 @@ } ], [ - "DeliverMin", + "LPTokenOut", { - "nth": 10, + "nth": 25, "isVLEncoded": false, "isSerialized": true, "isSigningField": true, @@ -826,9 +1598,9 @@ } ], [ - "MinimumOffer", + "LPTokenIn", { - "nth": 16, + "nth": 26, "isVLEncoded": false, "isSerialized": true, "isSigningField": true, @@ -836,9 +1608,9 @@ } ], [ - "RippleEscrow", + "EPrice", { - "nth": 17, + "nth": 27, "isVLEncoded": false, "isSerialized": true, "isSigningField": true, @@ -846,9 +1618,9 @@ } ], [ - "DeliveredAmount", + "Price", { - "nth": 18, + "nth": 28, "isVLEncoded": false, "isSerialized": true, "isSigningField": true, @@ -856,9 +1628,9 @@ } ], [ - "NFTokenBrokerFee", + "SignatureReward", { - "nth": 19, + "nth": 29, "isVLEncoded": false, "isSerialized": true, "isSigningField": true, @@ -866,22 +1638,22 @@ } ], [ - "taker_gets_funded", + "MinAccountCreateAmount", { - "nth": 258, + "nth": 30, "isVLEncoded": false, - "isSerialized": false, - "isSigningField": false, + "isSerialized": true, + "isSigningField": true, "type": "Amount" } ], [ - "taker_pays_funded", + "LPTokenBalance", { - "nth": 259, + "nth": 31, "isVLEncoded": false, - "isSerialized": false, - "isSigningField": false, + "isSerialized": true, + "isSigningField": true, "type": "Amount" } ], @@ -1085,6 +1857,46 @@ "type": "Blob" } ], + [ + "HookStateData", + { + "nth": 22, + "isVLEncoded": true, + "isSerialized": true, + "isSigningField": true, + "type": "Blob" + } + ], + [ + "HookReturnString", + { + "nth": 23, + "isVLEncoded": true, + "isSerialized": true, + "isSigningField": true, + "type": "Blob" + } + ], + [ + "HookParameterName", + { + "nth": 24, + "isVLEncoded": true, + "isSerialized": true, + "isSigningField": true, + "type": "Blob" + } + ], + [ + "HookParameterValue", + { + "nth": 25, + "isVLEncoded": true, + "isSerialized": true, + "isSigningField": true, + "type": "Blob" + } + ], [ "Account", { @@ -1146,9 +1958,9 @@ } ], [ - "Target", + "RegularKey", { - "nth": 7, + "nth": 8, "isVLEncoded": true, "isSerialized": true, "isSigningField": true, @@ -1156,9 +1968,9 @@ } ], [ - "RegularKey", + "NFTokenMinter", { - "nth": 8, + "nth": 9, "isVLEncoded": true, "isSerialized": true, "isSigningField": true, @@ -1166,9 +1978,9 @@ } ], [ - "NFTokenMinter", + "EmitCallback", { - "nth": 9, + "nth": 10, "isVLEncoded": true, "isSerialized": true, "isSigningField": true, @@ -1176,623 +1988,633 @@ } ], [ - "ObjectEndMarker", + "HookAccount", { - "nth": 1, - "isVLEncoded": false, + "nth": 16, + "isVLEncoded": true, "isSerialized": true, "isSigningField": true, - "type": "STObject" + "type": "AccountID" } ], [ - "TransactionMetaData", + "OtherChainSource", { - "nth": 2, - "isVLEncoded": false, + "nth": 18, + "isVLEncoded": true, "isSerialized": true, "isSigningField": true, - "type": "STObject" + "type": "AccountID" } ], [ - "CreatedNode", + "OtherChainDestination", { - "nth": 3, - "isVLEncoded": false, + "nth": 19, + "isVLEncoded": true, "isSerialized": true, "isSigningField": true, - "type": "STObject" + "type": "AccountID" } ], [ - "DeletedNode", + "AttestationSignerAccount", { - "nth": 4, - "isVLEncoded": false, + "nth": 20, + "isVLEncoded": true, "isSerialized": true, "isSigningField": true, - "type": "STObject" + "type": "AccountID" } ], [ - "ModifiedNode", + "AttestationRewardAccount", { - "nth": 5, - "isVLEncoded": false, + "nth": 21, + "isVLEncoded": true, "isSerialized": true, "isSigningField": true, - "type": "STObject" + "type": "AccountID" } ], [ - "PreviousFields", + "LockingChainDoor", { - "nth": 6, - "isVLEncoded": false, + "nth": 22, + "isVLEncoded": true, "isSerialized": true, "isSigningField": true, - "type": "STObject" + "type": "AccountID" } ], [ - "FinalFields", + "IssuingChainDoor", { - "nth": 7, - "isVLEncoded": false, + "nth": 23, + "isVLEncoded": true, "isSerialized": true, "isSigningField": true, - "type": "STObject" + "type": "AccountID" } ], [ - "NewFields", + "Indexes", { - "nth": 8, - "isVLEncoded": false, + "nth": 1, + "isVLEncoded": true, "isSerialized": true, "isSigningField": true, - "type": "STObject" + "type": "Vector256" } ], [ - "TemplateEntry", + "Hashes", { - "nth": 9, - "isVLEncoded": false, + "nth": 2, + "isVLEncoded": true, "isSerialized": true, "isSigningField": true, - "type": "STObject" + "type": "Vector256" } ], [ - "Memo", + "Amendments", { - "nth": 10, - "isVLEncoded": false, + "nth": 3, + "isVLEncoded": true, "isSerialized": true, "isSigningField": true, - "type": "STObject" + "type": "Vector256" } ], [ - "SignerEntry", + "NFTokenOffers", { - "nth": 11, + "nth": 4, + "isVLEncoded": true, + "isSerialized": true, + "isSigningField": true, + "type": "Vector256" + } + ], + [ + "Paths", + { + "nth": 1, "isVLEncoded": false, "isSerialized": true, "isSigningField": true, - "type": "STObject" + "type": "PathSet" } ], [ - "NFToken", + "LockingChainIssue", { - "nth": 12, + "nth": 1, "isVLEncoded": false, "isSerialized": true, "isSigningField": true, - "type": "STObject" + "type": "Issue" } ], [ - "Signer", + "IssuingChainIssue", { - "nth": 16, + "nth": 2, "isVLEncoded": false, "isSerialized": true, "isSigningField": true, - "type": "STObject" + "type": "Issue" } ], [ - "Majority", + "Asset", { - "nth": 18, + "nth": 3, "isVLEncoded": false, "isSerialized": true, "isSigningField": true, - "type": "STObject" + "type": "Issue" } ], [ - "DisabledValidator", + "Asset2", { - "nth": 19, + "nth": 4, "isVLEncoded": false, "isSerialized": true, "isSigningField": true, - "type": "STObject" + "type": "Issue" } ], [ - "ArrayEndMarker", + "XChainBridge", { "nth": 1, "isVLEncoded": false, "isSerialized": true, "isSigningField": true, - "type": "STArray" + "type": "XChainBridge" } ], [ - "Signers", + "TransactionMetaData", + { + "nth": 2, + "isVLEncoded": false, + "isSerialized": true, + "isSigningField": true, + "type": "STObject" + } + ], + [ + "CreatedNode", { "nth": 3, "isVLEncoded": false, "isSerialized": true, - "isSigningField": false, - "type": "STArray" + "isSigningField": true, + "type": "STObject" } ], [ - "SignerEntries", + "DeletedNode", { "nth": 4, "isVLEncoded": false, "isSerialized": true, "isSigningField": true, - "type": "STArray" + "type": "STObject" } ], [ - "Template", + "ModifiedNode", { "nth": 5, "isVLEncoded": false, "isSerialized": true, "isSigningField": true, - "type": "STArray" + "type": "STObject" } ], [ - "Necessary", + "PreviousFields", { "nth": 6, "isVLEncoded": false, "isSerialized": true, "isSigningField": true, - "type": "STArray" + "type": "STObject" } ], [ - "Sufficient", + "FinalFields", { "nth": 7, "isVLEncoded": false, "isSerialized": true, "isSigningField": true, - "type": "STArray" + "type": "STObject" } ], [ - "AffectedNodes", + "NewFields", { "nth": 8, "isVLEncoded": false, "isSerialized": true, "isSigningField": true, - "type": "STArray" + "type": "STObject" } ], [ - "Memos", + "TemplateEntry", { "nth": 9, "isVLEncoded": false, "isSerialized": true, "isSigningField": true, - "type": "STArray" + "type": "STObject" } ], [ - "NFTokens", + "Memo", { "nth": 10, "isVLEncoded": false, "isSerialized": true, "isSigningField": true, - "type": "STArray" + "type": "STObject" } ], [ - "Majorities", + "SignerEntry", { - "nth": 16, + "nth": 11, "isVLEncoded": false, "isSerialized": true, "isSigningField": true, - "type": "STArray" + "type": "STObject" } ], [ - "DisabledValidators", + "NFToken", { - "nth": 17, + "nth": 12, "isVLEncoded": false, "isSerialized": true, "isSigningField": true, - "type": "STArray" + "type": "STObject" } ], [ - "CloseResolution", + "EmitDetails", { - "nth": 1, + "nth": 13, "isVLEncoded": false, "isSerialized": true, "isSigningField": true, - "type": "UInt8" + "type": "STObject" } ], [ - "Method", + "Hook", { - "nth": 2, + "nth": 14, "isVLEncoded": false, "isSerialized": true, "isSigningField": true, - "type": "UInt8" + "type": "STObject" } ], [ - "TransactionResult", + "Signer", { - "nth": 3, + "nth": 16, "isVLEncoded": false, "isSerialized": true, "isSigningField": true, - "type": "UInt8" + "type": "STObject" } ], [ - "TakerPaysCurrency", + "Majority", { - "nth": 1, + "nth": 18, "isVLEncoded": false, "isSerialized": true, "isSigningField": true, - "type": "Hash160" + "type": "STObject" } ], [ - "TakerPaysIssuer", + "DisabledValidator", { - "nth": 2, + "nth": 19, "isVLEncoded": false, "isSerialized": true, "isSigningField": true, - "type": "Hash160" + "type": "STObject" } ], [ - "TakerGetsCurrency", + "EmittedTxn", { - "nth": 3, + "nth": 20, "isVLEncoded": false, "isSerialized": true, "isSigningField": true, - "type": "Hash160" + "type": "STObject" } ], [ - "TakerGetsIssuer", + "HookExecution", { - "nth": 4, + "nth": 21, "isVLEncoded": false, "isSerialized": true, "isSigningField": true, - "type": "Hash160" + "type": "STObject" } ], [ - "Paths", + "HookDefinition", { - "nth": 1, + "nth": 22, "isVLEncoded": false, "isSerialized": true, "isSigningField": true, - "type": "PathSet" + "type": "STObject" } ], [ - "Indexes", + "HookParameter", { - "nth": 1, - "isVLEncoded": true, + "nth": 23, + "isVLEncoded": false, "isSerialized": true, "isSigningField": true, - "type": "Vector256" + "type": "STObject" } ], [ - "Hashes", + "HookGrant", { - "nth": 2, - "isVLEncoded": true, + "nth": 24, + "isVLEncoded": false, "isSerialized": true, "isSigningField": true, - "type": "Vector256" + "type": "STObject" } ], [ - "Amendments", + "VoteEntry", { - "nth": 3, - "isVLEncoded": true, + "nth": 25, + "isVLEncoded": false, "isSerialized": true, "isSigningField": true, - "type": "Vector256" + "type": "STObject" } ], [ - "NFTokenOffers", + "AuctionSlot", { - "nth": 4, - "isVLEncoded": true, + "nth": 26, + "isVLEncoded": false, "isSerialized": true, "isSigningField": true, - "type": "Vector256" - } - ], - [ - "Transaction", - { - "nth": 1, - "isVLEncoded": false, - "isSerialized": false, - "isSigningField": false, - "type": "Transaction" + "type": "STObject" } ], [ - "LedgerEntry", + "AuthAccount", { - "nth": 1, + "nth": 27, "isVLEncoded": false, - "isSerialized": false, - "isSigningField": false, - "type": "LedgerEntry" + "isSerialized": true, + "isSigningField": true, + "type": "STObject" } ], [ - "Validation", + "XChainClaimProofSig", { - "nth": 1, + "nth": 28, "isVLEncoded": false, - "isSerialized": false, - "isSigningField": false, - "type": "Validation" + "isSerialized": true, + "isSigningField": true, + "type": "STObject" } ], [ - "SignerListID", + "XChainCreateAccountProofSig", { - "nth": 38, + "nth": 29, "isVLEncoded": false, "isSerialized": true, "isSigningField": true, - "type": "UInt32" + "type": "STObject" } ], [ - "SettleDelay", + "XChainClaimAttestationCollectionElement", { - "nth": 39, + "nth": 30, "isVLEncoded": false, "isSerialized": true, "isSigningField": true, - "type": "UInt32" + "type": "STObject" } ], [ - "TicketCount", + "XChainCreateAccountAttestationCollectionElement", { - "nth": 40, + "nth": 31, "isVLEncoded": false, "isSerialized": true, "isSigningField": true, - "type": "UInt32" + "type": "STObject" } ], [ - "TicketSequence", + "Signers", { - "nth": 41, + "nth": 3, "isVLEncoded": false, "isSerialized": true, - "isSigningField": true, - "type": "UInt32" + "isSigningField": false, + "type": "STArray" } ], [ - "NFTokenTaxon", + "SignerEntries", { - "nth": 42, + "nth": 4, "isVLEncoded": false, "isSerialized": true, "isSigningField": true, - "type": "UInt32" + "type": "STArray" } ], [ - "MintedNFTokens", + "Template", { - "nth": 43, + "nth": 5, "isVLEncoded": false, "isSerialized": true, "isSigningField": true, - "type": "UInt32" + "type": "STArray" } ], [ - "BurnedNFTokens", + "Necessary", { - "nth": 44, + "nth": 6, "isVLEncoded": false, "isSerialized": true, "isSigningField": true, - "type": "UInt32" + "type": "STArray" } ], [ - "Channel", + "Sufficient", { - "nth": 22, + "nth": 7, "isVLEncoded": false, "isSerialized": true, "isSigningField": true, - "type": "Hash256" + "type": "STArray" } ], [ - "ConsensusHash", + "AffectedNodes", { - "nth": 23, + "nth": 8, "isVLEncoded": false, "isSerialized": true, "isSigningField": true, - "type": "Hash256" + "type": "STArray" } ], [ - "CheckID", + "Memos", { - "nth": 24, + "nth": 9, "isVLEncoded": false, "isSerialized": true, "isSigningField": true, - "type": "Hash256" + "type": "STArray" } ], [ - "ValidatedHash", + "NFTokens", { - "nth": 25, + "nth": 10, "isVLEncoded": false, "isSerialized": true, "isSigningField": true, - "type": "Hash256" + "type": "STArray" } ], [ - "PreviousPageMin", + "Hooks", { - "nth": 26, + "nth": 11, "isVLEncoded": false, "isSerialized": true, "isSigningField": true, - "type": "Hash256" + "type": "STArray" } ], [ - "NextPageMin", + "VoteSlots", { - "nth": 27, + "nth": 12, "isVLEncoded": false, "isSerialized": true, "isSigningField": true, - "type": "Hash256" + "type": "STArray" } ], [ - "NFTokenBuyOffer", + "Majorities", { - "nth": 28, + "nth": 16, "isVLEncoded": false, "isSerialized": true, "isSigningField": true, - "type": "Hash256" + "type": "STArray" } ], [ - "NFTokenSellOffer", + "DisabledValidators", { - "nth": 29, + "nth": 17, "isVLEncoded": false, "isSerialized": true, "isSigningField": true, - "type": "Hash256" + "type": "STArray" } ], [ - "TickSize", + "HookExecutions", { - "nth": 16, + "nth": 18, "isVLEncoded": false, "isSerialized": true, "isSigningField": true, - "type": "UInt8" + "type": "STArray" } ], [ - "UNLModifyDisabling", + "HookParameters", { - "nth": 17, + "nth": 19, "isVLEncoded": false, "isSerialized": true, "isSigningField": true, - "type": "UInt8" + "type": "STArray" } ], [ - "DestinationNode", + "HookGrants", { - "nth": 9, + "nth": 20, "isVLEncoded": false, "isSerialized": true, "isSigningField": true, - "type": "UInt64" + "type": "STArray" } ], [ - "Cookie", + "XChainClaimAttestations", { - "nth": 10, + "nth": 21, "isVLEncoded": false, "isSerialized": true, "isSigningField": true, - "type": "UInt64" + "type": "STArray" } ], [ - "ServerVersion", + "XChainCreateAccountAttestations", { - "nth": 11, + "nth": 22, "isVLEncoded": false, "isSerialized": true, "isSigningField": true, - "type": "UInt64" + "type": "STArray" } ], [ - "NFTokenOfferNode", + "AuthAccounts", { - "nth": 12, + "nth": 25, "isVLEncoded": false, "isSerialized": true, "isSigningField": true, - "type": "UInt64" + "type": "STArray" } ] ], @@ -1810,6 +2632,9 @@ "telCAN_NOT_QUEUE_BLOCKED": -389, "telCAN_NOT_QUEUE_FEE": -388, "telCAN_NOT_QUEUE_FULL": -387, + "telWRONG_NETWORK": -386, + "telREQUIRES_NETWORK_ID": -385, + "telNETWORK_ID_MAKES_TX_NON_CANONICAL": -384, "temMALFORMED": -299, "temBAD_AMOUNT": -298, @@ -1844,10 +2669,18 @@ "temBAD_TICK_SIZE": -269, "temINVALID_ACCOUNT_ID": -268, "temCANNOT_PREAUTH_SELF": -267, - "temUNCERTAIN": -266, - "temUNKNOWN": -265, - "temSEQ_AND_TICKET": -264, - "temBAD_NFTOKEN_TRANSFER_FEE": -263, + "temINVALID_COUNT": -266, + "temUNCERTAIN": -265, + "temUNKNOWN": -264, + "temSEQ_AND_TICKET": -263, + "temBAD_NFTOKEN_TRANSFER_FEE": -262, + "temBAD_AMM_TOKENS": -261, + "temXCHAIN_EQUAL_DOOR_ACCOUNTS": -260, + "temXCHAIN_BAD_PROOF": -259, + "temXCHAIN_BRIDGE_BAD_ISSUES": -258, + "temXCHAIN_BRIDGE_NONDOOR_OWNER": -257, + "temXCHAIN_BRIDGE_BAD_MIN_ACCOUNT_CREATE_AMOUNT": -256, + "temXCHAIN_BRIDGE_BAD_REWARD_AMOUNT": -255, "tefFAILURE": -199, "tefALREADY": -198, @@ -1883,6 +2716,8 @@ "terNO_RIPPLE": -90, "terQUEUED": -89, "terPRE_TICKET": -88, + "terNO_AMM": -87, + "terSUBMITTED": -86, "tesSUCCESS": 0, @@ -1924,7 +2759,7 @@ "tecKILLED": 150, "tecHAS_OBLIGATIONS": 151, "tecTOO_SOON": 152, - + "tecHOOK_ERROR": 153, "tecMAX_SEQUENCE_REACHED": 154, "tecNO_SUITABLE_NFTOKEN_PAGE": 155, "tecNFTOKEN_BUY_SELL_MISMATCH": 156, @@ -1933,12 +2768,34 @@ "tecINSUFFICIENT_FUNDS": 159, "tecOBJECT_NOT_FOUND": 160, "tecINSUFFICIENT_PAYMENT": 161, - "tecINCORRECT_ASSET": 162, - "tecTOO_MANY": 163 + "tecUNFUNDED_AMM": 162, + "tecAMM_BALANCE": 163, + "tecAMM_FAILED": 164, + "tecAMM_INVALID_TOKENS": 165, + "tecAMM_EMPTY": 166, + "tecAMM_NOT_EMPTY": 167, + "tecAMM_ACCOUNT": 168, + "tecINCOMPLETE": 169, + "tecXCHAIN_BAD_TRANSFER_ISSUE": 170, + "tecXCHAIN_NO_CLAIM_ID": 171, + "tecXCHAIN_BAD_CLAIM_ID": 172, + "tecXCHAIN_CLAIM_NO_QUORUM": 173, + "tecXCHAIN_PROOF_UNKNOWN_KEY": 174, + "tecXCHAIN_CREATE_ACCOUNT_NONXRP_ISSUE": 175, + "tecXCHAIN_WRONG_CHAIN": 176, + "tecXCHAIN_REWARD_MISMATCH": 177, + "tecXCHAIN_NO_SIGNERS_LIST": 178, + "tecXCHAIN_SENDING_ACCOUNT_MISMATCH": 179, + "tecXCHAIN_INSUFF_CREATE_AMOUNT": 180, + "tecXCHAIN_ACCOUNT_CREATE_PAST": 181, + "tecXCHAIN_ACCOUNT_CREATE_TOO_MANY": 182, + "tecXCHAIN_PAYMENT_FAILED": 183, + "tecXCHAIN_SELF_COMMIT": 184, + "tecXCHAIN_BAD_PUBLIC_KEY_ACCOUNT_PAIR": 185, + "tecXCHAIN_CREATE_ACCOUNT_DISABLED": 186 }, "TRANSACTION_TYPES": { "Invalid": -1, - "Payment": 0, "EscrowCreate": 1, "EscrowFinish": 2, @@ -1961,13 +2818,29 @@ "DepositPreauth": 19, "TrustSet": 20, "AccountDelete": 21, + "SetHook": 22, "NFTokenMint": 25, "NFTokenBurn": 26, "NFTokenCreateOffer": 27, "NFTokenCancelOffer": 28, "NFTokenAcceptOffer": 29, + "Clawback": 30, + "AMMCreate": 35, + "AMMDeposit": 36, + "AMMWithdraw": 37, + "AMMVote": 38, + "AMMBid": 39, + "AMMDelete": 40, + "XChainCreateClaimID": 41, + "XChainCommit": 42, + "XChainClaim": 43, + "XChainAccountCreateCommit": 44, + "XChainAddClaimAttestation": 45, + "XChainAddAccountCreateAttestation": 46, + "XChainModifyBridge": 47, + "XChainCreateBridge": 48, "EnableAmendment": 100, "SetFee": 101, "UNLModify": 102 } -} \ No newline at end of file +} diff --git a/binary-codec/main.go b/binary-codec/main.go index e4a4997b..515e22df 100644 --- a/binary-codec/main.go +++ b/binary-codec/main.go @@ -4,12 +4,13 @@ import ( "bytes" "encoding/hex" "errors" + "reflect" "strings" - "github.com/xyield/xrpl-go/binary-codec/definitions" + "github.com/CreatureDev/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/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") @@ -20,27 +21,12 @@ const ( txSigPrefix = "53545800" ) -// Encode converts a JSON transaction object to a hex string in the canonical binary format. -// The binary format is defined in XRPL's core codebase. -func Encode(json map[string]any) (string, error) { - - st := &types.STObject{} - - // Iterate over the keys in the provided JSON - for k := range json { - - // Get the FieldIdNameMap from the definitions package - fh := definitions.Get().Fields[k] - - // If the field is not found in the FieldIdNameMap, delete it from the JSON - - if fh == nil { - delete(json, k) - continue - } +func encode(tx transactions.Tx, onlySigning bool, mutations map[string]types.FieldMutation) (string, error) { + st := &types.STObject{ + OnlySigning: onlySigning, + Mutations: mutations, } - - b, err := st.FromJson(json) + b, err := st.FromJson(tx) if err != nil { return "", err } @@ -48,23 +34,34 @@ func Encode(json map[string]any) (string, error) { return strings.ToUpper(hex.EncodeToString(b)), nil } +// Encode converts a JSON transaction object to a hex string in the canonical binary format. +// The binary format is defined in XRPL's core codebase. +func Encode(tx transactions.Tx) (string, error) { + return encode(tx, false, nil) +} + // EncodeForMultiSign: encodes a transaction into binary format in preparation for providing one // signature towards a multi-signed transaction. // (Only encodes fields that are intended to be signed.) -func EncodeForMultisigning(json map[string]any, xrpAccountID string) (string, error) { +func EncodeForMultisigning(tx transactions.Tx, xrpAccountID string) (string, error) { st := &types.AccountID{} - // SigningPubKey is required for multi-signing but should be set to empty string. - - json["SigningPubKey"] = "" - suffix, err := st.FromJson(xrpAccountID) if err != nil { return "", err } - encoded, err := Encode(removeNonSigningFields(json)) + // SigningPubKey is required for multi-signing but should be set to empty string. + err = setFieldFromTx(tx, "SigningPubKey", "placeholder", func(v any) bool { + return v.(string) == "" + }) + if err != nil { + return "", err + } + encoded, err := encode(tx, true, map[string]types.FieldMutation{ + "SigningPubKey": types.Zero(), + }) if err != nil { return "", err @@ -74,9 +71,9 @@ func EncodeForMultisigning(json map[string]any, xrpAccountID string) (string, er } // Encodes a transaction into binary format in preparation for signing. -func EncodeForSigning(json map[string]any) (string, error) { +func EncodeForSigning(tx transactions.Tx) (string, error) { - encoded, err := Encode(removeNonSigningFields(json)) + encoded, err := encode(tx, true, nil) if err != nil { return "", err @@ -86,20 +83,20 @@ func EncodeForSigning(json map[string]any) (string, error) { } // EncodeForPaymentChannelClaim: encodes a payment channel claim into binary format in preparation for signing. -func EncodeForSigningClaim(json map[string]any) (string, error) { +func EncodeForSigningClaim(tx transactions.PaymentChannelClaim) (string, error) { - if json["Channel"] == nil || json["Amount"] == nil { + if tx.Channel == "" || tx.Amount == 0 { return "", ErrSigningClaimFieldNotFound } - channel, err := types.NewHash256().FromJson(json["Channel"]) + channel, err := types.NewHash256().FromJson(tx.Channel) if err != nil { return "", err } t := &types.Amount{} - amount, err := t.FromJson(json["Amount"]) + amount, err := t.FromJson(tx.Amount) if err != nil { return "", err @@ -113,20 +110,6 @@ func EncodeForSigningClaim(json map[string]any) (string, error) { return strings.ToUpper(paymentChannelClaimPrefix + hex.EncodeToString(channel) + hex.EncodeToString(amount)), nil } -// removeNonSigningFields removes the fields from a JSON transaction object that should not be signed. -func removeNonSigningFields(json map[string]any) map[string]any { - - for k := range json { - fi, _ := definitions.Get().GetFieldInstanceByFieldName(k) - - if fi != nil && !fi.IsSigningField { - delete(json, k) - } - } - - return json -} - // Decode decodes a hex string in the canonical binary format into a JSON transaction object. func Decode(hexEncoded string) (map[string]any, error) { b, err := hex.DecodeString(hexEncoded) @@ -142,3 +125,21 @@ func Decode(hexEncoded string) (map[string]any, error) { return m.(map[string]any), nil } + +// Overwrites a field in a transaction with a new value if condition is met. +func setFieldFromTx(tx transactions.Tx, fieldName string, value any, condition func(any) bool) error { + rv := reflect.ValueOf(tx) + if rv.Kind() == reflect.Ptr { + rv = rv.Elem() + } else { + return errors.New("invalid transaction") + } + if !rv.FieldByName(fieldName).IsValid() { + return errors.New("invalid field name") + } + if condition != nil && condition(rv.FieldByName(fieldName).Interface()) { + rv.FieldByName(fieldName).Set(reflect.ValueOf(value)) + return nil + } + return nil +} diff --git a/binary-codec/main_test.go b/binary-codec/main_test.go index 75aa1d22..f30da168 100644 --- a/binary-codec/main_test.go +++ b/binary-codec/main_test.go @@ -3,325 +3,120 @@ package binarycodec import ( "testing" + "github.com/CreatureDev/xrpl-go/model/transactions" + "github.com/CreatureDev/xrpl-go/model/transactions/types" "github.com/stretchr/testify/require" - "github.com/xyield/xrpl-go/binary-codec/types" ) func TestEncode(t *testing.T) { tt := []struct { description string - input map[string]any + input transactions.Tx output string expectedErr error }{ - { - description: "large test tx", - input: map[string]any{ - "Account": "rMBzp8CgpE441cp5PVyA9rpVV7oT8hP3ys", - "Expiration": 595640108, - "Fee": "10", - "Flags": 524288, - "OfferSequence": 1752791, - "Sequence": 1752792, - "SigningPubKey": "03EE83BB432547885C219634A1BC407A9DB0474145D69737D09CCDC63E1DEE7FE3", - "TakerGets": "15000000000", - "TakerPays": map[string]any{ - "currency": "USD", - "issuer": "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B", - "value": "7072.8", - }, - "TransactionType": "OfferCreate", - "TxnSignature": "30440220143759437C04F7B61F012563AFE90D8DAFC46E86035E1D965A9CED282C97D4CE02204CFD241E86F17E011298FC1A39B63386C74306A5DE047E213B0F29EFA4571C2C", - "Paths": []any{ - []any{ - map[string]any{ - "account": "rPDXxSZcuVL3ZWoyU82bcde3zwvmShkRyF", - "type": 1, - "type_hex": "0000000000000001", - }, - map[string]any{ - "currency": "XRP", - "type": 16, - "type_hex": "0000000000000010", - }, - }, - []any{ - map[string]any{ - "account": "rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn", - "type": 1, - "type_hex": "0000000000000001", - }, - map[string]any{ - "account": "rMwjYedjc7qqtKYVLiAccJSmCwih4LnE2q", - "type": 1, - "type_hex": "0000000000000001", - }, - map[string]any{ - "currency": "XRP", - "type": 16, - "type_hex": "0000000000000010", - }, - }, - []any{ - map[string]any{ - "account": "rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn", - "type": 1, - "type_hex": "0000000000000001", - }, - map[string]any{ - "account": "rMwjYedjc7qqtKYVLiAccJSmCwih4LnE2q", - "type": 1, - "type_hex": "0000000000000001", - }, - map[string]any{ - "currency": "XRP", - "type": 16, - "type_hex": "0000000000000010", - }, - }, - }, - "Memos": []any{ - map[string]any{ - "Memo": map[string]any{ - "MemoData": "04C4D46544659A2D58525043686174", - }, - }, - }, - "LedgerEntryType": "RippleState", - "TransferFee": 30874, - "CloseResolution": 25, - "OwnerNode": "0000018446744073", - "Amendments": []string{ - "73734B611DDA23D3F5F62E20A173B78AB8406AC5015094DA53F53D39B9EDB06C", - "73734B611DDA23D3F5F62E20A173B78AB8406AC5015094DA53F53D39B9EDB06C", - }, - "EmailHash": "73734B611DDA23D3F5F62E20A173B78A", - "TakerPaysCurrency": "73734B611DDA23D3F5F62E20A173B78AB8406AC5", - "Digest": "73734B611DDA23D3F5F62E20A173B78AB8406AC5015094DA53F53D39B9EDB06C", - }, - output: "11007212000714789A220008000024001ABED82A2380BF2C2019001ABED73400000184467440734173734B611DDA23D3F5F62E20A173B78A501573734B611DDA23D3F5F62E20A173B78AB8406AC5015094DA53F53D39B9EDB06C64D55920AC9391400000000000000000000000000055534400000000000A20B3C85F482532A9578DBB3950B85CA06594D165400000037E11D60068400000000000000A732103EE83BB432547885C219634A1BC407A9DB0474145D69737D09CCDC63E1DEE7FE3744630440220143759437C04F7B61F012563AFE90D8DAFC46E86035E1D965A9CED282C97D4CE02204CFD241E86F17E011298FC1A39B63386C74306A5DE047E213B0F29EFA4571C2C8114DD76483FACDEE26E60D8A586BB58D09F27045C46F9EA7D0F04C4D46544659A2D58525043686174E1F1011019011173734B611DDA23D3F5F62E20A173B78AB8406AC5011201F3B1997562FD742B54D4EBDEA1D6AEA3D4906B8F100000000000000000000000000000000000000000FF014B4E9C06F24296074F7BC48F92A97916C6DC5EA901DD39C650A96EDA48334E70CC4A85B8B2E8502CD3100000000000000000000000000000000000000000FF014B4E9C06F24296074F7BC48F92A97916C6DC5EA901DD39C650A96EDA48334E70CC4A85B8B2E8502CD31000000000000000000000000000000000000000000003134073734B611DDA23D3F5F62E20A173B78AB8406AC5015094DA53F53D39B9EDB06C73734B611DDA23D3F5F62E20A173B78AB8406AC5015094DA53F53D39B9EDB06C", - expectedErr: nil, - }, - { - description: "zero issued currency amount", - input: map[string]any{ - "LowLimit": map[string]any{ - "currency": "LUC", - "issuer": "rsygE5ynt2iSasscfCCeqaGBGiFKMCAUu7", - "value": "0", - }, - }, - output: "6680000000000000000000000000000000000000004C5543000000000020A85019EA62B48F79EB67273B797EB916438FA4", - expectedErr: nil, - }, { description: "successfully serialized signed transaction 1", - input: map[string]any{ - "Account": "rMBzp8CgpE441cp5PVyA9rpVV7oT8hP3ys", - "Expiration": 595640108, - "Fee": "10", - "Flags": 524288, - "OfferSequence": 1752791, - "Sequence": 1752792, - "SigningPubKey": "03EE83BB432547885C219634A1BC407A9DB0474145D69737D09CCDC63E1DEE7FE3", - "TakerGets": "15000000000", - "TakerPays": map[string]any{ - "currency": "USD", - "issuer": "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B", - "value": "7072.8", + input: &transactions.OfferCreate{ + BaseTx: transactions.BaseTx{ + Account: "rMBzp8CgpE441cp5PVyA9rpVV7oT8hP3ys", + TransactionType: transactions.OfferCreateTx, + Fee: 10, + Flags: types.SetFlag(524288), + Sequence: 1752792, + SigningPubKey: "03EE83BB432547885C219634A1BC407A9DB0474145D69737D09CCDC63E1DEE7FE3", + TxnSignature: "30440220143759437C04F7B61F012563AFE90D8DAFC46E86035E1D965A9CED282C97D4CE02204CFD241E86F17E011298FC1A39B63386C74306A5DE047E213B0F29EFA4571C2C", + }, + Expiration: 595640108, + OfferSequence: 1752791, + TakerGets: types.XRPCurrencyAmount(15000000000), + TakerPays: types.IssuedCurrencyAmount{ + Currency: "USD", + Issuer: "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B", + Value: "7072.8", }, - "TransactionType": "OfferCreate", - "TxnSignature": "30440220143759437C04F7B61F012563AFE90D8DAFC46E86035E1D965A9CED282C97D4CE02204CFD241E86F17E011298FC1A39B63386C74306A5DE047E213B0F29EFA4571C2C", - "hash": "73734B611DDA23D3F5F62E20A173B78AB8406AC5015094DA53F53D39B9EDB06C", }, output: "120007220008000024001ABED82A2380BF2C2019001ABED764D55920AC9391400000000000000000000000000055534400000000000A20B3C85F482532A9578DBB3950B85CA06594D165400000037E11D60068400000000000000A732103EE83BB432547885C219634A1BC407A9DB0474145D69737D09CCDC63E1DEE7FE3744630440220143759437C04F7B61F012563AFE90D8DAFC46E86035E1D965A9CED282C97D4CE02204CFD241E86F17E011298FC1A39B63386C74306A5DE047E213B0F29EFA4571C2C8114DD76483FACDEE26E60D8A586BB58D09F27045C46", expectedErr: nil, }, { description: "successfully serialized signed transaction 2", - input: map[string]any{ - "TransactionType": "EscrowFinish", - "Flags": 2147483648, - "Sequence": 1, - "OfferSequence": 11, - "Fee": "10101", - "SigningPubKey": "0268D79CD579D077750740FA18A2370B7C2018B2714ECE70BA65C38D223E79BC9C", - "TxnSignature": "3045022100F06FB54049D6D50142E5CF2E2AC21946AF305A13E2A2D4BA881B36484DD01A540220311557EC8BEF536D729605A4CB4D4DC51B1E37C06C93434DD5B7651E1E2E28BF", - "Account": "r3Y6vCE8XqfZmYBRngy22uFYkmz3y9eCRA", - "Owner": "r9NpyVfLfUG8hatuCCHKzosyDtKnBdsEN3", - "Memos": []any{ - map[string]any{ - "Memo": map[string]any{ - "MemoData": "04C4D46544659A2D58525043686174", + input: &transactions.EscrowFinish{ + BaseTx: transactions.BaseTx{ + Account: "r3Y6vCE8XqfZmYBRngy22uFYkmz3y9eCRA", + TransactionType: transactions.EscrowFinishTx, + Fee: 10101, + Flags: types.SetFlag(2147483648), + Sequence: 1, + SigningPubKey: "0268D79CD579D077750740FA18A2370B7C2018B2714ECE70BA65C38D223E79BC9C", + TxnSignature: "3045022100F06FB54049D6D50142E5CF2E2AC21946AF305A13E2A2D4BA881B36484DD01A540220311557EC8BEF536D729605A4CB4D4DC51B1E37C06C93434DD5B7651E1E2E28BF", + Memos: []transactions.MemoWrapper{ + { + Memo: transactions.Memo{ + MemoData: "04C4D46544659A2D58525043686174", + }, }, }, }, + OfferSequence: 11, + Owner: "r9NpyVfLfUG8hatuCCHKzosyDtKnBdsEN3", }, output: "1200022280000000240000000120190000000B68400000000000277573210268D79CD579D077750740FA18A2370B7C2018B2714ECE70BA65C38D223E79BC9C74473045022100F06FB54049D6D50142E5CF2E2AC21946AF305A13E2A2D4BA881B36484DD01A540220311557EC8BEF536D729605A4CB4D4DC51B1E37C06C93434DD5B7651E1E2E28BF811452C7F01AD13B3CA9C1D133FA8F3482D2EF08FA7D82145A380FBD236B6A1CD14B939AD21101E5B6B6FFA2F9EA7D0F04C4D46544659A2D58525043686174E1F1", expectedErr: nil, }, { description: "successfully serialized signed transaction 3", - input: map[string]any{ - "Account": "rweYz56rfmQ98cAdRaeTxQS9wVMGnrdsFp", - "Amount": "10000000", - "Destination": "rweYz56rfmQ98cAdRaeTxQS9wVMGnrdsFp", - "Fee": "12", - "Flags": 0, - "LastLedgerSequence": 9902014, - "Memos": []any{ - map[string]any{ - "Memo": map[string]any{ - "MemoData": "7274312E312E31", - "MemoType": "636C69656E74", + input: &transactions.Payment{ + BaseTx: transactions.BaseTx{ + Account: "rweYz56rfmQ98cAdRaeTxQS9wVMGnrdsFp", + TransactionType: transactions.PaymentTx, + Fee: 12, + Flags: types.SetFlag(0), + Sequence: 842, + Memos: []transactions.MemoWrapper{ + { + Memo: transactions.Memo{ + MemoData: "7274312E312E31", + MemoType: "636C69656E74", + }, }, }, + LastLedgerSequence: 9902014, + SigningPubKey: "0379F17CFA0FFD7518181594BE69FE9A10471D6DE1F4055C6D2746AFD6CF89889E", + TxnSignature: "3045022100D55ED1953F860ADC1BC5CD993ABB927F48156ACA31C64737865F4F4FF6D015A80220630704D2BD09C8E99F26090C25F11B28F5D96A1350454402C2CED92B39FFDBAF", + }, + Amount: types.XRPCurrencyAmount(10000000), + Destination: "rweYz56rfmQ98cAdRaeTxQS9wVMGnrdsFp", + SendMax: types.IssuedCurrencyAmount{ + Currency: "USD", + Issuer: "rweYz56rfmQ98cAdRaeTxQS9wVMGnrdsFp", + Value: "0.6275558355", }, - "Paths": []any{ - []any{ - map[string]any{ - "account": "rPDXxSZcuVL3ZWoyU82bcde3zwvmShkRyF", - "type": 1, - "type_hex": "0000000000000001", + Paths: [][]transactions.PathStep{ + { + { + Account: "rPDXxSZcuVL3ZWoyU82bcde3zwvmShkRyF", }, - map[string]any{ - "currency": "XRP", - "type": 16, - "type_hex": "0000000000000010", + { + Currency: "XRP", }, }, - []any{ - map[string]any{ - "account": "rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn", - "type": 1, - "type_hex": "0000000000000001", + { + { + Account: "rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn", }, - map[string]any{ - "account": "rMwjYedjc7qqtKYVLiAccJSmCwih4LnE2q", - "type": 1, - "type_hex": "0000000000000001", + { + Account: "rMwjYedjc7qqtKYVLiAccJSmCwih4LnE2q", }, - map[string]any{ - "currency": "XRP", - "type": 16, - "type_hex": "0000000000000010", + { + Currency: "XRP", }, }, }, - "SendMax": map[string]any{ - "currency": "USD", - "issuer": "rweYz56rfmQ98cAdRaeTxQS9wVMGnrdsFp", - "value": "0.6275558355", - }, - "Sequence": 842, - "SigningPubKey": "0379F17CFA0FFD7518181594BE69FE9A10471D6DE1F4055C6D2746AFD6CF89889E", - "TransactionType": "Payment", - "TxnSignature": "3045022100D55ED1953F860ADC1BC5CD993ABB927F48156ACA31C64737865F4F4FF6D015A80220630704D2BD09C8E99F26090C25F11B28F5D96A1350454402C2CED92B39FFDBAF", - "hash": "B521424226FC100A2A802FE20476A5F8426FD3F720176DC5CCCE0D75738CC208", }, expectedErr: nil, output: "1200002200000000240000034A201B009717BE61400000000098968068400000000000000C69D4564B964A845AC0000000000000000000000000555344000000000069D33B18D53385F8A3185516C2EDA5DEDB8AC5C673210379F17CFA0FFD7518181594BE69FE9A10471D6DE1F4055C6D2746AFD6CF89889E74473045022100D55ED1953F860ADC1BC5CD993ABB927F48156ACA31C64737865F4F4FF6D015A80220630704D2BD09C8E99F26090C25F11B28F5D96A1350454402C2CED92B39FFDBAF811469D33B18D53385F8A3185516C2EDA5DEDB8AC5C6831469D33B18D53385F8A3185516C2EDA5DEDB8AC5C6F9EA7C06636C69656E747D077274312E312E31E1F1011201F3B1997562FD742B54D4EBDEA1D6AEA3D4906B8F100000000000000000000000000000000000000000FF014B4E9C06F24296074F7BC48F92A97916C6DC5EA901DD39C650A96EDA48334E70CC4A85B8B2E8502CD310000000000000000000000000000000000000000000", }, - { - description: "serialize OwnerNode example - UInt64", - input: map[string]any{"OwnerNode": "18446744073"}, - output: "340000018446744073", - expectedErr: nil, - }, - { - description: "serialize LedgerEntryType example - UInt8", - input: map[string]any{"LedgerEntryType": "RippleState"}, - output: "110072", - expectedErr: nil, - }, - { - description: "serialize int example - UInt8", - input: map[string]any{"CloseResolution": 25}, - output: "011019", - expectedErr: nil, - }, - { - description: "serialize hash 128", - input: map[string]any{"EmailHash": "73734B611DDA23D3F5F62E20A173B78A"}, - output: "4173734B611DDA23D3F5F62E20A173B78A", - expectedErr: nil, - }, - { - description: "hash128 wrong length", - input: map[string]any{"EmailHash": "73734B611DDA23D3F5F62E20A173"}, - output: "", - expectedErr: &types.ErrInvalidHashLength{Expected: 16}, - }, - { - description: "serialize hash 160", - input: map[string]any{"TakerPaysCurrency": "73734B611DDA23D3F5F62E20A173B78AB8406AC5"}, - output: "011173734B611DDA23D3F5F62E20A173B78AB8406AC5", - expectedErr: nil, - }, - { - description: "hash160 wrong length", - input: map[string]any{"TakerPaysCurrency": "73734B611DDA23D3F5F62E20A173B789"}, - output: "", - expectedErr: &types.ErrInvalidHashLength{Expected: 20}, - }, - { - description: "serialize hash 256", - input: map[string]any{"Digest": "73734B611DDA23D3F5F62E20A173B78AB8406AC5015094DA53F53D39B9EDB06C"}, - output: "501573734B611DDA23D3F5F62E20A173B78AB8406AC5015094DA53F53D39B9EDB06C", - expectedErr: nil, - }, - { - description: "hash256 wrong length", - input: map[string]any{"Digest": "73734B611DDA23D3F5F62E20A173B78AB8406AC5015094DA53F537"}, - output: "", - expectedErr: &types.ErrInvalidHashLength{Expected: 32}, - }, - { - description: "serialize Vector256 successfully,", - input: map[string]any{"Amendments": []string{"73734B611DDA23D3F5F62E20A173B78AB8406AC5015094DA53F53D39B9EDB06C", "73734B611DDA23D3F5F62E20A173B78AB8406AC5015094DA53F53D39B9EDB06C"}}, - output: "03134073734B611DDA23D3F5F62E20A173B78AB8406AC5015094DA53F53D39B9EDB06C73734B611DDA23D3F5F62E20A173B78AB8406AC5015094DA53F53D39B9EDB06C", - expectedErr: nil, - }, - { - description: "invalid input for Vector256 - not a string array", - input: map[string]any{"Amendments": []int{1, 2, 3}}, - output: "", - expectedErr: &types.ErrInvalidVector256Type{Got: "[]int"}, - }, - { - description: "invalid input for Vector256 - wrong hash length", - input: map[string]any{"Amendments": []string{"73734B611DDA23D3F5F62E20A173B78AB8406AC5015094DA53F53D39B9EDB06C56342689", "73734B611DDA23D3F5F62E20A173B78AB8406AC5015094DA53F53D39B9EDB06"}}, - output: "", - expectedErr: &types.ErrInvalidHashLength{Expected: types.HashLengthBytes}, - }, - { - description: "serialize STObject correctly", - input: map[string]any{ - "Memo": map[string]any{ - "MemoType": "04C4D46544659A2D58525043686174", - }, - }, - output: "EA7C0F04C4D46544659A2D58525043686174E1", - expectedErr: nil, - }, - { - description: "invalid pathset", - input: map[string]any{"Paths": []any{ - map[string]any{ - "account": "rDTXLQ7ZKZVKz33zJbHjgVShjsBnqMBhmN", - "currency": "USD", - "issuer": "r3Y6vCE8XqfZmYBRngy22uFYkmz3y9eCRA", - }, - map[string]any{ - "account": "rDTXLQ7ZKZVKz33zJbHjgVShjsBnqMBhmN", - "currency": "USD", - "issuer": "r3Y6vCE8XqfZmYBRngy22uFYkmz3y9eCRA", - }, - }, - }, - output: "", - expectedErr: types.ErrInvalidPathSet, - }, } for _, tc := range tt { @@ -449,30 +244,31 @@ func TestDecode(t *testing.T) { func TestEncodeForMultisigning(t *testing.T) { tt := []struct { description string - json map[string]any + input transactions.Tx accountID string output string expectedErr error }{ { description: "serialize tx1 for signing correctly", - json: map[string]any{ - "Account": "rMBzp8CgpE441cp5PVyA9rpVV7oT8hP3ys", - "Expiration": 595640108, - "Fee": "10", - "Flags": 524288, - "OfferSequence": 1752791, - "Sequence": 1752792, - "SigningPubKey": "03EE83BB432547885C219634A1BC407A9DB0474145D69737D09CCDC63E1DEE7FE3", - "TakerGets": "15000000000", - "TakerPays": map[string]any{ - "currency": "USD", - "issuer": "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B", - "value": "7072.8", + input: &transactions.OfferCreate{ + BaseTx: transactions.BaseTx{ + Account: "rMBzp8CgpE441cp5PVyA9rpVV7oT8hP3ys", + TransactionType: transactions.OfferCreateTx, + Fee: 10, + Flags: types.SetFlag(524288), + Sequence: 1752792, + SigningPubKey: "03EE83BB432547885C219634A1BC407A9DB0474145D69737D09CCDC63E1DEE7FE3", + TxnSignature: "30440220143759437C04F7B61F012563AFE90D8DAFC46E86035E1D965A9CED282C97D4CE02204CFD241E86F17E011298FC1A39B63386C74306A5DE047E213B0F29EFA4571C2C", + }, + Expiration: 595640108, + OfferSequence: 1752791, + TakerGets: types.XRPCurrencyAmount(15000000000), + TakerPays: types.IssuedCurrencyAmount{ + Currency: "USD", + Issuer: "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B", + Value: "7072.8", }, - "TransactionType": "OfferCreate", - "TxnSignature": "30440220143759437C04F7B61F012563AFE90D8DAFC46E86035E1D965A9CED282C97D4CE02204CFD241E86F17E011298FC1A39B63386C74306A5DE047E213B0F29EFA4571C2C", - "hash": "73734B611DDA23D3F5F62E20A173B78AB8406AC5015094DA53F53D39B9EDB06C", }, accountID: "rMBzp8CgpE441cp5PVyA9rpVV7oT8hP3ys", output: "534D5400120007220008000024001ABED82A2380BF2C2019001ABED764D55920AC9391400000000000000000000000000055534400000000000A20B3C85F482532A9578DBB3950B85CA06594D165400000037E11D60068400000000000000A73008114DD76483FACDEE26E60D8A586BB58D09F27045C46DD76483FACDEE26E60D8A586BB58D09F27045C46", @@ -480,22 +276,23 @@ func TestEncodeForMultisigning(t *testing.T) { }, { description: "SigningPubKey is not present", - json: map[string]any{ - "Account": "rMBzp8CgpE441cp5PVyA9rpVV7oT8hP3ys", - "Expiration": 595640108, - "Fee": "10", - "Flags": 524288, - "OfferSequence": 1752791, - "Sequence": 1752792, - "TakerGets": "15000000000", - "TakerPays": map[string]any{ - "currency": "USD", - "issuer": "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B", - "value": "7072.8", + input: &transactions.OfferCreate{ + BaseTx: transactions.BaseTx{ + Account: "rMBzp8CgpE441cp5PVyA9rpVV7oT8hP3ys", + TransactionType: transactions.OfferCreateTx, + Fee: 10, + Flags: types.SetFlag(524288), + Sequence: 1752792, + TxnSignature: "30440220143759437C04F7B61F012563AFE90D8DAFC46E86035E1D965A9CED282C97D4CE02204CFD241E86F17E011298FC1A39B63386C74306A5DE047E213B0F29EFA4571C2C", + }, + Expiration: 595640108, + OfferSequence: 1752791, + TakerGets: types.XRPCurrencyAmount(15000000000), + TakerPays: types.IssuedCurrencyAmount{ + Currency: "USD", + Issuer: "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B", + Value: "7072.8", }, - "TransactionType": "OfferCreate", - "TxnSignature": "30440220143759437C04F7B61F012563AFE90D8DAFC46E86035E1D965A9CED282C97D4CE02204CFD241E86F17E011298FC1A39B63386C74306A5DE047E213B0F29EFA4571C2C", - "hash": "73734B611DDA23D3F5F62E20A173B78AB8406AC5015094DA53F53D39B9EDB06C", }, accountID: "rMBzp8CgpE441cp5PVyA9rpVV7oT8hP3ys", output: "534D5400120007220008000024001ABED82A2380BF2C2019001ABED764D55920AC9391400000000000000000000000000055534400000000000A20B3C85F482532A9578DBB3950B85CA06594D165400000037E11D60068400000000000000A73008114DD76483FACDEE26E60D8A586BB58D09F27045C46DD76483FACDEE26E60D8A586BB58D09F27045C46", @@ -503,23 +300,24 @@ func TestEncodeForMultisigning(t *testing.T) { }, { description: "SigningPubKey empty string", - json: map[string]any{ - "Account": "rMBzp8CgpE441cp5PVyA9rpVV7oT8hP3ys", - "Expiration": 595640108, - "Fee": "10", - "Flags": 524288, - "OfferSequence": 1752791, - "Sequence": 1752792, - "SigningPubKey": "", - "TakerGets": "15000000000", - "TakerPays": map[string]any{ - "currency": "USD", - "issuer": "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B", - "value": "7072.8", + input: &transactions.OfferCreate{ + BaseTx: transactions.BaseTx{ + Account: "rMBzp8CgpE441cp5PVyA9rpVV7oT8hP3ys", + TransactionType: transactions.OfferCreateTx, + Fee: 10, + Flags: types.SetFlag(524288), + Sequence: 1752792, + SigningPubKey: "", + TxnSignature: "30440220143759437C04F7B61F012563AFE90D8DAFC46E86035E1D965A9CED282C97D4CE02204CFD241E86F17E011298FC1A39B63386C74306A5DE047E213B0F29EFA4571C2C", + }, + Expiration: 595640108, + OfferSequence: 1752791, + TakerGets: types.XRPCurrencyAmount(15000000000), + TakerPays: types.IssuedCurrencyAmount{ + Currency: "USD", + Issuer: "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B", + Value: "7072.8", }, - "TransactionType": "OfferCreate", - "TxnSignature": "30440220143759437C04F7B61F012563AFE90D8DAFC46E86035E1D965A9CED282C97D4CE02204CFD241E86F17E011298FC1A39B63386C74306A5DE047E213B0F29EFA4571C2C", - "hash": "73734B611DDA23D3F5F62E20A173B78AB8406AC5015094DA53F53D39B9EDB06C", }, accountID: "rMBzp8CgpE441cp5PVyA9rpVV7oT8hP3ys", output: "534D5400120007220008000024001ABED82A2380BF2C2019001ABED764D55920AC9391400000000000000000000000000055534400000000000A20B3C85F482532A9578DBB3950B85CA06594D165400000037E11D60068400000000000000A73008114DD76483FACDEE26E60D8A586BB58D09F27045C46DD76483FACDEE26E60D8A586BB58D09F27045C46", @@ -529,7 +327,7 @@ func TestEncodeForMultisigning(t *testing.T) { for _, tc := range tt { t.Run(tc.description, func(t *testing.T) { - got, err := EncodeForMultisigning(tc.json, tc.accountID) + got, err := EncodeForMultisigning(tc.input, tc.accountID) if tc.expectedErr != nil { require.EqualError(t, err, tc.expectedErr.Error()) @@ -546,31 +344,31 @@ func TestEncodeForSigningClaim(t *testing.T) { tt := []struct { description string - input map[string]any + input transactions.PaymentChannelClaim output string expectedErr error }{ { description: "successfully encode claim", - input: map[string]any{ - "Channel": "43904CBFCDCEC530B4037871F86EE90BF799DF8D2E0EA564BC8A3F332E4F5FB1", - "Amount": "1000", + input: transactions.PaymentChannelClaim{ + Channel: "43904CBFCDCEC530B4037871F86EE90BF799DF8D2E0EA564BC8A3F332E4F5FB1", + Amount: 1000, }, output: "434C4D0043904CBFCDCEC530B4037871F86EE90BF799DF8D2E0EA564BC8A3F332E4F5FB100000000000003E8", expectedErr: nil, }, { description: "fail to encode claim - no channel", - input: map[string]any{ - "Amount": "1000", + input: transactions.PaymentChannelClaim{ + Amount: 1000, }, output: "", expectedErr: ErrSigningClaimFieldNotFound, }, { description: "fail to encode claim - no amount", - input: map[string]any{ - "Channel": "43904CBFCDCEC530B4037871F86EE90BF799DF8D2E0EA564BC8A3F332E4F5FB1", + input: transactions.PaymentChannelClaim{ + Channel: "43904CBFCDCEC530B4037871F86EE90BF799DF8D2E0EA564BC8A3F332E4F5FB1", }, output: "", expectedErr: ErrSigningClaimFieldNotFound, @@ -595,39 +393,30 @@ func TestEncodeForSigningClaim(t *testing.T) { func TestEncodeForSigning(t *testing.T) { tt := []struct { description string - input map[string]any + input transactions.Tx output string expectedErr error }{ - { - description: "serialize STObject for signing correctly", - input: map[string]any{ - "Memo": map[string]any{ - "MemoType": "04C4D46544659A2D58525043686174", - }, - }, - output: "53545800EA7C0F04C4D46544659A2D58525043686174E1", - expectedErr: nil, - }, { description: "serialize tx1 for signing correctly", - input: map[string]any{ - "Account": "rMBzp8CgpE441cp5PVyA9rpVV7oT8hP3ys", - "Expiration": 595640108, - "Fee": "10", - "Flags": 524288, - "OfferSequence": 1752791, - "Sequence": 1752792, - "SigningPubKey": "03EE83BB432547885C219634A1BC407A9DB0474145D69737D09CCDC63E1DEE7FE3", - "TakerGets": "15000000000", - "TakerPays": map[string]any{ - "currency": "USD", - "issuer": "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B", - "value": "7072.8", + input: &transactions.OfferCreate{ + BaseTx: transactions.BaseTx{ + Account: "rMBzp8CgpE441cp5PVyA9rpVV7oT8hP3ys", + TransactionType: transactions.OfferCreateTx, + Fee: 10, + Flags: types.SetFlag(524288), + Sequence: 1752792, + SigningPubKey: "03EE83BB432547885C219634A1BC407A9DB0474145D69737D09CCDC63E1DEE7FE3", + TxnSignature: "30440220143759437C04F7B61F012563AFE90D8DAFC46E86035E1D965A9CED282C97D4CE02204CFD241E86F17E011298FC1A39B63386C74306A5DE047E213B0F29EFA4571C2C", + }, + Expiration: 595640108, + OfferSequence: 1752791, + TakerGets: types.XRPCurrencyAmount(15000000000), + TakerPays: types.IssuedCurrencyAmount{ + Currency: "USD", + Issuer: "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B", + Value: "7072.8", }, - "TransactionType": "OfferCreate", - "TxnSignature": "30440220143759437C04F7B61F012563AFE90D8DAFC46E86035E1D965A9CED282C97D4CE02204CFD241E86F17E011298FC1A39B63386C74306A5DE047E213B0F29EFA4571C2C", - "hash": "73734B611DDA23D3F5F62E20A173B78AB8406AC5015094DA53F53D39B9EDB06C", }, output: "53545800120007220008000024001ABED82A2380BF2C2019001ABED764D55920AC9391400000000000000000000000000055534400000000000A20B3C85F482532A9578DBB3950B85CA06594D165400000037E11D60068400000000000000A732103EE83BB432547885C219634A1BC407A9DB0474145D69737D09CCDC63E1DEE7FE38114DD76483FACDEE26E60D8A586BB58D09F27045C46", expectedErr: nil, 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/st_array_test.go b/binary-codec/st_array_test.go deleted file mode 100644 index 6b783157..00000000 --- a/binary-codec/st_array_test.go +++ /dev/null @@ -1,316 +0,0 @@ -package binarycodec - -import ( - "testing" - - "github.com/stretchr/testify/require" -) - -func TestSTArrayFromJson(t *testing.T) { - tt := []struct { - description string - input map[string]any - output string - expectedErr error - }{ - { - description: "nested stobject test", - input: map[string]any{ - "AffectedNodes": []any{ - map[string]any{ - "DeletedNode": map[string]any{ - "FinalFields": map[string]any{ - "ExchangeRate": "4a0745621d069432", - "Flags": 0, - "RootIndex": "036D7E923EF22B65E19D95A6365C3373E1E96586E27015074A0745621D069432", - "TakerGetsCurrency": "0000000000000000000000000000000000000000", - "TakerGetsIssuer": "0000000000000000000000000000000000000000", - "TakerPaysCurrency": "0000000000000000000000004254430000000000", - "TakerPaysIssuer": "06A148131B436B2561C85967685B098E050EED4E", - }, - "LedgerEntryType": "DirectoryNode", - "LedgerIndex": "036D7E923EF22B65E19D95A6365C3373E1E96586E27015074A0745621D069432", - }, - }, - map[string]any{ - "ModifiedNode": map[string]any{ - "FinalFields": map[string]any{ - "Flags": 0, - "Owner": "r68xfQkhFxZrbwo6RRKq728JF2fJYQRE1", - "RootIndex": "5ED0913938CD6D43BD6450201737394A9991753C4581E5682D61F35048D8FBFC", - }, - "LedgerEntryType": "DirectoryNode", - "LedgerIndex": "5ED0913938CD6D43BD6450201737394A9991753C4581E5682D61F35048D8FBFC", - }, - }, - map[string]any{ - "DeletedNode": map[string]any{ - "FinalFields": map[string]any{ - "Account": "r68xfQkhFxZrbwo6RRKq728JF2fJYQRE1", - "BookDirectory": "036D7E923EF22B65E19D95A6365C3373E1E96586E27015074A0745621D069432", - "BookNode": "0", - "Flags": 131072, - "OwnerNode": "0", - "PreviousTxnID": "B21E9DC8DCB75AD12C4ACF4C72E6E822244CF6CFFD7BD738ACEED1264374B687", - "PreviousTxnLgrSeq": 82010985, - "Sequence": 59434311, - "TakerGets": "1166610661", - "TakerPays": map[string]any{ - "currency": "BTC", - "issuer": "rchGBxcD1A1C2tdxF6papQYZ8kjRKMYcL", - "value": "0.023876", - }, - }, - "LedgerEntryType": "Offer", - "LedgerIndex": "C171AA6003AE67B218E5EFFEF3E49CB5A4FE5A06D82C1F7EEF322B036EF76CE7", - }, - }, - map[string]any{ - "ModifiedNode": map[string]any{ - "FinalFields": map[string]any{ - "Account": "r68xfQkhFxZrbwo6RRKq728JF2fJYQRE1", - "Balance": "3310960263", - "Flags": 0, - "MessageKey": "020000000000000000000000002B8F120A4CD1A6B236CC4389A30AB676CD722144", - "OwnerCount": 8, - "Sequence": 59434319, - }, - "LedgerEntryType": "AccountRoot", - "LedgerIndex": "F8C1F1AE7AEF06FEFB2311232CA30A7803820A79AE65F567354629D579BB38B1", - "PreviousFields": map[string]any{ - "Balance": "3310960413", - "OwnerCount": 9, - "Sequence": 59434318, - }, - "PreviousTxnID": "DC99E25A951DBBF89D331428DFFE72880159C03D0A4F48EBC81A277CFFBCE683", - "PreviousTxnLgrSeq": 82011654, - }, - }, - }, - "TransactionIndex": 31, - "TransactionResult": "tesSUCCESS", - }, - output: "201C0000001FF8E411006456036D7E923EF22B65E19D95A6365C3373E1E96586E27015074A0745621D069432E72200000000364A0745621D06943258036D7E923EF22B65E19D95A6365C3373E1E96586E27015074A0745621D06943201110000000000000000000000004254430000000000021106A148131B436B2561C85967685B098E050EED4E0311000000000000000000000000000000000000000004110000000000000000000000000000000000000000E1E1E5110064565ED0913938CD6D43BD6450201737394A9991753C4581E5682D61F35048D8FBFCE72200000000585ED0913938CD6D43BD6450201737394A9991753C4581E5682D61F35048D8FBFC821407B6FEE98BBDD29F92FDFAF6107BC741C4130E8FE1E1E411006F56C171AA6003AE67B218E5EFFEF3E49CB5A4FE5A06D82C1F7EEF322B036EF76CE7E7220002000024038AE5472504E3636933000000000000000034000000000000000055B21E9DC8DCB75AD12C4ACF4C72E6E822244CF6CFFD7BD738ACEED1264374B6875010036D7E923EF22B65E19D95A6365C3373E1E96586E27015074A0745621D06943264D4087B8271DDA000000000000000000000000000425443000000000006A148131B436B2561C85967685B098E050EED4E6540000000458910E5811407B6FEE98BBDD29F92FDFAF6107BC741C4130E8FE1E1E51100612504E3660655DC99E25A951DBBF89D331428DFFE72880159C03D0A4F48EBC81A277CFFBCE68356F8C1F1AE7AEF06FEFB2311232CA30A7803820A79AE65F567354629D579BB38B1E624038AE54E2D000000096240000000C5593F1DE1E7220000000024038AE54F2D000000086240000000C5593E877221020000000000000000000000002B8F120A4CD1A6B236CC4389A30AB676CD722144811407B6FEE98BBDD29F92FDFAF6107BC741C4130E8FE1E1F1031000", - expectedErr: nil, - }, - { - description: "large starray test", - input: map[string]any{ - "AffectedNodes": []any{ - map[string]any{ - "ModifiedNode": map[string]any{ - "LedgerEntryType": "NFTokenPage", - "LedgerIndex": "1D8CE533B1355B905B5C75F85B1F9A5149B94D7B49B94D7BC3CD6D2D00000291", - "PreviousFields": map[string]any{ - "NFTokens": []any{ - map[string]any{ - "NFToken": map[string]any{ - "NFTokenID": "000913881D8CE533B1355B905B5C75F85B1F9A5149B94D7BABAF4475000011D9", - "URI": "68747470733A2F2F697066732E696F2F697066732F516D57356232715736744D3975615659376E555162774356334D63514B566E6D5659516A6A4368784E65656B476B", - }, - }, - map[string]any{ - "Signer": map[string]any{ - "NFTokenID": "000913881D8CE533B1355B905B5C75F85B1F9A5149B94D7BAF373F1C00001382", - "URI": "68747470733A2F2F697066732E696F2F697066732F516D57356232715736744D3975615659376E555162774356334D63514B566E6D5659516A6A4368784E65656B476B", - }, - }, - map[string]any{ - "Majority": map[string]any{ - "NFTokenID": "000913881D8CE533B1355B905B5C75F85B1F9A5149B94D7BAFBD1B9100000CF5", - "URI": "68747470733A2F2F697066732E696F2F697066732F516D57356232715736744D3975615659376E555162774356334D63514B566E6D5659516A6A4368784E65656B476B", - }, - }, - map[string]any{ - "DisabledValidator": map[string]any{ - "NFTokenID": "000913881D8CE533B1355B905B5C75F85B1F9A5149B94D7BB17CF754000013BA", - "URI": "68747470733A2F2F697066732E696F2F697066732F516D57356232715736744D3975615659376E555162774356334D63514B566E6D5659516A6A4368784E65656B476B", - }, - }, - }, - }, - "PreviousTxnID": "0D46A35F56587D5FFF36551AF712E07E5617665BD5C52615B5AE7A338904C1BF", - "PreviousTxnLgrSeq": 81744044, - }, - "DeletedNode": map[string]any{ - "LedgerEntryType": "NFTokenPage", - "LedgerIndex": "1D8CE533B1355B905B5C75F85B1F9A5149B94D7B49B94D7BC3CD6D2D00000291", - "PreviousFields": map[string]any{ - "NFTokens": []any{ - map[string]any{ - "NFToken": map[string]any{ - "NFTokenID": "000913881D8CE533B1355B905B5C75F85B1F9A5149B94D7BABAF4475000011D9", - "URI": "68747470733A2F2F697066732E696F2F697066732F516D57356232715736744D3975615659376E555162774356334D63514B566E6D5659516A6A4368784E65656B476B", - }, - }, - map[string]any{ - "NFToken": map[string]any{ - "NFTokenID": "000913881D8CE533B1355B905B5C75F85B1F9A5149B94D7BAF373F1C00001382", - "URI": "68747470733A2F2F697066732E696F2F697066732F516D57356232715736744D3975615659376E555162774356334D63514B566E6D5659516A6A4368784E65656B476B", - }, - }, - map[string]any{ - "NFToken": map[string]any{ - "NFTokenID": "000913881D8CE533B1355B905B5C75F85B1F9A5149B94D7BAFBD1B9100000CF5", - "URI": "68747470733A2F2F697066732E696F2F697066732F516D57356232715736744D3975615659376E555162774356334D63514B566E6D5659516A6A4368784E65656B476B", - }, - }, - map[string]any{ - "NFToken": map[string]any{ - "NFTokenID": "000913881D8CE533B1355B905B5C75F85B1F9A5149B94D7BB17CF754000013BA", - "URI": "68747470733A2F2F697066732E696F2F697066732F516D57356232715736744D3975615659376E555162774356334D63514B566E6D5659516A6A4368784E65656B476B", - }, - }, - }, - }, - "PreviousTxnID": "0D46A35F56587D5FFF36551AF712E07E5617665BD5C52615B5AE7A338904C1BF", - "PreviousTxnLgrSeq": 81744044, - }, - }, - map[string]any{ - "ModifiedNode": map[string]any{ - "LedgerEntryType": "NFTokenPage", - "LedgerIndex": "1D8CE533B1355B905B5C75F85B1F9A5149B94D7B49B94D7BC3CD6D2D00000291", - "PreviousFields": map[string]any{ - "NFTokens": []any{ - map[string]any{ - "NFToken": map[string]any{ - "NFTokenID": "000913881D8CE533B1355B905B5C75F85B1F9A5149B94D7BABAF4475000011D9", - "URI": "68747470733A2F2F697066732E696F2F697066732F516D57356232715736744D3975615659376E555162774356334D63514B566E6D5659516A6A4368784E65656B476B", - }, - }, - map[string]any{ - "NFToken": map[string]any{ - "NFTokenID": "000913881D8CE533B1355B905B5C75F85B1F9A5149B94D7BAF373F1C00001382", - "URI": "68747470733A2F2F697066732E696F2F697066732F516D57356232715736744D3975615659376E555162774356334D63514B566E6D5659516A6A4368784E65656B476B", - }, - }, - map[string]any{ - "NFToken": map[string]any{ - "NFTokenID": "000913881D8CE533B1355B905B5C75F85B1F9A5149B94D7BAFBD1B9100000CF5", - "URI": "68747470733A2F2F697066732E696F2F697066732F516D57356232715736744D3975615659376E555162774356334D63514B566E6D5659516A6A4368784E65656B476B", - }, - }, - map[string]any{ - "NFToken": map[string]any{ - "NFTokenID": "000913881D8CE533B1355B905B5C75F85B1F9A5149B94D7BB17CF754000013BA", - "URI": "68747470733A2F2F697066732E696F2F697066732F516D57356232715736744D3975615659376E555162774356334D63514B566E6D5659516A6A4368784E65656B476B", - }, - }, - }, - }, - "PreviousTxnID": "0D46A35F56587D5FFF36551AF712E07E5617665BD5C52615B5AE7A338904C1BF", - "PreviousTxnLgrSeq": 81744044, - }, - }, - }, - "TransactionIndex": 55, - "TransactionResult": "tesSUCCESS", - }, - output: "201C00000037F8E41100502504DF50AC550D46A35F56587D5FFF36551AF712E07E5617665BD5C52615B5AE7A338904C1BF561D8CE533B1355B905B5C75F85B1F9A5149B94D7B49B94D7BC3CD6D2D00000291E6FAEC5A000913881D8CE533B1355B905B5C75F85B1F9A5149B94D7BABAF4475000011D9754368747470733A2F2F697066732E696F2F697066732F516D57356232715736744D3975615659376E555162774356334D63514B566E6D5659516A6A4368784E65656B476BE1EC5A000913881D8CE533B1355B905B5C75F85B1F9A5149B94D7BAF373F1C00001382754368747470733A2F2F697066732E696F2F697066732F516D57356232715736744D3975615659376E555162774356334D63514B566E6D5659516A6A4368784E65656B476BE1EC5A000913881D8CE533B1355B905B5C75F85B1F9A5149B94D7BAFBD1B9100000CF5754368747470733A2F2F697066732E696F2F697066732F516D57356232715736744D3975615659376E555162774356334D63514B566E6D5659516A6A4368784E65656B476BE1EC5A000913881D8CE533B1355B905B5C75F85B1F9A5149B94D7BB17CF754000013BA754368747470733A2F2F697066732E696F2F697066732F516D57356232715736744D3975615659376E555162774356334D63514B566E6D5659516A6A4368784E65656B476BE1F1E1E1E51100502504DF50AC550D46A35F56587D5FFF36551AF712E07E5617665BD5C52615B5AE7A338904C1BF561D8CE533B1355B905B5C75F85B1F9A5149B94D7B49B94D7BC3CD6D2D00000291E6FAEC5A000913881D8CE533B1355B905B5C75F85B1F9A5149B94D7BABAF4475000011D9754368747470733A2F2F697066732E696F2F697066732F516D57356232715736744D3975615659376E555162774356334D63514B566E6D5659516A6A4368784E65656B476BE1E0105A000913881D8CE533B1355B905B5C75F85B1F9A5149B94D7BAF373F1C00001382754368747470733A2F2F697066732E696F2F697066732F516D57356232715736744D3975615659376E555162774356334D63514B566E6D5659516A6A4368784E65656B476BE1E0125A000913881D8CE533B1355B905B5C75F85B1F9A5149B94D7BAFBD1B9100000CF5754368747470733A2F2F697066732E696F2F697066732F516D57356232715736744D3975615659376E555162774356334D63514B566E6D5659516A6A4368784E65656B476BE1E0135A000913881D8CE533B1355B905B5C75F85B1F9A5149B94D7BB17CF754000013BA754368747470733A2F2F697066732E696F2F697066732F516D57356232715736744D3975615659376E555162774356334D63514B566E6D5659516A6A4368784E65656B476BE1F1E1E1E51100502504DF50AC550D46A35F56587D5FFF36551AF712E07E5617665BD5C52615B5AE7A338904C1BF561D8CE533B1355B905B5C75F85B1F9A5149B94D7B49B94D7BC3CD6D2D00000291E6FAEC5A000913881D8CE533B1355B905B5C75F85B1F9A5149B94D7BABAF4475000011D9754368747470733A2F2F697066732E696F2F697066732F516D57356232715736744D3975615659376E555162774356334D63514B566E6D5659516A6A4368784E65656B476BE1EC5A000913881D8CE533B1355B905B5C75F85B1F9A5149B94D7BAF373F1C00001382754368747470733A2F2F697066732E696F2F697066732F516D57356232715736744D3975615659376E555162774356334D63514B566E6D5659516A6A4368784E65656B476BE1EC5A000913881D8CE533B1355B905B5C75F85B1F9A5149B94D7BAFBD1B9100000CF5754368747470733A2F2F697066732E696F2F697066732F516D57356232715736744D3975615659376E555162774356334D63514B566E6D5659516A6A4368784E65656B476BE1EC5A000913881D8CE533B1355B905B5C75F85B1F9A5149B94D7BB17CF754000013BA754368747470733A2F2F697066732E696F2F697066732F516D57356232715736744D3975615659376E555162774356334D63514B566E6D5659516A6A4368784E65656B476BE1F1E1E1F1031000", - expectedErr: nil, - }, - } - - for _, tc := range tt { - t.Run(tc.description, func(t *testing.T) { - got, err := Encode(tc.input) - - if tc.expectedErr != nil { - require.EqualError(t, err, tc.expectedErr.Error()) - require.Empty(t, got) - } else { - require.NoError(t, err) - require.Equal(t, tc.output, got) - } - }) - } - -} - -func TestSTArrayToJson(t *testing.T) { - tt := []struct { - description string - input string - output map[string]any - expectedErr error - }{ - { - description: "large starray", - input: "FAEC5A000913881D8CE533B1355B905B5C75F85B1F9A5149B94D7BABAF4475000011D9E1E010754368747470733A2F2F697066732E696F2F697066732F516D57356232715736744D3975615659376E555162774356334D63514B566E6D5659516A6A4368784E65656B476BE1F1", - output: map[string]any{ - "NFTokens": []any{ - map[string]any{ - "NFToken": map[string]any{ - "NFTokenID": "000913881D8CE533B1355B905B5C75F85B1F9A5149B94D7BABAF4475000011D9", - }, - }, - map[string]any{ - "Signer": map[string]any{ - "URI": "68747470733A2F2F697066732E696F2F697066732F516D57356232715736744D3975615659376E555162774356334D63514B566E6D5659516A6A4368784E65656B476B", - }, - }, - }, - }, - expectedErr: nil, - }, - { - description: "simple starray", - input: "F9EA364A0745621D0694327D0F04C4D46544659A2D58525043686174E1E9364A0745621D0694327D0F04C4D46544659A2D58525043686174E1F1", - output: map[string]any{ - "Memos": []any{ - map[string]any{ - "Memo": map[string]any{ - "MemoData": "04C4D46544659A2D58525043686174", - "ExchangeRate": "4A0745621D069432", - }, - }, - map[string]any{ - "TemplateEntry": map[string]any{ - "MemoData": "04C4D46544659A2D58525043686174", - "ExchangeRate": "4A0745621D069432", - }, - }, - }, - }, - }, - { - description: "smaller stobject test", - input: "E51100612504E3660655DC99E25A951DBBF89D331428DFFE72880159C03D0A4F48EBC81A277CFFBCE68356F8C1F1AE7AEF06FEFB2311232CA30A7803820A79AE65F567354629D579BB38B1E624038AE54E2D000000096240000000C5593F1DE1E7220000000024038AE54F2D000000086240000000C5593E877221020000000000000000000000002B8F120A4CD1A6B236CC4389A30AB676CD722144811407B6FEE98BBDD29F92FDFAF6107BC741C4130E8FE1E1", - output: map[string]any{ - "ModifiedNode": map[string]any{ - "FinalFields": map[string]any{ - "Account": "r68xfQkhFxZrbwo6RRKq728JF2fJYQRE1", - "Balance": "3310960263", - "Flags": 0, - "MessageKey": "020000000000000000000000002B8F120A4CD1A6B236CC4389A30AB676CD722144", - "OwnerCount": 8, - "Sequence": 59434319, - }, - "LedgerEntryType": "AccountRoot", - "LedgerIndex": "F8C1F1AE7AEF06FEFB2311232CA30A7803820A79AE65F567354629D579BB38B1", - "PreviousFields": map[string]any{ - "Balance": "3310960413", - "OwnerCount": 9, - "Sequence": 59434318, - }, - "PreviousTxnID": "DC99E25A951DBBF89D331428DFFE72880159C03D0A4F48EBC81A277CFFBCE683", - "PreviousTxnLgrSeq": 82011654, - }, - }, - }, - } - - for _, tc := range tt { - t.Run(tc.description, func(t *testing.T) { - act, err := Decode(tc.input) - if tc.expectedErr != nil { - require.Error(t, err, tc.expectedErr.Error()) - require.Nil(t, act) - } else { - require.NoError(t, err) - require.EqualValues(t, tc.output, act) - } - }) - } -} diff --git a/binary-codec/types/account_id.go b/binary-codec/types/account_id.go index 3232e998..2265acaf 100644 --- a/binary-codec/types/account_id.go +++ b/binary-codec/types/account_id.go @@ -1,8 +1,15 @@ package types import ( - addresscodec "github.com/xyield/xrpl-go/address-codec" - "github.com/xyield/xrpl-go/binary-codec/serdes" + "errors" + + 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 ( + ErrInvalidAccountID = errors.New("invalid account ID type") ) // AccountID struct represents an account ID. @@ -17,7 +24,16 @@ type AccountID struct{} // AccountIDs that appear as children of special fields (Amount issuer and PathSet account) are not length-prefixed. // So in Amount and PathSet fields, don't use the length indicator 0x14. func (a *AccountID) FromJson(value any) ([]byte, error) { - _, accountID, err := addresscodec.DecodeClassicAddressToAccountID(value.(string)) + var accountID []byte + var err error + switch v := value.(type) { + case types.Address: + _, accountID, err = addresscodec.DecodeClassicAddressToAccountID(string(v)) + case string: + _, accountID, err = addresscodec.DecodeClassicAddressToAccountID(v) + default: + return nil, ErrInvalidAccountID + } if err != nil { return nil, err diff --git a/binary-codec/types/account_id_test.go b/binary-codec/types/account_id_test.go new file mode 100644 index 00000000..b3a9a642 --- /dev/null +++ b/binary-codec/types/account_id_test.go @@ -0,0 +1,50 @@ +package types + +import ( + "testing" + + "github.com/CreatureDev/xrpl-go/model/transactions/types" + "github.com/stretchr/testify/require" +) + +func TestAccountIDFromJson(t *testing.T) { + tt := []struct { + description string + input any + expected []byte + expectedErr error + }{ + { + description: "convert address", + input: types.Address("r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59"), + expected: []byte{0x5e, 0x7b, 0x11, 0x25, 0x23, 0xf6, 0x8d, 0x2f, 0x5e, 0x87, 0x9d, 0xb4, 0xea, 0xc5, 0x1c, 0x66, 0x98, 0xa6, 0x93, 0x4}, + expectedErr: nil, + }, + { + description: "convert address from string type", + input: "r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59", + expected: []byte{0x5e, 0x7b, 0x11, 0x25, 0x23, 0xf6, 0x8d, 0x2f, 0x5e, 0x87, 0x9d, 0xb4, 0xea, 0xc5, 0x1c, 0x66, 0x98, 0xa6, 0x93, 0x4}, + expectedErr: nil, + }, + { + description: "invalid type should error", + input: false, + expected: nil, + expectedErr: ErrInvalidAccountID, + }, + } + + for _, tc := range tt { + t.Run(tc.description, func(t *testing.T) { + a := &AccountID{} + got, err := a.FromJson(tc.input) + if tc.expectedErr != nil { + require.EqualError(t, err, tc.expectedErr.Error()) + require.Empty(t, got) + } else { + require.NoError(t, err) + require.Equal(t, tc.expected, got) + } + }) + } +} diff --git a/binary-codec/types/amount.go b/binary-codec/types/amount.go index 57d648b0..703945f9 100644 --- a/binary-codec/types/amount.go +++ b/binary-codec/types/amount.go @@ -11,9 +11,10 @@ import ( "strconv" "strings" - addresscodec "github.com/xyield/xrpl-go/address-codec" - "github.com/xyield/xrpl-go/binary-codec/serdes" - 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 ( @@ -43,12 +44,12 @@ var ( // InvalidAmountError is a custom error type for invalid amounts. type InvalidAmountError struct { - Amount string + Amount types.XRPCurrencyAmount } // Error method for InvalidAmountError returns a formatted error string. func (e *InvalidAmountError) Error() string { - return fmt.Sprintf("value '%s' is an invalid amount", e.Amount) + return fmt.Sprintf("value '%v' is an invalid amount", e.Amount) } // OutOfRangeError is a custom error type for out-of-range values. @@ -77,11 +78,11 @@ type Amount struct{} // FromJson serializes an issued currency amount to its bytes representation from JSON. func (a *Amount) FromJson(value any) ([]byte, error) { - switch value := value.(type) { - case string: - return serializeXrpAmount(value) - case map[string]any: - return serializeIssuedCurrencyAmount(value["value"].(string), value["currency"].(string), value["issuer"].(string)) + switch v := value.(type) { + case types.XRPCurrencyAmount: + return serializeXrpAmount(v) + case types.IssuedCurrencyAmount: + return serializeIssuedCurrencyAmount(v) default: return nil, errors.New("invalid amount type") } @@ -190,21 +191,10 @@ func deserializeIssuer(data []byte) (string, error) { // verifyXrpValue validates the format of an XRP amount value. // XRP values should not contain a decimal point because they are represented as integers as drops. -func verifyXrpValue(value string) error { - - r := regexp.MustCompile(`\d+`) // regex to match only digits - m := r.FindAllString(value, -1) - - if len(m) != 1 { - return ErrInvalidXRPValue - } +func verifyXrpValue(value types.XRPCurrencyAmount) error { decimal := new(big.Float) - decimal, ok := decimal.SetString(value) // bigFloat for precision - - if !ok { - return errors.New("failed to convert string to big.Float") - } + decimal = decimal.SetUint64(uint64(value)) // bigFloat for precision if decimal.Sign() == 0 { return nil @@ -246,19 +236,13 @@ func verifyIOUValue(value string) error { } // serializeXrpAmount serializes an XRP amount value. -func serializeXrpAmount(value string) ([]byte, error) { +func serializeXrpAmount(value types.XRPCurrencyAmount) ([]byte, error) { if verifyXrpValue(value) != nil { return nil, verifyXrpValue(value) } - val, err := strconv.ParseUint(value, 10, 64) - - if err != nil { - return nil, err - } - - valWithPosBit := val | PosSignBitMask + valWithPosBit := value | PosSignBitMask valBytes := make([]byte, NativeAmountByteLength) binary.BigEndian.PutUint64(valBytes, uint64(valWithPosBit)) @@ -275,7 +259,7 @@ func serializeXrpAmount(value string) ([]byte, error) { // over-rounding in the least significant digits. // SerializeIssuedCurrencyValue serializes the value field of an issued currency amount to its bytes representation. -func SerializeIssuedCurrencyValue(value string) ([]byte, error) { +func serializeIssuedCurrencyValue(value string) ([]byte, error) { if verifyIOUValue(value) != nil { return nil, verifyIOUValue(value) @@ -400,26 +384,27 @@ func serializeIssuedCurrencyCodeChars(currency string) ([]byte, error) { // from value, currency code, and issuer address in string form (e.g. "USD", "r123456789"). // The currency code can be 3 allowed string characters, or 20 bytes of hex in standard currency format (e.g. with "00" prefix) // or non-standard currency format (e.g. without "00" prefix) -func serializeIssuedCurrencyAmount(value, currency, issuer string) ([]byte, error) { +func serializeIssuedCurrencyAmount(value types.IssuedCurrencyAmount) ([]byte, error) { var valBytes []byte var err error - if value == "0" { + if value.Value == "0" { valBytes = make([]byte, 8) binary.BigEndian.PutUint64(valBytes, uint64(ZeroCurrencyAmountHex)) } else { - valBytes, err = SerializeIssuedCurrencyValue(value) // serialize the value + valBytes, err = serializeIssuedCurrencyValue(value.Value) // serialize the value } + // valBytes, err := serializeIssuedCurrencyValue(value.Value) // serialize the value if err != nil { return nil, err } - currencyBytes, err := serializeIssuedCurrencyCode(currency) // serialize the currency code + currencyBytes, err := serializeIssuedCurrencyCode(value.Currency) // serialize the currency code if err != nil { return nil, err } - _, issuerBytes, err := addresscodec.DecodeClassicAddressToAccountID(issuer) // decode the issuer address + _, issuerBytes, err := addresscodec.DecodeClassicAddressToAccountID(string(value.Issuer)) // decode the issuer address if err != nil { return nil, err } diff --git a/binary-codec/types/amount_test.go b/binary-codec/types/amount_test.go index 2f9d2478..d40d00cf 100644 --- a/binary-codec/types/amount_test.go +++ b/binary-codec/types/amount_test.go @@ -3,37 +3,38 @@ package types import ( "testing" + "github.com/CreatureDev/xrpl-go/model/transactions/types" + bigdecimal "github.com/CreatureDev/xrpl-go/pkg/big-decimal" "github.com/stretchr/testify/require" - bigdecimal "github.com/xyield/xrpl-go/pkg/big-decimal" ) func TestVerifyXrpValue(t *testing.T) { tests := []struct { name string - input string + input types.XRPCurrencyAmount expErr error }{ - { - name: "invalid xrp value", - input: "1.0", - expErr: ErrInvalidXRPValue, - }, - { - name: "invalid xrp value - out of range", - input: "0.000000007", - expErr: ErrInvalidXRPValue, - }, + // { + // name: "invalid xrp value", + // input: 1.0, + // expErr: ErrInvalidXRPValue, + // }, + // { + // name: "invalid xrp value - out of range", + // input: 0.000000007, + // expErr: ErrInvalidXRPValue, + // }, { name: "valid xrp value - no decimal", - input: "125000708", + input: 125000708, expErr: nil, }, - { - name: "valid xrp value - no decimal - negative value", - input: "-125000708", - expErr: &InvalidAmountError{Amount: "-125000708"}, - }, + // { + // name: "invalid xrp value - no decimal - negative value", + // input: -125000708, + // expErr: &InvalidAmountError{Amount: "-125000708"}, + // }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { @@ -100,57 +101,45 @@ func TestVerifyIOUValue(t *testing.T) { func TestSerializeXrpAmount(t *testing.T) { tests := []struct { name string - input string + input types.XRPCurrencyAmount expectedOutput []byte expErr error }{ { name: "valid xrp value - 1", - input: "524801", + input: 524801, expectedOutput: []byte{0x40, 0x00, 0x00, 0x00, 0x00, 0x8, 0x2, 0x01}, expErr: nil, }, { name: "valid xrp value - 2", - input: "7696581656832", + input: 7696581656832, expectedOutput: []byte{0x40, 0x00, 0x7, 0x00, 0x00, 0x4, 0x1, 0x00}, expErr: nil, }, { name: "valid xrp value - 3", - input: "10000000", + input: 10000000, expectedOutput: []byte{0x40, 0x00, 0x00, 0x00, 0x00, 0x98, 0x96, 0x80}, expErr: nil, }, - { - name: "invalid xrp value - negative", - input: "-125000708", - expectedOutput: nil, - expErr: &InvalidAmountError{Amount: "-125000708"}, - }, - { - name: "invalid xrp value - decimal", - input: "125000708.0", - expectedOutput: nil, - expErr: ErrInvalidXRPValue, - }, { name: "boundary test - 1 less than max xrp value", - input: "99999999999999999", + input: 99999999999999999, expectedOutput: []byte{0x41, 0x63, 0x45, 0x78, 0x5d, 0x89, 0xff, 0xff}, expErr: nil, }, { name: "boundary test - max xrp value", - input: "10000000000000000", + input: 10000000000000000, expectedOutput: []byte{0x40, 0x23, 0x86, 0xf2, 0x6f, 0xc1, 0x00, 0x00}, expErr: nil, }, { name: "boundary test - 1 greater than max xrp value", - input: "100000000000000001", + input: 100000000000000001, expectedOutput: nil, - expErr: &InvalidAmountError{Amount: "100000000000000001"}, + expErr: &InvalidAmountError{Amount: 100000000000000001}, }, } for _, tt := range tests { @@ -232,7 +221,7 @@ func TestSerializeIssuedCurrencyValue(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - got, err := SerializeIssuedCurrencyValue(tt.input) + got, err := serializeIssuedCurrencyValue(tt.input) if tt.expectedErr != nil { require.EqualError(t, tt.expectedErr, err.Error()) @@ -349,35 +338,27 @@ func TestSerializeIssuedCurrencyCode(t *testing.T) { func TestSerializeIssuedCurrencyAmount(t *testing.T) { tests := []struct { - name string - inputValue string - inputCurrency string - inputIssuer string - expected []byte - expectedErr error + name string + input types.IssuedCurrencyAmount + expected []byte + expectedErr error }{ { - name: "valid serialized issued currency amount", - inputValue: "7072.8", - inputCurrency: "USD", - inputIssuer: "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B", - expected: []byte{0xD5, 0x59, 0x20, 0xAC, 0x93, 0x91, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x55, 0x53, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0A, 0x20, 0xB3, 0xC8, 0x5F, 0x48, 0x25, 0x32, 0xA9, 0x57, 0x8D, 0xBB, 0x39, 0x50, 0xB8, 0x5C, 0xA0, 0x65, 0x94, 0xD1}, - expectedErr: nil, - }, - { - name: "valid serialized issued currency amount - 2", - inputValue: "0.6275558355", - inputCurrency: "USD", - inputIssuer: "rweYz56rfmQ98cAdRaeTxQS9wVMGnrdsFp", - expected: []byte{0xd4, 0x56, 0x4b, 0x96, 0x4a, 0x84, 0x5a, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x55, 0x53, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00, 0x69, 0xd3, 0x3b, 0x18, 0xd5, 0x33, 0x85, 0xf8, 0xa3, 0x18, 0x55, 0x16, 0xc2, 0xed, 0xa5, 0xde, 0xdb, 0x8a, 0xc5, 0xc6}, - expectedErr: nil, + name: "valid serialized issued currency amount", + input: types.IssuedCurrencyAmount{ + Value: "7072.8", + Currency: "USD", + Issuer: "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B", + }, + expected: []byte{0xD5, 0x59, 0x20, 0xAC, 0x93, 0x91, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x55, 0x53, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0A, 0x20, 0xB3, 0xC8, 0x5F, 0x48, 0x25, 0x32, 0xA9, 0x57, 0x8D, 0xBB, 0x39, 0x50, 0xB8, 0x5C, 0xA0, 0x65, 0x94, 0xD1}, + expectedErr: nil, }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - got, err := serializeIssuedCurrencyAmount(tt.inputValue, tt.inputCurrency, tt.inputIssuer) + got, err := serializeIssuedCurrencyAmount(tt.input) if tt.expectedErr != nil { require.EqualError(t, tt.expectedErr, err.Error()) diff --git a/binary-codec/types/blob.go b/binary-codec/types/blob.go index 4acdc808..089c1b30 100644 --- a/binary-codec/types/blob.go +++ b/binary-codec/types/blob.go @@ -5,17 +5,23 @@ 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. -var ErrNoLengthPrefix error = errors.New("no length prefix size given") +var ( + ErrNoLengthPrefix error = errors.New("no length prefix size given") + ErrInvalidBlobType error = errors.New("invalid type for Blob") +) // Blob struct is used for manipulating hexadecimal data. type Blob struct{} // FromJson method for Blob converts a hexadecimal string from JSON to a byte array. func (b *Blob) FromJson(json any) ([]byte, error) { + if _, ok := json.(string); !ok { + return nil, ErrInvalidBlobType + } // Convert hexadecimal string to byte array. // Return an error if the conversion fails. v, err := hex.DecodeString(json.(string)) diff --git a/binary-codec/types/blob_test.go b/binary-codec/types/blob_test.go new file mode 100644 index 00000000..ce6fd08b --- /dev/null +++ b/binary-codec/types/blob_test.go @@ -0,0 +1,43 @@ +package types + +import ( + "testing" + + "github.com/stretchr/testify/require" +) + +func TestBlobFromJson(t *testing.T) { + tt := []struct { + description string + input any + expected []byte + expectedErr error + }{ + { + description: "convert string", + input: "0000000000000001", + expected: []byte{0, 0, 0, 0, 0, 0, 0, 1}, + expectedErr: nil, + }, + { + description: "invalid type should error", + input: -54, + expected: nil, + expectedErr: ErrInvalidBlobType, + }, + } + + for _, tc := range tt { + t.Run(tc.description, func(t *testing.T) { + b := &Blob{} + got, err := b.FromJson(tc.input) + if tc.expectedErr != nil { + require.EqualError(t, err, tc.expectedErr.Error()) + require.Empty(t, got) + } else { + require.NoError(t, err) + require.Equal(t, tc.expected, got) + } + }) + } +} diff --git a/binary-codec/types/hash.go b/binary-codec/types/hash.go index fa5f2aef..f2f11680 100644 --- a/binary-codec/types/hash.go +++ b/binary-codec/types/hash.go @@ -1,11 +1,12 @@ package types import ( - "encoding/hex" + "errors" "fmt" - "strings" +) - "github.com/xyield/xrpl-go/binary-codec/serdes" +var ( + ErrInvalidHashType = errors.New("invalid type for Hash, expected string") ) // ErrInvalidHashLength struct is used when the hash length does not meet the expected value. @@ -23,43 +24,3 @@ type hashI interface { SerializedType getLength() int } - -// hash struct represents a hash with a specific length. -type hash struct { - Length int -} - -// newHash is a constructor for creating a new hash with a specified length. -func newHash(l int) hash { - return hash{ - Length: l, - } -} - -// getLength method for hash returns the hash's length. -func (h hash) getLength() int { - return h.Length -} - -// FromJson method for hash converts a hexadecimal string from JSON to a byte array. -// It returns an error if the conversion fails or the length of the decoded byte array is not as expected. -func (h hash) FromJson(json any) ([]byte, error) { - v, err := hex.DecodeString(json.(string)) - if err != nil { - return nil, err - } - if h.getLength() != len(v) { - return nil, &ErrInvalidHashLength{Expected: h.getLength()} - } - return v, nil -} - -// ToJson method for hash reads a certain number of bytes from a BinaryParser and converts it into a hexadecimal string. -// It returns an error if the read operation fails. -func (h hash) ToJson(p *serdes.BinaryParser, opts ...int) (any, error) { - b, err := p.ReadBytes(h.Length) - if err != nil { - return nil, err - } - return strings.ToUpper(hex.EncodeToString(b)), nil -} diff --git a/binary-codec/types/hash128.go b/binary-codec/types/hash128.go index 97c59ea3..3eb62b84 100644 --- a/binary-codec/types/hash128.go +++ b/binary-codec/types/hash128.go @@ -1,13 +1,57 @@ package types +import ( + "encoding/hex" + "strings" + + "github.com/CreatureDev/xrpl-go/binary-codec/serdes" + "github.com/CreatureDev/xrpl-go/model/transactions/types" +) + +var _ hashI = (*Hash128)(nil) + // Hash128 struct represents a 128-bit hash. type Hash128 struct { - hashI } // NewHash128 is a constructor for creating a new 128-bit hash. func NewHash128() *Hash128 { - return &Hash128{ - newHash(16), + return &Hash128{} +} + +// getLength method for hash returns the hash's length. +func (h *Hash128) getLength() int { + return 16 +} + +// FromJson method for hash converts a hexadecimal string from JSON to a byte array. +// It returns an error if the conversion fails or the length of the decoded byte array is not as expected. +func (h *Hash128) FromJson(json any) ([]byte, error) { + var s string + switch json := json.(type) { + case string: + s = json + case types.Hash128: + s = string(json) + default: + return nil, ErrInvalidHashType + } + v, err := hex.DecodeString(s) + if err != nil { + return nil, err + } + if h.getLength() != len(v) { + return nil, &ErrInvalidHashLength{Expected: h.getLength()} + } + return v, nil +} + +// ToJson method for hash reads a certain number of bytes from a BinaryParser and converts it into a hexadecimal string. +// It returns an error if the read operation fails. +func (h *Hash128) ToJson(p *serdes.BinaryParser, opts ...int) (any, error) { + b, err := p.ReadBytes(h.getLength()) + if err != nil { + return nil, err } + return strings.ToUpper(hex.EncodeToString(b)), nil } diff --git a/binary-codec/types/hash128_test.go b/binary-codec/types/hash128_test.go new file mode 100644 index 00000000..10b5f3af --- /dev/null +++ b/binary-codec/types/hash128_test.go @@ -0,0 +1,50 @@ +package types + +import ( + "testing" + + "github.com/CreatureDev/xrpl-go/model/transactions/types" + "github.com/stretchr/testify/require" +) + +func TestHash128FromJson(t *testing.T) { + tt := []struct { + description string + input any + expected []byte + expectedErr error + }{ + { + description: "convert string", + input: "00000000000000000000000000000001", + expected: []byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, + expectedErr: nil, + }, + { + description: "convert hash128 type", + input: types.Hash128("00000000000000000000000000000001"), + expected: []byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, + expectedErr: nil, + }, + { + description: "invalid type should error", + input: -54, + expected: nil, + expectedErr: ErrInvalidHashType, + }, + } + + for _, tc := range tt { + t.Run(tc.description, func(t *testing.T) { + h128 := &Hash128{} + got, err := h128.FromJson(tc.input) + if tc.expectedErr != nil { + require.EqualError(t, err, tc.expectedErr.Error()) + require.Empty(t, got) + } else { + require.NoError(t, err) + require.Equal(t, tc.expected, got) + } + }) + } +} diff --git a/binary-codec/types/hash160.go b/binary-codec/types/hash160.go index c02a12d1..0d92e985 100644 --- a/binary-codec/types/hash160.go +++ b/binary-codec/types/hash160.go @@ -1,13 +1,50 @@ package types +import ( + "encoding/hex" + "strings" + + "github.com/CreatureDev/xrpl-go/binary-codec/serdes" +) + +var _ hashI = (*Hash128)(nil) + // Hash160 struct represents a 160-bit hash. type Hash160 struct { - hashI } // NewHash160 is a constructor for creating a new 160-bit hash. func NewHash160() *Hash160 { - return &Hash160{ - newHash(20), + return &Hash160{} +} + +// getLength method for hash returns the hash's length. +func (h *Hash160) getLength() int { + return 20 +} + +// FromJson method for hash converts a hexadecimal string from JSON to a byte array. +// It returns an error if the conversion fails or the length of the decoded byte array is not as expected. +func (h *Hash160) FromJson(json any) ([]byte, error) { + if _, ok := json.(string); !ok { + return nil, ErrInvalidHashType + } + v, err := hex.DecodeString(json.(string)) + if err != nil { + return nil, err + } + if h.getLength() != len(v) { + return nil, &ErrInvalidHashLength{Expected: h.getLength()} + } + return v, nil +} + +// ToJson method for hash reads a certain number of bytes from a BinaryParser and converts it into a hexadecimal string. +// It returns an error if the read operation fails. +func (h *Hash160) ToJson(p *serdes.BinaryParser, opts ...int) (any, error) { + b, err := p.ReadBytes(h.getLength()) + if err != nil { + return nil, err } + return strings.ToUpper(hex.EncodeToString(b)), nil } diff --git a/binary-codec/types/hash160_test.go b/binary-codec/types/hash160_test.go new file mode 100644 index 00000000..4a824a63 --- /dev/null +++ b/binary-codec/types/hash160_test.go @@ -0,0 +1,44 @@ +package types + +import ( + "testing" + + "github.com/stretchr/testify/require" +) + +func TestHash160FromJson(t *testing.T) { + tt := []struct { + description string + input any + expected []byte + expectedErr error + }{ + { + description: "convert string", + input: "0000000000000000000000000000000000000001", + expected: []byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, + expectedErr: nil, + }, + { + description: "invalid type", + input: -54, + expected: nil, + expectedErr: ErrInvalidHashType, + }, + } + + for _, tc := range tt { + t.Run(tc.description, func(t *testing.T) { + h160 := &Hash160{} + got, err := h160.FromJson(tc.input) + if tc.expectedErr != nil { + require.EqualError(t, err, tc.expectedErr.Error()) + require.Empty(t, got) + } else { + require.NoError(t, err) + require.Equal(t, tc.expected, got) + } + }) + + } +} diff --git a/binary-codec/types/hash256.go b/binary-codec/types/hash256.go index 3c690e49..10352e2c 100644 --- a/binary-codec/types/hash256.go +++ b/binary-codec/types/hash256.go @@ -1,13 +1,55 @@ package types +import ( + "encoding/hex" + "strings" + + "github.com/CreatureDev/xrpl-go/binary-codec/serdes" + "github.com/CreatureDev/xrpl-go/model/transactions/types" +) + +var _ hashI = (*Hash256)(nil) + // Hash256 struct represents a 256-bit hash. type Hash256 struct { - hashI } // NewHash256 is a constructor for creating a new 256-bit hash. func NewHash256() *Hash256 { - return &Hash256{ - newHash(32), + return &Hash256{} +} + +// getLength method for hash returns the hash's length. +func (h *Hash256) getLength() int { + return 32 +} + +func (h *Hash256) FromJson(json any) ([]byte, error) { + var s string + switch json := json.(type) { + case string: + s = json + case types.Hash256: + s = string(json) + default: + return nil, ErrInvalidHashType + } + v, err := hex.DecodeString(s) + if err != nil { + return nil, err + } + if h.getLength() != len(v) { + return nil, &ErrInvalidHashLength{Expected: h.getLength()} + } + return v, nil +} + +// ToJson method for hash reads a certain number of bytes from a BinaryParser and converts it into a hexadecimal string. +// It returns an error if the read operation fails. +func (h *Hash256) ToJson(p *serdes.BinaryParser, opts ...int) (any, error) { + b, err := p.ReadBytes(h.getLength()) + if err != nil { + return nil, err } + return strings.ToUpper(hex.EncodeToString(b)), nil } diff --git a/binary-codec/types/hash256_test.go b/binary-codec/types/hash256_test.go new file mode 100644 index 00000000..beb097f4 --- /dev/null +++ b/binary-codec/types/hash256_test.go @@ -0,0 +1,52 @@ +package types + +import ( + "bytes" + "strings" + "testing" + + "github.com/CreatureDev/xrpl-go/model/transactions/types" + "github.com/stretchr/testify/require" +) + +func TestHash256FromJson(t *testing.T) { + tt := []struct { + description string + input any + expected []byte + expectedErr error + }{ + { + description: "convert string", + input: strings.Repeat("0", 63) + "1", + expected: append(bytes.Repeat([]byte{0}, 31), byte(1)), + expectedErr: nil, + }, + { + description: "convert hash256 type", + input: types.Hash256(strings.Repeat("0", 63) + "1"), + expected: append(bytes.Repeat([]byte{0}, 31), byte(1)), + expectedErr: nil, + }, + { + description: "invalid type", + input: -54, + expected: nil, + expectedErr: ErrInvalidHashType, + }, + } + + for _, tc := range tt { + t.Run(tc.description, func(t *testing.T) { + h256 := &Hash256{} + got, err := h256.FromJson(tc.input) + if tc.expectedErr != nil { + require.EqualError(t, err, tc.expectedErr.Error()) + require.Empty(t, got) + } else { + require.NoError(t, err) + require.Equal(t, tc.expected, got) + } + }) + } +} diff --git a/binary-codec/types/pathset.go b/binary-codec/types/pathset.go index d35f90ec..d38fc7f3 100644 --- a/binary-codec/types/pathset.go +++ b/binary-codec/types/pathset.go @@ -4,8 +4,9 @@ import ( "errors" "fmt" - addresscodec "github.com/xyield/xrpl-go/address-codec" - "github.com/xyield/xrpl-go/binary-codec/serdes" + addresscodec "github.com/CreatureDev/xrpl-go/address-codec" + "github.com/CreatureDev/xrpl-go/binary-codec/serdes" + "github.com/CreatureDev/xrpl-go/model/transactions" ) const ( @@ -26,16 +27,20 @@ var ErrInvalidPathSet error = errors.New("invalid type to construct PathSet from // FromJson attempts to serialize a path set from a JSON representation of a slice of paths to a byte array. // It returns the byte array representation of the path set, or an error if the provided json does not represent a valid path set. func (p PathSet) FromJson(json any) ([]byte, error) { - - if _, ok := json.([]any)[0].([]any); !ok { + // var pathSet [][]transactions.PathStep + // if pathSet, ok := json.([][]transactions.PathStep); !ok { + // return nil, ErrInvalidPathSet + // } + pathSet, ok := json.([][]transactions.PathStep) + if !ok { return nil, ErrInvalidPathSet } - if !isPathSet(json.([]any)) { + if !isPathSet(pathSet) { return nil, ErrInvalidPathSet } - return newPathSet(json.([]any)), nil + return newPathSet(pathSet), nil } // ToJson decodes a path set from a binary representation using a provided binary parser, then translates it to a JSON representation. @@ -87,35 +92,35 @@ func (p PathSet) ToJson(parser *serdes.BinaryParser, opts ...int) (any, error) { // isPathSet determines if an array represents a valid path set. // It checks if the array is either empty or if its first element is a valid path step. -func isPathSet(v []any) bool { - return len(v) == 0 || len(v[0].([]any)) == 0 || isPathStep(v[0].([]any)[0].(map[string]any)) +func isPathSet(v [][]transactions.PathStep) bool { + return len(v) == 0 || len(v[0]) == 0 || isPathStep(v[0][0]) } // isPathStep determines if a map represents a valid path step. // It checks if any of the keys "account", "currency" or "issuer" are present in the map. -func isPathStep(v map[string]any) bool { - return v["account"] != nil || v["currency"] != nil || v["issuer"] != nil +func isPathStep(v transactions.PathStep) bool { + return v.Account != "" || v.Currency != "" || v.Issuer != "" } // newPathStep creates a path step from a map representation. // It generates a byte array representation of the path step, encoding account, currency, and issuer information as appropriate. -func newPathStep(v map[string]any) []byte { +func newPathStep(v transactions.PathStep) []byte { dataType := 0x00 b := make([]byte, 0) - if v["account"] != nil { - _, account, _ := addresscodec.DecodeClassicAddressToAccountID(v["account"].(string)) + if v.Account != "" { + _, account, _ := addresscodec.DecodeClassicAddressToAccountID(string(v.Account)) b = append(b, account...) dataType |= typeAccount } - if v["currency"] != nil { - currency, _ := serializeIssuedCurrencyCode(v["currency"].(string)) + if v.Currency != "" { + currency, _ := serializeIssuedCurrencyCode(v.Currency) b = append(b, currency...) dataType |= typeCurrency } - if v["issuer"] != nil { - _, issuer, _ := addresscodec.DecodeClassicAddressToAccountID(v["issuer"].(string)) + if v.Issuer != "" { + _, issuer, _ := addresscodec.DecodeClassicAddressToAccountID(string(v.Issuer)) b = append(b, issuer...) dataType |= typeIssuer } @@ -125,26 +130,26 @@ func newPathStep(v map[string]any) []byte { // newPath constructs a path from a slice of path steps. // It generates a byte array representation of the path, encoding each path step in turn. -func newPath(v []any) []byte { +func newPath(v []transactions.PathStep) []byte { b := make([]byte, 0) for _, step := range v { // for each step in the path (slice of path steps) - b = append(b, newPathStep(step.(map[string]any))...) // append the path step to the byte array + b = append(b, newPathStep(step)...) // append the path step to the byte array } return b } // newPathSet constructs a path set from a slice of paths. // It generates a byte array representation of the path set, encoding each path and adding padding and path separators as appropriate. -func newPathSet(v []any) []byte { +func newPathSet(v [][]transactions.PathStep) []byte { b := make([]byte, 0) padding := make([]byte, 20) for _, path := range v { // for each path in the path set (slice of paths) - b = append(b, newPath(path.([]any))...) // append the path to the byte array - b = append(b, padding...) // append 20 empty bytes to the byte array between paths - b = append(b, pathSeparatorByte) // between each path, append a path separator byte + b = append(b, newPath(path)...) // append the path to the byte array + b = append(b, padding...) // append 20 empty bytes to the byte array between paths + b = append(b, pathSeparatorByte) // between each path, append a path separator byte } b[len(b)-1] = pathsetEndByte // replace last path separator with path set end byte diff --git a/binary-codec/types/pathset_test.go b/binary-codec/types/pathset_test.go index ab00c418..4369a510 100644 --- a/binary-codec/types/pathset_test.go +++ b/binary-codec/types/pathset_test.go @@ -3,37 +3,38 @@ package types import ( "testing" + "github.com/CreatureDev/xrpl-go/binary-codec/serdes" + "github.com/CreatureDev/xrpl-go/model/transactions" "github.com/stretchr/testify/require" - "github.com/xyield/xrpl-go/binary-codec/serdes" ) func TestIsPathStep(t *testing.T) { tt := []struct { description string - input map[string]any + input transactions.PathStep expected bool }{ { description: "represents valid path step", - input: map[string]any{ - "account": "rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh", - "currency": "USD", - "issuer": "rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh", + input: transactions.PathStep{ + Account: "rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh", + Currency: "USD", + Issuer: "rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh", }, expected: true, }, { description: "represents valid path step", - input: map[string]any{ - "account": "rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh", - "currency": "USD", + input: transactions.PathStep{ + Account: "rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh", + Currency: "USD", }, expected: true, }, { description: "represents invalid path step", - input: map[string]any{}, + input: transactions.PathStep{}, expected: false, }, } @@ -49,15 +50,15 @@ func TestNewPathStep(t *testing.T) { tt := []struct { description string - input map[string]any + input transactions.PathStep expected []byte }{ { description: "created valid path step", - input: map[string]any{ - "account": "rDTXLQ7ZKZVKz33zJbHjgVShjsBnqMBhmN", - "currency": "USD", - "issuer": "r3Y6vCE8XqfZmYBRngy22uFYkmz3y9eCRA", + input: transactions.PathStep{ + Account: "rDTXLQ7ZKZVKz33zJbHjgVShjsBnqMBhmN", + Currency: "USD", + Issuer: "r3Y6vCE8XqfZmYBRngy22uFYkmz3y9eCRA", }, expected: []byte{0x31, 0x88, 0xa5, 0xa5, 0x7c, 0x82, 0x9f, 0x40, 0xf2, 0x5e, 0xa8, 0x33, 0x85, 0xbb, 0xde, 0x6c, 0x3d, 0x8b, 0x4c, 0xa0, 0x82, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x55, 0x53, 0x44, 0x0, 0x0, 0x0, 0x0, 0x0, 0x52, 0xc7, 0xf0, 0x1a, 0xd1, 0x3b, 0x3c, 0xa9, 0xc1, 0xd1, 0x33, 0xfa, 0x8f, 0x34, 0x82, 0xd2, 0xef, 0x8, 0xfa, 0x7d}, }, @@ -74,21 +75,21 @@ func TestNewPath(t *testing.T) { tt := []struct { description string - input []any + input []transactions.PathStep expected []byte }{ { description: "created valid path", - input: []any{ - map[string]any{ - "account": "rDTXLQ7ZKZVKz33zJbHjgVShjsBnqMBhmN", - "currency": "USD", - "issuer": "r3Y6vCE8XqfZmYBRngy22uFYkmz3y9eCRA", + input: []transactions.PathStep{ + { + Account: "rDTXLQ7ZKZVKz33zJbHjgVShjsBnqMBhmN", + Currency: "USD", + Issuer: "r3Y6vCE8XqfZmYBRngy22uFYkmz3y9eCRA", }, - map[string]any{ - "account": "rDTXLQ7ZKZVKz33zJbHjgVShjsBnqMBhmN", - "currency": "USD", - "issuer": "r3Y6vCE8XqfZmYBRngy22uFYkmz3y9eCRA", + { + Account: "rDTXLQ7ZKZVKz33zJbHjgVShjsBnqMBhmN", + Currency: "USD", + Issuer: "r3Y6vCE8XqfZmYBRngy22uFYkmz3y9eCRA", }, }, expected: []byte{0x31, 0x88, 0xa5, 0xa5, 0x7c, 0x82, 0x9f, 0x40, 0xf2, 0x5e, 0xa8, 0x33, 0x85, 0xbb, 0xde, 0x6c, 0x3d, 0x8b, 0x4c, 0xa0, 0x82, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x55, 0x53, 0x44, 0x0, 0x0, 0x0, 0x0, 0x0, 0x52, 0xc7, 0xf0, 0x1a, 0xd1, 0x3b, 0x3c, 0xa9, 0xc1, 0xd1, 0x33, 0xfa, 0x8f, 0x34, 0x82, 0xd2, 0xef, 0x8, 0xfa, 0x7d, 0x31, 0x88, 0xa5, 0xa5, 0x7c, 0x82, 0x9f, 0x40, 0xf2, 0x5e, 0xa8, 0x33, 0x85, 0xbb, 0xde, 0x6c, 0x3d, 0x8b, 0x4c, 0xa0, 0x82, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x55, 0x53, 0x44, 0x0, 0x0, 0x0, 0x0, 0x0, 0x52, 0xc7, 0xf0, 0x1a, 0xd1, 0x3b, 0x3c, 0xa9, 0xc1, 0xd1, 0x33, 0xfa, 0x8f, 0x34, 0x82, 0xd2, 0xef, 0x8, 0xfa, 0x7d}, @@ -106,46 +107,46 @@ func TestNewPath(t *testing.T) { func TestNewPathSet(t *testing.T) { tt := []struct { description string - input []any + input [][]transactions.PathStep expected []byte }{ { description: "created valid path set with multiple paths", - input: []any{ - []any{ - map[string]any{ - "account": "rDTXLQ7ZKZVKz33zJbHjgVShjsBnqMBhmN", - "currency": "USD", - "issuer": "r3Y6vCE8XqfZmYBRngy22uFYkmz3y9eCRA", + input: [][]transactions.PathStep{ + { + { + Account: "rDTXLQ7ZKZVKz33zJbHjgVShjsBnqMBhmN", + Currency: "USD", + Issuer: "r3Y6vCE8XqfZmYBRngy22uFYkmz3y9eCRA", }, - map[string]any{ - "account": "rDTXLQ7ZKZVKz33zJbHjgVShjsBnqMBhmN", - "currency": "USD", - "issuer": "r3Y6vCE8XqfZmYBRngy22uFYkmz3y9eCRA", + { + Account: "rDTXLQ7ZKZVKz33zJbHjgVShjsBnqMBhmN", + Currency: "USD", + Issuer: "r3Y6vCE8XqfZmYBRngy22uFYkmz3y9eCRA", }, }, - []any{ - map[string]any{ - "account": "rDTXLQ7ZKZVKz33zJbHjgVShjsBnqMBhmN", - "currency": "USD", - "issuer": "r3Y6vCE8XqfZmYBRngy22uFYkmz3y9eCRA", + { + { + Account: "rDTXLQ7ZKZVKz33zJbHjgVShjsBnqMBhmN", + Currency: "USD", + Issuer: "r3Y6vCE8XqfZmYBRngy22uFYkmz3y9eCRA", }, - map[string]any{ - "account": "rDTXLQ7ZKZVKz33zJbHjgVShjsBnqMBhmN", - "currency": "USD", - "issuer": "r3Y6vCE8XqfZmYBRngy22uFYkmz3y9eCRA", + { + Account: "rDTXLQ7ZKZVKz33zJbHjgVShjsBnqMBhmN", + Currency: "USD", + Issuer: "r3Y6vCE8XqfZmYBRngy22uFYkmz3y9eCRA", }, }, - []any{ - map[string]any{ - "account": "rDTXLQ7ZKZVKz33zJbHjgVShjsBnqMBhmN", - "currency": "USD", - "issuer": "r3Y6vCE8XqfZmYBRngy22uFYkmz3y9eCRA", + { + { + Account: "rDTXLQ7ZKZVKz33zJbHjgVShjsBnqMBhmN", + Currency: "USD", + Issuer: "r3Y6vCE8XqfZmYBRngy22uFYkmz3y9eCRA", }, - map[string]any{ - "account": "rDTXLQ7ZKZVKz33zJbHjgVShjsBnqMBhmN", - "currency": "USD", - "issuer": "r3Y6vCE8XqfZmYBRngy22uFYkmz3y9eCRA", + { + Account: "rDTXLQ7ZKZVKz33zJbHjgVShjsBnqMBhmN", + Currency: "USD", + Issuer: "r3Y6vCE8XqfZmYBRngy22uFYkmz3y9eCRA", }, }, }, 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 48688cc8..37613bfb 100644 --- a/binary-codec/types/st_array.go +++ b/binary-codec/types/st_array.go @@ -2,8 +2,9 @@ package types import ( "errors" + "reflect" - "github.com/xyield/xrpl-go/binary-codec/serdes" + "github.com/CreatureDev/xrpl-go/binary-codec/serdes" ) const ( @@ -22,19 +23,21 @@ var ErrNotSTObjectInSTArray = errors.New("not STObject in STArray. Array fields // of an STObject, appending the resulting byte slice to a "sink" slice. // The method returns an error if the JSON value is not a slice. func (t *STArray) FromJson(json any) ([]byte, error) { - if _, ok := json.([]any); !ok { + rv := reflect.ValueOf(json) + if rv.Kind() != reflect.Slice { return nil, ErrNotSTObjectInSTArray } - var sink []byte - for _, v := range json.([]any) { + for i := 0; i < rv.Len(); i++ { + val := rv.Index(i).Interface() st := &STObject{} - b, err := st.FromJson(v) + b, err := st.FromJson(val) if err != nil { return nil, err } sink = append(sink, b...) } + sink = append(sink, ArrayEndMarker) return sink, nil diff --git a/binary-codec/types/st_array_test.go b/binary-codec/types/st_array_test.go new file mode 100644 index 00000000..5e6d6165 --- /dev/null +++ b/binary-codec/types/st_array_test.go @@ -0,0 +1,201 @@ +package types + +import ( + "encoding/hex" + "strings" + "testing" + + "github.com/CreatureDev/xrpl-go/model/ledger" + "github.com/CreatureDev/xrpl-go/model/transactions" + "github.com/CreatureDev/xrpl-go/model/transactions/types" + "github.com/stretchr/testify/require" +) + +func TestSTArrayFromJson(t *testing.T) { + tt := []struct { + description string + input any + output string + expectedErr error + }{ + { + description: "nested stobject test", + input: []transactions.AffectedNode{ + { + DeletedNode: &transactions.DeletedNode{ + FinalFields: &ledger.DirectoryNode{ + Flags: types.SetFlag(0), + RootIndex: "036D7E923EF22B65E19D95A6365C3373E1E96586E27015074A0745621D069432", + TakerGetsCurrency: "0000000000000000000000000000000000000000", + TakerGetsIssuer: "0000000000000000000000000000000000000000", + TakerPaysCurrency: "0000000000000000000000004254430000000000", + TakerPaysIssuer: "06A148131B436B2561C85967685B098E050EED4E", + }, + LedgerEntryType: ledger.DirectoryNodeEntry, + LedgerIndex: "036D7E923EF22B65E19D95A6365C3373E1E96586E27015074A0745621D069432", + }, + }, + { + ModifiedNode: &transactions.ModifiedNode{ + FinalFields: &ledger.DirectoryNode{ + Flags: types.SetFlag(0), + Owner: "r68xfQkhFxZrbwo6RRKq728JF2fJYQRE1", + RootIndex: "5ED0913938CD6D43BD6450201737394A9991753C4581E5682D61F35048D8FBFC", + }, + LedgerEntryType: ledger.DirectoryNodeEntry, + LedgerIndex: "5ED0913938CD6D43BD6450201737394A9991753C4581E5682D61F35048D8FBFC", + }, + }, + { + DeletedNode: &transactions.DeletedNode{ + FinalFields: &ledger.Offer{ + Account: "r68xfQkhFxZrbwo6RRKq728JF2fJYQRE1", + BookDirectory: "036D7E923EF22B65E19D95A6365C3373E1E96586E27015074A0745621D069432", + BookNode: "0", + Flags: 131072, + OwnerNode: "0", + PreviousTxnID: "B21E9DC8DCB75AD12C4ACF4C72E6E822244CF6CFFD7BD738ACEED1264374B687", + PreviousTxnLgrSeq: 82010985, + Sequence: 59434311, + TakerGets: types.XRPCurrencyAmount(1166610661), + TakerPays: types.IssuedCurrencyAmount{ + Currency: "BTC", + Issuer: "rchGBxcD1A1C2tdxF6papQYZ8kjRKMYcL", + Value: "0.023876", + }, + }, + LedgerEntryType: ledger.OfferEntry, + LedgerIndex: "C171AA6003AE67B218E5EFFEF3E49CB5A4FE5A06D82C1F7EEF322B036EF76CE7", + }, + }, + { + ModifiedNode: &transactions.ModifiedNode{ + FinalFields: &ledger.AccountRoot{ + Account: "r68xfQkhFxZrbwo6RRKq728JF2fJYQRE1", + Balance: types.XRPCurrencyAmount(3310960263), + Flags: types.SetFlag(0), + MessageKey: "020000000000000000000000002B8F120A4CD1A6B236CC4389A30AB676CD722144", + OwnerCount: 8, + Sequence: 59434319, + }, + LedgerEntryType: ledger.AccountRootEntry, + LedgerIndex: "F8C1F1AE7AEF06FEFB2311232CA30A7803820A79AE65F567354629D579BB38B1", + PreviousFields: &ledger.AccountRoot{ + Balance: types.XRPCurrencyAmount(3310960413), + OwnerCount: 9, + Sequence: 59434318, + }, + PreviousTxnID: "DC99E25A951DBBF89D331428DFFE72880159C03D0A4F48EBC81A277CFFBCE683", + PreviousTxnLgrSeq: 82011654, + }, + }, + }, + output: "E411006456036D7E923EF22B65E19D95A6365C3373E1E96586E27015074A0745621D069432E7220000000058036D7E923EF22B65E19D95A6365C3373E1E96586E27015074A0745621D06943201110000000000000000000000004254430000000000021106A148131B436B2561C85967685B098E050EED4E0311000000000000000000000000000000000000000004110000000000000000000000000000000000000000E1E1E5110064565ED0913938CD6D43BD6450201737394A9991753C4581E5682D61F35048D8FBFCE72200000000585ED0913938CD6D43BD6450201737394A9991753C4581E5682D61F35048D8FBFC821407B6FEE98BBDD29F92FDFAF6107BC741C4130E8FE1E1E411006F56C171AA6003AE67B218E5EFFEF3E49CB5A4FE5A06D82C1F7EEF322B036EF76CE7E7220002000024038AE5472504E3636933000000000000000034000000000000000055B21E9DC8DCB75AD12C4ACF4C72E6E822244CF6CFFD7BD738ACEED1264374B6875010036D7E923EF22B65E19D95A6365C3373E1E96586E27015074A0745621D06943264D4087B8271DDA000000000000000000000000000425443000000000006A148131B436B2561C85967685B098E050EED4E6540000000458910E5811407B6FEE98BBDD29F92FDFAF6107BC741C4130E8FE1E1E51100612504E3660655DC99E25A951DBBF89D331428DFFE72880159C03D0A4F48EBC81A277CFFBCE68356F8C1F1AE7AEF06FEFB2311232CA30A7803820A79AE65F567354629D579BB38B1E624038AE54E2D000000096240000000C5593F1DE1E7220000000024038AE54F2D000000086240000000C5593E877221020000000000000000000000002B8F120A4CD1A6B236CC4389A30AB676CD722144811407B6FEE98BBDD29F92FDFAF6107BC741C4130E8FE1E1F1", + expectedErr: nil, + }, + } + + for _, tc := range tt { + t.Run(tc.description, func(t *testing.T) { + sa := &STArray{} + got, err := sa.FromJson(tc.input) + if tc.expectedErr != nil { + require.EqualError(t, err, tc.expectedErr.Error()) + require.Empty(t, got) + } else { + require.NoError(t, err) + require.Equal(t, tc.output, strings.ToUpper(hex.EncodeToString(got))) + } + }) + } + +} + +// func TestSTArrayToJson(t *testing.T) { +// tt := []struct { +// description string +// input string +// output map[string]any +// expectedErr error +// }{ +// { +// description: "large starray", +// input: "FAEC5A000913881D8CE533B1355B905B5C75F85B1F9A5149B94D7BABAF4475000011D9E1E010754368747470733A2F2F697066732E696F2F697066732F516D57356232715736744D3975615659376E555162774356334D63514B566E6D5659516A6A4368784E65656B476BE1F1", +// output: map[string]any{ +// "NFTokens": []any{ +// map[string]any{ +// "NFToken": map[string]any{ +// "NFTokenID": "000913881D8CE533B1355B905B5C75F85B1F9A5149B94D7BABAF4475000011D9", +// }, +// }, +// map[string]any{ +// "Signer": map[string]any{ +// "URI": "68747470733A2F2F697066732E696F2F697066732F516D57356232715736744D3975615659376E555162774356334D63514B566E6D5659516A6A4368784E65656B476B", +// }, +// }, +// }, +// }, +// expectedErr: nil, +// }, +// { +// description: "simple starray", +// input: "F9EA364A0745621D0694327D0F04C4D46544659A2D58525043686174E1E9364A0745621D0694327D0F04C4D46544659A2D58525043686174E1F1", +// output: map[string]any{ +// "Memos": []any{ +// map[string]any{ +// "Memo": map[string]any{ +// "MemoData": "04C4D46544659A2D58525043686174", +// "ExchangeRate": "4A0745621D069432", +// }, +// }, +// map[string]any{ +// "TemplateEntry": map[string]any{ +// "MemoData": "04C4D46544659A2D58525043686174", +// "ExchangeRate": "4A0745621D069432", +// }, +// }, +// }, +// }, +// }, +// { +// description: "smaller stobject test", +// input: "E51100612504E3660655DC99E25A951DBBF89D331428DFFE72880159C03D0A4F48EBC81A277CFFBCE68356F8C1F1AE7AEF06FEFB2311232CA30A7803820A79AE65F567354629D579BB38B1E624038AE54E2D000000096240000000C5593F1DE1E7220000000024038AE54F2D000000086240000000C5593E877221020000000000000000000000002B8F120A4CD1A6B236CC4389A30AB676CD722144811407B6FEE98BBDD29F92FDFAF6107BC741C4130E8FE1E1", +// output: map[string]any{ +// "ModifiedNode": map[string]any{ +// "FinalFields": map[string]any{ +// "Account": "r68xfQkhFxZrbwo6RRKq728JF2fJYQRE1", +// "Balance": "3310960263", +// "Flags": 0, +// "MessageKey": "020000000000000000000000002B8F120A4CD1A6B236CC4389A30AB676CD722144", +// "OwnerCount": 8, +// "Sequence": 59434319, +// }, +// "LedgerEntryType": "AccountRoot", +// "LedgerIndex": "F8C1F1AE7AEF06FEFB2311232CA30A7803820A79AE65F567354629D579BB38B1", +// "PreviousFields": map[string]any{ +// "Balance": "3310960413", +// "OwnerCount": 9, +// "Sequence": 59434318, +// }, +// "PreviousTxnID": "DC99E25A951DBBF89D331428DFFE72880159C03D0A4F48EBC81A277CFFBCE683", +// "PreviousTxnLgrSeq": 82011654, +// }, +// }, +// }, +// } + +// for _, tc := range tt { +// t.Run(tc.description, func(t *testing.T) { +// p := serdes.NewBinaryParser([]byte(tc.input)) +// sa := &STArray{} +// act, err := sa.ToJson(p) +// if tc.expectedErr != nil { +// require.Error(t, err, tc.expectedErr.Error()) +// require.Nil(t, act) +// } else { +// require.NoError(t, err) +// require.EqualValues(t, tc.output, act) +// } +// }) +// } +// } diff --git a/binary-codec/types/st_object.go b/binary-codec/types/st_object.go index 27dda6ea..8c7f6b64 100644 --- a/binary-codec/types/st_object.go +++ b/binary-codec/types/st_object.go @@ -1,17 +1,31 @@ package types import ( - "fmt" + "reflect" "sort" - "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" + "github.com/mitchellh/mapstructure" ) +// FieldMutation allows values to mutated before being serialized. +type FieldMutation func(any) any + +// Zero returns a FieldMutation that sets the value to its zero value. +func Zero() FieldMutation { + return func(v any) any { + return reflect.Zero(reflect.TypeOf(v)).Interface() + } +} + // STObject represents a map of serialized field instances, where each key is a field name // and the associated value is the field's value. This structure allows us to represent nested // and complex structures of the Ripple protocol. -type STObject struct{} +type STObject struct { + OnlySigning bool + Mutations map[string]FieldMutation +} // FromJson converts a JSON object into a serialized byte slice. // It works by converting the JSON object into a map of field instances (which include the field definition @@ -19,10 +33,23 @@ type STObject struct{} // This method returns an error if the JSON input is not a valid object. func (t *STObject) FromJson(json any) ([]byte, error) { s := serdes.NewSerializer() - if _, ok := json.(map[string]any); !ok { - return nil, fmt.Errorf("not a valid json node") + var m map[string]any + dec, err := mapstructure.NewDecoder(&mapstructure.DecoderConfig{TagName: "json", Result: &m, Squash: true}) + if err != nil { + return nil, err + } + err = dec.Decode(json) + if err != nil { + return nil, err + } + + for k, v := range t.Mutations { + if _, ok := m[k]; ok { + m[k] = v(m[k]) + } } - fimap, err := createFieldInstanceMapFromJson(json.(map[string]any)) + + fimap, err := createFieldInstanceMapFromJson(m) if err != nil { return nil, err @@ -31,10 +58,18 @@ func (t *STObject) FromJson(json any) ([]byte, error) { sk := getSortedKeys(fimap) for _, v := range sk { + if checkZero(fimap[v]) && !containsKey(t.Mutations, v.FieldName) { + continue + } + if !v.IsSerialized { continue } + if t.OnlySigning && !v.IsSigningField { + continue + } + st := GetSerializedType(v.Type) b, err := st.FromJson(fimap[v]) if err != nil { @@ -94,6 +129,48 @@ func (t *STObject) ToJson(p *serdes.BinaryParser, opts ...int) (any, error) { return m, nil } +// type fieldInstanceMap map[definitions.FieldInstance]any + +// func (f fieldInstanceMap) addFieldInstanceFromMap(rv reflect.Value) error { +// if rv.Kind() != reflect.Map { +// return errors.New("not of type map") +// } + +// iter := rv.MapRange() +// for iter.Next() { +// fi, err := definitions.Get().GetFieldInstanceByFieldName(iter.Key().String()) +// if err != nil { +// return err +// } +// f[*fi] = iter.Value().Interface() +// } +// return nil +// } + +// func (f fieldInstanceMap) addFieldInstanceFromStruct(rv reflect.Value) error { +// if rv.Kind() != reflect.Struct { +// return errors.New("not of type struct") +// } +// for i := 0; i < rv.NumField(); i++ { + +// rvField := rv.Type().Field(i) +// if rvField.Name == "BaseTx" { +// continue +// } +// if rv.Field(i).IsZero() { +// continue +// } +// fi, err := definitions.Get().GetFieldInstanceByFieldName(rvField.Name) + +// if err != nil { +// return err +// } + +// f[*fi] = rv.Field(i).Interface() +// } +// return nil +// } + // nolint // createFieldInstanceMapFromJson creates a map of field instances from a JSON object. // Each key-value pair in the JSON object is converted into a field instance, where the key @@ -113,6 +190,23 @@ func createFieldInstanceMapFromJson(json map[string]any) (map[definitions.FieldI m[*fi] = v } return m, nil + // rv := reflect.ValueOf(json) + // m := make(fieldInstanceMap) + // switch rv.Kind() { + // case reflect.Map: + // err := m.addFieldInstanceFromMap(rv) + // if err != nil { + // return nil, err + // } + // case reflect.Struct: + // err := m.addFieldInstanceFromStruct(rv) + // if err != nil { + // return nil, err + // } + // default: + // return nil, errors.New("not a valid json node") + // } + // return m, nil } // nolint @@ -151,3 +245,14 @@ func enumToStr(fieldType string, value any) (any, error) { return value, nil } } + +// check for zero value +func checkZero(v any) bool { + rv := reflect.ValueOf(v) + return rv.IsZero() +} + +func containsKey[T any](m map[string]T, key string) bool { + _, ok := m[key] + return ok +} diff --git a/binary-codec/types/st_object_test.go b/binary-codec/types/st_object_test.go index b6c98b83..35c98dd0 100644 --- a/binary-codec/types/st_object_test.go +++ b/binary-codec/types/st_object_test.go @@ -1,48 +1,54 @@ package types import ( - "errors" "fmt" "testing" + "github.com/CreatureDev/xrpl-go/binary-codec/definitions" + "github.com/CreatureDev/xrpl-go/model/transactions/types" "github.com/stretchr/testify/require" - "github.com/xyield/xrpl-go/binary-codec/definitions" ) func TestCreateFieldInstanceMapFromJson(t *testing.T) { tt := []struct { description string - input map[string]interface{} - output map[definitions.FieldInstance]interface{} + input map[string]any + output map[definitions.FieldInstance]any expectedErr error }{ { description: "convert valid Json", - input: map[string]interface{}{ - "Fee": "10", - "Flags": 524288, - "OfferSequence": 1752791, - "TakerGets": "150000000000", + input: map[string]any{ + "Fee": types.XRPCurrencyAmount(10), + "Flags": uint(524288), + "OfferSequence": uint(1752791), + "TakerGets": types.XRPCurrencyAmount(150000000000), }, - output: map[definitions.FieldInstance]interface{}{ - getFieldInstance(t, "Fee"): "10", - getFieldInstance(t, "Flags"): 524288, - getFieldInstance(t, "OfferSequence"): 1752791, - getFieldInstance(t, "TakerGets"): "150000000000", + output: map[definitions.FieldInstance]any{ + getFieldInstance(t, "Fee"): types.XRPCurrencyAmount(10), + getFieldInstance(t, "Flags"): uint(524288), + getFieldInstance(t, "OfferSequence"): uint(1752791), + getFieldInstance(t, "TakerGets"): types.XRPCurrencyAmount(150000000000), }, expectedErr: nil, }, - { - description: "not found error", - input: map[string]interface{}{ - "IncorrectField": 89, - "Flags": 525288, - "OfferSequence": 1752791, - }, - output: nil, - expectedErr: errors.New("FieldName IncorrectField not found"), - }, + // { + // description: "not found error", + // input: &invalidTxWithBase{ + // InvalidField: "invalid", + // }, + // output: nil, + // expectedErr: errors.New("FieldName InvalidField not found"), + // }, + // { + // description: "no base tx", + // input: &invalidTx{ + // InvalidField: "invalid", + // }, + // output: nil, + // expectedErr: errors.New("no base tx defined"), + // }, } for _, tc := range tt { @@ -53,7 +59,7 @@ func TestCreateFieldInstanceMapFromJson(t *testing.T) { require.EqualError(t, err, tc.expectedErr.Error()) } else { require.NoError(t, err) - require.Equal(t, tc.output, got) + require.EqualValues(t, tc.output, got) } }) } diff --git a/binary-codec/types/uint16.go b/binary-codec/types/uint16.go index e0ea88c3..352a44f8 100644 --- a/binary-codec/types/uint16.go +++ b/binary-codec/types/uint16.go @@ -4,8 +4,10 @@ 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" + "github.com/CreatureDev/xrpl-go/model/ledger" + "github.com/CreatureDev/xrpl-go/model/transactions" ) // UInt16 represents a 16-bit unsigned integer. @@ -15,21 +17,28 @@ type UInt16 struct{} // If the input value is a string, it's assumed to be a transaction type or ledger entry type name, and the // method will attempt to convert it into a corresponding type code. If the conversion fails, an error is returned. func (u *UInt16) FromJson(value any) ([]byte, error) { - - if _, ok := value.(string); ok { - tc, err := definitions.Get().GetTransactionTypeCodeByTransactionTypeName(value.(string)) + switch v := value.(type) { + case uint16: + value = v + case uint: + value = uint16(v) + case int: + value = uint16(v) + case transactions.TxType: + tc, err := definitions.Get().GetTransactionTypeCodeByTransactionTypeName(string(v)) + if err != nil { + return nil, err + } + value = uint16(tc) + case ledger.LedgerEntryType: + tc, err := definitions.Get().GetLedgerEntryTypeCodeByLedgerEntryTypeName(string(v)) if err != nil { - tc, err = definitions.Get().GetLedgerEntryTypeCodeByLedgerEntryTypeName(value.(string)) - if err != nil { - return nil, err - } + return nil, err } - value = int(tc) + value = uint16(tc) } - buf := new(bytes.Buffer) - err := binary.Write(buf, binary.BigEndian, uint16(value.(int))) - + err := binary.Write(buf, binary.BigEndian, value) if err != nil { return nil, err } diff --git a/binary-codec/types/uint16_test.go b/binary-codec/types/uint16_test.go new file mode 100644 index 00000000..6a2bed68 --- /dev/null +++ b/binary-codec/types/uint16_test.go @@ -0,0 +1,63 @@ +package types + +import ( + "testing" + + "github.com/CreatureDev/xrpl-go/model/ledger" + "github.com/CreatureDev/xrpl-go/model/transactions" + "github.com/stretchr/testify/require" +) + +func TestUInt16FromJson(t *testing.T) { + tt := []struct { + description string + input any + expected []byte + expectedErr error + }{ + { + description: "convert uint16", + input: uint16(1), + expected: []byte{0, 1}, + expectedErr: nil, + }, + { + description: "convert uint", + input: uint(1), + expected: []byte{0, 1}, + expectedErr: nil, + }, + { + description: "convert int", + input: int(1), + expected: []byte{0, 1}, + expectedErr: nil, + }, + { + description: "convert TxType", + input: transactions.PaymentTx, + expected: []byte{0, 0}, + expectedErr: nil, + }, + { + description: "convert LedgerEntryType", + input: ledger.AccountRootEntry, + expected: []byte{0, 97}, + expectedErr: nil, + }, + } + + for _, tc := range tt { + t.Run(tc.description, func(t *testing.T) { + u16 := &UInt16{} + got, err := u16.FromJson(tc.input) + if tc.expectedErr != nil { + require.EqualError(t, err, tc.expectedErr.Error()) + require.Empty(t, got) + } else { + require.NoError(t, err) + require.Equal(t, tc.expected, got) + } + }) + } +} diff --git a/binary-codec/types/uint32.go b/binary-codec/types/uint32.go index 28b6431e..e96c428f 100644 --- a/binary-codec/types/uint32.go +++ b/binary-codec/types/uint32.go @@ -3,18 +3,26 @@ package types import ( "bytes" "encoding/binary" + "errors" - "github.com/xyield/xrpl-go/binary-codec/serdes" + "github.com/CreatureDev/xrpl-go/binary-codec/serdes" + "github.com/CreatureDev/xrpl-go/model/transactions/types" ) +var ErrInvalidUInt32 = errors.New("invalid type for UInt32") + // UInt32 represents a 32-bit unsigned integer. type UInt32 struct{} // FromJson converts a JSON value into a serialized byte slice representing a 32-bit unsigned integer. // The input value is assumed to be an integer. If the serialization fails, an error is returned. func (u *UInt32) FromJson(value any) ([]byte, error) { + v, err := expandInt(value) + if err != nil { + return nil, err + } buf := new(bytes.Buffer) - err := binary.Write(buf, binary.BigEndian, uint32(value.(int))) + err = binary.Write(buf, binary.BigEndian, v) if err != nil { return nil, err @@ -32,3 +40,16 @@ func (u *UInt32) ToJson(p *serdes.BinaryParser, opts ...int) (any, error) { } return int(binary.BigEndian.Uint32(b)), nil } + +func expandInt(v any) (uint32, error) { + switch v := v.(type) { + case types.FlagsI: + return v.ToUint(), nil + case uint: + return uint32(v), nil + case uint32: + return v, nil + default: + return 0, ErrInvalidUInt32 + } +} diff --git a/binary-codec/types/uint32_test.go b/binary-codec/types/uint32_test.go new file mode 100644 index 00000000..d109b936 --- /dev/null +++ b/binary-codec/types/uint32_test.go @@ -0,0 +1,56 @@ +package types + +import ( + "testing" + + "github.com/CreatureDev/xrpl-go/model/transactions/types" + "github.com/stretchr/testify/require" +) + +func TestUint32FromJson(t *testing.T) { + tt := []struct { + description string + input any + expected []byte + expectedErr error + }{ + { + description: "convert uint32", + input: uint32(1), + expected: []byte{0, 0, 0, 1}, + expectedErr: nil, + }, + { + description: "convert uint", + input: uint(1), + expected: []byte{0, 0, 0, 1}, + expectedErr: nil, + }, + { + description: "convert flag", + input: types.SetFlag(1), + expected: []byte{0, 0, 0, 1}, + expectedErr: nil, + }, + { + description: "invalid type should error", + input: "invalid", + expected: nil, + expectedErr: ErrInvalidUInt32, + }, + } + + for _, tc := range tt { + t.Run(tc.description, func(t *testing.T) { + u32 := &UInt32{} + got, err := u32.FromJson(tc.input) + if tc.expectedErr != nil { + require.EqualError(t, err, tc.expectedErr.Error()) + require.Empty(t, got) + } else { + require.NoError(t, err) + require.Equal(t, tc.expected, got) + } + }) + } +} diff --git a/binary-codec/types/uint64.go b/binary-codec/types/uint64.go index 67f78b6b..659c590a 100644 --- a/binary-codec/types/uint64.go +++ b/binary-codec/types/uint64.go @@ -6,16 +6,20 @@ import ( "encoding/hex" "errors" "regexp" - "strconv" "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}$") + // UInt64 represents a 64-bit unsigned integer. type UInt64 struct{} -var ErrInvalidUInt64String error = errors.New("invalid UInt64 string, value should be a string representation of a UInt64") +var ( + ErrInvalidUInt64String error = errors.New("invalid UInt64 string, value should be hex encoded") + ErrInvalidUInt64Value error = errors.New("invalid UInt64 value, value should be an uint or a hex encoded string") +) // FromJson converts a JSON value into a serialized byte slice representing a 64-bit unsigned integer. // The input value is assumed to be a string representation of an integer. If the serialization fails, an error is returned. @@ -23,34 +27,32 @@ func (u *UInt64) FromJson(value any) ([]byte, error) { var buf = new(bytes.Buffer) - if _, ok := value.(string); !ok { - return nil, ErrInvalidUInt64String - } - - if !isNumeric(value.(string)) { - if hex, err := hex.DecodeString(value.(string)); err == nil { - buf.Write(hex) - return buf.Bytes(), nil - } - stringToUint64, err := strconv.ParseUint(value.(string), 10, 64) + switch v := value.(type) { + case uint64: + value = v + err := binary.Write(buf, binary.BigEndian, value) if err != nil { return nil, err } - value = stringToUint64 - err = binary.Write(buf, binary.BigEndian, value) + case uint: + value = uint64(v) + err := binary.Write(buf, binary.BigEndian, value) if err != nil { return nil, err } - return buf.Bytes(), nil - } else { - value = strings.Repeat("0", 16-len(value.(string))) + value.(string) // right justify the string + case string: + if !UINT64_HEX_REGEX.MatchString(v) { + return nil, ErrInvalidUInt64String + } + value = rjust(v, 16, "0") // right justify the string decoded, err := hex.DecodeString(value.(string)) if err != nil { return nil, err } buf.Write(decoded) + default: + return nil, ErrInvalidUInt64Value } - return buf.Bytes(), nil } @@ -65,8 +67,6 @@ func (u *UInt64) ToJson(p *serdes.BinaryParser, opts ...int) (any, error) { return strings.ToUpper(hex.EncodeToString(b)), nil } -// isNumeric checks if a string only contains numerical values. -func isNumeric(s string) bool { - match, _ := regexp.MatchString("^[0-9]+$", s) - return match +func rjust(s string, n int, pad string) string { + return strings.Repeat(pad, n-len(s)) + s } diff --git a/binary-codec/types/uint64_test.go b/binary-codec/types/uint64_test.go new file mode 100644 index 00000000..4dde35f3 --- /dev/null +++ b/binary-codec/types/uint64_test.go @@ -0,0 +1,67 @@ +package types + +import ( + "testing" + + "github.com/stretchr/testify/require" +) + +func TestUint64FromJson(t *testing.T) { + tt := []struct { + description string + input any + expected []byte + expectedErr error + }{ + { + description: "convert uint64", + input: uint64(1), + expected: []byte{0, 0, 0, 0, 0, 0, 0, 1}, + expectedErr: nil, + }, + { + description: "convert uint", + input: uint(1), + expected: []byte{0, 0, 0, 0, 0, 0, 0, 1}, + expectedErr: nil, + }, + { + description: "convert hex encoded string", + input: "0000000000000001", + expected: []byte{0, 0, 0, 0, 0, 0, 0, 1}, + expectedErr: nil, + }, + { + description: "convert short hex encoded string", + input: "10", + expected: []byte{0, 0, 0, 0, 0, 0, 0, 16}, + expectedErr: nil, + }, + { + description: "invalid string should error", + input: "invalid", + expected: nil, + expectedErr: ErrInvalidUInt64String, + }, + { + description: "invalid type should error", + input: -54, + expected: nil, + expectedErr: ErrInvalidUInt64Value, + }, + } + + for _, tc := range tt { + t.Run(tc.description, func(t *testing.T) { + u64 := &UInt64{} + got, err := u64.FromJson(tc.input) + if tc.expectedErr != nil { + require.EqualError(t, err, tc.expectedErr.Error()) + require.Empty(t, got) + } else { + require.NoError(t, err) + require.Equal(t, tc.expected, got) + } + }) + } +} diff --git a/binary-codec/types/uint8.go b/binary-codec/types/uint8.go index 3c69c663..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. @@ -15,25 +15,25 @@ type UInt8 struct{} // If the input value is a string, it's assumed to be a transaction result name, and the method will // attempt to convert it into a transaction result type code. If the conversion fails, an error is returned. func (u *UInt8) FromJson(value any) ([]byte, error) { - if s, ok := value.(string); ok { - tc, err := definitions.Get().GetTransactionResultTypeCodeByTransactionResultName(s) + var u8 uint8 + + switch v := value.(type) { + case string: + tc, err := definitions.Get().GetTransactionResultTypeCodeByTransactionResultName(v) if err != nil { return nil, err } - value = tc - } - - var intValue int - - switch v := value.(type) { + u8 = uint8(tc) + case uint8: + u8 = v case int: - intValue = v + u8 = uint8(v) case int32: - intValue = int(v) + u8 = uint8(v) } buf := new(bytes.Buffer) - err := binary.Write(buf, binary.BigEndian, uint8(intValue)) + err := binary.Write(buf, binary.BigEndian, u8) if err != nil { return nil, err } diff --git a/binary-codec/types/uint8_test.go b/binary-codec/types/uint8_test.go new file mode 100644 index 00000000..72e8a16a --- /dev/null +++ b/binary-codec/types/uint8_test.go @@ -0,0 +1,56 @@ +package types + +import ( + "testing" + + "github.com/CreatureDev/xrpl-go/binary-codec/definitions" + "github.com/stretchr/testify/require" +) + +func TestUint8FromJson(t *testing.T) { + tt := []struct { + description string + input any + expected []byte + expectedErr error + }{ + { + description: "find transaction code", + input: "tecAMM_ACCOUNT", + expected: []byte{168}, + expectedErr: nil, + }, + { + description: "regular uint8", + input: uint8(30), + expected: []byte{30}, + expectedErr: nil, + }, + { + description: "regular int", + input: int(30), + expected: []byte{30}, + expectedErr: nil, + }, + { + description: "invalid transaction result", + input: "invalid", + expected: nil, + expectedErr: &definitions.NotFoundError{Instance: "TransactionResultName", Input: "invalid"}, + }, + } + + for _, tc := range tt { + t.Run(tc.description, func(t *testing.T) { + u8 := &UInt8{} + got, err := u8.FromJson(tc.input) + if tc.expectedErr != nil { + require.EqualError(t, err, tc.expectedErr.Error()) + require.Empty(t, got) + } else { + require.NoError(t, err) + require.Equal(t, tc.expected, got) + } + }) + } +} diff --git a/binary-codec/types/vector256.go b/binary-codec/types/vector256.go index 4dd41caf..aba60bd7 100644 --- a/binary-codec/types/vector256.go +++ b/binary-codec/types/vector256.go @@ -5,7 +5,8 @@ import ( "fmt" "strings" - "github.com/xyield/xrpl-go/binary-codec/serdes" + "github.com/CreatureDev/xrpl-go/binary-codec/serdes" + "github.com/CreatureDev/xrpl-go/model/transactions/types" ) const HashLengthBytes = 32 @@ -27,18 +28,18 @@ type Vector256 struct{} // The input value is assumed to be an array of strings representing Hash256 values. // If the serialization fails, an error is returned. func (v *Vector256) FromJson(json any) ([]byte, error) { - - if _, ok := json.([]string); !ok { + switch json := json.(type) { + case []string: + return vector256FromValue(json) + case []types.Hash256: + var values []string + for _, hash := range json { + values = append(values, string(hash)) + } + return vector256FromValue([]string(values)) + default: return nil, &ErrInvalidVector256Type{fmt.Sprintf("%T", json)} } - - b, err := vector256FromValue(json.([]string)) - - if err != nil { - return nil, err - } - - return b, nil } // vector256FromValue takes a slice of strings representing Hash256 values, 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..15a4eab4 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 } @@ -111,7 +112,7 @@ func (c *JsonRpcClient) SendRequest(reqParams client.XRPLRequest) (client.XRPLRe var jr jsonrpcmodels.JsonRpcResponse jr, err = CheckForError(response) if err != nil { - return nil, err + return &jr, err } return &jr, nil @@ -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..3e63ef98 --- /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, res, err + } + var sr transactions.SubmitResponse + err = res.GetResult(&sr) + if err != nil { + return nil, res, 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 d209f8f0..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) { @@ -35,7 +36,7 @@ func TestAccountInfoResponse(t *testing.T) { AccountData: ledger.AccountRoot{ Account: "rG1QQv2nh2gr7RCZ1P8YYcBUKCCN633jCn", Balance: types.XRPCurrencyAmount(999999999960), - Flags: 8388608, + Flags: types.SetFlag(8388608), LedgerEntryType: ledger.AccountRootEntry, OwnerCount: 0, PreviousTxnID: "4294BEBE5B569A18C0A2702387C9B1E7146DC3A5850C1E87204951C6FDAA4C42", @@ -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 d8c5c1a0..850fcefb 100644 --- a/model/client/account/account_lines_response.go +++ b/model/client/account/account_lines_response.go @@ -1,11 +1,11 @@ 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 AccountLinesReponse struct { +type AccountLinesResponse struct { Account types.Address `json:"account"` Lines []TrustLine `json:"lines"` LedgerCurrentIndex common.LedgerIndex `json:"ledger_current_index,omitempty"` diff --git a/model/client/account/account_lines_test.go b/model/client/account/account_lines_test.go index 19fafafa..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) { @@ -34,7 +35,7 @@ func TestAccountLinesRequest(t *testing.T) { } func TestAccountLinesResponse(t *testing.T) { - s := AccountLinesReponse{ + s := AccountLinesResponse{ Account: "rLHmBn4fT92w4F6ViyYbjoizLTo83tHTHu", Lines: []TrustLine{ { @@ -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 f419d950..3c1bdbec 100644 --- a/model/client/account/offer_result.go +++ b/model/client/account/offer_result.go @@ -3,14 +3,18 @@ package account import ( "encoding/json" - "github.com/xyield/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/model/transactions/types" ) -type OfferResultFlags uint +type OfferResultFlags uint32 + +func (f OfferResultFlags) ToUint() uint32 { + return uint32(f) +} type OfferResult struct { Flags OfferResultFlags `json:"flags"` - Sequence uint `json:"seq"` + Sequence uint32 `json:"seq"` TakerGets types.CurrencyAmount `json:"taker_gets"` TakerPays types.CurrencyAmount `json:"taker_pays"` Quality string `json:"quality"` @@ -20,7 +24,7 @@ type OfferResult struct { func (r *OfferResult) UnmarshalJSON(data []byte) error { type orHelper struct { Flags OfferResultFlags `json:"flags"` - Sequence uint `json:"seq"` + Sequence uint32 `json:"seq"` TakerGets json.RawMessage `json:"taker_gets"` TakerPays json.RawMessage `json:"taker_pays"` Quality string `json:"quality"` diff --git a/model/client/account/queue_data.go b/model/client/account/queue_data.go index 8c6cb28a..123267fe 100644 --- a/model/client/account/queue_data.go +++ b/model/client/account/queue_data.go @@ -1,12 +1,12 @@ 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"` AuthChangeQueued bool `json:"auth_change_queued,omitempty"` - LowestSequence uint64 `json:"lowest_sequence,omitempty"` - HighestSequence uint64 `json:"highest_sequence,omitempty"` + LowestSequence uint32 `json:"lowest_sequence,omitempty"` + HighestSequence uint32 `json:"highest_sequence,omitempty"` MaxSpendDropsTotal types.XRPCurrencyAmount `json:"max_spend_drops_total,omitempty"` Transactions []QueueTransaction `json:"transactions,omitempty"` } 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 dc1799d9..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) { @@ -17,7 +17,7 @@ func TestSignForRequest(t *testing.T) { BaseTx: transactions.BaseTx{ TransactionType: transactions.TrustSetTx, Account: "rEuLyBCvcw4CFmzv8RepSiAoNgF8tTGJQC", - Flags: 262144, + Flags: types.SetFlag(262144), Sequence: 2, Fee: types.XRPCurrencyAmount(30000), }, @@ -60,7 +60,7 @@ func TestSignForResponse(t *testing.T) { TransactionType: transactions.TrustSetTx, Fee: types.XRPCurrencyAmount(30000), Sequence: 2, - Flags: 262144, + Flags: types.SetFlag(262144), Signers: []transactions.Signer{ { SignerData: transactions.SignerData{ 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 ecfff3a8..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) { @@ -55,7 +55,7 @@ func TestSignResponse(t *testing.T) { TransactionType: transactions.TrustSetTx, Fee: types.XRPCurrencyAmount(30000), Sequence: 2, - Flags: 262144, + Flags: types.SetFlag(262144), Signers: []transactions.Signer{ { SignerData: transactions.SignerData{ 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 0583b610..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 { @@ -14,6 +14,6 @@ type NFTInfoResponse struct { TransferFee uint `json:"transfer_fee"` Issuer types.Address `json:"issuer"` NFTokenTaxon uint `json:"nft_taxon"` - NFTokenSequence uint `json:"nft_sequence"` + NFTokenSequence uint32 `json:"nft_sequence"` URI types.NFTokenURI `json:"uri,omitempty"` } 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 a7c213f7..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) { @@ -36,6 +36,7 @@ func TestLedgerDataResponse(t *testing.T) { Account: "rKKzk9ghA2iuy3imqMXUHJqdRPMtNDGf4c", Balance: types.XRPCurrencyAmount(893730848), LedgerEntryType: ledger.AccountRootEntry, + Flags: types.SetFlag(0), PreviousTxnID: "C204A65CF2542946289A3358C67D991B5E135FABFA89F271DBA7A150C08CA046", PreviousTxnLgrSeq: 6487716, Sequence: 1, 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 aaefa667..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) { @@ -37,7 +38,7 @@ func TestLedgerEntryResponse(t *testing.T) { Balance: types.XRPCurrencyAmount(424021949), Domain: "6D64756F31332E636F6D", EmailHash: "98B4375E1D753E5B91627516F6D70977", - Flags: 9568256, + Flags: types.SetFlag(9568256), LedgerEntryType: ledger.AccountRootEntry, MessageKey: "0000000000000000000000070000000300", OwnerCount: 12, @@ -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 2e620eb6..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) { @@ -22,7 +22,7 @@ func TestSubmitMultisignedRequest(t *testing.T) { TransactionType: "Payment", Fee: types.XRPCurrencyAmount(10000), Sequence: 360, - Flags: 2147483648, + Flags: types.SetFlag(2147483648), SigningPubKey: "03AB40A0490F9B7ED8DF29D246BF2D6269820A0EE7742ACDD457BEA7C7D0931EDB", TxnSignature: "304402200E5C2DD81FDF0BE9AB2A8D797885ED49E804DBF28E806604D878756410CA98B102203349581946B0DDA06B36B35DBC20EDA27552C1F167BCF5C6ECFF49C6A46F8580", Signers: []transactions.Signer{ @@ -104,7 +104,7 @@ func TestSubmitMultisignedResponse(t *testing.T) { TransactionType: "Payment", Fee: types.XRPCurrencyAmount(10000), Sequence: 360, - Flags: 2147483648, + Flags: types.SetFlag(2147483648), SigningPubKey: "03AB40A0490F9B7ED8DF29D246BF2D6269820A0EE7742ACDD457BEA7C7D0931EDB", TxnSignature: "304402200E5C2DD81FDF0BE9AB2A8D797885ED49E804DBF28E806604D878756410CA98B102203349581946B0DDA06B36B35DBC20EDA27552C1F167BCF5C6ECFF49C6A46F8580", Signers: []transactions.Signer{ 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 29b92140..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 { @@ -14,8 +14,8 @@ type SubmitResponse struct { TxBlob string `json:"tx_blob"` Tx transactions.Tx `json:"tx_json"` Accepted bool `json:"accepted"` - AccountSequenceAvailable uint `json:"account_sequence_available"` - AccountSequenceNext uint `json:"account_sequence_next"` + AccountSequenceAvailable uint32 `json:"account_sequence_available"` + AccountSequenceNext uint32 `json:"account_sequence_next"` Applied bool `json:"applied"` Broadcast bool `json:"broadcast"` Kept bool `json:"kept"` @@ -32,8 +32,8 @@ func (r *SubmitResponse) UnmarshalJSON(data []byte) error { TxBlob string `json:"tx_blob"` Tx json.RawMessage `json:"tx_json"` Accepted bool `json:"accepted"` - AccountSequenceAvailable uint `json:"account_sequence_available"` - AccountSequenceNext uint `json:"account_sequence_next"` + AccountSequenceAvailable uint32 `json:"account_sequence_available"` + AccountSequenceNext uint32 `json:"account_sequence_next"` Applied bool `json:"applied"` Broadcast bool `json:"broadcast"` Kept bool `json:"kept"` diff --git a/model/client/transactions/submit_test.go b/model/client/transactions/submit_test.go index 0a22ad33..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) { @@ -48,7 +48,7 @@ func TestSubmitResponse(t *testing.T) { TransactionType: "Payment", Fee: types.XRPCurrencyAmount(10000), Sequence: 360, - Flags: 2147483648, + Flags: types.SetFlag(2147483648), SigningPubKey: "03AB40A0490F9B7ED8DF29D246BF2D6269820A0EE7742ACDD457BEA7C7D0931EDB", TxnSignature: "304402200E5C2DD81FDF0BE9AB2A8D797885ED49E804DBF28E806604D878756410CA98B102203349581946B0DDA06B36B35DBC20EDA27552C1F167BCF5C6ECFF49C6A46F8580", }, 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 ef928393..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) { @@ -18,7 +18,7 @@ func TestTxResponse(t *testing.T) { TransactionType: transactions.OfferCreateTx, Account: "rhhh49pFH96roGyuC4E5P4CHaNjS1k8gzM", Fee: types.XRPCurrencyAmount(12), - Flags: 0, + Flags: types.SetFlag(0), LastLedgerSequence: 56865248, Sequence: 5037710, SigningPubKey: "03B51A3EDF70E4098DA7FB053A01C5A6A0A163A30ED1445F14F87C7C3295FCB3BE", @@ -41,7 +41,7 @@ func TestTxResponse(t *testing.T) { { ModifiedNode: &transactions.ModifiedNode{ FinalFields: &ledger.DirectoryNode{ - Flags: 0, + Flags: types.SetFlag(0), RootIndex: "02BAAC1E67C1CE0E96F0FA2E8061020536CEDD043FEB0FF54F04C66806CF7400", TakerGetsCurrency: "0000000000000000000000000000000000000000", TakerGetsIssuer: "0000000000000000000000000000000000000000", @@ -57,7 +57,7 @@ func TestTxResponse(t *testing.T) { FinalFields: &ledger.AccountRoot{ Account: "rhhh49pFH96roGyuC4E5P4CHaNjS1k8gzM", Balance: types.XRPCurrencyAmount(10404767991), - Flags: 0, + Flags: types.SetFlag(0), OwnerCount: 3, Sequence: 5037711, }, @@ -96,7 +96,7 @@ func TestTxResponse(t *testing.T) { { ModifiedNode: &transactions.ModifiedNode{ FinalFields: &ledger.DirectoryNode{ - Flags: 0, + Flags: types.SetFlag(0), IndexNext: "0000000000000000", IndexPrevious: "0000000000000000", Owner: "rhhh49pFH96roGyuC4E5P4CHaNjS1k8gzM", 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 0e5f4020..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 { @@ -11,16 +11,16 @@ type AccountRoot struct { BurnedNFTokens uint32 `json:",omitempty"` Domain string `json:",omitempty"` EmailHash types.Hash128 `json:",omitempty"` - Flags uint64 + Flags *types.Flag LedgerEntryType LedgerEntryType MessageKey string `json:",omitempty"` MintedNFTokens uint32 `json:",omitempty"` NFTokenMinter types.Address `json:",omitempty"` - OwnerCount uint64 + OwnerCount uint32 PreviousTxnID types.Hash256 - PreviousTxnLgrSeq uint64 + PreviousTxnLgrSeq uint32 RegularKey types.Address `json:",omitempty"` - Sequence uint64 + Sequence uint32 TicketCount uint32 `json:",omitempty"` TickSize uint8 `json:",omitempty"` TransferRate uint32 `json:",omitempty"` diff --git a/model/ledger/account_root_test.go b/model/ledger/account_root_test.go index 9e45bcf8..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) { @@ -14,7 +14,7 @@ func TestAccountRoot(t *testing.T) { Balance: types.XRPCurrencyAmount(148446663), Domain: "6D64756F31332E636F6D", EmailHash: "98B4375E1D753E5B91627516F6D70977", - Flags: 8388608, + Flags: types.SetFlag(8388608), LedgerEntryType: AccountRootEntry, MessageKey: "0000000000000000000000070000000300", OwnerCount: 3, diff --git a/model/ledger/amendments.go b/model/ledger/amendments.go index 7fb94cbf..62779b2b 100644 --- a/model/ledger/amendments.go +++ b/model/ledger/amendments.go @@ -1,12 +1,12 @@ package ledger import ( - "github.com/xyield/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/model/transactions/types" ) type Amendments struct { Amendments []types.Hash256 `json:",omitempty"` - Flags uint + Flags uint32 LedgerEntryType LedgerEntryType Majorities []MajorityEntry `json:",omitempty"` } 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 719a498c..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 { @@ -9,7 +9,7 @@ type Check struct { DestinationNode string `json:",omitempty"` DestinationTag uint `json:",omitempty"` Expiration uint `json:",omitempty"` - Flags uint + Flags uint32 InvoiceID types.Hash256 `json:",omitempty"` LedgerEntryType LedgerEntryType OwnerNode string 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 7306202a..45f9e22d 100644 --- a/model/ledger/deposit_preauth.go +++ b/model/ledger/deposit_preauth.go @@ -1,17 +1,17 @@ package ledger import ( - "github.com/xyield/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/model/transactions/types" ) type DepositPreauthObj struct { Account types.Address Authorize types.Address - Flags uint + Flags uint32 LedgerEntryType LedgerEntryType OwnerNode string PreviousTxnID types.Hash256 - PreviousTxnLgrSeq uint + PreviousTxnLgrSeq uint32 } func (*DepositPreauthObj) EntryType() LedgerEntryType { 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 dcd8037c..bfc7d1d9 100644 --- a/model/ledger/directory_node.go +++ b/model/ledger/directory_node.go @@ -1,11 +1,11 @@ package ledger import ( - "github.com/xyield/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/model/transactions/types" ) type DirectoryNode struct { - Flags uint + Flags *types.Flag Indexes []types.Hash256 IndexNext string `json:",omitempty"` IndexPrevious string `json:",omitempty"` diff --git a/model/ledger/directory_node_test.go b/model/ledger/directory_node_test.go index 056af295..a2d96314 100644 --- a/model/ledger/directory_node_test.go +++ b/model/ledger/directory_node_test.go @@ -3,13 +3,13 @@ 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) { var s LedgerObject = &DirectoryNode{ - Flags: 0, + Flags: types.SetFlag(0), Indexes: []types.Hash256{ "AD7EAE148287EF12D213A251015F86E6D4BD34B3C4A0A1ED9A17198373F908AD", }, @@ -41,7 +41,7 @@ func TestOfferDirectoryNode(t *testing.T) { func TestOwnerDirectoryNode(t *testing.T) { var s LedgerObject = &DirectoryNode{ - Flags: 0, + Flags: types.SetFlag(0), Indexes: []types.Hash256{ "AD7EAE148287EF12D213A251015F86E6D4BD34B3C4A0A1ED9A17198373F908AD", "E83BBB58949A8303DF07172B16FB8EFBA66B9191F3836EC27A4568ED5997BAC5", diff --git a/model/ledger/escrow.go b/model/ledger/escrow.go index 97db6d60..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 { @@ -13,11 +13,11 @@ type Escrow struct { DestinationNode string `json:",omitempty"` DestinationTag uint `json:",omitempty"` FinishAfter uint `json:",omitempty"` - Flags uint + Flags uint32 LedgerEntryType LedgerEntryType OwnerNode string PreviousTxnID types.Hash256 - PreviousTxnLgrSeq uint + PreviousTxnLgrSeq uint32 SourceTag uint `json:",omitempty"` } 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.go b/model/ledger/fee_settings.go index ea0b58e5..0e63c36d 100644 --- a/model/ledger/fee_settings.go +++ b/model/ledger/fee_settings.go @@ -2,7 +2,7 @@ package ledger type FeeSettings struct { BaseFee string - Flags uint + Flags uint32 LedgerEntryType LedgerEntryType ReferenceFeeUnits uint ReserveBase uint 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 c1428c81..c00dd264 100644 --- a/model/ledger/ledger_hashes.go +++ b/model/ledger/ledger_hashes.go @@ -1,12 +1,12 @@ package ledger -import "github.com/xyield/xrpl-go/model/transactions/types" +import "github.com/CreatureDev/xrpl-go/model/transactions/types" type LedgerHashes struct { - FirstLedgerSequence uint - Flags uint + FirstLedgerSequence uint32 + Flags uint32 Hashes []types.Hash256 - LastLedgerSequence uint + LastLedgerSequence uint32 LedgerEntryType LedgerEntryType } 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.go b/model/ledger/negative_unl.go index 07a1b5d0..c02e2726 100644 --- a/model/ledger/negative_unl.go +++ b/model/ledger/negative_unl.go @@ -2,7 +2,7 @@ package ledger type NegativeUNL struct { DisabledValidators []DisabledValidatorEntry `json:",omitempty"` - Flags uint + Flags uint32 LedgerEntryType LedgerEntryType ValidatorToDisable string `json:",omitempty"` ValidatorToReEnable string `json:",omitempty"` @@ -17,6 +17,6 @@ type DisabledValidatorEntry struct { } type DisabledValidator struct { - FirstLedgerSequence uint + FirstLedgerSequence uint32 PublicKey string } 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 41e673e3..fbb8bfcf 100644 --- a/model/ledger/nftoken_offer.go +++ b/model/ledger/nftoken_offer.go @@ -3,21 +3,21 @@ package ledger import ( "encoding/json" - "github.com/xyield/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/model/transactions/types" ) type NFTokenOffer struct { Amount types.CurrencyAmount Destination types.Address `json:",omitempty"` Expiration uint `json:",omitempty"` - Flags uint + Flags uint32 LedgerEntryType LedgerEntryType NFTokenID types.Hash256 NFTokenOfferNode string `json:",omitempty"` Owner types.Address OwnerNode string `json:",omitempty"` PreviousTxnID types.Hash256 - PreviousTxnLgrSeq uint + PreviousTxnLgrSeq uint32 } func (*NFTokenOffer) EntryType() LedgerEntryType { @@ -30,14 +30,14 @@ func (n *NFTokenOffer) UnmarshalJSON(data []byte) error { Amount json.RawMessage Destination types.Address Expiration uint - Flags uint + Flags uint32 LedgerEntryType LedgerEntryType NFTokenID types.Hash256 NFTokenOfferNode string Owner types.Address OwnerNode string PreviousTxnID types.Hash256 - PreviousTxnLgrSeq uint + PreviousTxnLgrSeq uint32 } var h nftHelper if err := json.Unmarshal(data, &h); err != nil { 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 34f4e437..ea603dc4 100644 --- a/model/ledger/nftoken_page.go +++ b/model/ledger/nftoken_page.go @@ -1,13 +1,13 @@ 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 NextPageMin types.Hash256 `json:",omitempty"` PreviousPageMin types.Hash256 `json:",omitempty"` PreviousTxnID types.Hash256 `json:",omitempty"` - PreviousTxnLgrSeq uint `json:",omitempty"` + PreviousTxnLgrSeq uint32 `json:",omitempty"` NFTokens []types.NFToken } 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 15823ecc..7c068f89 100644 --- a/model/ledger/offer.go +++ b/model/ledger/offer.go @@ -3,10 +3,14 @@ package ledger import ( "encoding/json" - "github.com/xyield/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/model/transactions/types" ) -type OfferFlags uint +type OfferFlags uint32 + +func (f OfferFlags) ToUint() uint32 { + return uint32(f) +} const ( PassiveOffer OfferFlags = 0x00010000 @@ -19,11 +23,11 @@ type Offer struct { BookNode string Expiration uint `json:",omitempty"` Flags OfferFlags - LedgerEntryType LedgerEntryType + LedgerEntryType LedgerEntryType `json:",omitempty"` OwnerNode string PreviousTxnID types.Hash256 - PreviousTxnLgrSeq uint - Sequence uint + PreviousTxnLgrSeq uint32 + Sequence uint32 TakerPays types.CurrencyAmount TakerGets types.CurrencyAmount } @@ -42,8 +46,8 @@ func (o *Offer) UnmarshalJSON(data []byte) error { LedgerEntryType LedgerEntryType OwnerNode string PreviousTxnID types.Hash256 - PreviousTxnLgrSeq uint - Sequence uint + PreviousTxnLgrSeq uint32 + Sequence uint32 TakerPays json.RawMessage TakerGets json.RawMessage } 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 1c4cc98a..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 @@ -11,11 +11,11 @@ type PayChannel struct { DestinationTag uint `json:",omitempty"` DestinationNode string `json:",omitempty"` Expiration uint `json:",omitempty"` - Flags uint + Flags uint32 LedgerEntryType LedgerEntryType OwnerNode string PreviousTxnID types.Hash256 - PreviousTxnLgrSeq uint + PreviousTxnLgrSeq uint32 PublicKey string SettleDelay uint SourceTag uint `json:",omitempty"` 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 ad9816bd..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 @@ -17,7 +17,7 @@ type RippleState struct { LowQualityIn uint `json:",omitempty"` LowQualityOut uint `json:",omitempty"` PreviousTxnID types.Hash256 - PreviousTxnLgrSeq uint + PreviousTxnLgrSeq uint32 } func (*RippleState) EntryType() LedgerEntryType { 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 a6cdf4c6..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 @@ -8,15 +8,19 @@ const ( LsfOneOwnerCount SignerListFlags = 0x00010000 ) +func (f SignerListFlags) ToUint() uint32 { + return uint32(f) +} + type SignerList struct { LedgerEntryType LedgerEntryType Flags SignerListFlags PreviousTxnID string - PreviousTxnLgrSeq uint64 + PreviousTxnLgrSeq uint32 OwnerNode string SignerEntries []SignerEntryWrapper - SignerListID uint64 - SignerQuorum uint64 + SignerListID uint32 + SignerQuorum uint32 } type SignerEntryWrapper struct { @@ -25,7 +29,7 @@ type SignerEntryWrapper struct { type SignerEntry struct { Account types.Address - SignerWeight uint64 + SignerWeight uint16 WalletLocator types.Hash256 `json:",omitempty"` } 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 5f684c0c..770515c4 100644 --- a/model/ledger/ticket.go +++ b/model/ledger/ticket.go @@ -1,15 +1,15 @@ 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 - Flags uint + Flags uint32 LedgerEntryType LedgerEntryType OwnerNode string PreviousTxnID types.Hash256 - PreviousTxnLgrSeq uint - TicketSequence uint + PreviousTxnLgrSeq uint32 + TicketSequence uint32 } func (*Ticket) EntryType() LedgerEntryType { 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 90498d34..91ef1afe 100644 --- a/model/transactions/account_set.go +++ b/model/transactions/account_set.go @@ -1,21 +1,21 @@ package transactions import ( - "github.com/xyield/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/model/transactions/types" ) type AccountSet struct { BaseTx - ClearFlag uint `json:",omitempty"` + ClearFlag uint32 `json:",omitempty"` Domain string `json:",omitempty"` EmailHash types.Hash128 `json:",omitempty"` MessageKey string `json:",omitempty"` NFTokenMinter string `json:",omitempty"` - SetFlag uint `json:",omitempty"` + SetFlag uint32 `json:",omitempty"` TransferRate uint `json:",omitempty"` TickSize uint8 `json:",omitempty"` WalletLocator types.Hash256 `json:",omitempty"` - WalletSize uint `json:",omitempty"` + WalletSize uint32 `json:",omitempty"` } func (*AccountSet) TxType() TxType { 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 42e0c8d4..bc37de93 100644 --- a/model/transactions/escrow_cancel.go +++ b/model/transactions/escrow_cancel.go @@ -1,13 +1,13 @@ package transactions import ( - "github.com/xyield/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/model/transactions/types" ) type EscrowCancel struct { BaseTx Owner types.Address - OfferSequence uint + OfferSequence uint32 } func (*EscrowCancel) TxType() TxType { 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 734efd65..720d2b29 100644 --- a/model/transactions/escrow_finish.go +++ b/model/transactions/escrow_finish.go @@ -1,13 +1,13 @@ package transactions import ( - "github.com/xyield/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/model/transactions/types" ) type EscrowFinish struct { - BaseTx + BaseTx `mapstructure:",squash"` Owner types.Address - OfferSequence uint + OfferSequence uint32 Condition string `json:",omitempty"` Fulfillment string `json:",omitempty"` } 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 773a07ec..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) { @@ -14,7 +14,7 @@ func TestNFTokenCreateOfferTx(t *testing.T) { BaseTx: BaseTx{ Account: "rs8jBmmfpwgmrSPgwMsh7CvKRmRt1JTVSX", TransactionType: NFTokenCreateOfferTx, - Flags: 1, + Flags: types.SetFlag(1), }, NFTokenID: "000100001E962F495F07A990F4ED55ACCFEEF365DBAA76B6A048C0A200000007", Amount: types.XRPCurrencyAmount(1000000), 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 e214f5db..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) { @@ -15,7 +15,7 @@ func TestNFTokenMintTx(t *testing.T) { Account: "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B", TransactionType: NFTokenMintTx, Fee: types.XRPCurrencyAmount(10), - Flags: 8, + Flags: types.SetFlag(8), Memos: []MemoWrapper{ { Memo: Memo{ diff --git a/model/transactions/offer_cancel.go b/model/transactions/offer_cancel.go index db5fb80c..8068ce15 100644 --- a/model/transactions/offer_cancel.go +++ b/model/transactions/offer_cancel.go @@ -2,7 +2,7 @@ package transactions type OfferCancel struct { BaseTx - OfferSequence uint + OfferSequence uint32 } func (*OfferCancel) TxType() TxType { 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 0a5d813c..81edfa39 100644 --- a/model/transactions/offer_create.go +++ b/model/transactions/offer_create.go @@ -3,13 +3,13 @@ package transactions import ( "encoding/json" - "github.com/xyield/xrpl-go/model/transactions/types" + "github.com/CreatureDev/xrpl-go/model/transactions/types" ) type OfferCreate struct { BaseTx - Expiration uint `json:",omitempty"` - OfferSequence uint `json:",omitempty"` + Expiration uint `json:",omitempty"` + OfferSequence uint32 `json:",omitempty"` TakerGets types.CurrencyAmount TakerPays types.CurrencyAmount } @@ -21,8 +21,8 @@ func (*OfferCreate) TxType() TxType { func (o *OfferCreate) UnmarshalJSON(data []byte) error { type ocHelper struct { BaseTx - Expiration uint `json:",omitempty"` - OfferSequence uint `json:",omitempty"` + Expiration uint `json:",omitempty"` + OfferSequence uint32 `json:",omitempty"` TakerGets json.RawMessage TakerPays json.RawMessage } 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 af513448..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) { @@ -15,7 +15,7 @@ func TestPaymentTx(t *testing.T) { Account: "abc", TransactionType: PaymentTx, Fee: types.XRPCurrencyAmount(1000), - Flags: 262144, + Flags: types.SetFlag(262144), }, Amount: types.IssuedCurrencyAmount{ Issuer: "def", 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 a03d2d6d..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 { @@ -125,7 +125,7 @@ type ModifiedNode struct { FinalFields ledger.LedgerObject `json:"FinalFields,omitempty"` PreviousFields ledger.LedgerObject `json:"PreviousFields,omitempty"` PreviousTxnID string `json:"PreviousTxnID,omitempty"` - PreviousTxnLgrSeq uint64 `json:"PreviousTxnLgrSeq,omitempty"` + PreviousTxnLgrSeq uint32 `json:"PreviousTxnLgrSeq,omitempty"` } func (n *ModifiedNode) UnmarshalJSON(data []byte) error { @@ -135,7 +135,7 @@ func (n *ModifiedNode) UnmarshalJSON(data []byte) error { FinalFields json.RawMessage PreviousFields json.RawMessage PreviousTxnID string - PreviousTxnLgrSeq uint64 + PreviousTxnLgrSeq uint32 } err := json.Unmarshal(data, &h) if err != nil { 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 82f74931..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) { @@ -15,7 +15,7 @@ func TestTrustSetTx(t *testing.T) { Account: "ra5nK24KXen9AHvsdFTKHSANinZseWnPcX", TransactionType: TrustSetTx, Fee: types.XRPCurrencyAmount(12), - Flags: 262144, + Flags: types.SetFlag(262144), Sequence: 12, LastLedgerSequence: 8007750, }, diff --git a/model/transactions/tx.go b/model/transactions/tx.go index 590e937e..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 { @@ -29,15 +29,15 @@ type BaseTx struct { Account types.Address TransactionType TxType Fee types.XRPCurrencyAmount `json:",omitempty"` - Sequence uint `json:",omitempty"` + Sequence uint32 `json:",omitempty"` AccountTxnID types.Hash256 `json:",omitempty"` - Flags uint `json:",omitempty"` - LastLedgerSequence uint `json:",omitempty"` + Flags *types.Flag `json:",omitempty"` + LastLedgerSequence uint32 `json:",omitempty"` Memos []MemoWrapper `json:",omitempty"` Signers []Signer `json:",omitempty"` SourceTag uint `json:",omitempty"` SigningPubKey string `json:",omitempty"` - TicketSequence uint `json:",omitempty"` + TicketSequence uint32 `json:",omitempty"` TxnSignature string `json:",omitempty"` } 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/flags.go b/model/transactions/types/flags.go new file mode 100644 index 00000000..8a0e2415 --- /dev/null +++ b/model/transactions/types/flags.go @@ -0,0 +1,20 @@ +package types + +// FlagsI is an interface for types that can be converted to a uint. +type FlagsI interface { + ToUint() uint32 +} + +type Flag uint32 + +func (f *Flag) ToUint() uint32 { + return uint32(*f) +} + +// SetFlag is a helper function that allocates a new uint value +// to store v and returns a pointer to it. +func SetFlag(v uint32) *Flag { + p := new(uint32) + *p = v + return (*Flag)(p) +} 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 +}