-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Upgrade for new spawn * Fix make test
- Loading branch information
Showing
10 changed files
with
272 additions
and
142 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
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,29 +1,34 @@ | ||
// Import from `core` instead of from `std` since we are in no-std mode | ||
use crate::error::Error; | ||
use alloc::vec; | ||
use ckb_std::ckb_constants::Source; | ||
use ckb_std::ckb_types::core::ScriptHashType; | ||
use ckb_std::high_level::{load_script, spawn_cell}; | ||
use ckb_std::syscalls; | ||
use core::ffi::CStr; | ||
use core::result::Result; | ||
|
||
pub fn main() -> Result<(), Error> { | ||
let arg1 = CStr::from_bytes_with_nul(b"hello\0").unwrap(); | ||
let arg2 = CStr::from_bytes_with_nul(b"world\0").unwrap(); | ||
let argv = [ | ||
CStr::from_bytes_with_nul(b"hello\0").unwrap(), | ||
CStr::from_bytes_with_nul(b"world\0").unwrap(), | ||
]; | ||
let mut std_fds: [u64; 2] = [0, 0]; | ||
let mut son_fds: [u64; 3] = [0, 0, 0]; | ||
let (r0, w0) = syscalls::pipe()?; | ||
std_fds[0] = r0; | ||
son_fds[1] = w0; | ||
let (r1, w1) = syscalls::pipe()?; | ||
std_fds[1] = w1; | ||
son_fds[0] = r1; | ||
let code_hash = load_script().unwrap().args().raw_data(); | ||
ckb_std::debug!("code_hash: {:?}", code_hash); | ||
|
||
let mut content = vec![0; 80]; | ||
let ret = spawn_cell( | ||
&code_hash[..], | ||
ScriptHashType::Data1, | ||
&[arg1, arg2][..], | ||
8, | ||
&mut content, | ||
spawn_cell(&code_hash[..], ScriptHashType::Data1, &argv, &son_fds)?; | ||
let mut buf: [u8; 256] = [0; 256]; | ||
let len = syscalls::read(std_fds[0], &mut buf)?; | ||
assert_eq!(len, 10); | ||
buf[len] = 0; | ||
assert_eq!( | ||
CStr::from_bytes_until_nul(&buf).unwrap().to_str().unwrap(), | ||
"helloworld" | ||
); | ||
assert!(ret == Ok(0)); | ||
assert!(content.len() == 10); | ||
content.resize(content.len() + 1, 0); | ||
let c_str = CStr::from_bytes_until_nul(&content).unwrap(); | ||
assert_eq!(c_str.to_str().unwrap(), "helloworld"); | ||
Ok(()) | ||
} |
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
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.