This repository has been archived by the owner on Jun 17, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 272
Add Account class #275
Merged
Merged
Add Account class #275
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
a3bfdc8
add Account class and tests
ryanio 3f858db
export helpful types
ryanio cfe8a9a
check stateRoot in isEmpty
ryanio 6c89111
use hex strings for private keys
ryanio 18e90bf
lint
ryanio 0f5418e
rebuild docs, add types docs
ryanio b2fce00
fix typo
ryanio 36a0700
make codeHash more different-looking than KECCAK256_NULL
ryanio 69a5ef4
move `bnToRlp` to types file so it can be exported in the main packag…
ryanio b0aacc0
add validation for nonce and balance
ryanio e48478d
more docs, fixups
ryanio 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,167 @@ | ||
[ethereumjs-util](../README.md) › ["account"](../modules/_account_.md) › [Account](_account_.account.md) | ||
|
||
# Class: Account | ||
|
||
## Hierarchy | ||
|
||
* **Account** | ||
|
||
## Index | ||
|
||
### Constructors | ||
|
||
* [constructor](_account_.account.md#constructor) | ||
|
||
### Properties | ||
|
||
* [balance](_account_.account.md#balance) | ||
* [codeHash](_account_.account.md#codehash) | ||
* [nonce](_account_.account.md#nonce) | ||
* [stateRoot](_account_.account.md#stateroot) | ||
|
||
### Methods | ||
|
||
* [isContract](_account_.account.md#iscontract) | ||
* [isEmpty](_account_.account.md#isempty) | ||
* [serialize](_account_.account.md#serialize) | ||
* [fromAccountData](_account_.account.md#static-fromaccountdata) | ||
* [fromRlpSerializedAccount](_account_.account.md#static-fromrlpserializedaccount) | ||
* [fromValuesArray](_account_.account.md#static-fromvaluesarray) | ||
|
||
## Constructors | ||
|
||
### constructor | ||
|
||
\+ **new Account**(`nonce`: BN‹›, `balance`: BN‹›, `stateRoot`: Buffer‹›, `codeHash`: Buffer‹›): *[Account](_account_.account.md)* | ||
|
||
*Defined in [account.ts:61](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/account.ts#L61)* | ||
|
||
This constructor takes the values, validates and assigns them. | ||
Use the static factory methods to assist in creating an Account from varying data types. | ||
|
||
**Parameters:** | ||
|
||
Name | Type | Default | | ||
------ | ------ | ------ | | ||
`nonce` | BN‹› | new BN(0) | | ||
`balance` | BN‹› | new BN(0) | | ||
`stateRoot` | Buffer‹› | KECCAK256_RLP | | ||
`codeHash` | Buffer‹› | KECCAK256_NULL | | ||
|
||
**Returns:** *[Account](_account_.account.md)* | ||
|
||
## Properties | ||
|
||
### balance | ||
|
||
• **balance**: *BN* | ||
|
||
*Defined in [account.ts:27](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/account.ts#L27)* | ||
|
||
___ | ||
|
||
### codeHash | ||
|
||
• **codeHash**: *Buffer* | ||
|
||
*Defined in [account.ts:29](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/account.ts#L29)* | ||
|
||
___ | ||
|
||
### nonce | ||
|
||
• **nonce**: *BN* | ||
|
||
*Defined in [account.ts:26](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/account.ts#L26)* | ||
|
||
___ | ||
|
||
### stateRoot | ||
|
||
• **stateRoot**: *Buffer* | ||
|
||
*Defined in [account.ts:28](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/account.ts#L28)* | ||
|
||
## Methods | ||
|
||
### isContract | ||
|
||
▸ **isContract**(): *boolean* | ||
|
||
*Defined in [account.ts:96](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/account.ts#L96)* | ||
|
||
Returns a `Boolean` deteremining if the account is a contract. | ||
|
||
**Returns:** *boolean* | ||
|
||
___ | ||
|
||
### isEmpty | ||
|
||
▸ **isEmpty**(): *boolean* | ||
|
||
*Defined in [account.ts:103](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/account.ts#L103)* | ||
|
||
Returns a `Boolean` determining if the account is empty. | ||
|
||
**Returns:** *boolean* | ||
|
||
___ | ||
|
||
### serialize | ||
|
||
▸ **serialize**(): *Buffer* | ||
|
||
*Defined in [account.ts:89](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/account.ts#L89)* | ||
|
||
Returns the RLP serialization of the account as a `Buffer`. | ||
|
||
**Returns:** *Buffer* | ||
|
||
___ | ||
|
||
### `Static` fromAccountData | ||
|
||
▸ **fromAccountData**(`accountData`: [AccountData](../interfaces/_account_.accountdata.md)): *[Account](_account_.account.md)‹›* | ||
|
||
*Defined in [account.ts:31](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/account.ts#L31)* | ||
|
||
**Parameters:** | ||
|
||
Name | Type | | ||
------ | ------ | | ||
`accountData` | [AccountData](../interfaces/_account_.accountdata.md) | | ||
|
||
**Returns:** *[Account](_account_.account.md)‹›* | ||
|
||
___ | ||
|
||
### `Static` fromRlpSerializedAccount | ||
|
||
▸ **fromRlpSerializedAccount**(`serialized`: Buffer): *[Account](_account_.account.md)‹›* | ||
|
||
*Defined in [account.ts:42](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/account.ts#L42)* | ||
|
||
**Parameters:** | ||
|
||
Name | Type | | ||
------ | ------ | | ||
`serialized` | Buffer | | ||
|
||
**Returns:** *[Account](_account_.account.md)‹›* | ||
|
||
___ | ||
|
||
### `Static` fromValuesArray | ||
|
||
▸ **fromValuesArray**(`values`: Buffer[]): *[Account](_account_.account.md)‹›* | ||
|
||
*Defined in [account.ts:52](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/account.ts#L52)* | ||
|
||
**Parameters:** | ||
|
||
Name | Type | | ||
------ | ------ | | ||
`values` | Buffer[] | | ||
|
||
**Returns:** *[Account](_account_.account.md)‹›* |
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 |
---|---|---|
@@ -0,0 +1,48 @@ | ||
[ethereumjs-util](../README.md) › ["account"](../modules/_account_.md) › [AccountData](_account_.accountdata.md) | ||
|
||
# Interface: AccountData | ||
|
||
## Hierarchy | ||
|
||
* **AccountData** | ||
|
||
## Index | ||
|
||
### Properties | ||
|
||
* [balance](_account_.accountdata.md#optional-balance) | ||
* [codeHash](_account_.accountdata.md#optional-codehash) | ||
* [nonce](_account_.accountdata.md#optional-nonce) | ||
* [stateRoot](_account_.accountdata.md#optional-stateroot) | ||
|
||
## Properties | ||
|
||
### `Optional` balance | ||
|
||
• **balance**? : *[BNLike](../modules/_types_.md#bnlike)* | ||
|
||
*Defined in [account.ts:20](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/account.ts#L20)* | ||
|
||
___ | ||
|
||
### `Optional` codeHash | ||
|
||
• **codeHash**? : *[BufferLike](../modules/_types_.md#bufferlike)* | ||
|
||
*Defined in [account.ts:22](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/account.ts#L22)* | ||
|
||
___ | ||
|
||
### `Optional` nonce | ||
|
||
• **nonce**? : *[BNLike](../modules/_types_.md#bnlike)* | ||
|
||
*Defined in [account.ts:19](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/account.ts#L19)* | ||
|
||
___ | ||
|
||
### `Optional` stateRoot | ||
|
||
• **stateRoot**? : *[BufferLike](../modules/_types_.md#bufferlike)* | ||
|
||
*Defined in [account.ts:21](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/account.ts#L21)* |
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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
[ethereumjs-util](../README.md) › ["types"](../modules/_types_.md) › [TransformableToBuffer](_types_.transformabletobuffer.md) | ||
|
||
# Interface: TransformableToBuffer | ||
|
||
## Hierarchy | ||
|
||
* **TransformableToBuffer** | ||
|
||
## Index | ||
|
||
### Methods | ||
|
||
* [toBuffer](_types_.transformabletobuffer.md#tobuffer) | ||
|
||
## Methods | ||
|
||
### toBuffer | ||
|
||
▸ **toBuffer**(): *Buffer* | ||
|
||
*Defined in [types.ts:10](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/types.ts#L10)* | ||
|
||
**Returns:** *Buffer* |
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
[ethereumjs-util](../README.md) › ["@types/ethjs-util/index"](__types_ethjs_util_index_.md) | ||
|
||
# Module: "@types/ethjs-util/index" | ||
|
||
|
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.
I couldn't find a way to ignore this file in typedoc without getting the error
Could not find a declaration file for module 'ethjs-util'.
, so I guess there is no harm in having it for now, although I wish the file was filled with the type info rather than just being empty 😅The
library
mode in typedoc is pretty new and works quite well for our purposes, so perhaps it will be fixed or improved in the future: