forked from PegaSysEng/pantheon
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[NC-1344] Create a simple WorldStateDownloader (PegaSysEng#657)
- Loading branch information
Showing
35 changed files
with
1,436 additions
and
128 deletions.
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
95 changes: 95 additions & 0 deletions
95
...m/core/src/main/java/tech/pegasys/pantheon/ethereum/worldstate/StateTrieAccountValue.java
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,95 @@ | ||
/* | ||
* Copyright 2019 ConsenSys AG. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
*/ | ||
package tech.pegasys.pantheon.ethereum.worldstate; | ||
|
||
import tech.pegasys.pantheon.ethereum.core.Hash; | ||
import tech.pegasys.pantheon.ethereum.core.Wei; | ||
import tech.pegasys.pantheon.ethereum.rlp.RLPInput; | ||
import tech.pegasys.pantheon.ethereum.rlp.RLPOutput; | ||
|
||
/** Represents the raw values associated with an account in the world state trie. */ | ||
public class StateTrieAccountValue { | ||
|
||
private final long nonce; | ||
private final Wei balance; | ||
private final Hash storageRoot; | ||
private final Hash codeHash; | ||
|
||
public StateTrieAccountValue( | ||
final long nonce, final Wei balance, final Hash storageRoot, final Hash codeHash) { | ||
this.nonce = nonce; | ||
this.balance = balance; | ||
this.storageRoot = storageRoot; | ||
this.codeHash = codeHash; | ||
} | ||
|
||
/** | ||
* The account nonce, that is the number of transactions sent from that account. | ||
* | ||
* @return the account nonce. | ||
*/ | ||
public long getNonce() { | ||
return nonce; | ||
} | ||
|
||
/** | ||
* The available balance of that account. | ||
* | ||
* @return the balance, in Wei, of the account. | ||
*/ | ||
public Wei getBalance() { | ||
return balance; | ||
} | ||
|
||
/** | ||
* The hash of the root of the storage trie associated with this account. | ||
* | ||
* @return the hash of the root node of the storage trie. | ||
*/ | ||
public Hash getStorageRoot() { | ||
return storageRoot; | ||
} | ||
|
||
/** | ||
* The hash of the EVM bytecode associated with this account. | ||
* | ||
* @return the hash of the account code (which may be {@link Hash#EMPTY}. | ||
*/ | ||
public Hash getCodeHash() { | ||
return codeHash; | ||
} | ||
|
||
public void writeTo(final RLPOutput out) { | ||
out.startList(); | ||
|
||
out.writeLongScalar(nonce); | ||
out.writeUInt256Scalar(balance); | ||
out.writeBytesValue(storageRoot); | ||
out.writeBytesValue(codeHash); | ||
|
||
out.endList(); | ||
} | ||
|
||
public static StateTrieAccountValue readFrom(final RLPInput in) { | ||
in.enterList(); | ||
|
||
final long nonce = in.readLongScalar(); | ||
final Wei balance = in.readUInt256Scalar(Wei::wrap); | ||
final Hash storageRoot = Hash.wrap(in.readBytes32()); | ||
final Hash codeHash = Hash.wrap(in.readBytes32()); | ||
|
||
in.leaveList(); | ||
|
||
return new StateTrieAccountValue(nonce, balance, storageRoot, codeHash); | ||
} | ||
} |
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
Oops, something went wrong.