This repository has been archived by the owner on Feb 4, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 274
BlockInformation Type Port from Web3.js #232
Open
TheGreatAxios
wants to merge
2
commits into
simolus3:master
Choose a base branch
from
drd-dep-2:block_type
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,120 @@ | ||
import 'package:web3dart/credentials.dart'; | ||
import 'package:web3dart/src/crypto/formatting.dart'; | ||
import 'package:web3dart/web3dart.dart'; | ||
|
||
class BlockInformation { | ||
EtherAmount? baseFeePerGas; | ||
final EthereumAddress? from; // Author | ||
final String? boundary; | ||
final String? difficulty; | ||
final String? extraData; | ||
final String? gasLimit; | ||
final String? gasUsed; | ||
final String? hash; | ||
final String? logsBloom; | ||
final EthereumAddress? miner; | ||
final String? mixHash; | ||
final String? nonce; | ||
final EtherAmount? baseFeePerGas; | ||
final String? number; | ||
final String? parentHash; | ||
final String? receiptsRoot; | ||
final String? seedHash; | ||
final String? sha3Uncles; | ||
final String? size; | ||
final String? stateRoot; | ||
final String? timestamp; | ||
final String? totalDifficulty; | ||
final List<TransactionInformation>? transactions; | ||
final String? transactionsRoot; | ||
final List<dynamic>? uncles; | ||
|
||
BlockInformation({this.baseFeePerGas}); | ||
BlockInformation({ | ||
this.from, | ||
this.boundary, | ||
this.difficulty, | ||
this.extraData, | ||
this.gasLimit, | ||
this.gasUsed, | ||
this.hash, | ||
this.logsBloom, | ||
this.miner, | ||
this.mixHash, | ||
this.nonce, | ||
this.baseFeePerGas, | ||
this.number, | ||
this.parentHash, | ||
this.receiptsRoot, | ||
this.seedHash, | ||
this.sha3Uncles, | ||
this.size, | ||
this.stateRoot, | ||
this.timestamp, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah it should probably be a |
||
this.totalDifficulty, | ||
this.transactions, | ||
this.transactionsRoot, | ||
this.uncles, | ||
}); | ||
|
||
factory BlockInformation.fromJson(Map<String, dynamic> json) { | ||
final List<Map<String, dynamic>>? _list = List.castFrom(json['transactions'] as List<dynamic>); | ||
List<TransactionInformation>? _transactions; | ||
if (_list != null) { | ||
_transactions = _list.map((Map<String, dynamic> e) => TransactionInformation.fromMap(e)).toList(); | ||
} else { | ||
_transactions = null; | ||
} | ||
|
||
final EthereumAddress? _from = json.containsKey('author') ? EthereumAddress.fromHex(json['author'] as String) : null; | ||
final String? _boundary = json.containsKey('boundary') ? json['boundary'] as String : null; | ||
final String? _difficulty = json.containsKey('difficulty') ? json['difficulty'] as String : null; | ||
final String? _extraData = json.containsKey('extraData') ? json['extraData'] as String : null; | ||
final String? _gasLimit = json.containsKey('gasLimit') ? json['gasLimit'] as String : null; | ||
final String? _gasUsed = json.containsKey('gasUsed') ? json['gasUsed'] as String : null; | ||
final String? _hash = json.containsKey('hash') ? json['hash'] as String : null; | ||
final String? _logsBloom = json.containsKey('logsBloom') ? json['logsBloom'] as String : null; | ||
final EthereumAddress? _miner = json.containsKey('miner') ? EthereumAddress.fromHex(json['miner'] as String) : null; | ||
final String? _mixHash = json.containsKey('mixHash') ? json['mixHash'] as String : null; | ||
final String? _nonce = json.containsKey('nonce') ? json['nonce'] as String : null; | ||
final EtherAmount? _baseFeePerGas = json.containsKey('baseFeePerGas') ? EtherAmount.fromUnitAndValue(EtherUnit.wei, hexToInt(json['baseFeePerGas'] as String)) : null; | ||
final String? _number = json.containsKey('number') ? json['number'] as String : null; | ||
final String? _parentHash = json.containsKey('parentHash') ? json['parentHash'] as String : null; | ||
final String? _receiptsRoot = json.containsKey('receiptsRoot') ? json['receiptsRoot'] as String : null; | ||
final String? _seedHash = json.containsKey('seedHash') ? json['seedHash'] as String : null; | ||
final String? _sha3Uncles = json.containsKey('sha3Uncles') ? json['sha3Uncles'] as String : null; | ||
final String? _size = json.containsKey('size') ? json['size'] as String : null; | ||
final String? _stateRoot = json.containsKey('stateRoot') ? json['size'] as String : null; | ||
final String? _timestamp = json.containsKey('timestamp') ? json['timestamp'] as String : null; | ||
final String? _totalDifficulty = json.containsKey('totalDifficulty') ? json['totalDifficulty'] as String : null; | ||
final String? _transactionsRoot = json.containsKey('transactionsRoot') ? json['transactionsRoot'] as String : null; | ||
final List<dynamic>? _uncles = json.containsKey('uncles') ? json['uncles'] as List<dynamic> : null; | ||
|
||
|
||
return BlockInformation( | ||
baseFeePerGas: json.containsKey('baseFeePerGas') | ||
? EtherAmount.fromUnitAndValue( | ||
EtherUnit.wei, hexToInt(json['baseFeePerGas'] as String)) | ||
: null); | ||
from: _from, | ||
boundary: _boundary, | ||
difficulty: _difficulty, | ||
extraData: _extraData, | ||
gasLimit: _gasLimit, | ||
gasUsed: _gasUsed, | ||
hash: _hash, | ||
logsBloom: _logsBloom, | ||
miner: _miner, | ||
mixHash: _mixHash, | ||
nonce: _nonce, | ||
baseFeePerGas: _baseFeePerGas, | ||
number: _number, | ||
parentHash: _parentHash, | ||
receiptsRoot: _receiptsRoot, | ||
seedHash: _seedHash, | ||
sha3Uncles: _sha3Uncles, | ||
size: _size, | ||
stateRoot: _stateRoot, | ||
timestamp: _timestamp, | ||
totalDifficulty: _totalDifficulty, | ||
transactions: _transactions, | ||
transactionsRoot: _transactionsRoot, | ||
uncles: _uncles, | ||
); | ||
} | ||
|
||
bool get isSupportEIP1559 => baseFeePerGas != null; | ||
|
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
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 think we should not rush to add all the info that
eth_getBlockByNumber
returns without carefully choosing an appropriate data type for each field. If we make them strings and then decide to change toint
, it would be a breaking change.If we do not have resources to choose carefully, we should add only the fields we are conscious about, like this timestamp which is definitely int and not null.