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

feat: integrate wallet contract #2345

Merged
merged 45 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
24177fa
feat: hardcoded identity transfers in strategy tests
pauldelucia Nov 4, 2024
dacc6db
fix(drive): uncommitted state if db transaction fails (#2305)
shumkov Nov 4, 2024
306b86c
fix(drive): apply batch is not using transaction in `remove_all_votes…
QuantumExplorer Nov 4, 2024
99fe5fa
add comment
pauldelucia Nov 4, 2024
cee3098
Merge remote-tracking branch 'origin/v1.6-dev' into feat/hardcoded-id…
pauldelucia Nov 4, 2024
0d3e091
comment
pauldelucia Nov 5, 2024
e421514
use into_iter instead of iter
pauldelucia Nov 5, 2024
3d941ec
use current identities instead of hardcoded start identities
pauldelucia Nov 5, 2024
4bc0a65
let transfer keys be any security level or key type
pauldelucia Nov 5, 2024
dc48827
fix
pauldelucia Nov 5, 2024
cafda11
feat: hardcoded identity transfers in strategy tests (#2312)
pauldelucia Nov 5, 2024
b86f4e0
Merge branch 'v1.6-dev' of github.com:dashpay/platform into v1.6-dev
shumkov Nov 6, 2024
ae97f47
ci: run devcontainers workflow only on push to master (#2295)
shumkov Nov 6, 2024
48cca1a
ci: do not run test on push (#2308)
shumkov Nov 6, 2024
7315c91
feat: add wallet contract
HashEngineering Oct 31, 2024
2e16647
fix: remove unnecessary file
HashEngineering Nov 6, 2024
08cb2e5
fix: set v1.5.1
HashEngineering Nov 7, 2024
e9b8601
fix: rename dpns_contract to wallet_contract
HashEngineering Nov 7, 2024
c265209
tests: fix validation
HashEngineering Nov 7, 2024
a5fefa6
Merge branch 'v1.6-dev' of https://github.com/dashpay/platform into f…
HashEngineering Nov 21, 2024
6440612
fix: remove identityVerify document and tests
HashEngineering Nov 21, 2024
be4fe7f
feat: add wallet contract (#2314)
shumkov Nov 22, 2024
91a8303
chore: remove junk
shumkov Nov 22, 2024
19fbb51
chore: create wallet contract
shumkov Nov 22, 2024
eda1351
build: add wallet-contract
shumkov Nov 22, 2024
97d9400
build: invalid platform path
shumkov Nov 22, 2024
ab81b55
docs: fix doc block
shumkov Nov 22, 2024
39fe144
chore: re-export wallet contract
shumkov Nov 22, 2024
baea397
revert: unnecessary and broken refactoring
shumkov Nov 22, 2024
0f2ea36
docs: remove wrong comment
shumkov Nov 22, 2024
16534b0
refactor: remove unused param
shumkov Nov 22, 2024
d4ed535
docs: remove usage section
shumkov Nov 22, 2024
8f9db89
fix: duplicated ID
shumkov Nov 22, 2024
c036d95
docs: update description
shumkov Nov 22, 2024
c18f02d
docs: remove usage
shumkov Nov 22, 2024
bf1769f
feat: add mutability flags
shumkov Nov 22, 2024
03733de
refactor: rename contract
shumkov Nov 22, 2024
4dd3feb
chore: update yarn
shumkov Nov 22, 2024
837cbd7
ci: add wallet utils contract
shumkov Nov 22, 2024
1182e54
build: fix wallet utils contract path
shumkov Nov 25, 2024
7ec638b
chore: fix linter warning and tests
shumkov Nov 25, 2024
233c582
test: add more tests
shumkov Nov 25, 2024
4565ca3
ci: fix rs package name
shumkov Nov 25, 2024
953c7b2
feat: make tx_metadata mutable
shumkov Nov 25, 2024
33850fe
chore: change index name
shumkov Nov 25, 2024
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
1,114 changes: 668 additions & 446 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ members = [
"packages/simple-signer",
"packages/rs-json-schema-compatibility-validator",
"packages/check-features",
"packages/wallet-contract"
]
[workspace.package]

Expand All @@ -37,3 +38,4 @@ rust-version = "1.80"
tower-service = { git = "https://github.com/QuantumExplorer/tower", branch = "fix/indexMap2OnV0413" }
tower-layer = { git = "https://github.com/QuantumExplorer/tower", branch = "fix/indexMap2OnV0413" }
tower = { git = "https://github.com/QuantumExplorer/tower", branch = "fix/indexMap2OnV0413" }

6 changes: 6 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@ COPY --parents \
packages/masternode-reward-shares-contract \
packages/feature-flags-contract \
packages/dpns-contract \
packages/wallet-contract \
packages/data-contracts \
packages/strategy-tests \
packages/simple-signer \
Expand Down Expand Up @@ -374,6 +375,7 @@ COPY --parents \
packages/rs-platform-value-convertible \
packages/rs-drive-abci \
packages/dashpay-contract \
packages/wallet-contract \
packages/withdrawals-contract \
packages/masternode-reward-shares-contract \
packages/feature-flags-contract \
Expand Down Expand Up @@ -462,6 +464,7 @@ COPY --parents \
packages/wasm-dpp \
packages/dashpay-contract \
packages/withdrawals-contract \
packages/wallet-contract \
packages/masternode-reward-shares-contract \
packages/feature-flags-contract \
packages/dpns-contract \
Expand Down Expand Up @@ -569,6 +572,7 @@ LABEL description="Dashmate Helper Node.JS"

WORKDIR /platform

# TODO: Do one COPY with --parents
COPY --from=build-dashmate-helper /platform/.yarn /platform/.yarn
COPY --from=build-dashmate-helper /platform/package.json /platform/yarn.lock /platform/.yarnrc.yml /platform/.pnp* /platform/

Expand All @@ -580,6 +584,7 @@ COPY --from=build-dashmate-helper /platform/packages/js-dapi-client packages/js-
COPY --from=build-dashmate-helper /platform/packages/js-grpc-common packages/js-grpc-common
COPY --from=build-dashmate-helper /platform/packages/dapi-grpc packages/dapi-grpc
COPY --from=build-dashmate-helper /platform/packages/dash-spv packages/dash-spv
COPY --from=build-dashmate-helper /platform/packages/wallet-contract packages/wallet-contract
COPY --from=build-dashmate-helper /platform/packages/withdrawals-contract packages/withdrawals-contract
COPY --from=build-dashmate-helper /platform/packages/masternode-reward-shares-contract packages/masternode-reward-shares-contract
COPY --from=build-dashmate-helper /platform/packages/feature-flags-contract packages/feature-flags-contract
Expand Down Expand Up @@ -646,6 +651,7 @@ RUN apk add --no-cache zeromq-dev

WORKDIR /platform/packages/dapi

# TODO: Do one COPY with --parents
COPY --from=build-dapi /platform/.yarn /platform/.yarn
COPY --from=build-dapi /platform/package.json /platform/yarn.lock /platform/.yarnrc.yml /platform/.pnp* /platform/
# List of required dependencies. Based on:
Expand Down
1 change: 1 addition & 0 deletions packages/data-contracts/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ dpns-contract = { path = "../dpns-contract" }
dashpay-contract = { path = "../dashpay-contract" }
feature-flags-contract = { path = "../feature-flags-contract" }
platform-value = { path = "../rs-platform-value" }
wallet-contract = { path = "../wallet-contract" }
17 changes: 17 additions & 0 deletions packages/data-contracts/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,20 @@ impl From<feature_flags_contract::Error> for Error {
}
}
}

impl From<wallet_contract::Error> for Error {
fn from(e: wallet_contract::Error) -> Self {
match e {
wallet_contract::Error::UnknownVersionMismatch {
method,
known_versions,
received,
} => Error::UnknownVersionMismatch {
method,
known_versions,
received,
},
wallet_contract::Error::InvalidSchemaJson(e) => Error::InvalidSchemaJson(e),
}
}
}
10 changes: 10 additions & 0 deletions packages/data-contracts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pub use feature_flags_contract;
pub use masternode_reward_shares_contract;
use platform_value::Identifier;
use platform_version::version::PlatformVersion;
pub use wallet_contract;
pub use withdrawals_contract;

#[repr(u8)]
Expand All @@ -19,6 +20,7 @@ pub enum SystemDataContract {
FeatureFlags = 2,
DPNS = 3,
Dashpay = 4,
Wallet = 5,
shumkov marked this conversation as resolved.
Show resolved Hide resolved
}

pub struct DataContractSource {
Expand All @@ -37,6 +39,7 @@ impl SystemDataContract {
SystemDataContract::FeatureFlags => feature_flags_contract::ID_BYTES,
SystemDataContract::DPNS => dpns_contract::ID_BYTES,
SystemDataContract::Dashpay => dashpay_contract::ID_BYTES,
SystemDataContract::Wallet => wallet_contract::ID_BYTES,
shumkov marked this conversation as resolved.
Show resolved Hide resolved
};
Identifier::new(bytes)
}
Expand Down Expand Up @@ -82,6 +85,13 @@ impl SystemDataContract {
definitions: dashpay_contract::load_definitions(platform_version)?,
document_schemas: dashpay_contract::load_documents_schemas(platform_version)?,
},
SystemDataContract::Wallet => DataContractSource {
id_bytes: wallet_contract::ID_BYTES,
owner_id_bytes: wallet_contract::OWNER_ID_BYTES,
version: platform_version.system_data_contracts.wallet as u32,
definitions: wallet_contract::load_definitions(platform_version)?,
document_schemas: wallet_contract::load_documents_schemas(platform_version)?,
},
};

Ok(data)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ impl<C> Platform<C> {
previous_protocol_version,
platform_version,
),
None => return Ok(()),
None => Ok(()),
Some(version) => Err(Error::Execution(ExecutionError::UnknownVersionMismatch {
method: "perform_events_on_first_block_of_protocol_change".to_string(),
known_versions: vec![0],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ use crate::platform_types::platform_state::v0::PlatformStateV0Methods;
use crate::platform_types::platform_state::PlatformState;
use dpp::block::block_info::BlockInfo;
use dpp::dashcore::hashes::Hash;
use dpp::data_contracts::SystemDataContract;
use dpp::system_data_contracts::load_system_data_contract;
use dpp::version::PlatformVersion;
use dpp::version::ProtocolVersion;
use drive::drive::identity::key::fetch::{
Expand Down Expand Up @@ -52,6 +54,34 @@ impl<C> Platform<C> {
)?;
}

if previous_protocol_version < 6 && platform_version.protocol_version >= 6 {
self.transition_to_version_6(block_info, transaction, platform_version)?;
}

Ok(())
}

/// Initializes the wallet contract that supports mobile wallets with additional
/// functionality
///
/// This function is called during the transition from protocol version 5 to protocol version 6
/// and higher to set up the wallet contract in the platform.
fn transition_to_version_6(
&self,
block_info: &BlockInfo,
transaction: &Transaction,
platform_version: &PlatformVersion,
) -> Result<(), Error> {
let contract = load_system_data_contract(SystemDataContract::Wallet, platform_version)?;

self.drive.insert_contract(
&contract,
*block_info,
true,
Some(transaction),
platform_version,
)?;

Ok(())
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ pub struct SystemDataContractVersions {
pub dashpay: FeatureVersion,
pub masternode_reward_shares: FeatureVersion,
pub feature_flags: FeatureVersion,
pub wallet: FeatureVersion,
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ pub const SYSTEM_DATA_CONTRACT_VERSIONS_V1: SystemDataContractVersions =
dashpay: 1,
masternode_reward_shares: 1,
feature_flags: 1,
wallet: 1,
};
18 changes: 18 additions & 0 deletions packages/wallet-contract/.eslintrc
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
}
}
2 changes: 2 additions & 0 deletions packages/wallet-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/wallet-contract/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[package]
name = "wallet-contract"
description = "Wallet data contract schema and tools"
version = "1.5.0"
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" }
20 changes: 20 additions & 0 deletions packages/wallet-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.
27 changes: 27 additions & 0 deletions packages/wallet-contract/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Wallet 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 Dash Wallet apps

shumkov marked this conversation as resolved.
Show resolved Hide resolved
## Table of Contents

- [Install](#install)
- [Usage](#usage)
- [Contributing](#contributing)
- [License](#license)
shumkov marked this conversation as resolved.
Show resolved Hide resolved

shumkov marked this conversation as resolved.
Show resolved Hide resolved
## Install

```sh
npm install @dashevo/wallet-contract
```

## 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.
4 changes: 4 additions & 0 deletions packages/wallet-contract/lib/systemIds.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
ownerId: '11111111111111111111111111111111',
contractId: 'GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec'
shumkov marked this conversation as resolved.
Show resolved Hide resolved
};
29 changes: 29 additions & 0 deletions packages/wallet-contract/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"name": "@dashevo/wallet-contract",
"version": "1.5.0",
"description": "A contract and helper scripts for Wallet DApp",
"scripts": {
"lint": "eslint .",
"test": "yarn run test:unit",
"test:unit": "mocha 'test/unit/**/*.spec.js'"
},
"contributors": [
{
"name": "Eric Britten",
"email": "eric.britten@dash.org",
"url": "https://github.com/hashengineering"
}
],
"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"
}
}
55 changes: 55 additions & 0 deletions packages/wallet-contract/schema/v1/wallet-contract-documents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
{
"txMetadata": {
shumkov marked this conversation as resolved.
Show resolved Hide resolved
"type": "object",
"indices": [
{
"name": "ownerId",
"properties": [
{
"$ownerId": "asc"
}
]
},
{
"name": "ownerIdAndCreatedAt",
"properties": [
{
"$ownerId": "asc"
},
{
"$createdAt": "asc"
}
]
}
],
"properties": {
"keyIndex": {
"type": "integer",
"minimum": 0,
"description": "The index of the owners identity public key used to derive the encryption key.",
shumkov marked this conversation as resolved.
Show resolved Hide resolved
"position": 0
},
"encryptionKeyIndex": {
"type": "integer",
"minimum": 0,
"description": "The secondary index used to derive the encryption key that is used to encrypt and decrypt encryptedData.",
"position": 1
},
"encryptedMetadata": {
"type": "array",
"byteArray": true,
"minItems": 32,
"maxItems": 4096,
QuantumExplorer marked this conversation as resolved.
Show resolved Hide resolved
"description": "encrypted metadata using AES-CBC-256",
"position": 2
}
},
"required": [
"keyIndex",
"encryptionKeyIndex",
"encryptedMetadata",
"$createdAt"
QuantumExplorer marked this conversation as resolved.
Show resolved Hide resolved
],
"additionalProperties": false
}
}
17 changes: 17 additions & 0 deletions packages/wallet-contract/src/error.rs
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),
}
Loading
Loading