@@ -15,37 +15,35 @@ import Node from './Node.js';
1515import { DryRunResult , DryRunResults , SignedTx } from './apis/node/index.js' ;
1616import { decode , encode , Encoded , Encoding } from './utils/encoder.js' ;
1717
18- /**
19- * @category chain
20- * @param type - Type
21- * @param options - Options
22- */
23- export async function _getPollInterval (
18+ async function getEventInterval (
2419 type : 'key-block' | 'micro-block' ,
2520 {
2621 _expectedMineRate,
2722 _microBlockCycle,
2823 onNode,
2924 } : { _expectedMineRate ?: number ; _microBlockCycle ?: number ; onNode : Node } ,
3025) : Promise < number > {
31- const getVal = async (
32- t : string ,
33- val : number | undefined ,
34- devModeDef : number ,
35- def : number ,
36- ) : Promise < number | null > => {
37- if ( t !== type ) return null ;
38- if ( val != null ) return val ;
39- return ( await onNode ?. getNetworkId ( ) ) === 'ae_dev' ? devModeDef : def ;
40- } ;
26+ if ( _expectedMineRate != null && type === 'key-block' ) return _expectedMineRate ;
27+ if ( _microBlockCycle != null && type === 'micro-block' ) return _microBlockCycle ;
28+
29+ const networkId = await onNode . getNetworkId ( ) ;
30+ if ( networkId === 'ae_dev' ) return 0 ;
31+ if ( ! [ 'ae_mainnet' , 'ae_uat' ] . includes ( networkId ) && ( await onNode . _isHyperchain ( ) ) ) return 3000 ;
32+
33+ if ( type === 'key-block' ) return 180000 ;
34+ else return 3000 ;
35+ }
4136
42- const base =
43- ( await getVal ( 'key-block' , _expectedMineRate , 0 , 180000 ) ) ??
44- ( await getVal ( 'micro-block' , _microBlockCycle , 0 , 3000 ) ) ??
45- ( ( ) => {
46- throw new InternalError ( `Unknown type: ${ type } ` ) ;
47- } ) ( ) ;
48- return Math . floor ( base / 3 ) ;
37+ /**
38+ * @category chain
39+ * @param type - Type
40+ * @param options - Options
41+ */
42+ export async function _getPollInterval (
43+ type : Parameters < typeof getEventInterval > [ 0 ] ,
44+ options : Parameters < typeof getEventInterval > [ 1 ] ,
45+ ) : Promise < number > {
46+ return Math . floor ( ( await getEventInterval ( type , options ) ) / 3 ) ;
4947}
5048
5149const heightCache : WeakMap < Node , { time : number ; height : number } > = new WeakMap ( ) ;
0 commit comments