Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: v0.25 readme sync #23

Merged
merged 5 commits into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/other/incentives.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ In general, masternodes and miners are incentivized to perform this work by fees
Dash Platform collects fees for three activities:

* [Registering a new identity](../tutorials/identities-and-names/register-an-identity.md)
* [Registering a Data Contract](../tutorials/contracts-and-documents/submit-documents.md)
* [Registering a Data Contract](../tutorials/contracts-and-documents/register-a-data-contract.md)
* [Updating Application Data](tutorial-submit-a-state-transition)

New users may not have any Dash of their own, so when registering an identity, some Dash is converted into _credits_, which is Dash that can only be spent on Platform activity. Users can also convert Dash into credits after registration as needed.
Expand Down
35 changes: 21 additions & 14 deletions docs/reference/dapi-endpoints-platform-endpoints.md
Original file line number Diff line number Diff line change
Expand Up @@ -212,21 +212,22 @@ grpcurl -proto protos/platform/v0/platform.proto \
```javascript JavaScript (dapi-client)
// JavaScript (dapi-client)
const DAPIClient = require('@dashevo/dapi-client');
const DashPlatformProtocol = require('@dashevo/dpp');
const {
default: loadDpp, DashPlatformProtocol,
} = require('@dashevo/wasm-dpp');

const client = new DAPIClient();
loadDpp();
const dpp = new DashPlatformProtocol();

const publicKeyHash = 'b8d1591aa74d440e0af9c0be16c55bbc141847f7';
const publicKeysBuffer = [Buffer.from(publicKeyHash, 'hex')];

dpp.initialize().then(() => {
client.platform.getIdentitiesByPublicKeyHashes(publicKeysBuffer)
.then((response) => {
const retrievedIdentity = dpp.identity.createFromBuffer(response.identities[0]);
console.log(retrievedIdentity.toJSON());
});
});
client.platform.getIdentitiesByPublicKeyHashes(publicKeysBuffer)
.then((response) => {
const retrievedIdentity = dpp.identity.createFromBuffer(response.identities[0]);
console.log(retrievedIdentity.toJSON());
});
```
```javascript JavaScript (dapi-grpc)
// JavaScript (dapi-grpc)
Expand Down Expand Up @@ -275,27 +276,33 @@ grpcurl -proto protos/platform/v0/platform.proto \
```json Response (JavaScript)
// Response (JavaScript)
{
"protocolVersion": 1,
"$version": "0",
"id": "4EfA9Jrvv3nnCFdSf7fad59851iiTRZ6Wcu6YVJ4iSeF",
"publicKeys": [
{
"$version": "0",
"id": 0,
"type": 0,
"purpose": 0,
"securityLevel": 0,
"contractBounds": null,
"type": 0,
"readOnly": false,
"data": "Asi0dHtSjKxf3femzGNwLuBO19EzKQTghRA0PqANzlRq",
"readOnly": false
"disabledAt": null
},
{
"$version": "0",
"id": 1,
"type": 0,
"purpose": 0,
"securityLevel": 2,
"contractBounds": null,
"type": 0,
"readOnly": false,
"data": "AgHuKPhPVIU5BWfpOcK1hgELY6aeySyrU13JaoxxkTYC",
"readOnly": false
"disabledAt": null
}
],
"balance": 5255234422,
"balance": 2344694260,
"revision": 0
}
```
Expand Down
4 changes: 2 additions & 2 deletions docs/tutorials/connecting-to-testnet.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Platform services are provided via a combination of HTTP and gRPC connections to

## Prerequisites

- An installation of [NodeJS v12 or higher](https://nodejs.org/en/download/)
- An installation of [NodeJS v16 or higher](https://nodejs.org/en/download/)

## Connect via Dash SDK

Expand All @@ -17,7 +17,7 @@ Platform services are provided via a combination of HTTP and gRPC connections to
The JavaScript SDK package is available from npmjs.com and can be installed by running `npm install dash` from the command line:

```shell
npm install dash
npm install dash@0.25-dev
```

### 2. Connect to Dash Platform
Expand Down
5 changes: 3 additions & 2 deletions docs/tutorials/contracts-and-documents/delete-documents.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const clientOpts = {
},
apps: {
tutorialContract: {
contractId: '3iaEhdyAVbmSjd59CT6SCrqPjfAfMdPTc8ksydgqSaWE',
contractId: '8cvMFwa2YbEsNNoc1PXfTacy2PVq2SzVnkZLeQSzjfi6',
},
},
};
Expand All @@ -41,7 +41,8 @@ const deleteNoteDocument = async () => {
);

// Sign and submit the document delete transition
return platform.documents.broadcast({ delete: [document] }, identity);
await platform.documents.broadcast({ delete: [document] }, identity);
return document;
};

deleteNoteDocument()
Expand Down
63 changes: 12 additions & 51 deletions docs/tutorials/contracts-and-documents/register-a-data-contract.md
Original file line number Diff line number Diff line change
Expand Up @@ -193,16 +193,9 @@ const registerContract = async () => {
const contract = await platform.contracts.create(contractDocuments, identity);
console.dir({ contract: contract.toJSON() });

// Make sure contract passes validation checks
const validationResult = await platform.dpp.dataContract.validate(contract);

if (validationResult.isValid()) {
console.log('Validation passed, broadcasting contract..');
// Sign and submit the data contract
return platform.contracts.publish(contract, identity);
}
console.error(validationResult); // An array of detailed validation errors
throw validationResult.errors[0];
// Sign and submit the data contract
await platform.contracts.publish(contract, identity);
return contract;
};

registerContract()
Expand Down Expand Up @@ -249,16 +242,8 @@ const registerContract = async () => {
const contract = await platform.contracts.create(contractDocuments, identity);
console.dir({ contract: contract.toJSON() });

// Make sure contract passes validation checks
const validationResult = await platform.dpp.dataContract.validate(contract);

if (validationResult.isValid()) {
console.log('Validation passed, broadcasting contract..');
// Sign and submit the data contract
return platform.contracts.publish(contract, identity);
}
console.error(validationResult); // An array of detailed validation errors
throw validationResult.errors[0];
await platform.contracts.publish(contract, identity);
return contract;
};

registerContract()
Expand Down Expand Up @@ -319,16 +304,8 @@ const registerContract = async () => {
contract.setDefinitions(definitions);
console.dir({ contract: contract.toJSON() });

// Make sure contract passes validation checks
const validationResult = await platform.dpp.dataContract.validate(contract);

if (validationResult.isValid()) {
console.log('Validation passed, broadcasting contract..');
// Sign and submit the data contract
return platform.contracts.publish(contract, identity);
}
console.error(validationResult); // An array of detailed validation errors
throw validationResult.errors[0];
await platform.contracts.publish(contract, identity);
return contract;
};

registerContract()
Expand Down Expand Up @@ -371,16 +348,8 @@ const registerContract = async () => {
const contract = await platform.contracts.create(contractDocuments, identity);
console.dir({ contract: contract.toJSON() });

// Make sure contract passes validation checks
const validationResult = await platform.dpp.dataContract.validate(contract);

if (validationResult.isValid()) {
console.log('Validation passed, broadcasting contract..');
// Sign and submit the data contract
return platform.contracts.publish(contract, identity);
}
console.error(validationResult); // An array of detailed validation errors
throw validationResult.errors[0];
await platform.contracts.publish(contract, identity);
return contract;
};

registerContract()
Expand Down Expand Up @@ -425,16 +394,8 @@ const registerContract = async () => {
const contract = await platform.contracts.create(contractDocuments, identity);
console.dir({ contract: contract.toJSON() }, { depth: 5 });

// Make sure contract passes validation checks
const validationResult = await platform.dpp.dataContract.validate(contract);

if (validationResult.isValid()) {
console.log('Validation passed, broadcasting contract..');
// Sign and submit the data contract
return platform.contracts.publish(contract, identity);
}
console.error(validationResult); // An array of detailed validation errors
throw validationResult.errors[0];
await platform.contracts.publish(contract, identity);
return contract;
};

registerContract()
Expand All @@ -447,7 +408,7 @@ registerContract()

> 👍
>
> **Make a note of the returned data contract `$id` as it will be used used in subsequent tutorials throughout the documentation.**
> **Make a note of the returned data contract `id` as it will be used used in subsequent tutorials throughout the documentation.**

# What's Happening

Expand Down
53 changes: 28 additions & 25 deletions docs/tutorials/contracts-and-documents/retrieve-a-data-contract.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,20 @@ const Dash = require('dash');
const client = new Dash.Client({ network: 'testnet' });

const retrieveContract = async () => {
const contractId = '3iaEhdyAVbmSjd59CT6SCrqPjfAfMdPTc8ksydgqSaWE';
const contractId = '8cvMFwa2YbEsNNoc1PXfTacy2PVq2SzVnkZLeQSzjfi6';
return client.platform.contracts.get(contractId);
};

retrieveContract()
.then((d) => console.dir(d.toJSON(), { depth: 5 }))
.catch((e) => console.error('Something went wrong:\n', e))
.finally(() => client.disconnect());
```
```

## Updating the client app list

> 📘
>
> 📘
>
> In many cases it may be desirable to work with a newly retrieved data contract using the `<contract name>.<contract document>` syntax (e.g. `dpns.domain`). Data contracts that were created after the client was initialized or not included in the initial client options can be added via `client.getApps().set(...)`.

```javascript
Expand All @@ -46,38 +46,41 @@ client.platform.contracts.get(myContractId)
contract: myContract,
});
});
```
```

