@@ -6,6 +6,8 @@ import { Network, NetworkOption } from '../type/base';
66import { buildCCCDevnetKnownScripts } from '../scripts/private' ;
77import accounts from '../../account/account.json' ;
88import { validateNetworkOpt } from '../util/validator' ;
9+ import { genSystemScripts } from '../scripts/gen' ;
10+ import { readUserDeployedScriptsInfo } from '../scripts/util' ;
911
1012export interface ReplProp extends NetworkOption {
1113 proxyRpc ?: boolean ;
@@ -28,15 +30,28 @@ export function repl({ network = Network.devnet, proxyRpc = false }: ReplProp) {
2830 context . ccc = ccc ;
2931 context . cccA = cccA ;
3032 context . networks = networks ;
31- context . Client = initGlobalClientBuilder ( ) ;
32- context . client = initGlobalClientBuilder ( ) . new ( network ) ;
33+ context . Client = initGlobalClientBuilder ( proxyRpc ) ;
34+ context . client = initGlobalClientBuilder ( proxyRpc ) . new ( network ) ;
3335 context . accounts = accounts ;
36+ context . myScripts = buildMyScripts ( ) . new ( network ) ;
37+ context . systemScripts = buildSystemScripts ( ) . new ( network ) ;
38+
3439 context . help = printHelpText ;
3540}
3641
37- export function initGlobalClientBuilder ( ) {
42+ export function initGlobalClientBuilder ( proxyRpc : boolean ) {
3843 return {
3944 new : ( network : Network ) => {
45+ if ( proxyRpc ) {
46+ return network === 'mainnet'
47+ ? new ccc . ClientPublicMainnet ( { url : networks . mainnet . proxy_rpc_url } )
48+ : network === 'testnet'
49+ ? new ccc . ClientPublicTestnet ( { url : networks . testnet . proxy_rpc_url } )
50+ : new ccc . ClientPublicTestnet ( {
51+ url : networks . devnet . proxy_rpc_url ,
52+ scripts : buildCCCDevnetKnownScripts ( ) ,
53+ } ) ;
54+ }
4055 return network === 'mainnet'
4156 ? new ccc . ClientPublicMainnet ( )
4257 : network === 'testnet'
@@ -72,6 +87,29 @@ Global Variables to use:
7287 const myClient = Client.fromUrl('<your rpc url>', 'devnet' | 'testnet' | 'mainnet');
7388 - accounts, test accounts array from OffCKB
7489 - networks, network information configs
90+ - myScripts, user-deployed scripts information via offckb deploy
91+ - systemScripts, built-in scripts information in the blockchain
7592 - help, print this help message
7693` ) ;
7794}
95+
96+ export function buildSystemScripts ( ) {
97+ return {
98+ new : ( network : Network ) => {
99+ const systemScripts = genSystemScripts ( ) ;
100+ return network === Network . devnet
101+ ? systemScripts ?. devnet
102+ : network === Network . testnet
103+ ? systemScripts ?. testnet
104+ : systemScripts ?. mainnet ;
105+ } ,
106+ } ;
107+ }
108+
109+ export function buildMyScripts ( ) {
110+ return {
111+ new : ( network : Network ) => {
112+ return readUserDeployedScriptsInfo ( network ) ;
113+ } ,
114+ } ;
115+ }
0 commit comments