Skip to content

Commit 8def945

Browse files
authored
feat: v0.25 updates (#21)
* chore: update to 0.25.0-dev.19 version of dependencies * docs: update minimum version listed in README * fix: remove deprecated validation check * docs: update readme with info about identity and contract ID env * chore: update dependencies * chore: update to latest 0.25 deps * refactor: change how name response displayed * fix: update to return contract * fix: update doc logic for v0.25 * fix: modify update contract to work with v0.25 * chore: formatting * fix: modify key add identity for v0.25 * docs: readme update * docs: update node version
1 parent 3272f2d commit 8def945

File tree

12 files changed

+533
-443
lines changed

12 files changed

+533
-443
lines changed

1-Identities-and-Names/identity-update-add-key.js

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,10 @@ const updateIdentityAddKey = async () => {
3333

3434
const identityPublicKey = identityPrivateKey.toPublicKey().toBuffer();
3535

36-
const newPublicKey = new IdentityPublicKeyWithWitness({
37-
id: newKeyId,
38-
type: IdentityPublicKey.TYPES.ECDSA_SECP256K1,
39-
data: identityPublicKey,
40-
purpose: IdentityPublicKey.PURPOSES.AUTHENTICATION,
41-
securityLevel: IdentityPublicKey.SECURITY_LEVELS.HIGH,
42-
readOnly: false,
43-
signature: Buffer.alloc(0),
44-
});
36+
const newPublicKey = new IdentityPublicKeyWithWitness(1);
37+
newPublicKey.setId(newKeyId);
38+
newPublicKey.setSecurityLevel(IdentityPublicKey.SECURITY_LEVELS.HIGH);
39+
newPublicKey.setData(identityPublicKey);
4540

4641
const updateAdd = {
4742
add: [newPublicKey],

1-Identities-and-Names/name-resolve-by-name.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ const retrieveName = async () => {
1111
};
1212

1313
retrieveName()
14-
.then((d) => console.log('Name retrieved:\n', d.toJSON()))
14+
.then((d) => console.log('Name retrieved:\n', d.getData()))
1515
.catch((e) => console.error('Something went wrong:\n', e))
1616
.finally(() => client.disconnect());

1-Identities-and-Names/name-resolve-by-record.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ const retrieveNameByRecord = async () => {
1414
};
1515

1616
retrieveNameByRecord()
17-
.then((d) => console.log('Name retrieved:\n', d[0].toJSON()))
17+
.then((d) => console.log('Name retrieved:\n', d[0].getData()))
1818
.catch((e) => console.error('Something went wrong:\n', e))
1919
.finally(() => client.disconnect());

1-Identities-and-Names/name-search-by-name.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const retrieveNameBySearch = async () => {
1515
retrieveNameBySearch()
1616
.then((d) => {
1717
for (const name of d) {
18-
console.log('Name retrieved:\n', name.toJSON());
18+
console.log('Name retrieved:\n', name.getData());
1919
}
2020
})
2121
.catch((e) => console.error('Something went wrong:\n', e))

2-Contracts-and-Documents/contract-register-minimal.js

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,9 @@ const registerContract = async () => {
3333
const contract = await platform.contracts.create(contractDocuments, identity);
3434
console.dir({ contract: contract.toJSON() });
3535

36-
// Make sure contract passes validation checks
37-
const validationResult = await platform.dpp.dataContract.validate(contract);
38-
39-
if (validationResult.isValid()) {
40-
console.log('Validation passed, broadcasting contract..');
41-
// Sign and submit the data contract
42-
return platform.contracts.publish(contract, identity);
43-
}
44-
console.error(validationResult); // An array of detailed validation errors
45-
throw validationResult.errors[0];
36+
// Sign and submit the data contract
37+
await platform.contracts.publish(contract, identity);
38+
return contract;
4639
};
4740

4841
registerContract()

2-Contracts-and-Documents/contract-update-minimal.js

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,26 +21,17 @@ const updateContract = async () => {
2121
const existingDataContract = await platform.contracts.get(
2222
process.env.CONTRACT_ID,
2323
);
24-
const documents = existingDataContract.getDocuments();
24+
const documentSchema = existingDataContract.getDocumentSchema('note');
2525

26-
documents.note.properties.author = {
26+
documentSchema.properties.author = {
2727
type: 'string',
2828
};
2929

30-
existingDataContract.setDocuments(documents);
30+
existingDataContract.setDocumentSchema('note', documentSchema);
3131

32-
// Make sure contract passes validation checks
33-
const validationResult = await platform.dpp.dataContract.validate(
34-
existingDataContract,
35-
);
36-
37-
if (validationResult.isValid()) {
38-
console.log('Validation passed, broadcasting contract..');
39-
// Sign and submit the data contract
40-
return platform.contracts.update(existingDataContract, identity);
41-
}
42-
console.error(validationResult); // An array of detailed validation errors
43-
throw validationResult.errors[0];
32+
// Sign and submit the data contract
33+
await platform.contracts.update(existingDataContract, identity);
34+
return existingDataContract;
4435
};
4536

4637
updateContract()

2-Contracts-and-Documents/document-delete.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ const deleteNoteDocument = async () => {
3131
);
3232

3333
// Sign and submit the document delete transition
34-
return platform.documents.broadcast({ delete: [document] }, identity);
34+
await platform.documents.broadcast({ delete: [document] }, identity);
35+
return document;
3536
};
3637

3738
deleteNoteDocument()

2-Contracts-and-Documents/document-submit.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ const submitNoteDocument = async () => {
4040
delete: [], // Document(s) to delete
4141
};
4242
// Sign and submit the document(s)
43-
return platform.documents.broadcast(documentBatch, identity);
43+
await platform.documents.broadcast(documentBatch, identity);
44+
return noteDocument;
4445
};
4546

4647
submitNoteDocument()

2-Contracts-and-Documents/document-update.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ const updateNoteDocument = async () => {
3434
document.set('message', `Updated document @ ${new Date().toUTCString()}`);
3535

3636
// Sign and submit the document replace transition
37-
return platform.documents.broadcast({ replace: [document] }, identity);
37+
await platform.documents.broadcast({ replace: [document] }, identity);
38+
return document;
3839
};
3940

4041
updateNoteDocument()

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Code for the tutorials found on the
77

88
## Install
99

10-
Note: [NodeJS](https://nodejs.org/en/download/) (v12+) must be installed to run
10+
Note: [NodeJS](https://nodejs.org/en/download/) (v18+) must be installed to run
1111
the tutorial code.
1212

1313
### Clone this repository
@@ -41,6 +41,11 @@ Proceed with the tutorials
4141
align with the tutorials section found on the
4242
[documentation site](https://dashplatform.readme.io/docs/tutorials-introduction).
4343

44+
After [creating an identity](./1-Identities-and-Names/identity-register.js), set
45+
the `IDENTITY_ID` value in your `.env` file to your new identity ID. After
46+
[registering a data contract](./2-Contracts-and-Documents/contract-register-minimal.js),
47+
set the `CONTRACT_ID` value in your `.env` file to your new contract ID.
48+
4449
## Contributing
4550

4651
PRs accepted.

0 commit comments

Comments
 (0)