This repository has been archived by the owner on Feb 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Upgrade @truffle/codec's typedoc to v0.20.36 #4112
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,13 @@ | ||
/** | ||
* For reading/decoding constants expressed as AST nodes | ||
* | ||
* @category Solidity data location | ||
* | ||
* @packageDocumentation | ||
*/ | ||
|
||
import * as Read from "./read"; | ||
export { | ||
/** | ||
* @protected | ||
*/ | ||
Read | ||
}; | ||
export { Read }; | ||
|
||
import * as Decode from "./decode"; | ||
export { | ||
/** | ||
* @protected | ||
*/ | ||
Decode | ||
}; | ||
export { Decode }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,180 @@ | ||
/** | ||
* # Codec Output Format | ||
* | ||
* ## Module information | ||
* | ||
* This module primarily defines TypeScript types for the output format | ||
* used in results provided by packages | ||
* `@truffle/decoder@^4.0.0` and `@truffle/codec@^0.1.0`. | ||
* | ||
* See below for complete listing or continue reading | ||
* [Format information](#format-information) to learn about this format. | ||
* | ||
* ### How to import | ||
* | ||
* Import either as part of Codec or by itself: | ||
* | ||
* ```typescript | ||
* // when importing entire Codec, use Codec.Format.*: | ||
* import * as Codec from "@truffle/codec"; | ||
* | ||
* // or import Format directly: | ||
* import { Format } from "@truffle/codec"; | ||
* ``` | ||
* | ||
* ![Example struct decoding](media://example-struct-decoding.png) | ||
* | ||
* ## Format information | ||
* | ||
* This format is intended for use in smart contract and dapp development | ||
* tools and libraries, and for use in display contexts, such as when | ||
* building on-screen components to show transaction and smart contract | ||
* state information. | ||
* | ||
* This format seeks to provide an exhaustive schema for JavaScript | ||
* objects to encode **lossless**, **machine-readable** representations of | ||
* all possible Solidity and ABI data types and all possible values of those | ||
* types. | ||
* | ||
* This format targets types and values understood by the | ||
* [Solidity programming language](https://solidity.readthedocs.io) and | ||
* the [Contract ABI specification](https://solidity.readthedocs.io/en/v0.5.3/abi-spec.html), | ||
* within the context of the [Ethereum Virtual Machine](https://ethereum.github.io/yellowpaper/paper.pdf) | ||
* (EVM) and in raw data for transactions and logs according to the | ||
* [Ethereum JSON RPC](https://github.com/ethereum/wiki/wiki/JSON-RPC). | ||
* | ||
* Objects in this format may be deeply nested and/or contain circular | ||
* dependencies. As such, **do not** serialize objects in this format or | ||
* otherwise attempt to display them in full without considering potential | ||
* risk. **Objects in this format are for the machine to read, not humans!** | ||
* This module provides utilities for inspecting objects in this format, | ||
* including the **safe** [[Format.Utils.Inspect.ResultInspector]] wrapper | ||
* (for [util.inspect](https://nodejs.org/api/util.html#util_util_inspect_object_options)), | ||
* and the **unsafe** [[Format.Utils.Inspect.nativize]] function. For more | ||
* information, please see the documentation for those utilities. | ||
* | ||
* ### Specification | ||
* | ||
* Individual decoded values are represented by objects of the type | ||
* [[Format.Values.Result]], which contain the following fields: | ||
* 1. `type`: This is a [[Format.Types.Type|`Type`]] object describing the value's | ||
* type. Each `Type` has a `typeClass` field describing the overall broad type, | ||
* such as `"uint"` or `"bytes"`, together with additional information that gives | ||
* the specific type. For full detail, see [[Format.Types]]. | ||
* | ||
* 2. `kind`: This is either `"value"`, in which case the `Result` is a | ||
* [[Format.Values.Value|`Value`]], or `"error"`, in which case the `Result` is an | ||
* [[Format.Errors.ErrorResult|`ErrorResult`]]. In the former case, there will be | ||
* a `value` field containin the decoded value. In the latter case, there will be | ||
* an `error` field indicating what went wrong. *Warning*: When decoding a | ||
* complex type, such as an array, mapping, or array, getting a kind of `"value"` | ||
* does not necessarily mean the individual elements were decoded successfully. | ||
* Even if the `Result` for the array (mapping, struct) as a whole has kind | ||
* `"value"`, the elements might still have kind `"error"`. | ||
* | ||
* 3. `value`: As mentioned, this is included when `kind` is equal to `"value"`. | ||
* It contains information about the actual decoded value. See | ||
* [[Format.Values|`Format.Values`]] for more information. | ||
* | ||
* 4. `error`: The alternative to `value`. Generally includes information about | ||
* the raw data that led to the error. See [[Format.Errors|`Format.Errors`]] for | ||
* more information. | ||
* | ||
* 5. `reference`: This field is a debugger-only feature and does not | ||
* apply to results returned by @truffle/decoder, so it won't be documented here. | ||
* | ||
* ### Values vs. errors | ||
* | ||
* It's worth taking a moment here to answer the question: What counts as a value, | ||
* and what counts as an error? | ||
* | ||
* In general, the answer is that anything that can be generated via Solidity | ||
* alone (i.e. no assembly), with correctly-encoded inputs, and without making use | ||
* of compiler bugs, is a value, not an error. That means that, for instance, the | ||
* following things are values, not errors: | ||
* - A variable of contract type whose address does not actually hold a | ||
* contract of that type; | ||
* - An external function pointer that does not correspond to a valid | ||
* function; | ||
* - A string containing invalid UTF-8; | ||
* - ..., etc. | ||
* | ||
* By contrast, the following *are* errors: | ||
* - A `bool` which is neither `false` (0) nor `true` (1); | ||
* - An `enum` which is out of range; | ||
* - ..., etc. | ||
* | ||
* (You may be wondering about the enum case here, because if you go sufficiently | ||
* far back, to Solidity 0.4.4 or earlier, it *was* possible to generate | ||
* out-of-range enums without resorting to assembly or compiler bugs. However, | ||
* enums are only supported in full mode (see | ||
* [Notes on decoding modes](../#decoding-modes)), | ||
* which only supports 0.4.12 and later, so | ||
* we consider out-of-range enums an error. There are also additional technical | ||
* reasons why supporting out-of-range enums as a value would be difficult.) | ||
* | ||
* There are three special cases here that are likely worthy of note. | ||
* | ||
* Firstly, internal function pointers currently can't be meaningfully | ||
* decoded via @truffle/decoder. However, they decode to a bare-bones value, | ||
* not an error, as it is (in a sense) our own fault that we can't decode | ||
* these, so it doesn't make sense to report an error, which would mean that | ||
* something is wrong with the encoded data itself. This value that it | ||
* decodes to will give the program counter values it corresponds to, but | ||
* will not include the function name or defining class, as @truffle/decoder | ||
* is not presently capable of that. For now, full decoding of internal | ||
* function pointers remains a debugger-only feature. (But limited support for | ||
* this via @truffle/decoder is planned for the future.) | ||
* | ||
* (When using the debugger, an invalid internal function pointer will decode to an | ||
* error. However, when using @truffle/decoder, we have no way of discerning whether | ||
* the pointer is valid or not, so internal function pointers will always decode to | ||
* a value, if an uninformative one.) | ||
* | ||
* Secondly, when decoding events, it is impossible to decode indexed parameters | ||
* of reference type. Thus, these decode to an error | ||
* (`IndexedReferenceTypeError`, which see) rather than to a value. | ||
* | ||
* Thirdly, the decoder is currently limited when it comes to decoding state | ||
* variables that are declared constant, and not all such variables are yet | ||
* supported in decoding; attempting to decode one of these that is not currently | ||
* supported will yield an error. | ||
* | ||
* Similarly, there are various things that decode to errors for technical reasons. | ||
* Objects with encoded length fields larger than what fits in a JavaScript safe | ||
* integer, or pointed to by pointers with values larger than what fits in a | ||
* JavaScript safe integer, will decode to errors, even if they may technically be | ||
* legal. Such cases are impractical to handle and should never come up in real | ||
* use so we decode them to errors. Errors may also be returned in case of an | ||
* error in attempting to read the data to be decoded. | ||
* | ||
* Finally, except when decoding events, we do not return an error if the pointers | ||
* in an ABI-encoded array or tuple are arranged in a nonstandard way, or if | ||
* strings or bytestrings are incorrectly padded, because it is not worth the | ||
* trouble to detect these conditions. | ||
* | ||
* | ||
* ## Notes on this documentation | ||
* | ||
* Most of this doesn't have explanatory documentation | ||
* because it's largely self-explanatory, but particularly | ||
* non-obvious parts have been documented for clarity. | ||
* | ||
* A note on optional fields: A number of types or values | ||
* have optional fields. These contain helpful | ||
* but non-essential information, or information which | ||
* for technical reasons we can't guarantee we can determine. | ||
* | ||
* @category Data | ||
* | ||
* @packageDocumentation | ||
*/ | ||
import { Types, Values, Errors } from "./common"; | ||
import * as Utils from "./utils"; | ||
|
||
export { | ||
/** | ||
* Contains the types for type objects, and some | ||
* functions for working with them. | ||
* | ||
* @category Main Format | ||
*/ | ||
Types, | ||
/** | ||
* Contains the types for value and result objects. | ||
* @category Main Format | ||
*/ | ||
Values, | ||
/** | ||
* Contains the types for error and `ErrorResult` objects. | ||
* @category Main Format | ||
*/ | ||
Errors, | ||
Utils | ||
}; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Hm, why these deleted lines?
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.
Those options don't exist anymore!