Skip to content

Commit

Permalink
Merge pull request #208 from bitcoin-sv/fix-ship
Browse files Browse the repository at this point in the history
Fix SHIPBroadcaster
  • Loading branch information
ty-everett authored Feb 22, 2025
2 parents 232f07a + 4ab4946 commit 03d9981
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 29 deletions.
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ All notable changes to this project will be documented in this file. The format
## Table of Contents

- [Unreleased](#unreleased)
- [1.3.22 - 2025-02-19](#1321---2025-02-19)
- [1.3.23 - 2025-02-19](#1323---2025-02-21)
- [1.3.22 - 2025-02-19](#1322---2025-02-19)
- [1.3.21 - 2025-02-17](#1321---2025-02-17)
- [1.3.20- 2025-02-11](#1320---2025-02-17)
- [1.3.19 - 2025-02-16](#1319---2025-02-16)
Expand Down Expand Up @@ -88,6 +89,13 @@ All notable changes to this project will be documented in this file. The format

---

## [1.3.23] - 2025-02-21

### Fixed

- Fixed a bug with SHIPCast's default configuration.


## [1.3.22] - 2025-02-19

### Fixed
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@bsv/sdk",
"version": "1.3.22",
"version": "1.3.23",
"type": "module",
"description": "BSV Blockchain Software Development Kit",
"main": "dist/cjs/mod.js",
Expand Down
34 changes: 9 additions & 25 deletions src/overlay-tools/SHIPBroadcaster.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// @ts-nocheck
import {
Transaction,
BroadcastResponse,
Expand Down Expand Up @@ -60,10 +59,7 @@ export interface SHIPBroadcasterConfig {
/** Determines which topics (all, any, or a specific list) must be present within STEAK received from at least one host for the broadcast to be considered a success. */
requireAcknowledgmentFromAnyHostForTopics?: 'all' | 'any' | string[]
/** Determines a mapping whose keys are specific hosts and whose values are the topics (all, any, or a specific list) that must be present within the STEAK received by the given hosts, in order for the broadcast to be considered a success. */
requireAcknowledgmentFromSpecificHostsForTopics?: Record<
string,
'all' | 'any' | string[]
>
requireAcknowledgmentFromSpecificHostsForTopics?: Record<string, 'all' | 'any' | string[]>
}

/** Facilitates transaction broadcasts that return STEAK. */
Expand All @@ -73,8 +69,7 @@ export interface OverlayBroadcastFacilitator {

const MAX_SHIP_QUERY_TIMEOUT = 1000

export class HTTPSOverlayBroadcastFacilitator
implements OverlayBroadcastFacilitator {
export class HTTPSOverlayBroadcastFacilitator implements OverlayBroadcastFacilitator {
httpClient: typeof fetch

constructor (httpClient = fetch) {
Expand Down Expand Up @@ -106,24 +101,13 @@ implements OverlayBroadcastFacilitator {
/**
* Represents a SHIP transaction broadcaster.
*/
export default class SHIPCast implements Broadcaster {
export default class SHIPBroadcaster implements Broadcaster {
private readonly topics: string[]
private readonly facilitator: OverlayBroadcastFacilitator
private readonly resolver: LookupResolver
private readonly requireAcknowledgmentFromAllHostsForTopics:
| 'all'
| 'any'
| string[]

private readonly requireAcknowledgmentFromAnyHostForTopics:
| 'all'
| 'any'
| string[]

private readonly requireAcknowledgmentFromSpecificHostsForTopics: Record<
string,
'all' | 'any' | string[]
>
private readonly requireAcknowledgmentFromAllHostsForTopics: | 'all' | 'any' | string[]
private readonly requireAcknowledgmentFromAnyHostForTopics: | 'all' | 'any' | string[]
private readonly requireAcknowledgmentFromSpecificHostsForTopics: Record<string, 'all' | 'any' | string[]>

/**
* Constructs an instance of the SHIP broadcaster.
Expand All @@ -145,7 +129,7 @@ export default class SHIPCast implements Broadcaster {
requireAcknowledgmentFromAllHostsForTopics,
requireAcknowledgmentFromAnyHostForTopics,
requireAcknowledgmentFromSpecificHostsForTopics
} = config ?? defaultConfig
} = config ?? {}
this.facilitator = facilitator ?? new HTTPSOverlayBroadcastFacilitator()
this.resolver = resolver ?? new LookupResolver()
this.requireAcknowledgmentFromAllHostsForTopics =
Expand Down Expand Up @@ -215,14 +199,14 @@ export default class SHIPCast implements Broadcaster {

for (const result of successfulHosts) {
const host = result.host
const steak = result.steak
const steak = result.steak as STEAK

const acknowledgedTopics = new Set<string>()

for (const [topic, instructions] of Object.entries(steak)) {
const outputsToAdmit = instructions.outputsToAdmit
const coinsToRetain = instructions.coinsToRetain
const coinsRemoved = instructions.coinsRemoved
const coinsRemoved = instructions.coinsRemoved as number[]

if (
outputsToAdmit?.length > 0 ||
Expand Down

0 comments on commit 03d9981

Please sign in to comment.