# Example Data Contract

The following example response shows a retrieved contract:

```json
{
"protocolVersion":1,
"$id":"G1FVmxxrnbT6CiQU7w2xgY9oMMqkkZb7vS6fkeRrSTXG",
"$schema":"https://schema.dash.org/dpp-0-4-0/meta/data-contract",
"version":2,
"ownerId":"8uFQj2ptknrcwykhQbTzQatoQUyxn4VJQn1J25fxeDvk",
"documents":{
"note":{
"type":"object",
"properties":{
"author":{
"type":"string"
},
"message":{
"type":"string"
}
},
"additionalProperties":false
"$format_version": "0",
"id": "8cvMFwa2YbEsNNoc1PXfTacy2PVq2SzVnkZLeQSzjfi6",
"config": {
"$format_version": "0",
"canBeDeleted": false,
"readonly": false,
"keepsHistory": false,
"documentsKeepHistoryContractDefault": false,
"documentsMutableContractDefault": true,
"requiresIdentityEncryptionBoundedKey": null,
"requiresIdentityDecryptionBoundedKey": null
},
"version": 1,
"ownerId": "AsdMKouqE5NB7CeQFi4wr5oj8vFUYTtdSvxFtAvtCbhh",
"schemaDefs": null,
"documentSchemas": {
"note": {
"type": "object",
"properties": { "message": { "type": "string" } },
"additionalProperties": false
}
}
}
```
```

> 📘
>
> 📘
>
> Please refer to the [data contract reference page](../../reference/data-contracts.md) for more comprehensive details related to contracts and documents.

# What's Happening
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const clientOpts = {
network: 'testnet',
apps: {
tutorialContract: {
contractId: '3iaEhdyAVbmSjd59CT6SCrqPjfAfMdPTc8ksydgqSaWE',
contractId: '8cvMFwa2YbEsNNoc1PXfTacy2PVq2SzVnkZLeQSzjfi6',
},
},
};
Expand Down
7 changes: 3 additions & 4 deletions docs/tutorials/contracts-and-documents/submit-documents.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const clientOpts = {
},
apps: {
tutorialContract: {
contractId: '3iaEhdyAVbmSjd59CT6SCrqPjfAfMdPTc8ksydgqSaWE',
contractId: '8cvMFwa2YbEsNNoc1PXfTacy2PVq2SzVnkZLeQSzjfi6',
},
},
};
Expand All @@ -51,7 +51,8 @@ const submitNoteDocument = async () => {
delete: [], // Document(s) to delete
};
// Sign and submit the document(s)
return platform.documents.broadcast(documentBatch, identity);
await platform.documents.broadcast(documentBatch, identity);
return noteDocument;
};

submitNoteDocument()
Expand All @@ -60,8 +61,6 @@ submitNoteDocument()
.finally(() => client.disconnect());
```



