Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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
11 changes: 11 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ members = [
"packages/check-features",
"packages/wallet-utils-contract",
"packages/token-history-contract",
"packages/document-history-contract",
"packages/keyword-search-contract",
"packages/rs-sdk-ffi",
"packages/wasm-drive-verify",
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"test:dashpay-contract": "ultra -r --filter \"packages/@(dashpay-contract|js-dash-sdk|js-drive|js-dapi-client|wasm-dpp|wallet-lib|dapi|platform-test-suite)\" test",
"test:dpns-contract": "ultra -r --filter \"packages/@(dpns-contract|js-dash-sdk|js-drive|js-dapi-client|wasm-dpp|wallet-lib|dapi|platform-test-suite)\" test",
"test:token-history-contract": "ultra -r --filter \"packages/@(token-history-contract|js-dash-sdk|js-drive|js-dapi-client|wasm-dpp|wallet-lib|dapi|platform-test-suite)\" test",
"test:document-history-contract": "ultra -r --filter \"packages/@(document-history-contract|js-dash-sdk|js-drive|js-dapi-client|wasm-dpp|wallet-lib|dapi|platform-test-suite)\" test",
"test:dapi-client": "ultra -r --filter \"packages/@(js-dapi-client|wallet-lib|js-dash-sdk|platform-test-suite)\" test",
"test:sdk": "ultra -r --filter \"packages/@(js-dash-sdk|platform-test-suite)\" test",
"test:spv": "ultra -r --filter \"packages/@(dash-spv|js-dapi-client)\" test",
Expand Down Expand Up @@ -74,6 +75,7 @@
"packages/wasm-dpp2",
"packages/withdrawals-contract",
"packages/token-history-contract",
"packages/document-history-contract",
"packages/keyword-search-contract",
"packages/wasm-drive-verify",
"packages/wasm-sdk",
Expand Down
3 changes: 3 additions & 0 deletions packages/data-contracts/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ all-contracts = [
"wallet-utils",
"token-history",
"keyword-search",
"document-history",
]

# Individual contract features
Expand All @@ -27,6 +28,7 @@ dashpay = ["dep:dashpay-contract"]
wallet-utils = ["dep:wallet-utils-contract"]
token-history = ["dep:token-history-contract"]
keyword-search = ["dep:keyword-search-contract"]
document-history = ["dep:document-history-contract"]

[dependencies]
thiserror = "2.0.12"
Expand All @@ -40,3 +42,4 @@ platform-value = { path = "../rs-platform-value" }
wallet-utils-contract = { path = "../wallet-utils-contract", optional = true }
token-history-contract = { path = "../token-history-contract", optional = true }
keyword-search-contract = { path = "../keyword-search-contract", optional = true }
document-history-contract = { path = "../document-history-contract", optional = true }
18 changes: 18 additions & 0 deletions packages/data-contracts/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,24 @@ impl From<token_history_contract::Error> for Error {
}
}

#[cfg(feature = "document-history")]
impl From<document_history_contract::Error> for Error {
fn from(e: document_history_contract::Error) -> Self {
match e {
document_history_contract::Error::UnknownVersionMismatch {
method,
known_versions,
received,
} => Error::UnknownVersionMismatch {
method,
known_versions,
received,
},
document_history_contract::Error::InvalidSchemaJson(e) => Error::InvalidSchemaJson(e),
}
}
}

