Skip to content
This repository was archived by the owner on Jun 17, 2021. It is now read-only.

Commit c5dca47

Browse files
authored
Merge pull request #275 from ethereumjs/add-account-class
Add Account class
2 parents d8b8e44 + e48478d commit c5dca47

19 files changed

+772
-198
lines changed

CHANGELOG.md

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,36 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
88

99
## [7.0.6] - [UNRELEASED]
1010

11-
[ ADD REFERENCES TO YOUR WORK HERE UPON PRs. PLEASE ADOPT THE VERSION IF YOUR PR REQUIRES. ]
11+
### New `Account` class
12+
13+
This release adds a new `Account` class intended as a modern replacement for `ethereumjs-account`. It has a shape of `Account(nonce?: BN, balance?: BN, stateRoot?: Buffer, codeHash?: Buffer)`.
14+
15+
**Instantiation**
16+
17+
The static factory methods assist in creating an `Account` object from varying data types: `Object: fromAccountData`, `RLP: fromRlpSerializedAccount`, and `Array: fromValuesArray`.
18+
19+
**Methods**: `isEmpty(): boolean`, `isContract(): boolean`, `serialize(): Buffer`
20+
21+
Example usage:
22+
23+
```typescript
24+
import { Account, BN } from 'ethereumjs-util'
25+
26+
const account = new Account(
27+
new BN(0), // nonce, default: 0
28+
new BN(10).pow(new BN(18)), // balance, default: 0
29+
undefined, // stateRoot, default: KECCAK256_RLP (hash of RLP of null)
30+
undefined, // codeHash, default: KECCAK256_NULL (hash of null)
31+
)
32+
```
33+
34+
For more info see the documentation or examples of usage in `test/account.spec.ts`.
35+
36+
### New export: TypeScript types
37+
38+
A new file with helpful TypeScript types has been added to the exports of this project.
39+
40+
In this release it contains `BNLike`, `BufferLike`, and `TransformableToBuffer`.
1241

1342
## [7.0.5] - 2020-09-09
1443

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ assert.equal(new BN('dead', 16).add(new BN('101010', 2)), 57047)
3232
### Modules
3333

3434
- [account](docs/modules/_account_.md)
35+
- Account class
3536
- Private/public key and address-related functionality (creation, validation, conversion)
3637
- [address](docs/modules/_address_.md)
3738
- Address class and type
@@ -46,6 +47,8 @@ assert.equal(new BN('dead', 16).add(new BN('101010', 2)), 57047)
4647
- Helper function for creating a binary object (`DEPRECATED`)
4748
- [signature](docs/modules/_signature_.md)
4849
- Signing, signature validation, conversion, recovery
50+
- [types](docs/modules/_types_.md)
51+
- Helpful TypeScript types
4952
- [externals](docs/modules/_externals_.md)
5053
- Helper methods from `ethjs-util`
5154
- Re-exports of `BN`, `rlp`

docs/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
### Modules
88

9+
* ["@types/ethjs-util/index"](modules/__types_ethjs_util_index_.md)
910
* ["account"](modules/_account_.md)
1011
* ["address"](modules/_address_.md)
1112
* ["bytes"](modules/_bytes_.md)
@@ -15,3 +16,4 @@
1516
* ["helpers"](modules/_helpers_.md)
1617
* ["object"](modules/_object_.md)
1718
* ["signature"](modules/_signature_.md)
19+
* ["types"](modules/_types_.md)

