diff --git a/_code-samples/tx-serialization/js/index.js b/_code-samples/tx-serialization/js/index.js index 859fa34be1..82443c45a0 100644 --- a/_code-samples/tx-serialization/js/index.js +++ b/_code-samples/tx-serialization/js/index.js @@ -37,7 +37,11 @@ const args = parseArgs(process.argv.slice(2), { function _pretty(message, color) { if (!args.raw) { - console.log(color, message) + if (color) { + console.log(color,message) + } else { + console.log(message) + } } } @@ -60,4 +64,4 @@ if (args.json) { } else { rawJson = fs.readFileSync(args.filename, 'utf8') main(rawJson, args.verbose) -} \ No newline at end of file +} diff --git a/_code-samples/tx-serialization/js/package.json b/_code-samples/tx-serialization/js/package.json index 91450677f9..a9d2582664 100644 --- a/_code-samples/tx-serialization/js/package.json +++ b/_code-samples/tx-serialization/js/package.json @@ -7,10 +7,9 @@ "big-integer": "^1.6.52", "buffer": "^6.0.3", "decimal.js": "^10.4.3", - "fs": "^0.0.1-security", "minimist": "^1.2.7", "ripple-address-codec": "^5.0.0", - "xrpl": "^4.0.0" + "xrpl": "^4.2.5" }, "main": "index.js", "scripts": { diff --git a/_code-samples/tx-serialization/js/test-cases/README.md b/_code-samples/tx-serialization/js/test-cases/README.md index fac686e78c..32361eecf7 100644 --- a/_code-samples/tx-serialization/js/test-cases/README.md +++ b/_code-samples/tx-serialization/js/test-cases/README.md @@ -6,7 +6,7 @@ you can use to verify the behavior of the transaction serialization code. For example (starting from the `tx-serialization/js/` dir above this one): ```bash -$ node index.js -f test-cases/tx2.json | \ +$ node index.js -rf test-cases/tx2.json | \ diff - test-cases/tx2-binary.txt ``` @@ -46,7 +46,7 @@ CDC63E1DEE7FE3744630440220143759437C04F7B61F012563AFE90D8DAFC46E86035E1D965A9CED 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"/' | node index.js --stdin > /tmp/tx1-modified.txt && meld /tmp/tx1-modified.txt test-cases/tx1-binary.txt +$ cat test-cases/tx1.json | sed -e 's/"Fee": "10"/"Fee": "100"/' | node index.js --raw --stdin > /tmp/tx1-modified.txt && meld /tmp/tx1-modified.txt test-cases/tx1-binary.txt ``` ![Meld screenshot showing the `0A` / `64` difference](meld-example.png) diff --git a/_code-samples/tx-serialization/js/tx-serializer.js b/_code-samples/tx-serialization/js/tx-serializer.js index 5cba755d63..2b4cbfc3da 100644 --- a/_code-samples/tx-serialization/js/tx-serializer.js +++ b/_code-samples/tx-serialization/js/tx-serializer.js @@ -92,7 +92,7 @@ class TxSerializer { _decodeAddress(address) { const decoded = codec.decodeChecked(address) if (decoded[0] === 0 && decoded.length === 21) { - return decoded.slice(1) + return Buffer.from(decoded.slice(1)) } throw new Error("Not an AccountID!") @@ -161,7 +161,7 @@ class TxSerializer { const byte2 = this.uint8ToBytes(typeCode) const byte3 = this.uint8ToBytes(fieldCode) - return "" + byte1 + byte2 + byte3 //TODO: bytes is python function + return "" + byte1 + byte2 + byte3 } } @@ -681,9 +681,8 @@ class TxSerializer { fieldsAsBytes.push(fieldBytes) } } - return fieldsAsBytes.join('') } } -module.exports = TxSerializer \ No newline at end of file +module.exports = TxSerializer