File tree Expand file tree Collapse file tree 12 files changed +533
-443
lines changed
2-Contracts-and-Documents Expand file tree Collapse file tree 12 files changed +533
-443
lines changed Original file line number Diff line number Diff 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 ] ,
Original file line number Diff line number Diff line change @@ -11,6 +11,6 @@ const retrieveName = async () => {
1111} ;
1212
1313retrieveName ( )
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 ( ) ) ;
Original file line number Diff line number Diff line change @@ -14,6 +14,6 @@ const retrieveNameByRecord = async () => {
1414} ;
1515
1616retrieveNameByRecord ( )
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 ( ) ) ;
Original file line number Diff line number Diff line change @@ -15,7 +15,7 @@ const retrieveNameBySearch = async () => {
1515retrieveNameBySearch ( )
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 ) )
Original file line number Diff line number Diff 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
4841registerContract ( )
Original file line number Diff line number Diff 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
4637updateContract ( )
Original file line number Diff line number Diff 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
3738deleteNoteDocument ( )
Original file line number Diff line number Diff 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
4647submitNoteDocument ( )
Original file line number Diff line number Diff 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
4041updateNoteDocument ( )
Original file line number Diff line number Diff 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
1111the tutorial code.
1212
1313### Clone this repository
@@ -41,6 +41,11 @@ Proceed with the tutorials
4141align 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
4651PRs accepted.
You can’t perform that action at this time.
0 commit comments