pub struct Context {
pub cells: HashMap<OutPoint, (CellOutput, Bytes)>,
pub transaction_infos: HashMap<OutPoint, TransactionInfo>,
pub headers: HashMap<Byte32, HeaderView>,
pub epoches: HashMap<Byte32, EpochExt>,
pub block_extensions: HashMap<Byte32, Bytes>,
pub cells_by_data_hash: HashMap<Byte32, OutPoint>,
pub cells_by_type_hash: HashMap<Byte32, OutPoint>,
/* private fields */
}Expand description
Verification Context.
Fields§
§cells: HashMap<OutPoint, (CellOutput, Bytes)>§transaction_infos: HashMap<OutPoint, TransactionInfo>§headers: HashMap<Byte32, HeaderView>§epoches: HashMap<Byte32, EpochExt>§block_extensions: HashMap<Byte32, Bytes>§cells_by_data_hash: HashMap<Byte32, OutPoint>§cells_by_type_hash: HashMap<Byte32, OutPoint>Implementations§
Source§impl Context
impl Context
Sourcepub fn new_with_deterministic_rng() -> Self
pub fn new_with_deterministic_rng() -> Self
Create a new context with a deterministic random number generator, which can be used to generate deterministic out point of deployed contract.
Sourcepub fn add_contract_dir(&mut self, path: &str)
pub fn add_contract_dir(&mut self, path: &str)
Add new script search paths. Note that this does not replace the default search paths.
Sourcepub fn deploy_cell(&mut self, data: Bytes) -> OutPoint
pub fn deploy_cell(&mut self, data: Bytes) -> OutPoint
Deploy a cell.
Sourcepub fn deploy_cell_by_name(&mut self, filename: &str) -> OutPoint
pub fn deploy_cell_by_name(&mut self, filename: &str) -> OutPoint
Deploy a cell by filename. It provides the same functionality as the deploy_cell function, but looks for data in the file system.
Sourcepub fn insert_header(&mut self, header: HeaderView)
pub fn insert_header(&mut self, header: HeaderView)
Insert a block header into context. Afterwards, the header can be retrieved by its hash.
Sourcepub fn link_cell_with_block(
&mut self,
out_point: OutPoint,
block_hash: Byte32,
tx_index: usize,
)
pub fn link_cell_with_block( &mut self, out_point: OutPoint, block_hash: Byte32, tx_index: usize, )
Link a cell with a block to make the load_header_by_cell syscalls works.
Sourcepub fn get_cell_by_data_hash(&self, data_hash: &Byte32) -> Option<OutPoint>
pub fn get_cell_by_data_hash(&self, data_hash: &Byte32) -> Option<OutPoint>
Get the out-point of a cell by data_hash. The cell must has deployed to this context.
Sourcepub fn create_cell(&mut self, cell: CellOutput, data: Bytes) -> OutPoint
pub fn create_cell(&mut self, cell: CellOutput, data: Bytes) -> OutPoint
Create a cell with data.
Sourcepub fn create_cell_with_out_point(
&mut self,
out_point: OutPoint,
cell: CellOutput,
data: Bytes,
)
pub fn create_cell_with_out_point( &mut self, out_point: OutPoint, cell: CellOutput, data: Bytes, )
Create cell with specified out-point and cell data.
Sourcepub fn get_cell(&self, out_point: &OutPoint) -> Option<(CellOutput, Bytes)>
pub fn get_cell(&self, out_point: &OutPoint) -> Option<(CellOutput, Bytes)>
Get cell output and data by out-point.
Sourcepub fn build_script_with_hash_type(
&mut self,
out_point: &OutPoint,
hash_type: ScriptHashType,
args: Bytes,
) -> Option<Script>
pub fn build_script_with_hash_type( &mut self, out_point: &OutPoint, hash_type: ScriptHashType, args: Bytes, ) -> Option<Script>
Build script with out_point, hash_type, args. Return none if the out-point is not exist.
Sourcepub fn build_script(
&mut self,
out_point: &OutPoint,
args: Bytes,
) -> Option<Script>
pub fn build_script( &mut self, out_point: &OutPoint, args: Bytes, ) -> Option<Script>
Build script with out_point, args and hash_type(ScriptHashType::Type). Return none if the out-point is not exist.
Sourcepub fn complete_tx(&mut self, tx: TransactionView) -> TransactionView
pub fn complete_tx(&mut self, tx: TransactionView) -> TransactionView
Complete cell deps for a transaction. This function searches context cells; generate cell dep for referenced scripts.
Sourcepub fn capture_debug(&self) -> bool
pub fn capture_debug(&self) -> bool
Return capture_debug flag.
Sourcepub fn set_capture_debug(&mut self, capture_debug: bool)
pub fn set_capture_debug(&mut self, capture_debug: bool)
Capture debug output, default value is false.
Sourcepub fn captured_messages(&self) -> Vec<Message>
pub fn captured_messages(&self) -> Vec<Message>
Return captured messages.
Sourcepub fn verify_tx(
&self,
tx: &TransactionView,
max_cycles: u64,
) -> Result<Cycle, CKBError>
pub fn verify_tx( &self, tx: &TransactionView, max_cycles: u64, ) -> Result<Cycle, CKBError>
Verify the transaction in CKB-VM.
Sourcepub fn dump_tx(
&self,
tx: &TransactionView,
) -> Result<ReprMockTransaction, CKBError>
pub fn dump_tx( &self, tx: &TransactionView, ) -> Result<ReprMockTransaction, CKBError>
Dump the transaction in mock transaction format, so we can offload it to ckb debugger.
Trait Implementations§
Source§impl CellDataProvider for Context
impl CellDataProvider for Context
Source§fn get_cell_data_hash(&self, out_point: &OutPoint) -> Option<Byte32>
fn get_cell_data_hash(&self, out_point: &OutPoint) -> Option<Byte32>
Source§impl ExtensionProvider for Context
impl ExtensionProvider for Context
Source§impl HeaderProvider for Context
impl HeaderProvider for Context
Source§fn get_header(&self, block_hash: &Byte32) -> Option<HeaderView>
fn get_header(&self, block_hash: &Byte32) -> Option<HeaderView>
Auto Trait Implementations§
impl Freeze for Context
impl RefUnwindSafe for Context
impl Send for Context
impl Sync for Context
impl Unpin for Context
impl UnsafeUnpin for Context
impl UnwindSafe for Context
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more