@@ -50,7 +50,7 @@ export class TangleService {
5050 try {
5151 // If the query is an integer then lookup a milestone
5252 if ( / ^ \d + $ / . test ( query ) ) {
53- console . log ( "tangelSearch milestone" )
53+ console . log ( "tangelSearch: milestone" )
5454 const milestone = await client . milestone ( Number . parseInt ( query , 10 ) ) ;
5555
5656 return {
@@ -70,6 +70,7 @@ export class TangleService {
7070 await this . info ( ) ;
7171 }
7272 if ( this . _nodeInfo && Bech32Helper . matches ( queryLower , this . _nodeInfo . protocol . bech32HRP ) ) {
73+ console . log ( "tangelSearch: address bech32" )
7374 const address = await this . addressBalance ( queryLower ) ;
7475
7576 if ( address ) {
@@ -92,8 +93,9 @@ export class TangleService {
9293
9394 // If the query is 64 bytes hex, try and look for a message
9495 if ( Converter . isHex ( queryLower ) && queryLower . length === 64 ) {
95- console . log ( "tangelSearch message" )
96+
9697 try {
98+ console . log ( "tangelSearch: message" )
9799 const message = await client . message ( queryLower ) ;
98100
99101 return {
@@ -109,8 +111,7 @@ export class TangleService {
109111
110112 // If the query is 64 bytes hex, try and look for a transaction included message
111113 try {
112- console . log ( "tangelSearch transaction-included-message" )
113-
114+ console . log ( "tangelSearch: transaction-included-message" )
114115 const message = await client . transactionIncludedMessage ( queryLower ) ;
115116 return {
116117 message
@@ -127,7 +128,7 @@ export class TangleService {
127128 try {
128129 // If the query is 68 bytes hex, try and look for an output
129130 if ( Converter . isHex ( queryLower ) && queryLower . length === 68 ) {
130- console . log ( "tangelSearch output" )
131+ console . log ( "tangelSearch: output" )
131132 const output = await client . output ( queryLower ) ;
132133
133134 return {
@@ -147,7 +148,7 @@ export class TangleService {
147148 await this . info ( ) ;
148149 }
149150 if ( this . _nodeInfo && Converter . isHex ( queryLower ) && queryLower . length === 64 ) {
150- console . log ( "tangelSearch address ed25519" )
151+ console . log ( "tangelSearch: address ed25519" )
151152 // We have 64 characters hex so could possible be a raw ed25519 address
152153 // const address = await client.addressEd25519(queryLower);
153154 // const addressOutputs = await client.addressEd25519Outputs(queryLower);
@@ -156,7 +157,8 @@ export class TangleService {
156157 const bech32 = Bech32Helper . toBech32 ( ED25519_ADDRESS_TYPE , Converter . hexToBytes ( queryLower ) , this . _nodeInfo . protocol . bech32HRP )
157158 const address = await this . addressBalance ( bech32 ) ;
158159
159- if ( address ) {
160+ // TODO: confirm address.ledgerIndex > 0 condition is valid way to decide if address exists? Address object will always be retrieved even for bech32 addresses that dont exist.
161+ if ( address && address . ledgerIndex > 0 ) {
160162 const indexerPlugin = new IndexerPluginClient ( client ) ;
161163 const addressOutputs = await indexerPlugin . outputs ( { addressBech32 : bech32 } ) ;
162164 return {
@@ -173,48 +175,6 @@ export class TangleService {
173175 }
174176 }
175177
176- try {
177- if ( query . length > 0 ) {
178- let messages ;
179- let indexMessageType : "utf8" | "hex" | undefined ;
180- console . log ( "tangelSearch final message search" )
181- // If the query is between 2 and 128 hex chars assume hex encoded bytes
182- if ( query . length >= 2 && query . length <= 128 && Converter . isHex ( queryLower ) ) {
183- console . log ( "1. try" )
184- console . log ( queryLower )
185- messages = await client . message ( queryLower ) ;
186- console . log ( messages )
187- // if (messages.count > 0) {
188- indexMessageType = "hex" ;
189- // }
190- }
191-
192- // If not already found and query less than 64 bytes assume its UTF8
193- if ( ! indexMessageType && query . length <= 64 ) {
194- console . log ( "2. try" )
195- messages = await client . message ( query ) ;
196- console . log ( messages )
197- // if (messages.count > 0) {
198- indexMessageType = "utf8" ;
199- // }
200- }
201-
202- // if (messages && messages.count > 0) {
203- if ( messages ) {
204- return {
205- indexMessageIds : messages . parentMessageIds ,
206- indexMessageType
207- } ;
208- }
209- }
210- } catch ( err ) {
211- if ( err instanceof ClientError && this . checkForUnavailable ( err ) ) {
212- return {
213- unavailable : true
214- } ;
215- }
216- }
217-
218178 return { } ;
219179 }
220180
0 commit comments