#[cfg(feature = "keyword-search")]
impl From<keyword_search_contract::Error> for Error {
fn from(e: keyword_search_contract::Error) -> Self {
Expand Down
27 changes: 27 additions & 0 deletions packages/data-contracts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ pub use masternode_reward_shares_contract;
use platform_value::Identifier;
use platform_version::version::PlatformVersion;

#[cfg(feature = "document-history")]
pub use document_history_contract;

#[cfg(feature = "token-history")]
pub use token_history_contract;

Expand All @@ -42,6 +45,7 @@ pub enum SystemDataContract {
WalletUtils = 5,
TokenHistory = 6,
KeywordSearch = 7,
DocumentHistory = 8,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Suggestion: Register DocumentHistory with the C/Swift trusted context provider

The new SystemDataContract::DocumentHistory variant is not propagated through the rs-sdk and rs-sdk-trusted-context-provider feature lists, and TrustedHttpContextProvider::get_data_contract has no branch that loads it. rs-sdk-ffi enables the existing system-contract features and dash_sdk_create_trusted constructs this provider without a fallback, so dash_sdk_document_fetch_by_contract_id returns "Contract ... not found in trusted context" for the document-history ID. Add a document-history-contract feature through rs-sdk, rs-sdk-trusted-context-provider, and rs-sdk-ffi, include it in all-system-contracts, and load SystemDataContract::DocumentHistory alongside TokenHistory and KeywordSearch.

source: ['codex']

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 31b4f83 — added a document-history-contract feature through rs-sdk, rs-sdk-trusted-context-provider (included in its all-system-contracts umbrella and enabled by rs-sdk-ffi's provider dependency), and a DocumentHistory branch in TrustedHttpContextProvider::get_data_contract alongside TokenHistory and KeywordSearch.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved in this update — Register DocumentHistory with the C/Swift trusted context provider no longer present.

Auto-resolved by the review system based on the latest commit diff. If you believe this was closed in error, reopen the thread.

}

pub struct DataContractSource {
Expand Down Expand Up @@ -118,6 +122,14 @@ impl SystemDataContract {
92, 20, 14, 101, 92, 2, 101, 187, 194, 168, 8, 113, 109, 225, 132, 121, 133, 19,
89, 24, 173, 81, 205, 253, 11, 118, 102, 75, 169, 91, 163, 124,
],

#[cfg(feature = "document-history")]
SystemDataContract::DocumentHistory => document_history_contract::ID_BYTES,
#[cfg(not(feature = "document-history"))]
SystemDataContract::DocumentHistory => [
88, 18, 140, 208, 179, 231, 242, 57, 225, 203, 4, 210, 245, 95, 136, 92, 160, 167,
112, 118, 173, 238, 83, 62, 234, 230, 222, 16, 231, 30, 99, 98,
],
};
Identifier::new(bytes)
}
Expand Down Expand Up @@ -212,6 +224,21 @@ impl SystemDataContract {
}),
#[cfg(not(feature = "keyword-search"))]
SystemDataContract::KeywordSearch => Err(Error::ContractNotIncluded("keyword-search")),

#[cfg(feature = "document-history")]
SystemDataContract::DocumentHistory => Ok(DataContractSource {
id_bytes: document_history_contract::ID_BYTES,
owner_id_bytes: document_history_contract::OWNER_ID_BYTES,
version: platform_version.system_data_contracts.document_history as u32,
definitions: document_history_contract::load_definitions(platform_version)?,
document_schemas: document_history_contract::load_documents_schemas(
platform_version,
)?,
}),
#[cfg(not(feature = "document-history"))]
SystemDataContract::DocumentHistory => {
Err(Error::ContractNotIncluded("document-history"))
}
}
}
}
2 changes: 2 additions & 0 deletions packages/document-history-contract/.mocharc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
require: test/bootstrap.js
recursive: true
13 changes: 13 additions & 0 deletions packages/document-history-contract/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[package]
name = "document-history-contract"
description = "Document history data contract schema and tools"
version.workspace = true
edition = "2021"
rust-version.workspace = true
license = "MIT"

[dependencies]
thiserror = "2.0.12"
platform-version = { path = "../rs-platform-version" }
serde_json = { version = "1.0" }
platform-value = { path = "../rs-platform-value" }
20 changes: 20 additions & 0 deletions packages/document-history-contract/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
The MIT License (MIT)

Copyright (c) 2019 Dash Core Group, Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
39 changes: 39 additions & 0 deletions packages/document-history-contract/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Document History Contract

[![Build Status](https://github.com/dashpay/platform/actions/workflows/release.yml/badge.svg)](https://github.com/dashpay/platform/actions/workflows/release.yml)

System data contract recording document transfer, purchase, and price-change
events for document types that opt in via the `keepsTransferHistory`,
`keepsPurchaseHistory`, and `keepsPricingHistory` configuration flags.

History documents are written by the protocol itself during document
transfer, purchase, and price-update state transitions
(`creationRestrictionMode: 2` — they can never be created directly), and are
immutable and permanent once written.

The document types carry provable aggregation trees:

- `purchase` is doctype-averageable on `price` (O(1) provable all-time sale
count, total volume, and average sale price), and its `byContract` and
`byDocument` indices are range-averageable over `$createdAt` (provable
per-contract and per-document sale count / volume / average between dates).
- `priceUpdate` is doctype-countable, and its `byContract` and `byDocument`
indices are range-averageable over `$createdAt` (provable average asking
price between dates). These are listing-event-weighted averages, not
time-weighted prices.
- `transfer` is doctype-countable, and its `byContract` index is
range-countable over `$createdAt` (provable transfer counts per contract
and time window).

## Table of Contents

- [Contributing](#contributing)
- [License](#license)

## Contributing

Feel free to dive in! [Open an issue](https://github.com/dashpay/platform/issues/new/choose) or submit PRs.

## License

[MIT](LICENSE) &copy; Dash Core Group, Inc.
10 changes: 10 additions & 0 deletions packages/document-history-contract/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import baseConfig from '../../eslint/base.mjs';
import mochaTestConfig from '../../eslint/mocha-tests.mjs';

export default [
...baseConfig,
mochaTestConfig,
{
ignores: ['dist/**', 'node_modules/**'],
},
];
4 changes: 4 additions & 0 deletions packages/document-history-contract/lib/systemIds.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
ownerId: '11111111111111111111111111111111',
contractId: '6voHRaoiPcfmMhbqCA9dixH98xcgPQ9UEcuaXjpVu3LD',
};
27 changes: 27 additions & 0 deletions packages/document-history-contract/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "@dashevo/document-history-contract",
"version": "4.0.0",
"description": "The document history contract",
"scripts": {
"lint": "eslint .",
"test": "yarn run test:unit",
"test:unit": "mocha 'test/unit/**/*.spec.js'"
},
"contributors": [
{
"name": "Samuel Westrich",
"email": "sam@dash.org",
"url": "https://github.com/quantumexplorer"
}
],
"license": "MIT",
"devDependencies": {
"@dashevo/wasm-dpp": "workspace:*",
"chai": "^4.3.10",
"dirty-chai": "^2.0.1",
"eslint": "^9.18.0",
"mocha": "^11.1.0",
"sinon": "^18.0.1",
"sinon-chai": "^3.7.0"
}
}
Loading
Loading