Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion sdk/wallet-sdk/src/wallet/__test__/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ export const ctx: SDKContext = {
userId: 'userId',
logger: mockLogger,
error: mockErrorHandler,
defaultSynchronizerId: '',
}

export const offlineCtx: OfflineSDKContext = {
Expand Down
22 changes: 6 additions & 16 deletions sdk/wallet-sdk/src/wallet/init/__test__/plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,9 @@ describe('plugin', () => {

it('should call a plugin constructor when registering', async () => {
// Mock the authenticated user response
mock.ledgerProvider.request
.mockResolvedValueOnce({
user: { id: 'test-user-id' },
})
// Mock the connected synchronizers response
.mockResolvedValueOnce({
connectedSynchronizers: [{ id: 'sync-1' }],
})
mock.ledgerProvider.request.mockResolvedValueOnce({
user: { id: 'test-user-id' },
})

const sdk = await SDK.create({
ledgerProvider: mock.ledgerProvider as never,
Expand All @@ -67,14 +62,9 @@ describe('plugin', () => {

it('should successfully register a plugin under provided name', async () => {
// Mock the authenticated user response
mock.ledgerProvider.request
.mockResolvedValueOnce({
user: { id: 'test-user-id' },
})
// Mock the connected synchronizers response
.mockResolvedValueOnce({
connectedSynchronizers: [{ id: 'sync-1' }],
})
mock.ledgerProvider.request.mockResolvedValueOnce({
user: { id: 'test-user-id' },
})

const sdk = await SDK.create({
ledgerProvider: mock.ledgerProvider as never,
Expand Down
1 change: 0 additions & 1 deletion sdk/wallet-sdk/src/wallet/init/types/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ export type SDKContext = {
userId: string
logger: SDKLogger
error: SDKErrorHandler
defaultSynchronizerId: string
}

export type OfflineSDKContext = {
Expand Down
11 changes: 6 additions & 5 deletions sdk/wallet-sdk/src/wallet/namespace/amulet/amulet.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ const mockAmuletService = {
const config: AmuletNamespaceConfig = {
commonCtx: {
...ctx,
defaultSynchronizerId: 'mock-synchronizer-id',
logger: mockLogger,
} as any,
registry: {
Expand All @@ -64,7 +63,6 @@ const config: AmuletNamespaceConfig = {
const configNoValidator: AmuletNamespaceConfig = {
commonCtx: {
...ctx,
defaultSynchronizerId: 'mock-synchronizer-id',
logger: mockLogger,
} as any,
registry: {
Expand Down Expand Up @@ -133,7 +131,9 @@ describe('AmuletNamespace', () => {
['dc-1'] as any,
])

const result = await amuletNamespace.tapInternal('10000')
const result = await amuletNamespace.tapInternal('10000', {
synchronizerId: 'mock-synchronizer-id',
})

expect(amuletNamespace.tap).toHaveBeenCalledWith(
config.validatorParty,
Expand All @@ -142,7 +142,7 @@ describe('AmuletNamespace', () => {
expect(mockSubmit).toHaveBeenCalledWith({
commands: [{ ExerciseCommand: tapCommand }],
disclosedContracts: ['dc-1'],
synchronizerId: config.commonCtx.defaultSynchronizerId,
synchronizerId: 'mock-synchronizer-id',
actAs: [config.validatorParty],
})
expect(result).toStrictEqual({
Expand Down Expand Up @@ -253,6 +253,7 @@ describe('AmuletNamespace with no validator party', () => {

const result = await amuletNamespace.tapInternal('10000', {
partyId: 'providerParty::123',
synchronizerId: 'mock-synchronizer-id',
})

expect(amuletNamespace.tap).toHaveBeenCalledWith(
Expand All @@ -262,7 +263,7 @@ describe('AmuletNamespace with no validator party', () => {
expect(mockSubmit).toHaveBeenCalledWith({
commands: [{ ExerciseCommand: tapCommand }],
disclosedContracts: ['dc-1'],
synchronizerId: config.commonCtx.defaultSynchronizerId,
synchronizerId: 'mock-synchronizer-id',
actAs: ['providerParty::123'],
})
expect(result).toStrictEqual({
Expand Down
16 changes: 9 additions & 7 deletions sdk/wallet-sdk/src/wallet/namespace/amulet/namespace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { PreapprovalNamespace } from './preapproval.js'
import { Decimal } from 'decimal.js'
import { parseAssets, ParsedURL } from '../utils/url.js'
import { resolveProviderParty } from './utils.js'
import { resolveSynchronizerId } from '../../synchronizer.js'

const defaultMaxRetries = 10
const defaultDelayMs = 5000
Expand Down Expand Up @@ -94,15 +95,14 @@ export class AmuletNamespace {
'tapInternal',
options?.partyId
)
const synchronizerId =
options?.synchronizerId ??
this.sdkContext.commonCtx.defaultSynchronizerId
const [tapCommand, disclosedContracts] = await this.tap(partyId, amount)

return await this.ledger.internal.submit({
commands: [tapCommand],
disclosedContracts,
synchronizerId,
...(options?.synchronizerId !== undefined && {
synchronizerId: options.synchronizerId,
}),
actAs: [partyId],
})
}
Expand Down Expand Up @@ -137,9 +137,11 @@ export class AmuletNamespace {
if (featuredAppRights) {
return featuredAppRights
}
const synchronizerId =
options.synchronizerId ??
this.sdkContext.commonCtx.defaultSynchronizerId
const synchronizerId = await resolveSynchronizerId(
this.sdkContext.commonCtx.ledgerProvider,
this.sdkContext.commonCtx.error,
options.synchronizerId
)

const [featuredAppCommand, dc] =
await this.sdkContext.amuletService.selfGrantFeatureAppRight(
Expand Down
13 changes: 6 additions & 7 deletions sdk/wallet-sdk/src/wallet/namespace/amulet/preapproval.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { LedgerNamespace } from '../ledger/namespace.js'
import { fetchAmulet } from './namespace.js'
import { SDKLogger } from '../../logger/logger.js'
import { resolveProviderParty } from './utils.js'
import { resolveSynchronizerId } from '../../synchronizer.js'

const EMPTY_COMMAND_RESULT = [null, []] as const

Expand Down Expand Up @@ -127,13 +128,11 @@ export class PreapprovalNamespace {
parties?.provider
)

const synchronizerId =
args.synchronizerId ?? this.ctx.commonCtx.defaultSynchronizerId
if (!synchronizerId)
this.ctx.commonCtx.error.throw({
type: 'Unexpected',
message: 'Cannot obtain synchronizer id',
})
const synchronizerId = await resolveSynchronizerId(
this.ctx.commonCtx.ledgerProvider,
this.ctx.commonCtx.error,
args.synchronizerId
)

if (
!preapprovalStatus ||
Expand Down
33 changes: 25 additions & 8 deletions sdk/wallet-sdk/src/wallet/namespace/amulet/traffic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ describe('TrafficNamespace', () => {
config = {
commonCtx: {
...mock.ctx,
defaultSynchronizerId: 'SYNCDEFAULT::123',
} as any,
amuletService: {
getMemberTrafficStatus: vi.fn(),
Expand Down Expand Up @@ -69,9 +68,18 @@ describe('TrafficNamespace', () => {
},
})

mock.ledgerProvider.request.mockResolvedValueOnce({
participantId: 'PAR::234',
})
mock.ledgerProvider.request
.mockResolvedValueOnce({
connectedSynchronizers: [
{
synchronizerId: 'SYNCDEFAULT::123',
synchronizerAlias: 'global',
},
],
})
.mockResolvedValueOnce({
participantId: 'PAR::234',
})

const result = await trafficNamespace.status()

Expand Down Expand Up @@ -149,17 +157,26 @@ describe('TrafficNamespace', () => {
[],
])

mock.ledgerProvider.request.mockResolvedValueOnce({
participantId: 'PAR::234',
})
mock.ledgerProvider.request
.mockResolvedValueOnce({
connectedSynchronizers: [
{
synchronizerId: 'SYNCDEFAULT::123',
synchronizerAlias: 'global',
},
],
})
.mockResolvedValueOnce({
participantId: 'PAR::234',
})

await trafficNamespace.buy({
buyer: buyer,
ccAmount: 125,
inputUtxos: utxos,
})

expect(mock.ledgerProvider.request).toHaveBeenCalledTimes(1)
expect(mock.ledgerProvider.request).toHaveBeenCalledTimes(2)
expect(config.amuletService.buyMemberTraffic).toHaveBeenCalledWith(
'DSO::123',
buyer,
Expand Down
18 changes: 11 additions & 7 deletions sdk/wallet-sdk/src/wallet/namespace/amulet/traffic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,19 @@ import { PartyId } from '@canton-network/core-types'
import { PreparedCommand } from '../transactions/types.js'
import { Ops } from '@canton-network/core-provider-ledger'
import { AmuletNamespaceConfig, fetchAmulet } from './namespace.js'
import { resolveSynchronizerId } from '../../synchronizer.js'

export class TrafficNamespace {
constructor(private readonly sdkContext: AmuletNamespaceConfig) {}

async status(
params?: Partial<{ memberId?: string; synchronizerId?: string }>
) {
const synchronizerId =
params?.synchronizerId ||
this.sdkContext.commonCtx.defaultSynchronizerId
const synchronizerId = await resolveSynchronizerId(
this.sdkContext.commonCtx.ledgerProvider,
this.sdkContext.commonCtx.error,
params?.synchronizerId
)

const memberId =
params?.memberId ??
Expand Down Expand Up @@ -46,6 +49,11 @@ export class TrafficNamespace {
}): Promise<PreparedCommand> {
const { buyer, ccAmount, inputUtxos } = params
const migrationId = params.migrationId ?? 0
const synchronizerId = await resolveSynchronizerId(
this.sdkContext.commonCtx.ledgerProvider,
this.sdkContext.commonCtx.error,
params.synchronizerId
)
const defaultAmulet = await fetchAmulet(this.sdkContext)
const memberId =
params.memberId ??
Expand All @@ -61,10 +69,6 @@ export class TrafficNamespace {
)
).participantId

const synchronizerId =
params.synchronizerId ||
this.sdkContext.commonCtx.defaultSynchronizerId

const [command, dc] =
await this.sdkContext.amuletService.buyMemberTraffic(
defaultAmulet.admin,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe('Dar Namespace', () => {
const uploadSpy = vi.spyOn(dar, 'upload')

const darBytes = new Uint8Array()
await dar.upload(darBytes, 'packageId')
await dar.upload(darBytes, 'packageId', 'synchronizerId')

expect(checkSpy).toHaveBeenCalledExactlyOnceWith('packageId')
expect(checkSpy).toHaveResolvedWith(false)
Expand Down
10 changes: 8 additions & 2 deletions sdk/wallet-sdk/src/wallet/namespace/ledger/dar/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import { SDKContext } from '../../../sdk.js'
import { Ops } from '@canton-network/core-provider-ledger'
import { resolveSynchronizerId } from '../../../synchronizer.js'

export class DarNamespace {
constructor(private readonly sdkContext: SDKContext) {}
Expand All @@ -23,14 +24,19 @@ export class DarNamespace {
return
}

const resolvedSynchronizerId = await resolveSynchronizerId(
this.sdkContext.ledgerProvider,
this.sdkContext.error,
synchronizerId
)

await this.sdkContext.ledgerProvider.request<Ops.PostV2Packages>({
method: 'ledgerApi',
params: {
resource: '/v2/packages',
requestMethod: 'post',
query: {
synchronizerId:
synchronizerId ?? this.sdkContext.defaultSynchronizerId,
synchronizerId: resolvedSynchronizerId,
vetAllPackages: vetAllPackages ?? true,
},
body: darBytes as never,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ describe('Internal Leger Namespace', () => {
},
],
actAs: ['partyId'],
synchronizerId: 'synchronizerId',
}
const result = await internal.submit(arg)

Expand Down Expand Up @@ -79,6 +80,7 @@ describe('Internal Leger Namespace', () => {
},
],
actAs: ['partyId'],
synchronizerId: 'synchronizerId',
}
const result = await internal.prepare(arg)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { SDKContext } from '../../../sdk.js'
import { v4 } from 'uuid'
import { Ops } from '@canton-network/core-provider-ledger'
import { InternalOperationParams } from './types.js'
import { resolveSynchronizerId } from '../../../synchronizer.js'

export class InternalLedgerNamespace {
constructor(private readonly ctx: SDKContext) {}
Expand All @@ -14,13 +15,18 @@ export class InternalLedgerNamespace {
) {
const {
commands,
synchronizerId = this.ctx.defaultSynchronizerId,
synchronizerId: synchronizerIdArg,
disclosedContracts = [],
readAs = [],
actAs,
commandId = v4(),
packageIdSelectionPreference = [],
} = args
const synchronizerId = await resolveSynchronizerId(
this.ctx.ledgerProvider,
this.ctx.error,
synchronizerIdArg
)
const request = {
commands,
commandId,
Expand Down Expand Up @@ -49,14 +55,19 @@ export class InternalLedgerNamespace {
) {
const {
commands,
synchronizerId = this.ctx.defaultSynchronizerId,
synchronizerId: synchronizerIdArg,
disclosedContracts = [],
readAs = [],
actAs,
commandId = v4(),
packageIdSelectionPreference = [],
verboseHashing = false,
} = args
const synchronizerId = await resolveSynchronizerId(
this.ctx.ledgerProvider,
this.ctx.error,
synchronizerIdArg
)
const request = {
commands,
commandId,
Expand Down
Loading
Loading