docs/classes/_account_.account.md

Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
[ethereumjs-util](../README.md)["account"](../modules/_account_.md)[Account](_account_.account.md)
2+
3+
# Class: Account
4+
5+
## Hierarchy
6+
7+
* **Account**
8+
9+
## Index
10+
11+
### Constructors
12+
13+
* [constructor](_account_.account.md#constructor)
14+
15+
### Properties
16+
17+
* [balance](_account_.account.md#balance)
18+
* [codeHash](_account_.account.md#codehash)
19+
* [nonce](_account_.account.md#nonce)
20+
* [stateRoot](_account_.account.md#stateroot)
21+
22+
### Methods
23+
24+
* [isContract](_account_.account.md#iscontract)
25+
* [isEmpty](_account_.account.md#isempty)
26+
* [serialize](_account_.account.md#serialize)
27+
* [fromAccountData](_account_.account.md#static-fromaccountdata)
28+
* [fromRlpSerializedAccount](_account_.account.md#static-fromrlpserializedaccount)
29+
* [fromValuesArray](_account_.account.md#static-fromvaluesarray)
30+
31+
## Constructors
32+
33+
### constructor
34+
35+
\+ **new Account**(`nonce`: BN‹›, `balance`: BN‹›, `stateRoot`: Buffer‹›, `codeHash`: Buffer‹›): *[Account](_account_.account.md)*
36+
37+
*Defined in [account.ts:61](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/account.ts#L61)*
38+
39+
This constructor takes the values, validates and assigns them.
40+
Use the static factory methods to assist in creating an Account from varying data types.
41+
42+
**Parameters:**
43+
44+
Name | Type | Default |
45+
------ | ------ | ------ |
46+
`nonce` | BN‹› | new BN(0) |
47+
`balance` | BN‹› | new BN(0) |
48+
`stateRoot` | Buffer‹› | KECCAK256_RLP |
49+
`codeHash` | Buffer‹› | KECCAK256_NULL |
50+
51+
**Returns:** *[Account](_account_.account.md)*
52+
53+
## Properties
54+
55+
### balance
56+
57+
**balance**: *BN*
58+
59+
*Defined in [account.ts:27](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/account.ts#L27)*
60+
61+
___
62+
63+
### codeHash
64+
65+
**codeHash**: *Buffer*
66+
67+
*Defined in [account.ts:29](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/account.ts#L29)*
68+
69+
___
70+
71+
### nonce
72+
73+
**nonce**: *BN*
74+
75+
*Defined in [account.ts:26](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/account.ts#L26)*
76+
77+
___
78+
79+
### stateRoot
80+
81+
**stateRoot**: *Buffer*
82+
83+
*Defined in [account.ts:28](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/account.ts#L28)*
84+
85+
## Methods
86+
87+
### isContract
88+
89+
**isContract**(): *boolean*
90+
91+
*Defined in [account.ts:96](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/account.ts#L96)*
92+
93+
Returns a `Boolean` deteremining if the account is a contract.
94+
95+
**Returns:** *boolean*
96+
97+
___
98+
99+
### isEmpty
100+
101+
**isEmpty**(): *boolean*
102+
103+
*Defined in [account.ts:103](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/account.ts#L103)*
104+
105+
Returns a `Boolean` determining if the account is empty.
106+
107+
**Returns:** *boolean*
108+
109+
___
110+
111+
### serialize
112+
113+
**serialize**(): *Buffer*
114+
115+
*Defined in [account.ts:89](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/account.ts#L89)*
116+
117+
Returns the RLP serialization of the account as a `Buffer`.
118+
119+
**Returns:** *Buffer*
120+
121+
___
122+
123+
### `Static` fromAccountData
124+
125+
**fromAccountData**(`accountData`: [AccountData](../interfaces/_account_.accountdata.md)): *[Account](_account_.account.md)‹›*
126+
127+
*Defined in [account.ts:31](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/account.ts#L31)*
128+
129+
**Parameters:**
130+
131+
Name | Type |
132+
------ | ------ |
133+
`accountData` | [AccountData](../interfaces/_account_.accountdata.md) |
134+
135+
**Returns:** *[Account](_account_.account.md)‹›*
136+
137+
___
138+
139+
### `Static` fromRlpSerializedAccount
140+
141+
**fromRlpSerializedAccount**(`serialized`: Buffer): *[Account](_account_.account.md)‹›*
142+
143+
*Defined in [account.ts:42](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/account.ts#L42)*
144+
145+
**Parameters:**
146+
147+
Name | Type |
148+
------ | ------ |
149+
`serialized` | Buffer |
150+
151+
**Returns:** *[Account](_account_.account.md)‹›*
152+
153+
___
154+
155+
### `Static` fromValuesArray
156+
157+
**fromValuesArray**(`values`: Buffer[]): *[Account](_account_.account.md)‹›*
158+
159+
*Defined in [account.ts:52](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/account.ts#L52)*
160+
161+
**Parameters:**
162+
163+
Name | Type |
164+
------ | ------ |
165+
`values` | Buffer[] |
166+
167+
**Returns:** *[Account](_account_.account.md)‹›*
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
[ethereumjs-util](../README.md)["account"](../modules/_account_.md)[AccountData](_account_.accountdata.md)
2+
3+
# Interface: AccountData
4+
5+
## Hierarchy
6+
7+
* **AccountData**
8+
9+
## Index
10+
11+
### Properties
12+
13+
* [balance](_account_.accountdata.md#optional-balance)
14+
* [codeHash](_account_.accountdata.md#optional-codehash)
15+
* [nonce](_account_.accountdata.md#optional-nonce)
16+
* [stateRoot](_account_.accountdata.md#optional-stateroot)
17+
18+
## Properties
19+
20+
### `Optional` balance
21+
22+
**balance**? : *[BNLike](../modules/_types_.md#bnlike)*
23+
24+
*Defined in [account.ts:20](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/account.ts#L20)*
25+
26+
___
27+
28+
### `Optional` codeHash
29+
30+
**codeHash**? : *[BufferLike](../modules/_types_.md#bufferlike)*
31+
32+
*Defined in [account.ts:22](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/account.ts#L22)*
33+
34+
___
35+
36+
### `Optional` nonce
37+
38+
**nonce**? : *[BNLike](../modules/_types_.md#bnlike)*
39+
40+
*Defined in [account.ts:19](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/account.ts#L19)*
41+
42+
___
43+
44+
### `Optional` stateRoot
45+
46+
**stateRoot**? : *[BufferLike](../modules/_types_.md#bufferlike)*
47+
48+
*Defined in [account.ts:21](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/account.ts#L21)*
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
[ethereumjs-util](../README.md)["types"](../modules/_types_.md)[TransformableToBuffer](_types_.transformabletobuffer.md)
2+
3+
# Interface: TransformableToBuffer
4+
5+
## Hierarchy
6+
7+
* **TransformableToBuffer**
8+
9+
## Index
10+
11+
### Methods
12+
13+
* [toBuffer](_types_.transformabletobuffer.md#tobuffer)
14+
15+
## Methods
16+
17+
### toBuffer
18+
19+
**toBuffer**(): *Buffer*
20+
21+
*Defined in [types.ts:10](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/types.ts#L10)*
22+
23+
**Returns:** *Buffer*
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[ethereumjs-util](../README.md)["@types/ethjs-util/index"](__types_ethjs_util_index_.md)
2+
3+
# Module: "@types/ethjs-util/index"
4+
5+

0 commit comments

Comments
 (0)