Skip to content

Commit

Permalink
5811 merge block tags (#5823)
Browse files Browse the repository at this point in the history
* finalized and safe tags

* doc updates

* block tag tests

* test fixtures

* types optimization

* updated validation of blocks comp

* modified tests and added tests data

* blocks validation updated

* updated compareBlockNumbers and added tests

* change log updates

* updated same style

* removed genesis tag support and updated test data

* updated changelog

* update changelog

* changelog update

* updates

* latest vs safe test
  • Loading branch information
jdevcs authored Feb 14, 2023
1 parent d87d3a6 commit 57c7563
Show file tree
Hide file tree
Showing 46 changed files with 571 additions and 60 deletions.
1 change: 1 addition & 0 deletions packages/web3-core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added

- Added rpc exception codes following eip-1474 as an experimental feature (if `useRpcCallSpecification` at `enableExperimentalFeatures` is `true`) (#5525)
- Added support of `safe` and `finalized` block tags (#5823)
2 changes: 2 additions & 0 deletions packages/web3-core/src/web3_config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@ export abstract class Web3Config
* - `"earliest"` - String: The genesis block
* - `"latest"` - String: The latest block (current head of the blockchain)
* - `"pending"` - String: The currently mined block (including pending transactions)
* - `"finalized"` - String: (For POS networks) The finalized block is one which has been accepted as canonical by greater than 2/3 of validators
* - `"safe"` - String: (For POS networks) The safe head block is one which under normal network conditions, is expected to be included in the canonical chain. Under normal network conditions the safe head and the actual tip of the chain will be equivalent (with safe head trailing only by a few seconds). Safe heads will be less likely to be reorged than the proof of work network`s latest blocks.
*/
public set defaultBlock(val) {
this.emit(Web3ConfigEvent.CONFIG_CHANGE, {
Expand Down
1 change: 1 addition & 0 deletions packages/web3-eth-contract/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -227,3 +227,4 @@ const transactionHash = receipt.transactionHash;
### Added

- Added functionality of `createAccessList` for contracts ( #5780 )
- Added support of `safe` and `finalized` block tags (#5823)
10 changes: 5 additions & 5 deletions packages/web3-eth-contract/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export interface ContractEventOptions {
*/
filter?: Record<string, unknown>;
/**
* The block number (greater than or equal to) from which to get events on. Pre-defined block numbers as `earliest`, `latest` and `pending` can also be used. For specific range use {@link Contract.getPastEvents}.
* The block number (greater than or equal to) from which to get events on. Pre-defined block numbers as `earliest`, `latest`, `pending`, `safe` or `finalized` can also be used. For specific range use {@link Contract.getPastEvents}.
*/
fromBlock?: BlockNumberOrTag;
/**
Expand Down Expand Up @@ -236,7 +236,7 @@ export interface NonPayableMethodObject<Inputs = unknown[], Outputs = unknown[]>
* ```
*
* @param tx - The options used for calling.
* @param block - If you pass this parameter it will not use the default block set with contract.defaultBlock. Pre-defined block numbers as `earliest`, `latest`, and `pending` can also be used. Useful for requesting data from or replaying transactions in past blocks.
* @param block - If you pass this parameter it will not use the default block set with contract.defaultBlock. Pre-defined block numbers as `earliest`, `latest`, `pending`, `safe` or `finalized can also be used. Useful for requesting data from or replaying transactions in past blocks.
* @returns - The return value(s) of the smart contract method. If it returns a single value, it’s returned as is. If it has multiple return values they are returned as an object with properties and indices.
*/

Expand Down Expand Up @@ -355,7 +355,7 @@ export interface NonPayableMethodObject<Inputs = unknown[], Outputs = unknown[]>
* This method generates an access list for a transaction. You must specify a `from` address and `gas` if it’s not specified in options.
*
* @param options - The options used for createAccessList.
* @param block - If you pass this parameter it will not use the default block set with contract.defaultBlock. Pre-defined block numbers as `earliest`, `latest`, and `pending` can also be used. Useful for requesting data from or replaying transactions in past blocks.
* @param block - If you pass this parameter it will not use the default block set with contract.defaultBlock. Pre-defined block numbers as `earliest`, `latest`, `pending`, `safe` or `finalized can also be used. Useful for requesting data from or replaying transactions in past blocks.
* @returns The returned data of the createAccessList, e.g. The generated access list for transaction.
*
* ```ts
Expand Down Expand Up @@ -426,7 +426,7 @@ export interface PayableMethodObject<Inputs = unknown[], Outputs = unknown[]> {
* ```
*
* @param tx - The options used for calling.
* @param block - If you pass this parameter it will not use the default block set with contract.defaultBlock. Pre-defined block numbers as `earliest`, `latest`, and `pending` can also be used. Useful for requesting data from or replaying transactions in past blocks.
* @param block - If you pass this parameter it will not use the default block set with contract.defaultBlock. Pre-defined block numbers as `earliest`, `latest`, `pending`, `safe` or `finalized can also be used. Useful for requesting data from or replaying transactions in past blocks.
* @returns - The return value(s) of the smart contract method. If it returns a single value, it’s returned as is. If it has multiple return values they are returned as an object with properties and indices.
*/
call<SpecialOutput = Outputs>(
Expand Down Expand Up @@ -544,7 +544,7 @@ export interface PayableMethodObject<Inputs = unknown[], Outputs = unknown[]> {
* This method generates an access list for a transaction. You must specify a `from` address and `gas` if it’s not specified in options.
*
* @param options - The options used for createAccessList.
* @param block - If you pass this parameter it will not use the default block set with contract.defaultBlock. Pre-defined block numbers as `earliest`, `latest`, and `pending` can also be used. Useful for requesting data from or replaying transactions in past blocks.
* @param block - If you pass this parameter it will not use the default block set with contract.defaultBlock. Pre-defined block numbers as `earliest`, `latest`, `pending`, `safe` or `finalized can also be used. Useful for requesting data from or replaying transactions in past blocks.
* @returns The returned data of the createAccessList, e.g. The generated access list for transaction.
*
* ```ts
Expand Down
1 change: 1 addition & 0 deletions packages/web3-eth/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added

- Added `createAccessList` functionality ( #5780 )
- Added support of `safe` and `finalized` block tags (#5823)
Loading

0 comments on commit 57c7563

Please sign in to comment.