-
Notifications
You must be signed in to change notification settings - Fork 571
fix(rbc): throw error instead of throwing away unknown fields #2927
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
cdd56e1
c0eaa7e
2e33147
a1d0be1
fc688df
6ca4645
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -116,14 +116,25 @@ class STObject extends SerializedType { | |||
| return Object.assign(acc, handled ?? { [key]: val }) | ||||
| }, {}) | ||||
|
|
||||
| let sorted = Object.keys(xAddressDecoded) | ||||
| .map((f: string): FieldInstance => definitions.field[f] as FieldInstance) | ||||
| .filter( | ||||
| (f: FieldInstance): boolean => | ||||
| f !== undefined && | ||||
| xAddressDecoded[f.name] !== undefined && | ||||
| f.isSerialized, | ||||
| function isValidFieldInstance( | ||||
| f: FieldInstance | undefined, | ||||
| ): f is FieldInstance { | ||||
| return ( | ||||
| f !== undefined && | ||||
| xAddressDecoded[f.name] !== undefined && | ||||
| f.isSerialized | ||||
| ) | ||||
| } | ||||
|
|
||||
| let sorted = Object.keys(xAddressDecoded) | ||||
| .map((f: string): FieldInstance | undefined => { | ||||
| if (!(f in definitions.field)) { | ||||
| if (f[0] === f[0].toLowerCase()) return undefined | ||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't understand this condition -- Can you point me to the documentation which explains the capitalization of the first character? I observe examples where the first character of the field-name is both upper and lower case. Ex:
Is there any explanation here? https://xrpl.org/docs/references/protocol/binary-format
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lower-case fields are synthetic fields that aren't serialized, like
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. okay thanks. This is useful information, it will be helpful if its mentioned in the docs. Perhaps I missed it? |
||||
| throw new Error(`Field ${f} is not defined in the definitions`) | ||||
| } | ||||
| return definitions.field[f] as FieldInstance | ||||
| }) | ||||
| .filter(isValidFieldInstance) | ||||
| .sort((a, b) => { | ||||
| return a.ordinal - b.ordinal | ||||
| }) | ||||
|
|
||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -116,4 +116,13 @@ describe('encoding and decoding tx_json', function () { | |
| encode(my_tx) | ||
| }).toThrow() | ||
| }) | ||
|
|
||
| it('throws when there is an unknown field', function () { | ||
| const my_tx = Object.assign({}, tx_json, { | ||
| BadField: 1, | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If this field was titled
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. SFields are always capitalized. Synthetic fields (non-serialized fields that are returned in RPC outputs) are lower-case. |
||
| }) | ||
| expect(() => { | ||
| encode(my_tx) | ||
| }).toThrow() | ||
| }) | ||
| }) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function is needed for typing