Skip to content
This repository has been archived by the owner on Jun 11, 2024. It is now read-only.

Commit

Permalink
Merge pull request #7302 from LiskHQ/7225_interop_endpoint
Browse files Browse the repository at this point in the history
Add interoperability endpoints for mainchain and sidechain - Closes #7225
  • Loading branch information
ishantiw authored Jul 18, 2022
2 parents aae180c + 5973386 commit 3719231
Show file tree
Hide file tree
Showing 7 changed files with 500 additions and 6 deletions.
58 changes: 57 additions & 1 deletion framework/src/modules/interoperability/mainchain/endpoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,61 @@
*/

import { BaseEndpoint } from '../../base_endpoint';
import { MainchainInteroperabilityStore } from './store';
import { ImmutableStoreCallback, StoreCallback } from '../types';
import { BaseInteroperableAPI } from '../base_interoperable_api';
import { ModuleEndpointContext } from '../../../types';

export class MainchainInteroperabilityEndpoint extends BaseEndpoint {}
export class MainchainInteroperabilityEndpoint extends BaseEndpoint {
protected readonly interoperableCCAPIs = new Map<number, BaseInteroperableAPI>();

public constructor(moduleID: Buffer, interoperableCCAPIs: Map<number, BaseInteroperableAPI>) {
super(moduleID);
this.interoperableCCAPIs = interoperableCCAPIs;
}

public async getChainAccount(context: ModuleEndpointContext, chainID: Buffer) {
const interoperabilityStore = this.getInteroperabilityStore(context.getStore);
const result = await interoperabilityStore.getChainAccount(chainID);

return result;
}

public async getChannel(context: ModuleEndpointContext, chainID: Buffer) {
const interoperabilityStore = this.getInteroperabilityStore(context.getStore);

const result = await interoperabilityStore.getChannel(chainID);

return result;
}

public async getOwnChainAccount(context: ModuleEndpointContext) {
const interoperabilityStore = this.getInteroperabilityStore(context.getStore);

const result = await interoperabilityStore.getOwnChainAccount();

return result;
}

public async getTerminatedStateAccount(context: ModuleEndpointContext, chainID: Buffer) {
const interoperabilityStore = this.getInteroperabilityStore(context.getStore);

const result = await interoperabilityStore.getTerminatedStateAccount(chainID);

return result;
}

public async getTerminatedOutboxAccount(context: ModuleEndpointContext, chainID: Buffer) {
const interoperabilityStore = this.getInteroperabilityStore(context.getStore);

const result = await interoperabilityStore.getTerminatedOutboxAccount(chainID);

return result;
}

protected getInteroperabilityStore(
getStore: StoreCallback | ImmutableStoreCallback,
): MainchainInteroperabilityStore {
return new MainchainInteroperabilityStore(this.moduleID, getStore, this.interoperableCCAPIs);
}
}
40 changes: 38 additions & 2 deletions framework/src/modules/interoperability/mainchain/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,51 @@ import { BaseInteroperabilityModule } from '../base_interoperability_module';
import { MainchainInteroperabilityAPI } from './api';
import { MainchainCCAPI } from './cc_api';
import { MainchainInteroperabilityEndpoint } from './endpoint';
import {
getChainAccountRequestSchema,
getChannelRequestSchema,
getTerminatedStateAccountRequestSchema,
getTerminatedOutboxAccountRequestSchema,
chainAccountSchema,
channelSchema,
ownChainAccountSchema,
terminatedStateSchema,
terminatedOutboxSchema,
} from '../schemas';

