This repository has been archived by the owner on Nov 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Merged
Changes from 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
8fac81c
BlockId in client interface
arkpar aee53b2
Sync fixes and tests
arkpar 6910659
Updated to latest primitives
arkpar 85ea144
Updated dependencies
arkpar 9e3cebd
Updated for new (old) primitives
arkpar 9ce27eb
Network as workspace member
arkpar f2e767a
substrate-network
arkpar 832bfcc
Removed obsolete file
arkpar 9fc7597
begin_transaction on hash
arkpar 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Empty file.
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 |
---|---|---|
|
@@ -139,22 +139,27 @@ impl<B, E> Client<B, E> where | |
}) | ||
} | ||
|
||
fn state_at(&self, hash: &block::HeaderHash) -> error::Result<B::State> { | ||
self.backend.state_at(BlockId::Hash(*hash)) | ||
fn state_at(&self, id: BlockId) -> error::Result<B::State> { | ||
self.backend.state_at(id) | ||
} | ||
|
||
/// Return single storage entry of contract under given address in state in a block of given hash. | ||
pub fn storage(&self, hash: &block::HeaderHash, key: &StorageKey) -> error::Result<StorageData> { | ||
Ok(self.state_at(hash)? | ||
/// Expose backend reference. To be used in tests only | ||
pub fn backend(&self) -> &B { | ||
&self.backend | ||
} | ||
|
||
/// Return single storage entry of contract under given address in state in a block of given id. | ||
pub fn storage(&self, id: &BlockId, key: &StorageKey) -> error::Result<StorageData> { | ||
Ok(self.state_at(*id)? | ||
.storage(&key.0) | ||
.map(|x| StorageData(x.to_vec()))?) | ||
} | ||
|
||
/// Execute a call to a contract on top of state in a block of given hash. | ||
/// Execute a call to a contract on top of state in a block of given id. | ||
/// | ||
/// No changes are made. | ||
pub fn call(&self, hash: &block::HeaderHash, method: &str, call_data: &[u8]) -> error::Result<CallResult> { | ||
let state = self.state_at(hash)?; | ||
pub fn call(&self, id: &BlockId, method: &str, call_data: &[u8]) -> error::Result<CallResult> { | ||
let state = self.state_at(*id)?; | ||
let mut changes = state_machine::OverlayedChanges::default(); | ||
|
||
let _ = state_machine::execute( | ||
|
@@ -176,7 +181,7 @@ impl<B, E> Client<B, E> where | |
blockchain::BlockStatus::Unknown => return Ok(ImportResult::UnknownParent), | ||
} | ||
|
||
let mut transaction = self.backend.begin_transaction(BlockId::Number(header.number))?; | ||
let mut transaction = self.backend.begin_transaction(BlockId::Number(header.number - 1))?; | ||
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. why 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.
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. Changed it to |
||
let mut _state = transaction.state()?; | ||
// TODO: execute block on _state | ||
|
||
|
@@ -197,9 +202,9 @@ impl<B, E> Client<B, E> where | |
} | ||
|
||
/// Get block status. | ||
pub fn block_status(&self, hash: &block::HeaderHash) -> error::Result<BlockStatus> { | ||
pub fn block_status(&self, id: &BlockId) -> error::Result<BlockStatus> { | ||
// TODO: more efficient implementation | ||
match self.backend.blockchain().header(BlockId::Hash(*hash)).map_err(|e| error::Error::from_blockchain(Box::new(e)))?.is_some() { | ||
match self.backend.blockchain().header(*id).map_err(|e| error::Error::from_blockchain(Box::new(e)))?.is_some() { | ||
true => Ok(BlockStatus::InChain), | ||
false => Ok(BlockStatus::Unknown), | ||
} | ||
|
@@ -210,8 +215,13 @@ impl<B, E> Client<B, E> where | |
self.backend.blockchain().hash(block_number) | ||
} | ||
|
||
/// Get block header by hash. | ||
pub fn header(&self, hash: &block::HeaderHash) -> error::Result<Option<block::Header>> { | ||
self.backend.blockchain().header(BlockId::Hash(*hash)) | ||
/// Get block header by id. | ||
pub fn header(&self, id: &BlockId) -> error::Result<Option<block::Header>> { | ||
self.backend.blockchain().header(*id) | ||
} | ||
|
||
/// Get block body by id. | ||
pub fn body(&self, id: &BlockId) -> error::Result<Option<block::Body>> { | ||
self.backend.blockchain().body(*id) | ||
} | ||
} |
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.
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 can't see how this could possibly work in general - the polkadot runtime, at least, alters the state regardless of whether there are any transactions; the
transaction_root
must also be valid for blocks to be executed.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.
This is for tests only. And since this is substrate client, the code that uses it should not care. I guess we could have more elaborate testing framework under
/polkadot