mirror of
https://github.com/XRPLF/xrpl-dev-portal.git
synced 2025-11-25 14:15:50 +00:00
Serialization: clean up sample code, add CLI usage
This commit is contained in:
52
content/_code-samples/tx-serialization/test-cases/README.md
Normal file
52
content/_code-samples/tx-serialization/test-cases/README.md
Normal file
@@ -0,0 +1,52 @@
|
||||
# Transaction Serialization Test Cases
|
||||
|
||||
This folder contains several transactions in their JSON and binary forms, which
|
||||
you can use to verify the behavior of transaction serialization code.
|
||||
|
||||
For example (starting from the `tx-serialization/` dir above this one):
|
||||
|
||||
```bash
|
||||
$ python3 serialize.py -f test-cases/tx2.json | \
|
||||
diff - test-cases/tx2-binary.txt
|
||||
```
|
||||
|
||||
The expected result is no output because the output of `serialize.py` matches
|
||||
the contents of `test-cases/tx2-binary.txt` exactly.
|
||||
|
||||
For an example of how the output is different if you change the `Fee` parameter of sample transaction 1, we can pipe a modified version of the file into the serializer:
|
||||
|
||||
```bash
|
||||
$ cat test-cases/tx1.json | \
|
||||
sed -e 's/"Fee": "10"/"Fee": "100"/' | \
|
||||
python3 serialize.py --stdin | \
|
||||
diff - test-cases/tx1-binary.txt --color
|
||||
```
|
||||
|
||||
The output shows that the two versions of the transaction binary are different (but because they're all on one line, it's not super clear _where_ within the line the difference is):
|
||||
|
||||
```text
|
||||
1c1
|
||||
< 120007220008000024001ABED82A2380BF2C2019001ABED764D55920AC93914000000000000000
|
||||
00000000000055534400000000000A20B3C85F482532A9578DBB3950B85CA06594D165400000037E
|
||||
11D600684000000000000064732103EE83BB432547885C219634A1BC407A9DB0474145D69737D09C
|
||||
CDC63E1DEE7FE3744630440220143759437C04F7B61F012563AFE90D8DAFC46E86035E1D965A9CED
|
||||
282C97D4CE02204CFD241E86F17E011298FC1A39B63386C74306A5DE047E213B0F29EFA4571C2C81
|
||||
14DD76483FACDEE26E60D8A586BB58D09F27045C46
|
||||
---
|
||||
> 120007220008000024001ABED82A2380BF2C2019001ABED764D55920AC93914000000000000000
|
||||
00000000000055534400000000000A20B3C85F482532A9578DBB3950B85CA06594D165400000037E
|
||||
11D60068400000000000000A732103EE83BB432547885C219634A1BC407A9DB0474145D69737D09C
|
||||
CDC63E1DEE7FE3744630440220143759437C04F7B61F012563AFE90D8DAFC46E86035E1D965A9CED
|
||||
282C97D4CE02204CFD241E86F17E011298FC1A39B63386C74306A5DE047E213B0F29EFA4571C2C81
|
||||
14DD76483FACDEE26E60D8A586BB58D09F27045C46
|
||||
```
|
||||
|
||||
(If you're curious, the difference appears in the third line of each blob in this example. The modified version of the transaction serializes the `Fee` amount ending in `64` (hex for 100) while the original version ended in `0A` (hex for 10).)
|
||||
|
||||
For a friendlier display, you could pipe the output of the serializer to a file and use a visual tool like [Meld](http://meldmerge.org/) that shows intra-line differences:
|
||||
|
||||
```bash
|
||||
$ cat test-cases/tx1.json | sed -e 's/"Fee": "10"/"Fee": "100"/' | python3 serialize.py --stdin > /tmp/tx1-modified.txt && meld /tmp/tx1-modified.txt test-cases/tx1-binary.txt
|
||||
```
|
||||
|
||||

|
||||
Binary file not shown.
|
After Width: | Height: | Size: 9.4 KiB |
@@ -1,125 +0,0 @@
|
||||
{
|
||||
"Account": "rMBzp8CgpE441cp5PVyA9rpVV7oT8hP3ys",
|
||||
"Expiration": 595640108,
|
||||
"Fee": "10",
|
||||
"Flags": 524288,
|
||||
"OfferSequence": 1752791,
|
||||
"Sequence": 1752792,
|
||||
"SigningPubKey": "03EE83BB432547885C219634A1BC407A9DB0474145D69737D09CCDC63E1DEE7FE3",
|
||||
"TakerGets": "15000000000",
|
||||
"TakerPays": {
|
||||
"currency": "USD",
|
||||
"issuer": "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B",
|
||||
"value": "7072.8"
|
||||
},
|
||||
"TransactionType": "OfferCreate",
|
||||
"TxnSignature": "30440220143759437C04F7B61F012563AFE90D8DAFC46E86035E1D965A9CED282C97D4CE02204CFD241E86F17E011298FC1A39B63386C74306A5DE047E213B0F29EFA4571C2C",
|
||||
"hash": "73734B611DDA23D3F5F62E20A173B78AB8406AC5015094DA53F53D39B9EDB06C",
|
||||
"metaData": {
|
||||
"AffectedNodes": [
|
||||
{
|
||||
"ModifiedNode": {
|
||||
"FinalFields": {
|
||||
"Flags": 0,
|
||||
"IndexNext": "0000000000000000",
|
||||
"IndexPrevious": "0000000000000000",
|
||||
"Owner": "rMBzp8CgpE441cp5PVyA9rpVV7oT8hP3ys",
|
||||
"RootIndex": "10AF5737F535F47CA9E8B6F82C4B7F4D998B1B7C44185C6078A22C751FD9FB7D"
|
||||
},
|
||||
"LedgerEntryType": "DirectoryNode",
|
||||
"LedgerIndex": "10AF5737F535F47CA9E8B6F82C4B7F4D998B1B7C44185C6078A22C751FD9FB7D"
|
||||
}
|
||||
},
|
||||
{
|
||||
"DeletedNode": {
|
||||
"FinalFields": {
|
||||
"Account": "rMBzp8CgpE441cp5PVyA9rpVV7oT8hP3ys",
|
||||
"BookDirectory": "DFA3B6DDAB58C7E8E5D944E736DA4B7046C30E4F460FD9DE4E10BFD011CB2800",
|
||||
"BookNode": "0000000000000000",
|
||||
"Expiration": 595640096,
|
||||
"Flags": 131072,
|
||||
"OwnerNode": "0000000000000000",
|
||||
"PreviousTxnID": "50C2CBD3BEF831D80C2950D3001E67F1D257665569A9D77B1F0E0B8B4D178CEB",
|
||||
"PreviousTxnLgrSeq": 43010795,
|
||||
"Sequence": 1752791,
|
||||
"TakerGets": "15000000000",
|
||||
"TakerPays": {
|
||||
"currency": "USD",
|
||||
"issuer": "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B",
|
||||
"value": "7071.75"
|
||||
}
|
||||
},
|
||||
"LedgerEntryType": "Offer",
|
||||
"LedgerIndex": "233E9A034C083E895EF7B4F6A643291FEF1608D55C8C5783F71E9C5F82D3E7FB"
|
||||
}
|
||||
},
|
||||
{
|
||||
"ModifiedNode": {
|
||||
"FinalFields": {
|
||||
"Account": "rMBzp8CgpE441cp5PVyA9rpVV7oT8hP3ys",
|
||||
"Balance": "37180946255",
|
||||
"Flags": 0,
|
||||
"OwnerCount": 6,
|
||||
"Sequence": 1752793
|
||||
},
|
||||
"LedgerEntryType": "AccountRoot",
|
||||
"LedgerIndex": "9EB65374048F2AED1995A6725D4234545432083B0C5728627E06443A8E1F4C98",
|
||||
"PreviousFields": {
|
||||
"Balance": "37180946265",
|
||||
"Sequence": 1752792
|
||||
},
|
||||
"PreviousTxnID": "50C2CBD3BEF831D80C2950D3001E67F1D257665569A9D77B1F0E0B8B4D178CEB",
|
||||
"PreviousTxnLgrSeq": 43010795
|
||||
}
|
||||
},
|
||||
{
|
||||
"DeletedNode": {
|
||||
"FinalFields": {
|
||||
"ExchangeRate": "4E10BFD011CB2800",
|
||||
"Flags": 0,
|
||||
"RootIndex": "DFA3B6DDAB58C7E8E5D944E736DA4B7046C30E4F460FD9DE4E10BFD011CB2800",
|
||||
"TakerGetsCurrency": "0000000000000000000000000000000000000000",
|
||||
"TakerGetsIssuer": "0000000000000000000000000000000000000000",
|
||||
"TakerPaysCurrency": "0000000000000000000000005553440000000000",
|
||||
"TakerPaysIssuer": "0A20B3C85F482532A9578DBB3950B85CA06594D1"
|
||||
},
|
||||
"LedgerEntryType": "DirectoryNode",
|
||||
"LedgerIndex": "DFA3B6DDAB58C7E8E5D944E736DA4B7046C30E4F460FD9DE4E10BFD011CB2800"
|
||||
}
|
||||
},
|
||||
{
|
||||
"CreatedNode": {
|
||||
"LedgerEntryType": "DirectoryNode",
|
||||
"LedgerIndex": "DFA3B6DDAB58C7E8E5D944E736DA4B7046C30E4F460FD9DE4E10C0730D0B8000",
|
||||
"NewFields": {
|
||||
"ExchangeRate": "4E10C0730D0B8000",
|
||||
"RootIndex": "DFA3B6DDAB58C7E8E5D944E736DA4B7046C30E4F460FD9DE4E10C0730D0B8000",
|
||||
"TakerPaysCurrency": "0000000000000000000000005553440000000000",
|
||||
"TakerPaysIssuer": "0A20B3C85F482532A9578DBB3950B85CA06594D1"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"CreatedNode": {
|
||||
"LedgerEntryType": "Offer",
|
||||
"LedgerIndex": "FD6C2E2D72319FB0C22FC50B0AF993B2AF26717927EAEB1E8857971EE2C3CADD",
|
||||
"NewFields": {
|
||||
"Account": "rMBzp8CgpE441cp5PVyA9rpVV7oT8hP3ys",
|
||||
"BookDirectory": "DFA3B6DDAB58C7E8E5D944E736DA4B7046C30E4F460FD9DE4E10C0730D0B8000",
|
||||
"Expiration": 595640108,
|
||||
"Flags": 131072,
|
||||
"Sequence": 1752792,
|
||||
"TakerGets": "15000000000",
|
||||
"TakerPays": {
|
||||
"currency": "USD",
|
||||
"issuer": "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B",
|
||||
"value": "7072.8"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"TransactionIndex": 0,
|
||||
"TransactionResult": "tesSUCCESS"
|
||||
}
|
||||
}
|
||||
@@ -1,94 +0,0 @@
|
||||
{
|
||||
"hash": "C0B450C8601E19CB0BDED71C4B523B2A4AAB77415B08E7923D8DA3F831631702",
|
||||
"ledger_index": 36259236,
|
||||
"date": "2018-02-01T09:45:32+00:00",
|
||||
"tx": {
|
||||
"TransactionType": "EscrowFinish",
|
||||
"Flags": 2147483648,
|
||||
"Sequence": 1,
|
||||
"OfferSequence": 11,
|
||||
"Fee": "10101",
|
||||
"SigningPubKey": "0268D79CD579D077750740FA18A2370B7C2018B2714ECE70BA65C38D223E79BC9C",
|
||||
"TxnSignature": "3045022100F06FB54049D6D50142E5CF2E2AC21946AF305A13E2A2D4BA881B36484DD01A540220311557EC8BEF536D729605A4CB4D4DC51B1E37C06C93434DD5B7651E1E2E28BF",
|
||||
"Account": "r3Y6vCE8XqfZmYBRngy22uFYkmz3y9eCRA",
|
||||
"Owner": "r9NpyVfLfUG8hatuCCHKzosyDtKnBdsEN3",
|
||||
"Memos": [
|
||||
{
|
||||
"Memo": {
|
||||
"MemoData": "04C4D46544659A2D58525043686174"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"meta": {
|
||||
"TransactionIndex": 35,
|
||||
"AffectedNodes": [
|
||||
{
|
||||
"DeletedNode": {
|
||||
"LedgerEntryType": "Escrow",
|
||||
"LedgerIndex": "983EBDF89C1C30CECDB105B593E7DEBE602AF89012EDB4DD76D24ACEF92C89EF",
|
||||
"FinalFields": {
|
||||
"Flags": 0,
|
||||
"PreviousTxnLgrSeq": 35059511,
|
||||
"FinishAfter": 570758400,
|
||||
"OwnerNode": "0000000000000000",
|
||||
"PreviousTxnID": "6F54E04D7B205CBE2FCAEF1C249E62A9759721C7FE1F6992FD800266C8E4814C",
|
||||
"Amount": "1000000000000000",
|
||||
"Account": "r9NpyVfLfUG8hatuCCHKzosyDtKnBdsEN3",
|
||||
"Destination": "r9NpyVfLfUG8hatuCCHKzosyDtKnBdsEN3"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"ModifiedNode": {
|
||||
"LedgerEntryType": "DirectoryNode",
|
||||
"LedgerIndex": "C05DC35EBDCA5D8697190FF41950EC5AFCBF7F61C1177DC73000CC17C2149886",
|
||||
"FinalFields": {
|
||||
"Flags": 0,
|
||||
"RootIndex": "C05DC35EBDCA5D8697190FF41950EC5AFCBF7F61C1177DC73000CC17C2149886",
|
||||
"Owner": "r9NpyVfLfUG8hatuCCHKzosyDtKnBdsEN3"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"ModifiedNode": {
|
||||
"LedgerEntryType": "AccountRoot",
|
||||
"PreviousTxnLgrSeq": 36230933,
|
||||
"PreviousTxnID": "9366F75CD350ACE0EEFC0A392ECBD5AC2B84C06E5DEC2DE895B76FFC7BD55553",
|
||||
"LedgerIndex": "C180CA555CE8820D8F1086CDCA756FF8D5813FEB2AE3FF002B9F48F870CA08A0",
|
||||
"PreviousFields": {
|
||||
"Sequence": 1,
|
||||
"Balance": "26000000"
|
||||
},
|
||||
"FinalFields": {
|
||||
"Flags": 0,
|
||||
"Sequence": 2,
|
||||
"OwnerCount": 0,
|
||||
"Balance": "25989899",
|
||||
"Account": "r3Y6vCE8XqfZmYBRngy22uFYkmz3y9eCRA"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"ModifiedNode": {
|
||||
"LedgerEntryType": "AccountRoot",
|
||||
"PreviousTxnLgrSeq": 36253527,
|
||||
"PreviousTxnID": "F2AA5584005847C19F59A9C87E7BF3108F97F2567C5083159EEC40B08ED90F46",
|
||||
"LedgerIndex": "DCED5AAFE87AA8D00E651DBBFBA2F992927BC3DC5FFD905EF49019ED02824B3A",
|
||||
"PreviousFields": {
|
||||
"OwnerCount": 14,
|
||||
"Balance": "200923000"
|
||||
},
|
||||
"FinalFields": {
|
||||
"Flags": 1048576,
|
||||
"Sequence": 18,
|
||||
"OwnerCount": 13,
|
||||
"Balance": "1000000200923000",
|
||||
"Account": "r9NpyVfLfUG8hatuCCHKzosyDtKnBdsEN3"
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"TransactionResult": "tesSUCCESS"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user