Skip to content
This repository has been archived by the owner on Dec 16, 2021. It is now read-only.

Commit

Permalink
feat: pass dashpay contract id and block height to drive (#220)
Browse files Browse the repository at this point in the history
  • Loading branch information
Konstantin Shuplenkov authored Dec 25, 2020
1 parent af23a4d commit 1e3730d
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 2 deletions.
2 changes: 2 additions & 0 deletions docker-compose.platform.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ services:
- DPNS_CONTRACT_ID=${PLATFORM_DPNS_CONTRACT_ID}
- DPNS_CONTRACT_BLOCK_HEIGHT=${PLATFORM_DPNS_CONTRACT_BLOCK_HEIGHT}
- DPNS_TOP_LEVEL_IDENTITY=${PLATFORM_DPNS_OWNER_ID}
- DASHPAY_CONTRACT_ID=${PLATFORM_DASHPAY_CONTRACT_ID}
- DASHPAY_CONTRACT_BLOCK_HEIGHT=${PLATFORM_DASHPAY_CONTRACT_BLOCK_HEIGHT}
- NODE_ENV=${ENVIRONMENT:?err}
- LOGGING_LEVEL=${PLATFORM_DRIVE_ABCI_LOG_LEVEL:?err}
- INITIAL_CORE_CHAINLOCKED_HEIGHT=${PLATFORM_DRIVE_TENDERDASH_GENESIS_INITIAL_CORE_CHAIN_LOCKED_HEIGHT:-1}
Expand Down
23 changes: 22 additions & 1 deletion src/config/configJsonSchema.js
Original file line number Diff line number Diff line change
Expand Up @@ -323,8 +323,29 @@ module.exports = {
required: ['contract', 'ownerId'],
additionalProperties: false,
},
dashpay: {
type: 'object',
properties: {
contract: {
properties: {
id: {
type: ['string', 'null'],
minLength: 1,
},
blockHeight: {
type: ['integer', 'null'],
minimum: 1,
},
},
required: ['id', 'blockHeight'],
additionalProperties: false,
},
},
required: ['contract'],
additionalProperties: false,
},
},
required: ['dapi', 'drive', 'dpns'],
required: ['dapi', 'drive', 'dpns', 'dashpay'],
additionalProperties: false,
},
externalIp: {
Expand Down
6 changes: 6 additions & 0 deletions src/config/systemConfigs/systemConfigs.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,12 @@ const baseConfig = {
},
ownerId: null,
},
dashpay: {
contract: {
id: null,
blockHeight: null,
},
},
},
externalIp: null,
network: NETWORKS.TESTNET,
Expand Down
38 changes: 37 additions & 1 deletion src/listr/tasks/platform/initTaskFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,16 +172,52 @@ function initTaskFactory(
dashpayDocumentSchema, ctx.identity,
);

await ctx.client.platform.contracts.broadcast(
ctx.dashpayStateTransition = await ctx.client.platform.contracts.broadcast(
ctx.dataContract,
ctx.identity,
);

config.set('platform.dashpay.contract.id', ctx.dataContract.getId().toString());

// eslint-disable-next-line no-param-reassign
task.output = `Dashpay contract ID: ${ctx.dataContract.getId()}`;
},
options: { persistentOutput: true },
},
{
title: 'Obtain Dashpay contract commit block height',
task: async (ctx, task) => {
const stateTransitionHash = crypto.createHash('sha256')
.update(ctx.dashpayStateTransition.toBuffer())
.digest();

if (ctx.dapiAddress || config.get('network') !== NETWORKS.LOCAL) {
task.skip('Can\'t obtain Dashpay contract commit block height from remote node.'
+ `Please, get block height manually using state transition hash "0x${stateTransitionHash.toString('hex')}"`
+ 'and set it to "platform.dashpay.contract.id" config option');

return;
}

const tenderdashRpcClient = createTenderdashRpcClient();

const params = { hash: stateTransitionHash.toString('base64') };

const response = await tenderdashRpcClient.request('tx', params);

if (response.error) {
throw new Error(`Tendermint error: ${response.error.message}: ${response.error.data}`);
}

const { result: { height: contractBlockHeight } } = response;

config.set('platform.dashpay.contract.blockHeight', contractBlockHeight);

// eslint-disable-next-line no-param-reassign
task.output = `Dashpay contract block height: ${contractBlockHeight}`;
},
options: { persistentOutput: true },
},
{
title: 'Disconnect SDK',
task: async (ctx) => ctx.client.disconnect(),
Expand Down

0 comments on commit 1e3730d

Please sign in to comment.