11use arc_swap:: ArcSwap ;
22use ckb_always_success_script:: ALWAYS_SUCCESS ;
3- use ckb_types:: { core:: ScriptHashType , packed, prelude:: * } ;
3+ use ckb_types:: { bytes :: Bytes , core :: cell :: CellMeta , core:: ScriptHashType , packed, prelude:: * } ;
44
5+ use crate :: traits:: BYTE_SHANNONS ;
56use crate :: { ckb_blake2b_256, types:: Hex } ;
67
8+ use std:: sync:: OnceLock ;
9+
10+ static CELL : OnceLock < CellMeta > = OnceLock :: new ( ) ;
11+
712lazy_static:: lazy_static! {
813 pub static ref CHAIN_ID : ArcSwap <u64 > = ArcSwap :: from_pointee( Default :: default ( ) ) ;
914 pub static ref PROTOCOL_VERSION : ArcSwap <Hex > = ArcSwap :: from_pointee( Default :: default ( ) ) ;
@@ -20,3 +25,26 @@ lazy_static::lazy_static! {
2025 . index( 0u32 . pack( ) )
2126 . build( ) ;
2227}
28+
29+ pub fn always_success_script_meta ( ) -> & ' static CellMeta {
30+ CELL . get_or_init ( || {
31+ let capacity = ( 32 + 8 + 1 + ALWAYS_SUCCESS . len ( ) ) as u64 * BYTE_SHANNONS ;
32+ let deploy_cell_output = packed:: CellOutputBuilder :: default ( )
33+ . capacity ( capacity. pack ( ) )
34+ . build ( ) ;
35+ let deploy_cell_out_point = packed:: OutPointBuilder :: default ( )
36+ . tx_hash ( ALWAYS_SUCCESS_DEPLOY_TX_HASH . pack ( ) )
37+ . index ( 0u32 . pack ( ) )
38+ . build ( ) ;
39+ CellMeta {
40+ cell_output : deploy_cell_output,
41+ out_point : deploy_cell_out_point,
42+ transaction_info : None ,
43+ data_bytes : ALWAYS_SUCCESS . len ( ) as u64 ,
44+ mem_cell_data : Some ( Bytes :: from ( ALWAYS_SUCCESS . to_vec ( ) ) ) ,
45+ mem_cell_data_hash : Some ( packed:: Byte32 :: new_unchecked ( Bytes :: from (
46+ ckb_blake2b_256 ( ALWAYS_SUCCESS ) . to_vec ( ) ,
47+ ) ) ) ,
48+ }
49+ } )
50+ }
0 commit comments