@bsv/overlay-discovery-services 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -6,7 +6,7 @@ import { isValidDomain } from '../utils/isValidDomain.js'
6
6
  import { getDocumentation } from '../utils/getDocumentation.js'
7
7
 
8
8
  /**
9
- * SHIP Topic Manager
9
+ * 🚢 SHIP Topic Manager
10
10
  * Implements the TopicManager interface for SHIP (Service Host Interconnect Protocol) tokens.
11
11
  *
12
12
  * The SHIP Topic Manager identifies admissible outputs based on SHIP protocol requirements.
@@ -40,20 +40,36 @@ export class SHIPTopicManager implements TopicManager {
40
40
 
41
41
  if (shipIdentifier !== 'SHIP') continue
42
42
 
43
- // Validate domain and service
43
+ // Validate domain
44
44
  if (!isValidDomain(domain)) continue
45
- // if (!isValidTopicName(topic)) continue
45
+ // Additional validations can be added here
46
46
 
47
47
  // Verify the token locking key and signature
48
48
  verifyToken(identityKey, result.lockingPublicKey, result.fields, result.signature)
49
49
 
50
50
  outputsToAdmit.push(i)
51
51
  } catch (error) {
52
- console.error('Error processing output:', error)
52
+ // It's common for other outputs to be invalid; no need to log an error here
53
+ continue
53
54
  }
54
55
  }
55
56
  } catch (error) {
56
- console.error('Error identifying admissible outputs:', error)
57
+ // Only log an error if no outputs were admitted and no previous coins consumed
58
+ if (outputsToAdmit.length === 0 && (!previousCoins || previousCoins.length === 0)) {
59
+ console.error('⛴️ Error identifying admissible outputs:', error)
60
+ }
61
+ }
62
+
63
+ if (outputsToAdmit.length > 0) {
64
+ console.log(`🛳️ Ahoy! Admitted ${outputsToAdmit.length} SHIP ${outputsToAdmit.length === 1 ? 'output' : 'outputs'}!`)
65
+ }
66
+
67
+ if (previousCoins && previousCoins.length > 0) {
68
+ console.log(`🚢 Consumed ${previousCoins.length} previous SHIP ${previousCoins.length === 1 ? 'coin' : 'coins'}!`)
69
+ }
70
+
71
+ if (outputsToAdmit.length === 0 && (!previousCoins || previousCoins.length === 0)) {
72
+ console.warn('⚓ No SHIP outputs admitted and no previous SHIP coins consumed.')
57
73
  }
58
74
 
59
75
  return {
@@ -6,7 +6,7 @@ import { isValidServiceName } from '../utils/isValidServiceName.js'
6
6
  import { getDocumentation } from '../utils/getDocumentation.js'
7
7
 
8
8
  /**
9
- * SLAP Topic Manager
9
+ * 🤚 SLAP Topic Manager
10
10
  * Implements the TopicManager interface for SLAP (Service Lookup Availability Protocol) tokens.
11
11
  *
12
12
  * The SLAP Topic Manager identifies admissible outputs based on SLAP protocol requirements.
@@ -19,7 +19,10 @@ export class SLAPTopicManager implements TopicManager {
19
19
  * @param previousCoins - The previous coins to consider.
20
20
  * @returns A promise that resolves with the admittance instructions.
21
21
  */
22
- async identifyAdmissibleOutputs(beef: number[], previousCoins: number[]): Promise<AdmittanceInstructions> {
22
+ async identifyAdmissibleOutputs(
23
+ beef: number[],
24
+ previousCoins: number[]
25
+ ): Promise<AdmittanceInstructions> {
23
26
  const outputsToAdmit: number[] = []
24
27
  try {
25
28
  const parsedTransaction = Transaction.fromBEEF(beef)
@@ -44,15 +47,37 @@ export class SLAPTopicManager implements TopicManager {
44
47
  if (!isValidServiceName(service)) continue
45
48
 
46
49
  // Verify the token locking key and signature
47
- verifyToken(identityKey, result.lockingPublicKey, result.fields, result.signature)
50
+ verifyToken(
51
+ identityKey,
52
+ result.lockingPublicKey,
53
+ result.fields,
54
+ result.signature
55
+ )
48
56
 
49
57
  outputsToAdmit.push(i)
50
58
  } catch (error) {
51
- console.error('Error processing output:', error)
59
+ // It's common for other outputs to be invalid; no need to log an error here
60
+ continue
52
61
  }
53
62
  }
54
63
  } catch (error) {
55
- console.error('Error identifying admissible outputs:', error)
64
+ // Only log an error if no outputs were admitted and no previous coins consumed
65
+ if (outputsToAdmit.length === 0 && (!previousCoins || previousCoins.length === 0)) {
66
+ console.error('🤚 Error identifying admissible outputs:', error)
67
+ }
68
+ }
69
+
70
+ // Friendly logging with slappy emojis!
71
+ if (outputsToAdmit.length > 0) {
72
+ console.log(`👏 Admitted ${outputsToAdmit.length} SLAP ${outputsToAdmit.length === 1 ? 'output' : 'outputs'}!`)
73
+ }
74
+
75
+ if (previousCoins && previousCoins.length > 0) {
76
+ console.log(`✋ Consumed ${previousCoins.length} previous SLAP ${previousCoins.length === 1 ? 'coin' : 'coins'}!`)
77
+ }
78
+
79
+ if (outputsToAdmit.length === 0 && (!previousCoins || previousCoins.length === 0)) {
80
+ console.warn('😕 No SLAP outputs admitted and no previous SLAP coins consumed.')
56
81
  }
57
82
 
58
83
  return {
@@ -82,7 +107,7 @@ export class SLAPTopicManager implements TopicManager {
82
107
  }> {
83
108
  return {
84
109
  name: 'SLAP Topic Manager',
85
- shortDescription: 'Manages SLAP tokens for service lookup availability.',
110
+ shortDescription: 'Manages SLAP tokens for service lookup availability.'
86
111
  }
87
112
  }
88
113
  }