Skip to content

Commit

Permalink
Rename syncing to scanning
Browse files Browse the repository at this point in the history
  • Loading branch information
dguenther committed May 14, 2024
1 parent 999dd19 commit 87d95d6
Show file tree
Hide file tree
Showing 15 changed files with 103 additions and 103 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import { parseBoolean } from '../../args'
import { IronfishCommand } from '../../command'
import { RemoteFlags } from '../../flags'

export class SyncingCommand extends IronfishCommand {
static description = `Enable or disable syncing for an account`
export class ScanningCommand extends IronfishCommand {
static description = `Enable or disable scanning for an account`

static flags = {
...RemoteFlags,
Expand All @@ -27,7 +27,7 @@ export class SyncingCommand extends IronfishCommand {
]

async start(): Promise<void> {
const { args } = await this.parse(SyncingCommand)
const { args } = await this.parse(ScanningCommand)
const account = args.account as string | undefined
const enabled = args.enabled as boolean | null | undefined

Expand All @@ -42,15 +42,15 @@ export class SyncingCommand extends IronfishCommand {
const client = await this.sdk.connectRpc()

if (enabled) {
await client.wallet.startSyncing({
await client.wallet.startScanning({
account: account,
})
this.log(`Started syncing for account ${account}.`)
this.log(`Started scanning for account ${account}.`)
} else {
await client.wallet.stopSyncing({
await client.wallet.stopScanning({
account: account,
})
this.log(`Stopped syncing for account ${account}.`)
this.log(`Stopped scanning for account ${account}.`)
}
}
}
28 changes: 14 additions & 14 deletions ironfish/src/rpc/clients/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,11 @@ import type {
SetConfigResponse,
ShowChainRequest,
ShowChainResponse,
StartSyncingRequest,
StartSyncingResponse,
StartScanningRequest,
StartScanningResponse,
StopNodeResponse,
StopSyncingRequest,
StopSyncingResponse,
StopScanningRequest,
StopScanningResponse,
SubmitBlockRequest,
SubmitBlockResponse,
UnsetConfigRequest,
Expand Down Expand Up @@ -580,20 +580,20 @@ export abstract class RpcClient {
).waitForEnd()
},

startSyncing: (
params: StartSyncingRequest,
): Promise<RpcResponseEnded<StartSyncingResponse>> => {
return this.request<StartSyncingResponse>(
`${ApiNamespace.wallet}/startSyncing`,
startScanning: (
params: StartScanningRequest,
): Promise<RpcResponseEnded<StartScanningResponse>> => {
return this.request<StartScanningResponse>(
`${ApiNamespace.wallet}/startScanning`,
params,
).waitForEnd()
},

stopSyncing: (
params: StopSyncingRequest,
): Promise<RpcResponseEnded<StopSyncingResponse>> => {
return this.request<StopSyncingResponse>(
`${ApiNamespace.wallet}/stopSyncing`,
stopScanning: (
params: StopScanningRequest,
): Promise<RpcResponseEnded<StopScanningResponse>> => {
return this.request<StopScanningResponse>(
`${ApiNamespace.wallet}/stopScanning`,
params,
).waitForEnd()
},
Expand Down
8 changes: 4 additions & 4 deletions ironfish/src/rpc/routes/wallet/getAccountStatus.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,18 @@ describe('Route wallet/getAccountStatus', () => {
sequence: routeTest.chain.head.sequence,
inChain: true,
},
syncingEnabled: true,
scanningEnabled: true,
viewOnly: false,
},
})
})

it('returns false if syncing is disabled', async () => {
it('returns false if scanning is disabled', async () => {
const account = await routeTest.node.wallet.createAccount(uuid(), {
setCreatedAt: true,
setDefault: true,
})
await routeTest.client.wallet.stopSyncing({ account: account.name })
await routeTest.client.wallet.stopScanning({ account: account.name })

const response = await routeTest.client.wallet.getAccountStatus({
account: account.name,
Expand All @@ -57,7 +57,7 @@ describe('Route wallet/getAccountStatus', () => {
sequence: routeTest.chain.head.sequence,
inChain: true,
},
syncingEnabled: false,
scanningEnabled: false,
viewOnly: false,
},
})
Expand Down
10 changes: 5 additions & 5 deletions ironfish/src/rpc/routes/wallet/getAccountsStatus.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ describe('Route wallet/getAccountsStatus', () => {
sequence: routeTest.chain.head.sequence,
inChain: true,
},
syncingEnabled: true,
scanningEnabled: true,
viewOnly: false,
},
],
Expand All @@ -61,19 +61,19 @@ describe('Route wallet/getAccountsStatus', () => {
name: account.name,
id: account.id,
head: null,
syncingEnabled: true,
scanningEnabled: true,
viewOnly: true,
},
],
})
})

it('returns false when syncing is disabled', async () => {
it('returns false when scanning is disabled', async () => {
const account = await routeTest.node.wallet.createAccount(uuid(), {
setCreatedAt: true,
setDefault: true,
})
await routeTest.client.wallet.stopSyncing({ account: account.name })
await routeTest.client.wallet.stopScanning({ account: account.name })
const response = await routeTest.client.wallet.getAccountsStatus()

expect(response.status).toBe(200)
Expand All @@ -87,7 +87,7 @@ describe('Route wallet/getAccountsStatus', () => {
sequence: routeTest.chain.head.sequence,
inChain: true,
},
syncingEnabled: false,
scanningEnabled: false,
viewOnly: false,
},
],
Expand Down
4 changes: 2 additions & 2 deletions ironfish/src/rpc/routes/wallet/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ export * from './rename'
export * from './renameAccount'
export * from './rescanAccount'
export * from './sendTransaction'
export * from './startSyncing'
export * from './stopSyncing'
export * from './startScanning'
export * from './stopScanning'
export * from './types'
export * from './use'
export * from './useAccount'
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
import { v4 as uuid } from 'uuid'
import { Assert } from '../../../assert'
import { createRouteTest } from '../../../testUtilities/routeTest'
import { StopSyncingResponse } from './stopSyncing'
import { StartScanningResponse } from './startScanning'

describe('Route wallet/stopSyncing', () => {
describe('Route wallet/startScanning', () => {
const routeTest = createRouteTest()
let accountName: string

Expand All @@ -20,44 +20,44 @@ describe('Route wallet/stopSyncing', () => {
await routeTest.node.wallet.setDefaultAccount(accountName)
})

it('Should set syncing to false', async () => {
it('Should set scanning to true', async () => {
let account = routeTest.node.wallet.getAccountByName(accountName)
Assert.isNotNull(account)
account.updateSyncingEnabled(true)
expect(account.syncingEnabled).toBe(true)
account.updateScanningEnabled(false)
expect(account.scanningEnabled).toBe(false)

await routeTest.client
.request<StopSyncingResponse>('wallet/stopSyncing', {
.request<StartScanningResponse>('wallet/startScanning', {
account: accountName,
})
.waitForEnd()

account = routeTest.node.wallet.getAccountByName(accountName)
Assert.isNotNull(account)
expect(account.syncingEnabled).toBe(false)
expect(account.scanningEnabled).toBe(true)
})

it('Should do nothing if syncing is already stopped', async () => {
it('Should do nothing if scanning is already started', async () => {
let account = routeTest.node.wallet.getAccountByName(accountName)
Assert.isNotNull(account)
account.updateSyncingEnabled(false)
expect(account.syncingEnabled).toBe(false)
account.updateScanningEnabled(true)
expect(account.scanningEnabled).toBe(true)

await routeTest.client
.request<StopSyncingResponse>('wallet/stopSyncing', {
.request<StartScanningResponse>('wallet/startScanning', {
account: accountName,
})
.waitForEnd()

account = routeTest.node.wallet.getAccountByName(accountName)
Assert.isNotNull(account)
expect(account.syncingEnabled).toBe(false)
expect(account.scanningEnabled).toBe(true)
})

it(`Should error if the account doesn't exist`, async () => {
await expect(async () => {
await routeTest.client
.request<StopSyncingResponse>('wallet/stopSyncing', {
.request<StartScanningResponse>('wallet/startScanning', {
account: 'foo',
})
.waitForEnd()
Expand All @@ -66,7 +66,9 @@ describe('Route wallet/stopSyncing', () => {

it(`Should error if the no account is passed`, async () => {
await expect(async () => {
await routeTest.client.request<StopSyncingResponse>('wallet/stopSyncing', {}).waitForEnd()
await routeTest.client
.request<StartScanningResponse>('wallet/startScanning', {})
.waitForEnd()
}).rejects.toThrow('account must be defined')
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,27 @@ import { routes } from '../router'
import { AssertHasRpcContext } from '../rpcContext'
import { getAccount } from './utils'

export type StopSyncingRequest = { account: string }
export type StopSyncingResponse = undefined
export type StartScanningRequest = { account: string }
export type StartScanningResponse = undefined

export const StopSyncingRequestSchema: yup.ObjectSchema<StopSyncingRequest> = yup
export const StartScanningRequestSchema: yup.ObjectSchema<StartScanningRequest> = yup
.object({
account: yup.string().defined(),
})
.defined()

export const StopSyncingResponseSchema: yup.MixedSchema<StopSyncingResponse> = yup
export const StartScanningResponseSchema: yup.MixedSchema<StartScanningResponse> = yup
.mixed()
.oneOf([undefined] as const)

routes.register<typeof StopSyncingRequestSchema, StopSyncingResponse>(
`${ApiNamespace.wallet}/stopSyncing`,
StopSyncingRequestSchema,
routes.register<typeof StartScanningRequestSchema, StartScanningResponse>(
`${ApiNamespace.wallet}/startScanning`,
StartScanningRequestSchema,
(request, context): void => {
AssertHasRpcContext(request, context, 'wallet')

const account = getAccount(context.wallet, request.data.account)
account.updateSyncingEnabled(false)
account.updateScanningEnabled(true)
request.end()
},
)
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
import { v4 as uuid } from 'uuid'
import { Assert } from '../../../assert'
import { createRouteTest } from '../../../testUtilities/routeTest'
import { StartSyncingResponse } from './startSyncing'
import { StopScanningResponse } from './stopScanning'

describe('Route wallet/startSyncing', () => {
describe('Route wallet/stopScanning', () => {
const routeTest = createRouteTest()
let accountName: string

Expand All @@ -20,44 +20,44 @@ describe('Route wallet/startSyncing', () => {
await routeTest.node.wallet.setDefaultAccount(accountName)
})

it('Should set syncing to true', async () => {
it('Should set scanning to false', async () => {
let account = routeTest.node.wallet.getAccountByName(accountName)
Assert.isNotNull(account)
account.updateSyncingEnabled(false)
expect(account.syncingEnabled).toBe(false)
account.updateScanningEnabled(true)
expect(account.scanningEnabled).toBe(true)

await routeTest.client
.request<StartSyncingResponse>('wallet/startSyncing', {
.request<StopScanningResponse>('wallet/stopScanning', {
account: accountName,
})
.waitForEnd()

account = routeTest.node.wallet.getAccountByName(accountName)
Assert.isNotNull(account)
expect(account.syncingEnabled).toBe(true)
expect(account.scanningEnabled).toBe(false)
})

it('Should do nothing if syncing is already started', async () => {
it('Should do nothing if scanning is already stopped', async () => {
let account = routeTest.node.wallet.getAccountByName(accountName)
Assert.isNotNull(account)
account.updateSyncingEnabled(true)
expect(account.syncingEnabled).toBe(true)
account.updateScanningEnabled(false)
expect(account.scanningEnabled).toBe(false)

await routeTest.client
.request<StartSyncingResponse>('wallet/startSyncing', {
.request<StopScanningResponse>('wallet/stopScanning', {
account: accountName,
})
.waitForEnd()

account = routeTest.node.wallet.getAccountByName(accountName)
Assert.isNotNull(account)
expect(account.syncingEnabled).toBe(true)
expect(account.scanningEnabled).toBe(false)
})

it(`Should error if the account doesn't exist`, async () => {
await expect(async () => {
await routeTest.client
.request<StartSyncingResponse>('wallet/startSyncing', {
.request<StopScanningResponse>('wallet/stopScanning', {
account: 'foo',
})
.waitForEnd()
Expand All @@ -67,7 +67,7 @@ describe('Route wallet/startSyncing', () => {
it(`Should error if the no account is passed`, async () => {
await expect(async () => {
await routeTest.client
.request<StartSyncingResponse>('wallet/startSyncing', {})
.request<StopScanningResponse>('wallet/stopScanning', {})
.waitForEnd()
}).rejects.toThrow('account must be defined')
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,27 @@ import { routes } from '../router'
import { AssertHasRpcContext } from '../rpcContext'
import { getAccount } from './utils'

export type StartSyncingRequest = { account: string }
export type StartSyncingResponse = undefined
export type StopScanningRequest = { account: string }
export type StopScanningResponse = undefined

export const StartSyncingRequestSchema: yup.ObjectSchema<StartSyncingRequest> = yup
export const StopScanningRequestSchema: yup.ObjectSchema<StopScanningRequest> = yup
.object({
account: yup.string().defined(),
})
.defined()

export const StartSyncingResponseSchema: yup.MixedSchema<StartSyncingResponse> = yup
export const StopScanningResponseSchema: yup.MixedSchema<StopScanningResponse> = yup
.mixed()
.oneOf([undefined] as const)

routes.register<typeof StartSyncingRequestSchema, StartSyncingResponse>(
`${ApiNamespace.wallet}/startSyncing`,
StartSyncingRequestSchema,
routes.register<typeof StopScanningRequestSchema, StopScanningResponse>(
`${ApiNamespace.wallet}/stopScanning`,
StopScanningRequestSchema,
(request, context): void => {
AssertHasRpcContext(request, context, 'wallet')

const account = getAccount(context.wallet, request.data.account)
account.updateSyncingEnabled(true)
account.updateScanningEnabled(false)
request.end()
},
)
Loading

0 comments on commit 87d95d6

Please sign in to comment.