export class MainchainInteroperabilityModule extends BaseInteroperabilityModule {
public crossChainAPI = new MainchainCCAPI(this.id);
public api = new MainchainInteroperabilityAPI(this.id, this.interoperableCCAPIs);
public endpoint = new MainchainInteroperabilityEndpoint(this.id);
public endpoint = new MainchainInteroperabilityEndpoint(this.id, this.interoperableCCAPIs);

public metadata(): ModuleMetadata {
return {
endpoints: [],
endpoints: [
{
name: this.endpoint.getChainAccount.name,
request: getChainAccountRequestSchema,
response: chainAccountSchema,
},
{
name: this.endpoint.getChannel.name,
request: getChannelRequestSchema,
response: channelSchema,
},
{
name: this.endpoint.getOwnChainAccount.name,
response: ownChainAccountSchema,
},
{
name: this.endpoint.getTerminatedStateAccount.name,
request: getTerminatedStateAccountRequestSchema,
response: terminatedStateSchema,
},
{
name: this.endpoint.getTerminatedOutboxAccount.name,
request: getTerminatedOutboxAccountRequestSchema,
response: terminatedOutboxSchema,
},
],
commands: this.commands.map(command => ({
id: command.id,
name: command.name,
Expand Down
30 changes: 30 additions & 0 deletions framework/src/modules/interoperability/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -746,3 +746,33 @@ export const stateRecoveryInitParams = {
},
},
};

export const getChainAccountRequestSchema = {
$id: '/modules/interoperability/endpoint/getChainAccountRequest',
type: 'object',
required: ['chainID'],
properties: {
chainID: {
dataType: 'bytes',
fieldNumber: 1,
},
},
};

export const getChainAccountResponseSchema = {
$id: '/modules/interoperability/endpoint/getChainAccountResponse',
type: 'object',
required: ['chainID'],
properties: {
name: {
dataType: 'string',
fieldNumber: 1,
},
},
};

export const getChannelRequestSchema = getChainAccountRequestSchema;

export const getTerminatedStateAccountRequestSchema = getChainAccountRequestSchema;

export const getTerminatedOutboxAccountRequestSchema = getChainAccountRequestSchema;
58 changes: 57 additions & 1 deletion framework/src/modules/interoperability/sidechain/endpoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,61 @@
*/

import { BaseEndpoint } from '../../base_endpoint';
import { SidechainInteroperabilityStore } from './store';
import { ImmutableStoreCallback, StoreCallback } from '../types';
import { BaseInteroperableAPI } from '../base_interoperable_api';
import { ModuleEndpointContext } from '../../../types';

export class SidechainInteroperabilityEndpoint extends BaseEndpoint {}
export class SidechainInteroperabilityEndpoint extends BaseEndpoint {
protected readonly interoperableCCAPIs = new Map<number, BaseInteroperableAPI>();

public constructor(moduleID: Buffer, interoperableCCAPIs: Map<number, BaseInteroperableAPI>) {
super(moduleID);
this.interoperableCCAPIs = interoperableCCAPIs;
}

public async getChainAccount(context: ModuleEndpointContext, chainID: Buffer) {
const interoperabilityStore = this.getInteroperabilityStore(context.getStore);
const result = await interoperabilityStore.getChainAccount(chainID);

return result;
}

public async getChannel(context: ModuleEndpointContext, chainID: Buffer) {
const interoperabilityStore = this.getInteroperabilityStore(context.getStore);

const result = await interoperabilityStore.getChannel(chainID);

return result;
}

public async getOwnChainAccount(context: ModuleEndpointContext) {
const interoperabilityStore = this.getInteroperabilityStore(context.getStore);

const result = await interoperabilityStore.getOwnChainAccount();

return result;
}

public async getTerminatedStateAccount(context: ModuleEndpointContext, chainID: Buffer) {
const interoperabilityStore = this.getInteroperabilityStore(context.getStore);

const result = await interoperabilityStore.getTerminatedStateAccount(chainID);

return result;
}

public async getTerminatedOutboxAccount(context: ModuleEndpointContext, chainID: Buffer) {
const interoperabilityStore = this.getInteroperabilityStore(context.getStore);

const result = await interoperabilityStore.getTerminatedOutboxAccount(chainID);

return result;
}

protected getInteroperabilityStore(
getStore: StoreCallback | ImmutableStoreCallback,
): SidechainInteroperabilityStore {
return new SidechainInteroperabilityStore(this.moduleID, getStore, this.interoperableCCAPIs);
}
}
40 changes: 38 additions & 2 deletions framework/src/modules/interoperability/sidechain/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,22 @@ import { SidechainInteroperabilityAPI } from './api';
import { SidechainCCAPI } from './cc_api';
// import { MainchainRegistrationCommand } from './commands/mainchain_registration';
import { SidechainInteroperabilityEndpoint } from './endpoint';
import {
getChainAccountRequestSchema,
getChannelRequestSchema,
getTerminatedStateAccountRequestSchema,
getTerminatedOutboxAccountRequestSchema,
chainAccountSchema,
channelSchema,
ownChainAccountSchema,
terminatedStateSchema,
terminatedOutboxSchema,
} from '../schemas';

export class SidechainInteroperabilityModule extends BaseInteroperabilityModule {
public crossChainAPI: BaseInteroperableAPI = new SidechainCCAPI(this.id);
public api = new SidechainInteroperabilityAPI(this.id, this.interoperableCCAPIs);
public endpoint = new SidechainInteroperabilityEndpoint(this.id);
public endpoint = new SidechainInteroperabilityEndpoint(this.id, this.interoperableCCAPIs);
// private readonly _mainchainRegistrationCommand = new MainchainRegistrationCommand(
// this.id,
// new Map(),
Expand All @@ -33,7 +44,32 @@ export class SidechainInteroperabilityModule extends BaseInteroperabilityModule

public metadata(): ModuleMetadata {
return {
endpoints: [],
endpoints: [
{
name: this.endpoint.getChainAccount.name,
request: getChainAccountRequestSchema,
response: chainAccountSchema,
},
{
name: this.endpoint.getChannel.name,
request: getChannelRequestSchema,
response: channelSchema,
},
{
name: this.endpoint.getOwnChainAccount.name,
response: ownChainAccountSchema,
},
{
name: this.endpoint.getTerminatedStateAccount.name,
request: getTerminatedStateAccountRequestSchema,
response: terminatedStateSchema,
},
{
name: this.endpoint.getTerminatedOutboxAccount.name,
request: getTerminatedOutboxAccountRequestSchema,
response: terminatedOutboxSchema,
},
],
commands: this.commands.map(command => ({
id: command.id,
name: command.name,
Expand Down
Loading

0 comments on commit 3719231

Please sign in to comment.