mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-20 12:15:51 +00:00
@@ -1,5 +1,8 @@
|
|||||||
# ripple-binary-codec Release History
|
# ripple-binary-codec Release History
|
||||||
|
|
||||||
|
## 1.0.1 (2020-09-08)
|
||||||
|
- Filter out fields with undefined values
|
||||||
|
|
||||||
## 1.0.0 (2020-08-17)
|
## 1.0.0 (2020-08-17)
|
||||||
|
|
||||||
- Migrate to TypeScript
|
- Migrate to TypeScript
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ Decode a hex-string into a transaction object.
|
|||||||
```
|
```
|
||||||
|
|
||||||
### encode(json: object): string
|
### encode(json: object): string
|
||||||
Encode a transaction object into a hex-string.
|
Encode a transaction object into a hex-string. Note that encode filters out fields with undefined values.
|
||||||
```js
|
```js
|
||||||
> api.encode({
|
> api.encode({
|
||||||
LedgerEntryType: 'AccountRoot',
|
LedgerEntryType: 'AccountRoot',
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "ripple-binary-codec",
|
"name": "ripple-binary-codec",
|
||||||
"version": "1.0.0",
|
"version": "1.0.1",
|
||||||
"description": "XRP Ledger binary codec",
|
"description": "XRP Ledger binary codec",
|
||||||
"files": [
|
"files": [
|
||||||
"dist/*",
|
"dist/*",
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ Each ledger's state tree contain [ledger objects](https://xrpl.org/ledger-object
|
|||||||
|
|
||||||
## Fields
|
## Fields
|
||||||
|
|
||||||
These are Serialization Fields (`sf`) [defined in rippled's SField.cpp](https://github.com/ripple/rippled/blob/develop/src/ripple/protocol/impl/SField.cpp).
|
These are Serialization Fields (`sf`) [defined in rippled's SField.cpp](https://github.com/ripple/rippled/blob/develop/src/ripple/protocol/impl/SField.cpp). Fields with undefined values are omitted before encoding.
|
||||||
|
|
||||||
### Key
|
### Key
|
||||||
|
|
||||||
|
|||||||
@@ -109,7 +109,12 @@ class STObject extends SerializedType {
|
|||||||
|
|
||||||
let sorted = Object.keys(xAddressDecoded)
|
let sorted = Object.keys(xAddressDecoded)
|
||||||
.map((f: string): FieldInstance => Field[f] as FieldInstance)
|
.map((f: string): FieldInstance => Field[f] as FieldInstance)
|
||||||
.filter((f: FieldInstance): boolean => f !== undefined && f.isSerialized)
|
.filter(
|
||||||
|
(f: FieldInstance): boolean =>
|
||||||
|
f !== undefined &&
|
||||||
|
xAddressDecoded[f.name] !== undefined &&
|
||||||
|
f.isSerialized
|
||||||
|
)
|
||||||
.sort((a, b) => {
|
.sort((a, b) => {
|
||||||
return a.ordinal - b.ordinal;
|
return a.ordinal - b.ordinal;
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -50,6 +50,53 @@ const PaymentChannel = {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let json_undefined = {
|
||||||
|
TakerPays: "223174650",
|
||||||
|
Account: "rPk2dXr27rMw9G5Ej9ad2Tt7RJzGy8ycBp",
|
||||||
|
TransactionType: "OfferCreate",
|
||||||
|
Memos: [
|
||||||
|
{
|
||||||
|
Memo: {
|
||||||
|
MemoType: "584D4D2076616C7565",
|
||||||
|
MemoData: "322E3230393635",
|
||||||
|
MemoFormat: undefined,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
Fee: "15",
|
||||||
|
OfferSequence: undefined,
|
||||||
|
TakerGets: {
|
||||||
|
currency: "XMM",
|
||||||
|
value: "100",
|
||||||
|
issuer: "rExAPEZvbkZqYPuNcZ7XEBLENEshsWDQc8",
|
||||||
|
},
|
||||||
|
Flags: 524288,
|
||||||
|
Sequence: undefined,
|
||||||
|
LastLedgerSequence: 6220135,
|
||||||
|
};
|
||||||
|
|
||||||
|
let json_omitted = {
|
||||||
|
TakerPays: "223174650",
|
||||||
|
Account: "rPk2dXr27rMw9G5Ej9ad2Tt7RJzGy8ycBp",
|
||||||
|
TransactionType: "OfferCreate",
|
||||||
|
Memos: [
|
||||||
|
{
|
||||||
|
Memo: {
|
||||||
|
MemoType: "584D4D2076616C7565",
|
||||||
|
MemoData: "322E3230393635",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
Fee: "15",
|
||||||
|
TakerGets: {
|
||||||
|
currency: "XMM",
|
||||||
|
value: "100",
|
||||||
|
issuer: "rExAPEZvbkZqYPuNcZ7XEBLENEshsWDQc8",
|
||||||
|
},
|
||||||
|
Flags: 524288,
|
||||||
|
LastLedgerSequence: 6220135,
|
||||||
|
};
|
||||||
|
|
||||||
const NegativeUNL = require("./fixtures/negative-unl.json");
|
const NegativeUNL = require("./fixtures/negative-unl.json");
|
||||||
|
|
||||||
function bytesListTest() {
|
function bytesListTest() {
|
||||||
@@ -179,6 +226,15 @@ function NegativeUNLTest() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function omitUndefinedTest() {
|
||||||
|
test("omits fields with undefined value", () => {
|
||||||
|
let encodedOmitted = encode(json_omitted);
|
||||||
|
let encodedUndefined = encode(json_undefined);
|
||||||
|
expect(encodedOmitted).toEqual(encodedUndefined);
|
||||||
|
expect(decode(encodedOmitted)).toEqual(decode(encodedUndefined));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
describe("Binary Serialization", function () {
|
describe("Binary Serialization", function () {
|
||||||
describe("nestedObjectTests", () => nestedObjectTests());
|
describe("nestedObjectTests", () => nestedObjectTests());
|
||||||
describe("BytesList", () => bytesListTest());
|
describe("BytesList", () => bytesListTest());
|
||||||
@@ -188,4 +244,5 @@ describe("Binary Serialization", function () {
|
|||||||
describe("Escrow", () => EscrowTest());
|
describe("Escrow", () => EscrowTest());
|
||||||
describe("PaymentChannel", () => PaymentChannelTest());
|
describe("PaymentChannel", () => PaymentChannelTest());
|
||||||
describe("NegativeUNLTest", () => NegativeUNLTest());
|
describe("NegativeUNLTest", () => NegativeUNLTest());
|
||||||
|
describe("OmitUndefined", () => omitUndefinedTest());
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user