diff --git a/ao/src/contracts/operator-registry.lua b/ao/src/contracts/operator-registry.lua index b8454a8..380d11f 100644 --- a/ao/src/contracts/operator-registry.lua +++ b/ao/src/contracts/operator-registry.lua @@ -102,6 +102,8 @@ function OperatorRegistry.init() .VerifiedFingerprintsToOperatorAddresses[fingerprint] = address OperatorRegistry .RegistrationCreditsFingerprintsToOperatorAddresses[fingerprint] = nil + OperatorRegistry + .ClaimableFingerprintsToOperatorAddresses[fingerprint] = nil ao.send({ Target = msg.From, @@ -376,6 +378,24 @@ function OperatorRegistry.init() end ) + Handlers.add( + 'View-State', + Handlers.utils.hasMatchingTag('Action', 'View-State'), + function (msg) + ao.send({ + Target = msg.From, + Action = 'View-State-Response', + Data = json.encode({ + ClaimableFingerprintsToOperatorAddresses = OperatorRegistry.ClaimableFingerprintsToOperatorAddresses, + VerifiedFingerprintsToOperatorAddresses = OperatorRegistry.VerifiedFingerprintsToOperatorAddresses, + BlockedOperatorAddresses = OperatorRegistry.BlockedOperatorAddresses, + RegistrationCreditsFingerprintsToOperatorAddresses = OperatorRegistry.RegistrationCreditsFingerprintsToOperatorAddresses, + VerifiedHardwareFingerprints = OperatorRegistry.VerifiedHardwareFingerprints + }) + }) + end + ) + Handlers.add( 'Info', Handlers.utils.hasMatchingTag('Action', 'Info'), @@ -398,6 +418,8 @@ function OperatorRegistry.init() info.total = info.total + 1 end + info.total = info.total + info.claimed + for _ in pairs(OperatorRegistry.VerifiedHardwareFingerprints) do info.hardware = info.hardware + 1 end diff --git a/ao/test/spec/contracts/operator-registry.spec.ts b/ao/test/spec/contracts/operator-registry.spec.ts index ec95958..c594ca8 100644 --- a/ao/test/spec/contracts/operator-registry.spec.ts +++ b/ao/test/spec/contracts/operator-registry.spec.ts @@ -1406,4 +1406,70 @@ describe('Operator Registry', () => { .to.deep.equal({ claimed: 3, hardware: 2, total: 6 }) }) }) + + describe('View State', () => { + it('Provides reply to View-State messages', async () => { + const verifiedRelays = [ + { address: ALICE_ADDRESS, fingerprint: FINGERPRINT_A }, + { address: BOB_ADDRESS, fingerprint: FINGERPRINT_B }, + { address: CHARLS_ADDRESS, fingerprint: FINGERPRINT_C } + ] + for (const { address, fingerprint } of verifiedRelays) { + await setupAdminAddOperatorCertificates(handle, address, fingerprint) + await addRegistrationCredit(handle, address, fingerprint) + await handle({ + From: address, + Tags: [ + { name: 'Action', value: 'Submit-Fingerprint-Certificate' }, + { + name: 'Fingerprint-Certificate', + value: fingerprint + } + ] + }) + } + const unclaimedRelays = [ + { address: ALICE_ADDRESS, fingerprint: FINGERPRINT_D }, + { address: BOB_ADDRESS, fingerprint: FINGERPRINT_E }, + { address: CHARLS_ADDRESS, fingerprint: FINGERPRINT_F }, + ] + for (const { address, fingerprint } of unclaimedRelays) { + await setupAdminAddOperatorCertificates(handle, address, fingerprint) + } + + await handle({ + From: OWNER_ADDRESS, + Tags: [ + { name: 'Action', value: 'Add-Verified-Hardware' } + ], + Data: `${FINGERPRINT_B},${FINGERPRINT_E}` + }) + + const result = await handle({ + From: ALICE_ADDRESS, + Tags: [{ name: 'Action', value: 'View-State' }] + }) + + const parsed = JSON.parse(result.Messages[0].Data) + expect(result.Messages).to.have.lengthOf(1) + expect(parsed).to.deep.equal({ + ClaimableFingerprintsToOperatorAddresses: { + [FINGERPRINT_D]: ALICE_ADDRESS, + [FINGERPRINT_E]: BOB_ADDRESS, + [FINGERPRINT_F]: CHARLS_ADDRESS + }, + VerifiedFingerprintsToOperatorAddresses: { + [FINGERPRINT_A]: ALICE_ADDRESS, + [FINGERPRINT_B]: BOB_ADDRESS, + [FINGERPRINT_C]: CHARLS_ADDRESS + }, + BlockedOperatorAddresses: [], + RegistrationCreditsFingerprintsToOperatorAddresses: [], + VerifiedHardwareFingerprints: { + [FINGERPRINT_B]: true, + [FINGERPRINT_E]: true + } + }) + }) + }) })