> 👍 Initializing the Client with a contract identity
>
> The example above shows how access to contract documents via `<contract name>.<contract document>` syntax (e.g. `tutorialContract.note`) can be enabled by passing a contract identity to the constructor. Please refer to the [Dash SDK documentation](https://github.com/dashevo/platform/blob/master/packages/js-dash-sdk/docs/getting-started/multiple-apps.md) for details.
Expand Down
25 changes: 7 additions & 18 deletions docs/tutorials/contracts-and-documents/update-a-data-contract.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,26 +38,17 @@ const updateContract = async () => {
const identity = await platform.identities.get('an identity ID goes here');

const existingDataContract = await platform.contracts.get('a contract ID goes here');
const documents = existingDataContract.getDocuments();
const documentSchema = existingDataContract.getDocumentSchema('note');

documents.note.properties.author = {
documentSchema.properties.author = {
type: 'string',
};

existingDataContract.setDocuments(documents);
existingDataContract.setDocumentSchema('note', documentSchema);

// Make sure contract passes validation checks
const validationResult = await platform.dpp.dataContract.validate(
existingDataContract,
);

if (validationResult.isValid()) {
console.log('Validation passed, broadcasting contract..');
// Sign and submit the data contract
return platform.contracts.update(existingDataContract, identity);
}
console.error(validationResult); // An array of detailed validation errors
throw validationResult.errors[0];
// Sign and submit the data contract
await platform.contracts.update(existingDataContract, identity);
return existingDataContract;
};

updateContract()
Expand All @@ -66,15 +57,13 @@ updateContract()
.finally(() => client.disconnect());
```



> 📘
>
> Please refer to the [data contract reference page](../../reference/data-contracts.md) for more comprehensive details related to contracts and documents.

# What's Happening

After we initialize the Client, we retrieve an existing contract owned by our identity. We then get the contract's documents and modify a document (adding an `author` property to the `note` document in the example).The `setDocuments` method takes one argument: the object containing the updated document types.
After we initialize the Client, we retrieve an existing contract owned by our identity. We then get the contract's document schema and modify a document (adding an `author` property to the `note` document in the example). The `setDocumentSchema` method takes two arguments: the name of the document schema to be updated and the object containing the updated document types.

Once the data contract has been updated, we still need to submit it to DAPI. The `platform.contracts.update` method takes a data contract and an identity parameter. Internally, it creates a State Transition containing the updated contract, signs the state transition, and submits the signed state transition to DAPI. A response will only be returned if an error is encountered.

Expand Down
Loading