@@ -10,7 +10,7 @@ import {
1010 makeLeader ,
1111} from '@agoric/casting' ;
1212import { makeImportContext } from './makeImportContext' ;
13- import { archivingAlternative , networkConfigUrl , rpcUrl } from 'config' ;
13+ import { archivingAlternative , networkConfigUrl , rpcUrl , apiUrl } from 'config' ;
1414import {
1515 AgoricChainStoragePathKind ,
1616 makeAgoricChainStorageWatcher ,
@@ -31,7 +31,11 @@ export const marshal = makeImportContext().fromBoard;
3131const fromAgoricNet = ( str : string ) : Promise < MinimalNetworkConfig > => {
3232 const [ netName , chainName ] = str . split ( ',' ) ;
3333 if ( chainName ) {
34- return Promise . resolve ( { chainName, rpcAddrs : [ rpcUrl ( netName ) ] } ) ;
34+ return Promise . resolve ( {
35+ chainName,
36+ rpcAddrs : [ rpcUrl ( netName ) ] ,
37+ apiAddrs : [ apiUrl ( netName ) ] ,
38+ } ) ;
3539 }
3640 return fetch ( networkConfigUrl ( netName ) ) . then ( res => res . json ( ) ) ;
3741} ;
@@ -70,7 +74,7 @@ export const makeRpcUtils = async () => {
7074 const netConfigURL = networkConfigUrl ( agoricNet ) ;
7175 const networkConfig = await fromAgoricNet ( agoricNet ) ;
7276
73- const { rpcAddrs, chainName } = networkConfig ;
77+ const { rpcAddrs, chainName, apiAddrs } = networkConfig ;
7478 const leader = makeLeader ( archivingAlternative ( chainName , rpcAddrs [ 0 ] ) , { } ) ;
7579
7680 const { vstorage : vst } = makeVstorageKit ( { fetch } , { chainName, rpcAddrs } ) ;
@@ -89,11 +93,19 @@ export const makeRpcUtils = async () => {
8993 return response . children ;
9094 } ,
9195 } ;
92-
96+ let didError = false ;
9397 const storageWatcher = makeAgoricChainStorageWatcher (
94- sample ( rpcAddrs ) ,
98+ sample ( apiAddrs ) ,
9599 chainName ,
96- marshal . unserialize ,
100+ e => {
101+ if ( didError ) {
102+ console . error ( e ) ;
103+ return ;
104+ }
105+ didError = true ;
106+ notifyError ( new Error ( 'Error reading vstorage data for path "' + e ) ) ;
107+ } ,
108+ marshal ,
97109 ) ;
98110
99111 return {
@@ -158,26 +170,12 @@ export const usePublishedDatum = (path?: string) => {
158170
159171 const { storageWatcher } = rpcUtils ;
160172 setStatus ( LoadStatus . Waiting ) ;
161-
162- let didError = false ;
163173 return storageWatcher . watchLatest (
164174 [ AgoricChainStoragePathKind . Data , `published.${ path } ` ] ,
165175 value => {
166176 setData ( value ) ;
167177 setStatus ( LoadStatus . Received ) ;
168178 } ,
169- e => {
170- if ( didError ) {
171- console . error ( e ) ;
172- return ;
173- }
174- didError = true ;
175- notifyError (
176- new Error (
177- 'Error reading vstorage data for path "' + path + '": ' + e ,
178- ) ,
179- ) ;
180- } ,
181179 ) ;
182180 } , [ path , rpcUtils ] ) ;
183181
0 commit comments