@@ -50,9 +50,9 @@ export class ABlockWallet {
5050 /* -------------------------------------------------------------------------- */
5151 /* Member Variables */
5252 /* -------------------------------------------------------------------------- */
53- private intercomHost : string | undefined ;
5453 private computeHost : string | undefined ;
5554 private storageHost : string | undefined ;
55+ private intercomHost : string | undefined ;
5656 private notaryHost : string | undefined ;
5757 private keyMgmt : mgmtClient | undefined ;
5858 private computeRoutesPoW : Map < string , number > | undefined ;
@@ -62,9 +62,9 @@ export class ABlockWallet {
6262 /* Constructor */
6363 /* -------------------------------------------------------------------------- */
6464 constructor ( ) {
65- this . intercomHost = undefined ;
6665 this . computeHost = undefined ;
6766 this . storageHost = undefined ;
67+ this . intercomHost = undefined ;
6868 this . notaryHost = undefined ;
6969 this . keyMgmt = undefined ;
7070 this . computeRoutesPoW = undefined ;
@@ -184,27 +184,31 @@ export class ABlockWallet {
184184 * Common network initialization (retrieval of PoW list for compute as well as storage)
185185 *
186186 * @private
187- * @param {IClientConfig } config - Additional configuration parameters
187+ * @param {IClientConfig } config - Configuration parameters
188188 * @memberof ABlockWallet
189189 */
190- public async initNetwork ( config : IClientConfig ) : Promise < IClientResponse > {
191- this . intercomHost = config . intercomHost ;
190+ private async initNetwork ( config : IClientConfig ) : Promise < IClientResponse > {
192191 this . computeHost = config . computeHost ;
193192 this . storageHost = config . storageHost ;
193+ this . intercomHost = config . intercomHost ;
194194 this . notaryHost = config . notaryHost ;
195- // Set routes proof-of-work requirements
195+
196+ if ( this . computeHost == undefined )
197+ return {
198+ status : 'error' ,
199+ reason : IErrorInternal . NoComputeHostProvided
200+ } as IClientResponse ;
196201
197202 // Initialize routes proof-of-work for compute host
198- if ( this . computeHost !== undefined ) {
199- this . computeRoutesPoW = new Map ( ) ;
200- const initComputeResult = await this . initNetworkForHost (
201- this . computeHost ,
202- this . computeRoutesPoW ,
203- ) ;
204- if ( initComputeResult . status == 'error' ) return initComputeResult ;
205- }
203+ this . computeRoutesPoW = new Map ( ) ;
204+ const initComputeResult = await this . initNetworkForHost (
205+ this . computeHost ,
206+ this . computeRoutesPoW ,
207+ ) ;
208+ if ( initComputeResult . status == 'error' ) return initComputeResult ;
206209
207- // Initialize routes proof-of-work for storage host
210+
211+ // Optional - Initialize routes proof-of-work for storage host
208212 if ( this . storageHost !== undefined ) {
209213 this . storageRoutesPoW = new Map ( ) ;
210214 const initStorageResult = await this . initNetworkForHost (
@@ -215,10 +219,10 @@ export class ABlockWallet {
215219 }
216220
217221 if (
218- this . storageHost === undefined &&
219222 this . computeHost === undefined &&
220- this . notaryHost === undefined &&
221- this . intercomHost === undefined
223+ this . storageHost === undefined &&
224+ this . intercomHost === undefined &&
225+ this . notaryHost === undefined
222226 )
223227 return {
224228 status : 'error' ,
@@ -237,16 +241,10 @@ export class ABlockWallet {
237241 * @param {IClientConfig } config - Additional configuration parameters
238242 * @memberof ABlockWallet
239243 */
240- public async initNetworkForHost (
241- host : string | undefined ,
244+ private async initNetworkForHost (
245+ host : string ,
242246 routesPow : Map < string , number > ,
243247 ) : Promise < IClientResponse > {
244- if ( ! host ) {
245- return {
246- status : 'error' ,
247- reason : IErrorInternal . NoHostsProvided ,
248- } as IClientResponse ;
249- }
250248 // Set routes proof-of-work requirements
251249 const debugData = await this . getDebugData ( host ) ;
252250 if ( debugData . status === 'error' )
@@ -359,8 +357,10 @@ export class ABlockWallet {
359357 */
360358 public async fetchTransactions ( transactionHashes : string [ ] ) : Promise < IClientResponse > {
361359 try {
362- if ( ! this . storageHost || ! this . keyMgmt || ! this . storageRoutesPoW )
360+ if ( ! this . keyMgmt )
363361 throw new Error ( IErrorInternal . ClientNotInitialized ) ;
362+ if ( ! this . storageHost || ! this . storageRoutesPoW ) /* Storage is optional on wallet init, but must be initialized here */
363+ throw new Error ( IErrorInternal . StorageNotInitialized ) ;
364364 const headers = this . getRequestIdAndNonceHeadersForRoute (
365365 this . computeRoutesPoW ,
366366 IAPIRoute . FetchBalance ,
@@ -509,8 +509,10 @@ export class ABlockWallet {
509509 */
510510 async getNotaryBurnAddress ( ) : Promise < IClientResponse > {
511511 try {
512- if ( ! this . notaryHost || ! this . keyMgmt )
512+ if ( ! this . keyMgmt )
513513 throw new Error ( IErrorInternal . ClientNotInitialized ) ;
514+ if ( ! this . notaryHost )
515+ throw new Error ( IErrorInternal . NotaryNotInitialized ) ;
514516 const headers = this . getRequestIdAndNonceHeadersForRoute (
515517 new Map ( ) ,
516518 IAPIRoute . GetNotaryBurnAddress ,
@@ -554,8 +556,10 @@ export class ABlockWallet {
554556 signatures : IGenericKeyPair < string > ,
555557 ) : Promise < IClientResponse > {
556558 try {
557- if ( ! this . notaryHost || ! this . keyMgmt )
559+ if ( ! this . keyMgmt )
558560 throw new Error ( IErrorInternal . ClientNotInitialized ) ;
561+ if ( ! this . notaryHost )
562+ throw new Error ( IErrorInternal . NotaryNotInitialized ) ;
559563 const headers = this . getRequestIdAndNonceHeadersForRoute (
560564 new Map ( ) ,
561565 IAPIRoute . GetNotarySignature ,
@@ -684,8 +688,10 @@ export class ABlockWallet {
684688 receiveAddress : IKeypairEncrypted ,
685689 ) : Promise < IClientResponse > {
686690 try {
687- if ( ! this . computeHost || ! this . intercomHost || ! this . keyMgmt || ! this . computeRoutesPoW )
691+ if ( ! this . computeHost || ! this . keyMgmt || ! this . computeRoutesPoW )
688692 throw new Error ( IErrorInternal . ClientNotInitialized ) ;
693+ if ( ! this . intercomHost )
694+ throw new Error ( IErrorInternal . IntercomNotInitialized ) ;
689695 const senderKeypair = throwIfErr ( this . keyMgmt . decryptKeypair ( receiveAddress ) ) ;
690696 const [ allAddresses , keyPairMap ] = throwIfErr (
691697 this . keyMgmt . getAllAddressesAndKeypairMap ( allKeypairs ) ,
@@ -829,8 +835,10 @@ export class ABlockWallet {
829835 allEncryptedTxs : ICreateTransactionEncrypted [ ] ,
830836 ) : Promise < IClientResponse > {
831837 try {
832- if ( ! this . computeHost || ! this . intercomHost || ! this . keyMgmt || ! this . computeRoutesPoW )
838+ if ( ! this . computeHost || ! this . keyMgmt || ! this . computeRoutesPoW )
833839 throw new Error ( IErrorInternal . ClientNotInitialized ) ;
840+ if ( ! this . intercomHost )
841+ throw new Error ( IErrorInternal . IntercomNotInitialized ) ;
834842
835843 // Generate a key-pair map
836844 const [ allAddresses , keyPairMap ] = throwIfErr (
@@ -1229,8 +1237,10 @@ export class ABlockWallet {
12291237 allKeypairs : IKeypairEncrypted [ ] ,
12301238 ) : Promise < IClientResponse > {
12311239 try {
1232- if ( ! this . computeHost || ! this . intercomHost || ! this . keyMgmt || ! this . computeRoutesPoW )
1240+ if ( ! this . computeHost || ! this . keyMgmt || ! this . computeRoutesPoW )
12331241 throw new Error ( IErrorInternal . ClientNotInitialized ) ;
1242+ if ( ! this . intercomHost )
1243+ throw new Error ( IErrorInternal . IntercomNotInitialized ) ;
12341244 const [ allAddresses , keyPairMap ] = throwIfErr (
12351245 this . keyMgmt . getAllAddressesAndKeypairMap ( allKeypairs ) ,
12361246 ) ;
@@ -1336,13 +1346,12 @@ export class ABlockWallet {
13361346 * Get information regarding the PoW required for all routes
13371347 *
13381348 * @private
1339- * @param {(string | undefined ) } host - Host address to retrieve proof-of-work data from
1349+ * @param {(string) } host - Host address to retrieve proof-of-work data from
13401350 * @return {* } {Promise<IClientResponse>}
13411351 * @memberof ABlockWallet
13421352 */
1343- private async getDebugData ( host : string | undefined ) : Promise < IClientResponse > {
1353+ private async getDebugData ( host : string ) : Promise < IClientResponse > {
13441354 try {
1345- if ( ! host ) throw new Error ( IErrorInternal . ClientNotInitialized ) ;
13461355 const routesPow =
13471356 host === this . computeHost ? this . computeRoutesPoW : this . storageRoutesPoW ;
13481357 const headers = this . getRequestIdAndNonceHeadersForRoute (
0 commit comments