-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fce1b3c
commit 67e1ec6
Showing
20 changed files
with
2,816 additions
and
77 deletions.
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
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
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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
use ckb_std::error::SysError; | ||
use molecule::error::VerificationError; | ||
use molecule::lazy_reader::Error as LazyReaderError; | ||
|
||
#[derive(Debug)] | ||
pub enum Error { | ||
Sys(SysError), | ||
LazyReader(LazyReaderError), | ||
MoleculeEncoding, | ||
WrongSighashAll, | ||
WrongWitnessLayout, | ||
WrongOtxStart, | ||
WrongOtx, | ||
NoSealFound, | ||
AuthError, | ||
ScriptHashAbsent, | ||
WrongCount, | ||
} | ||
|
||
impl From<SysError> for Error { | ||
fn from(e: SysError) -> Self { | ||
Error::Sys(e) | ||
} | ||
} | ||
|
||
impl From<VerificationError> for Error { | ||
fn from(_: VerificationError) -> Self { | ||
Error::MoleculeEncoding | ||
} | ||
} | ||
|
||
impl From<LazyReaderError> for Error { | ||
fn from(e: LazyReaderError) -> Self { | ||
Error::LazyReader(e) | ||
} | ||
} |
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,56 @@ | ||
use core::cmp::min; | ||
|
||
use alloc::boxed::Box; | ||
use ckb_std::{error::SysError, syscalls}; | ||
use molecule::lazy_reader::{Cursor, Error, Read}; | ||
|
||
use crate::log; | ||
|
||
pub struct TransactionReader { | ||
pub total_length: usize, | ||
} | ||
|
||
impl TransactionReader { | ||
pub fn new() -> Self { | ||
let mut buf = [0u8; 4]; | ||
let result = syscalls::load_transaction(&mut buf, 0); | ||
let total_length = match result { | ||
Ok(l) => l, | ||
Err(e) => match e { | ||
SysError::LengthNotEnough(l) => l, | ||
_ => panic!("error on load_transaction"), | ||
}, | ||
}; | ||
Self { total_length } | ||
} | ||
} | ||
|
||
impl Read for TransactionReader { | ||
fn read(&self, buf: &mut [u8], offset: usize) -> Result<usize, Error> { | ||
log!( | ||
"try to read {} bytes into buffer with offset {}", | ||
buf.len(), | ||
offset | ||
); | ||
if offset >= self.total_length { | ||
return Err(Error::OutOfBound(offset, self.total_length)); | ||
} | ||
|
||
let remaining_len = self.total_length - offset; | ||
let min_len = min(remaining_len, buf.len()); | ||
|
||
if (offset + min_len) > self.total_length { | ||
return Err(Error::OutOfBound(offset + min_len, self.total_length)); | ||
} | ||
let actual_len = syscalls::load_transaction(buf, offset).map_err(|_| Error::Common)?; | ||
let read_len = min(buf.len(), actual_len); | ||
log!("totally read {} bytes", read_len); | ||
Ok(read_len) | ||
} | ||
} | ||
|
||
impl From<TransactionReader> for Cursor { | ||
fn from(data: TransactionReader) -> Self { | ||
Cursor::new(data.total_length, Box::new(data)) | ||
} | ||
} |
Oops, something went wrong.