-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
29dadbf
commit bfbce84
Showing
18 changed files
with
495 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"extends": "airbnb-base", | ||
"rules": { | ||
"no-plusplus": 0, | ||
"eol-last": [ | ||
"error", | ||
"always" | ||
], | ||
"class-methods-use-this": "off", | ||
"curly": [ | ||
"error", | ||
"all" | ||
] | ||
}, | ||
"globals": { | ||
"BigInt": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
require: test/bootstrap.js | ||
recursive: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
[package] | ||
name = "token-history-contract" | ||
description = "Token history data contract schema and tools" | ||
version = "1.6.2" | ||
edition = "2021" | ||
rust-version.workspace = true | ||
license = "MIT" | ||
|
||
[dependencies] | ||
thiserror = "1.0.64" | ||
platform-version = { path = "../rs-platform-version" } | ||
serde_json = { version = "1.0" } | ||
platform-value = { path = "../rs-platform-value" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Search Contract | ||
|
||
[![Build Status](https://github.com/dashpay/platform/actions/workflows/release.yml/badge.svg)](https://github.com/dashpay/platform/actions/workflows/release.yml) | ||
[![NPM version](https://img.shields.io/npm/v/@dashevo/wallet-contract.svg?style=flat-square)](https://npmjs.org/package/@dashevo/wallet-contract) | ||
|
||
JSON Contracts for Searching Data Contracts | ||
|
||
## Table of Contents | ||
|
||
- [Install](#install) | ||
- [Contributing](#contributing) | ||
- [License](#license) | ||
|
||
## Install | ||
|
||
```sh | ||
npm install @dashevo/search-contract | ||
``` | ||
|
||
## Contributing | ||
|
||
Feel free to dive in! [Open an issue](https://github.com/dashpay/platform/issues/new/choose) or submit PRs. | ||
|
||
## License | ||
|
||
[MIT](LICENSE) © Dash Core Group, Inc. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module.exports = { | ||
ownerId: '11111111111111111111111111111111', | ||
contractId: '8v8CoKCDdBcQu1Y7GDNJjR7a5vkMmgpXycJURkaUhfU9', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{ | ||
"name": "@dashevo/search-contract", | ||
"version": "1.6.2", | ||
"description": "A contract that allows searching for contracts", | ||
"scripts": { | ||
"lint": "eslint .", | ||
"test": "yarn run test:unit", | ||
"test:unit": "mocha 'test/unit/**/*.spec.js'" | ||
}, | ||
"contributors": [ | ||
{ | ||
"name": "Samuel Westrich", | ||
"email": "[email protected]", | ||
"url": "https://github.com/quantumexplorer" | ||
} | ||
], | ||
"license": "MIT", | ||
"devDependencies": { | ||
"@dashevo/wasm-dpp": "workspace:*", | ||
"chai": "^4.3.10", | ||
"dirty-chai": "^2.0.1", | ||
"eslint": "^8.53.0", | ||
"eslint-config-airbnb-base": "^15.0.0", | ||
"eslint-plugin-import": "^2.29.0", | ||
"mocha": "^10.2.0", | ||
"sinon": "^17.0.1", | ||
"sinon-chai": "^3.7.0" | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
packages/search-contract/schema/v1/search-contract-documents.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
{ | ||
"contract": { | ||
"type": "object", | ||
"documentsMutable": false, | ||
"canBeDeleted": false, | ||
"referenceType": "contract", | ||
"creationRestrictionMode": 2, | ||
"indices": [ | ||
{ | ||
"name": "byKeyword", | ||
"properties": [ | ||
{ | ||
"keyword": "asc" | ||
} | ||
] | ||
} | ||
], | ||
"properties": { | ||
"keyword": { | ||
"type": "string", | ||
"minLength": 3, | ||
"maxLength": 50, | ||
"position": 0 | ||
} | ||
}, | ||
"required": [ | ||
"$contractId", | ||
"keyword" | ||
], | ||
"additionalProperties": false | ||
}, | ||
"token": { | ||
"type": "object", | ||
"documentsMutable": false, | ||
"canBeDeleted": false, | ||
"referenceType": "token", | ||
"creationRestrictionMode": 2, | ||
"indices": [ | ||
{ | ||
"name": "byKeyword", | ||
"properties": [ | ||
{ | ||
"keyword": "asc" | ||
} | ||
] | ||
} | ||
], | ||
"properties": { | ||
"keyword": { | ||
"type": "string", | ||
"minLength": 3, | ||
"maxLength": 50, | ||
"position": 0 | ||
} | ||
}, | ||
"required": [ | ||
"$tokenId", | ||
"keyword" | ||
], | ||
"additionalProperties": false | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
use platform_version::version::FeatureVersion; | ||
|
||
#[derive(thiserror::Error, Debug)] | ||
pub enum Error { | ||
/// Platform expected some specific versions | ||
#[error("platform unknown version on {method}, received: {received}")] | ||
UnknownVersionMismatch { | ||
/// method | ||
method: String, | ||
/// the allowed versions for this method | ||
known_versions: Vec<FeatureVersion>, | ||
/// requested core height | ||
received: FeatureVersion, | ||
}, | ||
#[error("schema deserialize error: {0}")] | ||
InvalidSchemaJson(#[from] serde_json::Error), | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
mod error; | ||
pub mod v1; | ||
|
||
pub use crate::error::Error; | ||
use platform_value::{Identifier, IdentifierBytes32}; | ||
use platform_version::version::PlatformVersion; | ||
use serde_json::Value; | ||
|
||
pub const ID_BYTES: [u8; 32] = [ | ||
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, | ||
]; | ||
|
||
pub const OWNER_ID_BYTES: [u8; 32] = [0; 32]; | ||
|
||
pub const ID: Identifier = Identifier(IdentifierBytes32(ID_BYTES)); | ||
pub const OWNER_ID: Identifier = Identifier(IdentifierBytes32(OWNER_ID_BYTES)); | ||
pub fn load_definitions(platform_version: &PlatformVersion) -> Result<Option<Value>, Error> { | ||
match platform_version.system_data_contracts.withdrawals { | ||
1 => Ok(None), | ||
version => Err(Error::UnknownVersionMismatch { | ||
method: "search_contract::load_definitions".to_string(), | ||
known_versions: vec![1], | ||
received: version, | ||
}), | ||
} | ||
} | ||
pub fn load_documents_schemas(platform_version: &PlatformVersion) -> Result<Value, Error> { | ||
match platform_version.system_data_contracts.withdrawals { | ||
1 => v1::load_documents_schemas(), | ||
version => Err(Error::UnknownVersionMismatch { | ||
method: "search_contract::load_documents_schemas".to_string(), | ||
known_versions: vec![1], | ||
received: version, | ||
}), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
use crate::Error; | ||
use serde_json::Value; | ||
|
||
pub mod document_types { | ||
pub mod contract { | ||
pub const NAME: &str = "contract"; | ||
|
||
pub mod properties { | ||
pub const KEY_INDEX: &str = "byKeyword"; | ||
} | ||
} | ||
|
||
pub mod token { | ||
pub const NAME: &str = "token"; | ||
|
||
pub mod properties { | ||
pub const KEY_INDEX: &str = "byKeyword"; | ||
} | ||
} | ||
} | ||
|
||
pub fn load_documents_schemas() -> Result<Value, Error> { | ||
serde_json::from_str(include_str!( | ||
"../../schema/v1/search-contract-documents.json" | ||
)) | ||
.map_err(Error::InvalidSchemaJson) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"env": { | ||
"node": true, | ||
"mocha": true | ||
}, | ||
"rules": { | ||
"import/no-extraneous-dependencies": "off" | ||
}, | ||
"globals": { | ||
"expect": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
const sinon = require('sinon'); | ||
const sinonChai = require('sinon-chai'); | ||
|
||
const { expect, use } = require('chai'); | ||
const dirtyChai = require('dirty-chai'); | ||
|
||
const { | ||
default: loadWasmDpp, | ||
} = require('@dashevo/wasm-dpp'); | ||
|
||
use(dirtyChai); | ||
use(sinonChai); | ||
|
||
exports.mochaHooks = { | ||
beforeAll: loadWasmDpp, | ||
|
||
beforeEach() { | ||
if (!this.sinon) { | ||
this.sinon = sinon.createSandbox(); | ||
} else { | ||
this.sinon.restore(); | ||
} | ||
}, | ||
|
||
afterEach() { | ||
this.sinon.restore(); | ||
}, | ||
}; | ||
|
||
global.expect = expect; |
Oops, something went wrong.