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

Commit

Permalink
Merge pull request #275 from ethereumjs/add-account-class
Browse files Browse the repository at this point in the history
Add Account class
  • Loading branch information
holgerd77 authored Oct 7, 2020
2 parents d8b8e44 + e48478d commit c5dca47
Show file tree
Hide file tree
Showing 19 changed files with 772 additions and 198 deletions.
31 changes: 30 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,36 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)

## [7.0.6] - [UNRELEASED]

[ ADD REFERENCES TO YOUR WORK HERE UPON PRs. PLEASE ADOPT THE VERSION IF YOUR PR REQUIRES. ]
### New `Account` class

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)`.

**Instantiation**

The static factory methods assist in creating an `Account` object from varying data types: `Object: fromAccountData`, `RLP: fromRlpSerializedAccount`, and `Array: fromValuesArray`.

**Methods**: `isEmpty(): boolean`, `isContract(): boolean`, `serialize(): Buffer`

Example usage:

```typescript
import { Account, BN } from 'ethereumjs-util'

const account = new Account(
new BN(0), // nonce, default: 0
new BN(10).pow(new BN(18)), // balance, default: 0
undefined, // stateRoot, default: KECCAK256_RLP (hash of RLP of null)
undefined, // codeHash, default: KECCAK256_NULL (hash of null)
)
```

For more info see the documentation or examples of usage in `test/account.spec.ts`.

### New export: TypeScript types

A new file with helpful TypeScript types has been added to the exports of this project.

In this release it contains `BNLike`, `BufferLike`, and `TransformableToBuffer`.

## [7.0.5] - 2020-09-09

Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ assert.equal(new BN('dead', 16).add(new BN('101010', 2)), 57047)
### Modules

- [account](docs/modules/_account_.md)
- Account class
- Private/public key and address-related functionality (creation, validation, conversion)
- [address](docs/modules/_address_.md)
- Address class and type
Expand All @@ -46,6 +47,8 @@ assert.equal(new BN('dead', 16).add(new BN('101010', 2)), 57047)
- Helper function for creating a binary object (`DEPRECATED`)
- [signature](docs/modules/_signature_.md)
- Signing, signature validation, conversion, recovery
- [types](docs/modules/_types_.md)
- Helpful TypeScript types
- [externals](docs/modules/_externals_.md)
- Helper methods from `ethjs-util`
- Re-exports of `BN`, `rlp`
Expand Down
2 changes: 2 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

### Modules

* ["@types/ethjs-util/index"](modules/__types_ethjs_util_index_.md)
* ["account"](modules/_account_.md)
* ["address"](modules/_address_.md)
* ["bytes"](modules/_bytes_.md)
Expand All @@ -15,3 +16,4 @@
* ["helpers"](modules/_helpers_.md)
* ["object"](modules/_object_.md)
* ["signature"](modules/_signature_.md)
* ["types"](modules/_types_.md)
167 changes: 167 additions & 0 deletions docs/classes/_account_.account.md
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)‹›*
48 changes: 48 additions & 0 deletions docs/interfaces/_account_.accountdata.md
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)*
23 changes: 23 additions & 0 deletions docs/interfaces/_types_.transformabletobuffer.md
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*
5 changes: 5 additions & 0 deletions docs/modules/__types_ethjs_util_index_.md
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"


Loading

0 comments on commit c5dca47

Please sign in to comment.