lisk-sdk
lisk-sdk copied to clipboard
Create Base, Mainchain and Sidechain RecoveryClient classes
Description
- Create
SidechainRecoveryClient
class
abstract class BaseRecoveryClient {
private _apiClient!: apiClient.APIClient;
private _queryKeys!: Set<string>;
public connect(_connectionObj: ConnectionObj) {
// check for mode of connection and use connectionString to connect to the relevant client
}
public async getInclusionProof(_keys: string[]) {
// Call RPC to get inclusionProof and return in appropriate format
// await this._apiClient.invoke('state_prove', {});
}
public addQueryKeyForInclusionProof(queryKey: string) {
this._queryKeys.add(queryKey);
}
public collectInclusionProofs() {
// subscribe to chain_newBlock event and on every new block query the client with all the proofs
this._apiClient.subscribe('chain_newBlock', _ => {
this.getInclusionProof([...this._queryKeys.values()]);
// save proof for each key in stateRecoveryDB with key { sidechainID+queryKey }
});
}
public removeQueryKey(queryKey: string) {
this._queryKeys.delete(queryKey);
}
// Based on finalized height and last certificate on the other chain delete irrelevant recovery data
public cleanupStateRecoveryData() {}
// Disconnect client and release resources
public disconnectClient() {}
}
class MainchainRecoveryClient extends BaseRecoveryClient {
// Collect new CCMs from the on-chain events
// Collect inclusionProofs for the sidechain outbox for the CCMs: This part is done by calling addQueryKeyForInclusionProof from the manager class
public collectCCMsAndProofs() {
// collect CCMs on every newBlock and by calling getEvents for the block height and save them in messageRecoveryDB
}
// Based on finalized height and last certificate on the other chain delete irrelevant message recovery data
public cleanupMessageRecoveryData() {}
}
class SidechainRecoveryClient extends BaseRecoveryClient {}
Acceptance Criteria
- Should have all the method definition
- Should have all the unit tests for the implemented methods