@bsv/create-dpp-app 0.1.0-beta.1 → 0.1.0-beta.2
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.
- package/NOTICE +2 -0
- package/PATENTS +12 -0
- package/README.md +26 -6
- package/dist/index.js +36 -8
- package/package.json +9 -5
- package/template/Dockerfile +4 -2
- package/template/README.md +297 -42
- package/template/_env.example +82 -13
- package/template/_github/workflows/ci.yml +3 -3
- package/template/apps/api/API.md +86 -16
- package/template/apps/api/package.json +9 -4
- package/template/apps/api/src/bound-profiles.ts +590 -0
- package/template/apps/api/src/claims.ts +175 -56
- package/template/apps/api/src/cli.ts +64 -7
- package/template/apps/api/src/config.ts +124 -10
- package/template/apps/api/src/custody.ts +241 -69
- package/template/apps/api/src/dev-index.ts +58 -9
- package/template/apps/api/src/env-file.ts +55 -0
- package/template/apps/api/src/epcis/exchange.ts +434 -0
- package/template/apps/api/src/epcis/mongo-storage.ts +381 -0
- package/template/apps/api/src/epcis/routes.ts +364 -0
- package/template/apps/api/src/epcis/sources.ts +142 -0
- package/template/apps/api/src/go-live.ts +226 -0
- package/template/apps/api/src/http-error.ts +15 -0
- package/template/apps/api/src/identifiers.ts +1 -1
- package/template/apps/api/src/index-client.ts +131 -6
- package/template/apps/api/src/index-projects.ts +53 -0
- package/template/apps/api/src/lifecycle-authority.ts +49 -0
- package/template/apps/api/src/lifecycle.ts +485 -0
- package/template/apps/api/src/main.ts +10 -2
- package/template/apps/api/src/parties.ts +2 -2
- package/template/apps/api/src/platform.ts +72 -17
- package/template/apps/api/src/portability/commands.ts +224 -0
- package/template/apps/api/src/portability/export.ts +708 -0
- package/template/apps/api/src/portability/package.ts +270 -0
- package/template/apps/api/src/portability/restore.ts +863 -0
- package/template/apps/api/src/profiles.ts +38 -13
- package/template/apps/api/src/reader.ts +172 -3
- package/template/apps/api/src/resolver.ts +159 -0
- package/template/apps/api/src/sector-examples.ts +390 -0
- package/template/apps/api/src/server.ts +253 -60
- package/template/apps/api/src/store.ts +198 -21
- package/template/apps/api/src/validation-engine.ts +172 -0
- package/template/apps/api/src/wallet.ts +30 -17
- package/template/apps/api/src/worker.ts +20 -13
- package/template/apps/api/src/writer.ts +383 -131
- package/template/apps/api/test/bound-http.test.ts +496 -0
- package/template/apps/api/test/bound-profiles.test.ts +547 -0
- package/template/apps/api/test/config.test.ts +148 -3
- package/template/apps/api/test/custody-journal.test.ts +415 -0
- package/template/apps/api/test/custody-recovery-profile.test.ts +224 -0
- package/template/apps/api/test/custom-profile.test.ts +167 -0
- package/template/apps/api/test/env-file.test.ts +53 -0
- package/template/apps/api/test/epcis-fixtures.ts +270 -0
- package/template/apps/api/test/epcis-http.test.ts +1179 -0
- package/template/apps/api/test/epcis-mongo-storage.test.ts +313 -0
- package/template/apps/api/test/epcis-separation.test.ts +253 -0
- package/template/apps/api/test/epcis-web.test.ts +230 -0
- package/template/apps/api/test/exit-exercise.test.ts +1038 -0
- package/template/apps/api/test/external-index.test.ts +3 -2
- package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/background.ttl +33 -0
- package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/binding.json +141 -0
- package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/context.jsonld +36 -0
- package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/product.schema.json +44 -0
- package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/shapes.ttl +112 -0
- package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/vectors/conflicting-gtin.json +44 -0
- package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/vectors/conflicting-serial.json +44 -0
- package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/vectors/granularity-mismatch.json +44 -0
- package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/vectors/item-gtin-13.json +43 -0
- package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/vectors/item.json +42 -0
- package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/vectors/missing-required-property.json +43 -0
- package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/vectors/model-as-subject.json +44 -0
- package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/vectors/no-passport-identifier.json +43 -0
- package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/vectors/other-product.json +44 -0
- package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/vectors/part-not-dishwasher-safe.json +45 -0
- package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/vectors/registration/altered-artefact.json +19 -0
- package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/vectors/registration/altered-background.ttl +33 -0
- package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/vectors/registration/conflicting-binding.json +141 -0
- package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/vectors/registration/conflicting-second-registration.json +19 -0
- package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/vectors/registration/untrusted-binding.json +13 -0
- package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/vectors/unlisted-context.json +47 -0
- package/template/apps/api/test/fixtures/custom-profile/example-bottle@1/vectors/wrong-binding-digest.json +44 -0
- package/template/apps/api/test/fixtures/custom-profile/example-notebook@1/binding.json +88 -0
- package/template/apps/api/test/fixtures/custom-profile/example-notebook@1/product.schema.json +25 -0
- package/template/apps/api/test/fixtures/custom-profile/example-notebook@1/vectors/item.json +26 -0
- package/template/apps/api/test/fixtures/custom-profile/example-notebook@1/vectors/missing-required-property.json +27 -0
- package/template/apps/api/test/fixtures/custom-profile/example-notebook@1/vectors/no-passport-identifier.json +27 -0
- package/template/apps/api/test/fixtures/custom-profile/example-notebook@1/vectors/other-product.json +28 -0
- package/template/apps/api/test/go-live.test.ts +179 -0
- package/template/apps/api/test/gs1-global-setup.ts +33 -0
- package/template/apps/api/test/gs1-test-env.ts +5 -0
- package/template/apps/api/test/identifier-host.test.ts +256 -0
- package/template/apps/api/test/index-projects.test.ts +81 -0
- package/template/apps/api/test/lifecycle-claims.test.ts +546 -0
- package/template/apps/api/test/lifecycle-fixtures.ts +167 -0
- package/template/apps/api/test/lifecycle.test.ts +17 -6
- package/template/apps/api/test/manifest-notice.test.ts +36 -0
- package/template/apps/api/test/network-guard.ts +113 -0
- package/template/apps/api/test/portability.test.ts +655 -0
- package/template/apps/api/test/profile-bundle-resolver.test.ts +198 -0
- package/template/apps/api/test/retired-profiles.test.ts +216 -0
- package/template/apps/api/test/sector-cutover.test.ts +95 -0
- package/template/apps/api/test/sector-forms.test.ts +420 -0
- package/template/apps/api/test/unjoined-index.test.ts +62 -0
- package/template/apps/api/test/validation-engine.test.ts +328 -0
- package/template/apps/api/test/wallet-monitor.test.ts +38 -0
- package/template/apps/api/test/writer-journal.test.ts +327 -0
- package/template/apps/api/vitest.config.ts +3 -0
- package/template/apps/web/src/app.tsx +8 -4
- package/template/apps/web/src/components/bound/bound-passport-form.tsx +368 -0
- package/template/apps/web/src/components/bound/field-view.tsx +237 -0
- package/template/apps/web/src/components/bound/pieces.tsx +169 -0
- package/template/apps/web/src/components/bound/readings.tsx +152 -0
- package/template/apps/web/src/components/bound/structured-value.tsx +114 -0
- package/template/apps/web/src/components/claim-dialog.tsx +344 -0
- package/template/apps/web/src/components/epcis-events.tsx +119 -0
- package/template/apps/web/src/components/layout.tsx +17 -0
- package/template/apps/web/src/components/lifecycle-claims.tsx +199 -0
- package/template/apps/web/src/components/passport-form.tsx +2 -2
- package/template/apps/web/src/components/read-passport.tsx +4 -3
- package/template/apps/web/src/components/reading.tsx +32 -39
- package/template/apps/web/src/lib/api.ts +136 -26
- package/template/apps/web/src/lib/bound/battery-form.ts +269 -0
- package/template/apps/web/src/lib/bound/display.ts +122 -0
- package/template/apps/web/src/lib/bound/fields.ts +128 -0
- package/template/apps/web/src/lib/bound/form-model.ts +521 -0
- package/template/apps/web/src/lib/bound/forms.ts +15 -0
- package/template/apps/web/src/lib/bound/identity.ts +48 -0
- package/template/apps/web/src/lib/bound/textile-form.ts +236 -0
- package/template/apps/web/src/lib/bound/units.ts +37 -0
- package/template/apps/web/src/lib/epcis.ts +345 -0
- package/template/apps/web/src/lib/format.ts +27 -4
- package/template/apps/web/src/lib/lifecycle.ts +350 -0
- package/template/apps/web/src/pages/accept.tsx +8 -3
- package/template/apps/web/src/pages/events.tsx +388 -0
- package/template/apps/web/src/pages/new-passport.tsx +25 -2
- package/template/apps/web/src/pages/operations.tsx +22 -3
- package/template/apps/web/src/pages/passport.tsx +226 -162
- package/template/apps/web/src/pages/public-passport.tsx +50 -10
- package/template/apps/web/src/pages/wallet.tsx +1 -1
- package/template/apps/web/vite.config.ts +12 -4
- package/template/deploy/compose.yml +14 -2
- package/template/package.json +9 -3
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// The platform wallet: a BRC-100 wallet the API owns, which countersigns
|
|
2
|
-
// every state as publisher,
|
|
3
|
-
//
|
|
2
|
+
// every state as publisher, funds and submits the transactions, and
|
|
3
|
+
// obtains their merkle proofs. Live it is
|
|
4
4
|
// @bsv/wallet-toolbox on a SQLite file with a root key from the environment;
|
|
5
5
|
// in tests it is a ProtoWallet with a fixed key and made-up funding, which
|
|
6
6
|
// is what makes the first run need no money.
|
|
@@ -27,7 +27,7 @@ import {
|
|
|
27
27
|
type WalletInterface,
|
|
28
28
|
type WalletProtocol,
|
|
29
29
|
} from '@bsv/sdk'
|
|
30
|
-
import { OWNER_PROTOCOL_ID, type
|
|
30
|
+
import { OWNER_PROTOCOL_ID, type DataSigner } from '@bsv/dpp-protocol'
|
|
31
31
|
import type { Network } from './config.js'
|
|
32
32
|
|
|
33
33
|
export interface Tip {
|
|
@@ -51,14 +51,16 @@ export interface Built {
|
|
|
51
51
|
* mined transaction's merkle path. Its shape is the same live and in tests,
|
|
52
52
|
* so everything after the build is one code path.
|
|
53
53
|
*/
|
|
54
|
+
export class ActionAlreadySeen extends Error {}
|
|
55
|
+
|
|
54
56
|
export interface WriterAdapter {
|
|
55
|
-
build(args: { lockingScript: LockingScript; tip?: Tip; passportId: string }): Promise<Built>
|
|
57
|
+
build(args: { lockingScript: LockingScript; tip?: Tip & { signer: PublisherWallet }; passportId: string }): Promise<Built>
|
|
56
58
|
send(built: Built): Promise<'accepted' | 'refused' | 'unanswered'>
|
|
57
59
|
discard(built: Built): Promise<void>
|
|
58
60
|
merklePathFor(txid: string): Promise<MerklePath | undefined>
|
|
59
61
|
}
|
|
60
62
|
|
|
61
|
-
/** The slice of the platform wallet the packages call: publisher signature and
|
|
63
|
+
/** The slice of the platform wallet the packages call: publisher signature and public key derivation. */
|
|
62
64
|
export type PublisherWallet = DataSigner & {
|
|
63
65
|
getPublicKey: ProtoWallet['getPublicKey']
|
|
64
66
|
}
|
|
@@ -75,8 +77,8 @@ export interface PlatformWallet {
|
|
|
75
77
|
network: Network
|
|
76
78
|
identityKey: string
|
|
77
79
|
publisher: PublisherWallet
|
|
78
|
-
/** Signs acceptance records with the
|
|
79
|
-
|
|
80
|
+
/** Signs acceptance records with createSignature under the managed record protocol: the same wallet that publishes, one derivation from its root. */
|
|
81
|
+
custodian: DataSigner
|
|
80
82
|
adapter: WriterAdapter
|
|
81
83
|
fundingAddress(): Promise<FundingAddress>
|
|
82
84
|
/** Take in a payment made to a funding address, by its transaction id, once it is on the network. */
|
|
@@ -112,7 +114,7 @@ export async function openToolboxWallet(options: ToolboxWalletOptions): Promise<
|
|
|
112
114
|
// CommonJS, loaded once here: the toolbox carries its own copy of the SDK,
|
|
113
115
|
// so its objects cross into this module as bytes and hex, never as instances.
|
|
114
116
|
const toolbox = await import('@bsv/wallet-toolbox')
|
|
115
|
-
const { Monitor, Services, Setup, StorageKnex, Wallet, WalletStorageManager } = toolbox
|
|
117
|
+
const { Monitor, Services, Setup, StorageKnex, Task, Wallet, WalletStorageManager } = toolbox
|
|
116
118
|
// The toolbox loads the SDK's CommonJS build; its key deriver must come from that same copy.
|
|
117
119
|
const sdkCjs = createRequire(import.meta.url)('@bsv/sdk') as typeof import('@bsv/sdk')
|
|
118
120
|
const chain = options.network
|
|
@@ -138,11 +140,14 @@ export async function openToolboxWallet(options: ToolboxWalletOptions): Promise<
|
|
|
138
140
|
if (options.arcUrl != null) serviceOptions.arcUrl = options.arcUrl
|
|
139
141
|
const services = new Services(serviceOptions)
|
|
140
142
|
const monitor = new Monitor(Monitor.createDefaultWalletMonitorOptions(chain, manager, services))
|
|
143
|
+
// Wallet sends stay under the writer's publishing gate. The monitor only follows headers and proofs.
|
|
144
|
+
monitor.addTask(new Task.TaskNewHeader(monitor))
|
|
145
|
+
monitor.addTask(new Task.TaskCheckForProofs(monitor))
|
|
141
146
|
const keyDeriver = new sdkCjs.CachedKeyDeriver(sdkCjs.PrivateKey.fromHex(options.rootKeyHex))
|
|
142
147
|
const wallet = new Wallet({ chain, keyDeriver: keyDeriver as unknown as ConstructorParameters<typeof Wallet>[0]['keyDeriver'], storage: manager, services, monitor })
|
|
143
|
-
await storage.findOrInsertUser(identityKey)
|
|
148
|
+
const { user } = await storage.findOrInsertUser(identityKey)
|
|
144
149
|
// The monitor asks a header source for proofs once a block is a minute old and attaches them to the wallet's transactions.
|
|
145
|
-
|
|
150
|
+
const monitoring = monitor.startTasks()
|
|
146
151
|
|
|
147
152
|
const brc100 = wallet as unknown as WalletInterface
|
|
148
153
|
|
|
@@ -165,7 +170,7 @@ export async function openToolboxWallet(options: ToolboxWalletOptions): Promise<
|
|
|
165
170
|
}
|
|
166
171
|
return { tx: Transaction.fromAtomicBEEF(created.tx), txid: created.txid, beef: Array.from(created.tx) }
|
|
167
172
|
}
|
|
168
|
-
//
|
|
173
|
+
// The funding wallet builds the action and adds the controller's signature to the passport input.
|
|
169
174
|
const created = await brc100.createAction({
|
|
170
175
|
description: 'dpp state',
|
|
171
176
|
inputBEEF: tip.beef,
|
|
@@ -179,7 +184,7 @@ export async function openToolboxWallet(options: ToolboxWalletOptions): Promise<
|
|
|
179
184
|
const unsigned = Transaction.fromAtomicBEEF(signable.tx)
|
|
180
185
|
const at = unsigned.inputs.findIndex((input) => (input.sourceTXID ?? input.sourceTransaction?.id('hex')) === tip.txid && input.sourceOutputIndex === tip.outputIndex)
|
|
181
186
|
if (at === -1) throw new Error('the wallet built a transaction that does not spend the tip')
|
|
182
|
-
const unlockingScript = await new PushDrop(
|
|
187
|
+
const unlockingScript = await new PushDrop(tip.signer as WalletInterface).unlock(OWNER_PROTOCOL_ID, passportId, 'self').sign(unsigned, at)
|
|
183
188
|
const signed = await brc100.signAction({ reference: signable.reference, spends: { [at]: { unlockingScript: unlockingScript.toHex() } }, options: { noSend: true } })
|
|
184
189
|
if (signed.tx == null || signed.txid == null) throw new Error('the wallet did not return a signed transaction')
|
|
185
190
|
return { tx: Transaction.fromAtomicBEEF(signed.tx), txid: signed.txid, beef: Array.from(signed.tx), reference: signable.reference }
|
|
@@ -205,7 +210,11 @@ export async function openToolboxWallet(options: ToolboxWalletOptions): Promise<
|
|
|
205
210
|
},
|
|
206
211
|
async discard(built) {
|
|
207
212
|
// An unsent action holds the wallet's inputs until it is sent or aborted; an issue without a reference is found by its txid.
|
|
208
|
-
|
|
213
|
+
// A retry after a local abort or network rejection finds a terminal wallet row.
|
|
214
|
+
const [held] = await storage.findTransactions({ partial: { userId: user.userId, txid: built.txid }, noRawTx: true })
|
|
215
|
+
if (held?.status === 'failed' || held?.noSendExpiryState === 'cancelled') return
|
|
216
|
+
const result = await brc100.abortAction({ reference: built.reference ?? built.txid })
|
|
217
|
+
if (!result.aborted) throw new ActionAlreadySeen(`the wallet already sees ${built.txid} on the network`)
|
|
209
218
|
},
|
|
210
219
|
async merklePathFor(txid) {
|
|
211
220
|
// The wallet attaches the proof as part of being a wallet, but can list a transaction only while its output is unspent.
|
|
@@ -235,7 +244,7 @@ export async function openToolboxWallet(options: ToolboxWalletOptions): Promise<
|
|
|
235
244
|
network: chain,
|
|
236
245
|
identityKey,
|
|
237
246
|
publisher: brc100 as unknown as PublisherWallet,
|
|
238
|
-
|
|
247
|
+
custodian: brc100 as unknown as DataSigner,
|
|
239
248
|
adapter,
|
|
240
249
|
async fundingAddress() {
|
|
241
250
|
const derivationPrefix = Utils.toBase64(Random(8))
|
|
@@ -266,7 +275,11 @@ export async function openToolboxWallet(options: ToolboxWalletOptions): Promise<
|
|
|
266
275
|
},
|
|
267
276
|
async close() {
|
|
268
277
|
monitor.stopTasks()
|
|
269
|
-
|
|
278
|
+
try {
|
|
279
|
+
await monitoring
|
|
280
|
+
} finally {
|
|
281
|
+
await wallet.destroy()
|
|
282
|
+
}
|
|
270
283
|
},
|
|
271
284
|
}
|
|
272
285
|
}
|
|
@@ -309,7 +322,7 @@ export function openTestWallet(rootKeyHex = '11'.repeat(32), network: Network =
|
|
|
309
322
|
tx.addInput({ sourceTransaction: tip.tx, sourceOutputIndex: 1, unlockingScript: new UnlockingScript([]) })
|
|
310
323
|
tx.addOutput({ satoshis: 1, lockingScript })
|
|
311
324
|
tx.addOutput({ satoshis: Math.max(1_000, (tip.tx.outputs[1]?.satoshis ?? 9_000) - 1_000), lockingScript: ANYONE_CAN_SPEND })
|
|
312
|
-
tx.inputs[0].unlockingScript = await new PushDrop(
|
|
325
|
+
tx.inputs[0].unlockingScript = await new PushDrop(tip.signer as WalletInterface).unlock(OWNER_PROTOCOL_ID, passportId, 'self').sign(tx, 0)
|
|
313
326
|
}
|
|
314
327
|
return { tx, txid: tx.id('hex'), beef: tx.toAtomicBEEF(), reference: tip == null ? undefined : 'test-reference' }
|
|
315
328
|
},
|
|
@@ -329,7 +342,7 @@ export function openTestWallet(rootKeyHex = '11'.repeat(32), network: Network =
|
|
|
329
342
|
network,
|
|
330
343
|
identityKey,
|
|
331
344
|
publisher: wallet,
|
|
332
|
-
|
|
345
|
+
custodian: wallet,
|
|
333
346
|
adapter,
|
|
334
347
|
async fundingAddress() {
|
|
335
348
|
return { address: rootKey.toPublicKey().toAddress(network === 'test' ? 'testnet' : 'mainnet'), derivationPrefix: 'test', derivationSuffix: 'test', senderIdentityKey: ANYONE_IDENTITY_KEY }
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
// library.
|
|
8
8
|
import { Utils } from '@bsv/sdk'
|
|
9
9
|
import type { IndexClient } from './index-client.js'
|
|
10
|
-
import type
|
|
10
|
+
import { isInterrupted, type PassportRecord, type Store } from './store.js'
|
|
11
11
|
import type { Writer } from './writer.js'
|
|
12
12
|
|
|
13
13
|
export interface Duty {
|
|
@@ -25,22 +25,27 @@ export interface WorkerOptions {
|
|
|
25
25
|
log?: (line: string) => void
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
/**
|
|
29
|
-
|
|
28
|
+
/** Each passport's journal records its spends in lineage order, even across clock changes. */
|
|
29
|
+
async function journalDuties(store: Store): Promise<Duty[]> {
|
|
30
30
|
const duties: Duty[] = []
|
|
31
31
|
for (const passport of await store.listPassports()) {
|
|
32
32
|
for (const state of passport.states) {
|
|
33
|
-
if (state
|
|
33
|
+
if (isInterrupted(state)) {
|
|
34
34
|
duties.push({ passportId: passport.passportId, txid: state.txid, op: state.op, duty: 'resolve-interrupted', since: state.timestamp })
|
|
35
35
|
continue
|
|
36
36
|
}
|
|
37
37
|
if (state.network !== 'accepted' && state.network !== 'dry-run') continue
|
|
38
|
-
if (state.index
|
|
38
|
+
if (state.index !== 'admitted' && state.index !== 'duplicate') duties.push({ passportId: passport.passportId, txid: state.txid, op: state.op, duty: 'announce', since: state.timestamp })
|
|
39
39
|
if (state.proof == null) duties.push({ passportId: passport.passportId, txid: state.txid, op: state.op, duty: 'prove', since: state.timestamp })
|
|
40
40
|
else if (state.proofPushed !== true) duties.push({ passportId: passport.passportId, txid: state.txid, op: state.op, duty: 'push-proof', since: state.timestamp })
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
|
-
return duties
|
|
43
|
+
return duties
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** The operator's view of the work still owed, oldest timestamp first. */
|
|
47
|
+
export async function pendingDuties(store: Store): Promise<Duty[]> {
|
|
48
|
+
return (await journalDuties(store)).sort((a, b) => a.since.localeCompare(b.since))
|
|
44
49
|
}
|
|
45
50
|
|
|
46
51
|
/** One pass over the pending duties. Returns what it did, one line each. */
|
|
@@ -52,24 +57,26 @@ export async function runDuties(options: WorkerOptions): Promise<string[]> {
|
|
|
52
57
|
done.push(line)
|
|
53
58
|
log(line)
|
|
54
59
|
}
|
|
55
|
-
|
|
60
|
+
const waitingForPredecessor = new Set<string>()
|
|
61
|
+
for (const duty of await journalDuties(store)) {
|
|
56
62
|
const passport = await store.getPassport(duty.passportId)
|
|
57
63
|
const state = passport?.states.find((s) => s.txid === duty.txid)
|
|
58
64
|
if (passport == null || state == null) continue
|
|
59
65
|
// Only the operator can say what became of an interrupted write; it is listed, never guessed.
|
|
60
|
-
if (duty.duty === 'resolve-interrupted') continue
|
|
66
|
+
if (duty.duty === 'resolve-interrupted' || isInterrupted(state)) continue
|
|
61
67
|
try {
|
|
62
68
|
if (duty.duty === 'announce') {
|
|
63
|
-
|
|
64
|
-
state.
|
|
65
|
-
|
|
66
|
-
|
|
69
|
+
if (waitingForPredecessor.has(passport.passportId)) continue
|
|
70
|
+
const announced = await index.announce(Utils.toArray(state.sentBeef ?? state.beef, 'base64') as number[])
|
|
71
|
+
await writer.recordAnnouncement(passport.passportId, duty.txid, announced, index.lastRefusal)
|
|
72
|
+
if (announced !== 'admitted' && announced !== 'duplicate') waitingForPredecessor.add(passport.passportId)
|
|
67
73
|
say(`${duty.op} ${duty.txid.slice(0, 12)}... announced again: ${announced}${index.lastRefusal == null ? '' : ` (${index.lastRefusal})`}`)
|
|
68
74
|
} else {
|
|
69
75
|
const proven = await writer.prove(passport, duty.txid)
|
|
70
76
|
say(`${duty.op} ${duty.txid.slice(0, 12)}... ${proven ? 'proof held' : 'no proof yet'}`)
|
|
71
77
|
}
|
|
72
78
|
} catch (cause) {
|
|
79
|
+
if (duty.duty === 'announce') waitingForPredecessor.add(passport.passportId)
|
|
73
80
|
say(`${duty.op} ${duty.txid.slice(0, 12)}... ${duty.duty} failed: ${cause instanceof Error ? cause.message : String(cause)}`)
|
|
74
81
|
}
|
|
75
82
|
}
|
|
@@ -102,5 +109,5 @@ export function startWorker(options: WorkerOptions & { intervalMs?: number }): {
|
|
|
102
109
|
|
|
103
110
|
export function summariseJournal(passport: PassportRecord): { states: number; proven: number; pending: number; status: string } {
|
|
104
111
|
const proven = passport.states.filter((s) => s.proof != null && s.proofPushed === true).length
|
|
105
|
-
return { states: passport.states.length, proven, pending: passport.states.length - proven, status: passport.status }
|
|
112
|
+
return { states: passport.states.length, proven, pending: passport.states.length - proven, status: passport.states.some((s) => !isInterrupted(s)) ? passport.status : passport.states.length === 0 ? 'not-issued' : 'awaiting-send' }
|
|
106
113
|
}
|