-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathcontract-update-history.js
37 lines (29 loc) · 1.23 KB
/
contract-update-history.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// See https://docs.dash.org/projects/platform/en/stable/docs/tutorials/contracts-and-documents/update-documents.html
const setupDashClient = require('../setupDashClient');
const client = setupDashClient();
const updateContract = async () => {
const { platform } = client;
const identity = await platform.identities.get(process.env.IDENTITY_ID); // Your identity ID
const existingDataContract = await platform.contracts.get(
process.env.CONTRACT_ID,
);
const documentSchema = existingDataContract.getDocumentSchema('note');
console.log(documentSchema);
documentSchema.properties.author = {
type: 'string',
position: 1,
};
existingDataContract.setDocumentSchema('note', documentSchema);
existingDataContract.setConfig({
keepsHistory: true, // Enable storing of contract history
});
console.log(existingDataContract.getDocumentSchema('note'));
console.dir(existingDataContract.toJSON());
// Sign and submit the data contract
await platform.contracts.update(existingDataContract, identity);
return existingDataContract;
};
updateContract()
.then((d) => console.log('Contract updated:\n', d.toJSON()))
.catch((e) => console.error('Something went wrong:\n', e))
.finally(() => client.disconnect());