Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
e09a6d2
feat(wasm-dpp): implement utility function to produce generic from Js…
markin-io Jan 6, 2023
ca928a9
chore(wasm-dpp): match terser-webpack-plugin versions
markin-io Jan 6, 2023
a615ff3
feat(wasm-dpp): implement ChainAssetLockProof binding with tests
markin-io Dec 2, 2022
6eeeab7
refactor(rs-dpp): return type for chain_asset_lock_proof#createIdenti…
markin-io Dec 2, 2022
113deb2
refactor(rs-dpp): fix formatting
markin-io Dec 2, 2022
e8ef49e
refactor(wasm-dpp): removed unnecessary chain asset lock fixture
markin-io Dec 2, 2022
9126682
feat(wasm-dpp): bootstrap instant_asset_lock_proof.rs binding
markin-io Dec 2, 2022
b601b6f
feat(wasm-dpp): instant_asset_lock_proof.rs bindings for getOutPoint …
markin-io Dec 5, 2022
643aea4
feat(wasm-dpp): instant_asset_lock_proof.rs finish bindings
markin-io Dec 5, 2022
4e0a997
feat(wasm-dpp): createAssetLockProofInstance binding
markin-io Dec 6, 2022
63db516
feat(wasm-dpp): add identity_create_transition constructor
markin-io Dec 8, 2022
566bf07
feat(wasm-dpp): IdentityCreateTransition set and get assetLockProof
markin-io Dec 8, 2022
b76b5ef
feat(wasm-dpp): IdentityCreateTransition setPublicKeys, getPublicKeys…
markin-io Dec 9, 2022
ef0816b
feat(wasm-dpp): IdentityCreateTransition toObject, toJSON
markin-io Dec 12, 2022
f7624d5
feat(wasm-dpp): IdentityCreateTransition getModifiedDataIds
markin-io Dec 12, 2022
ec73c28
test(wasm-dpp): lint tests
markin-io Dec 13, 2022
ff2d61f
fix(wasm-dpp): identity_create_transition unknown asset lock proof
markin-io Dec 20, 2022
50f959d
fix(wasm-dpp): missing protocol version
markin-io Dec 20, 2022
4dc5472
feat(wasm-dpp): implement validateIdentityCreateTransitionStateFactory
markin-io Dec 20, 2022
a7c6cc3
feat(wasm-dpp): remaining unit tests for IdentityCreateTransition.spe…
markin-io Dec 22, 2022
afbd271
refactor(wasm-dpp): to_object.rs of identity_create_transition.rs
markin-io Dec 26, 2022
082f8ae
refactor(wasm-dpp): to_json in identity_create_transition.rs
markin-io Dec 26, 2022
04bfd02
fix(rs-dpp): signature instead of identity
markin-io Dec 26, 2022
cdbc6a0
fix(rs-dpp): signature instead of identity
markin-io Dec 26, 2022
d29bec5
fix(wasm-dpp): return undefined signatures in case buffer len is zero
markin-io Dec 26, 2022
57b4697
fix(wasm-dpp): identity_create_transition accept asset lock proof ins…
markin-io Dec 26, 2022
54d525c
fix(wasm-dpp): identity_create_transition accept public key instances…
markin-io Dec 26, 2022
9b593b0
fix(wasm-dpp): broken import
markin-io Dec 26, 2022
a354806
test(rs-dpp): fix identity related tests that uses state repository
markin-io Dec 26, 2022
bff8d4b
test(rs-dpp): finish test for validateIdentityCreateTransitionStateFa…
markin-io Dec 26, 2022
3c009f2
fix(rs-dpp): signature population for identity_public_key binding
markin-io Dec 27, 2022
0727087
wip(wasm-dpp): generic validation result
markin-io Dec 27, 2022
75441fa
feat: validation result map fn
fominok Dec 27, 2022
729a5cb
fix(rs-dpp): out point buffer endianness
markin-io Jan 4, 2023
fa7de0d
feat(wasm-dpp): validateChainAssetLockProofStructureFactory.spec.js
markin-io Jan 4, 2023
f883a88
refactor(wasm-dpp): support arbitrary JS object in fetch_transaction
markin-io Jan 4, 2023
50b5efd
feat(wasm-dpp): validateInstantAssetLockProofStructureFactory.spec.js
markin-io Jan 5, 2023
f991a8b
feat(wasm-dpp): validateAssetLockTransactionFactory.spec.js
markin-io Jan 5, 2023
5e14cc6
fix(wasm-dpp): references in ExternalStateRepositoryLike
markin-io Jan 5, 2023
a563854
fix(wasm-dpp): validation result mapping for data_contrat_update vali…
markin-io Jan 9, 2023
0e56a04
feat(wasm-dpp): fetchAssetLockTransactionOutputFactory.spec.js and fe…
markin-io Jan 10, 2023
f5770d2
feat(wasm-dpp): applyIdentityCreateTransitionFactory.spec.js
markin-io Jan 10, 2023
f81d747
feat(wasm-dpp): validatePublicKeySignaturesFactory.spec.js
markin-io Jan 12, 2023
4cfac78
feat(wasm-dpp): implement validateIdentityCreateTransitionBasicFactor…
markin-io Jan 13, 2023
e43228e
fix: inconsistencies after rebase
markin-io Jan 15, 2023
a691b7f
refactor: use expectError from wasm-dpp
markin-io Jan 15, 2023
d49ce51
refactor(wasm-dpp): asset lock proof unit tests cleanup and fine tuning
markin-io Jan 15, 2023
3f9acc6
refactor(wasm-dpp): asset lock proof integration tests cleanup and fi…
markin-io Jan 15, 2023
27d547c
fix(rs-dpp): automocks for StateRepositoryLike
markin-io Jan 16, 2023
c2aca5c
refactor(wasm-dpp): unit tests for IdentityCreateTransition cleanup a…
markin-io Jan 17, 2023
7a2e0ca
refactor(wasm-dpp): integration tests for IdentityCreateTransition cl…
markin-io Jan 17, 2023
0ee034f
refactor(wasm-dpp): JSON conversion for validation logic
markin-io Jan 17, 2023
5e6c3eb
refactor(wasm-dpp): asset lock type
markin-io Jan 17, 2023
349dcc4
test(wasm-dpp): fix private key in validateIdentityCreateTransitionBa…
markin-io Jan 17, 2023
2ecbc4d
test(rs-dpp): fix tests for fetch_transaction
markin-io Jan 17, 2023
69eb2e0
refactor(js-dpp): revert code change
markin-io Jan 17, 2023
402440f
test(wasm-dpp): increase karma timeout
markin-io Jan 17, 2023
0c41864
refactor(wasm-dpp): Buffer::from_bytes references instead of as_slice()
markin-io Jan 19, 2023
f0eb1f7
refactor(wasm-dpp): Buffer::from_bytes references instead of as_slice()
markin-io Jan 19, 2023
7cfd03f
refactor(wasm-dpp): unimplemented for unrecognized from_dpp error
markin-io Jan 19, 2023
741a939
refactor(wasm-dpp): implement validators structs instead of functions
markin-io Jan 19, 2023
e36b634
refactor(wasm-dpp): eslint
markin-io Jan 19, 2023
af5c81c
fix(wasm-dpp): state_transition.to_owned().clone()
markin-io Jan 19, 2023
18ae42c
test(wasm-dpp): derive rawStateTransition from JS mock
markin-io Jan 20, 2023
fcc6a23
chore(rs-dpp): clippy errors
markin-io Jan 20, 2023
5deee50
refactor(wasm-dpp): remove redundant js_name
markin-io Jan 24, 2023
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
61 changes: 32 additions & 29 deletions packages/rs-dpp/src/data_trigger/reward_share_data_triggers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const MAX_DOCUMENTS: usize = 16;
pub async fn create_masternode_reward_shares_data_trigger<'a, SR>(
document_transition: &DocumentTransition,
context: &DataTriggerExecutionContext<'a, SR>,
_top_level_identity: Option<&Identifier>,
_top_level_identifier: Option<&Identifier>,
) -> Result<DataTriggerExecutionResult, anyhow::Error>
where
SR: StateRepositoryLike,
Expand Down Expand Up @@ -70,15 +70,15 @@ where

// payToId identity exists
let pay_to_identifier = Identifier::from_bytes(&pay_to_id_bytes)?;
let maybe_identifier: Option<Vec<u8>> = context
let maybe_identity = context
.state_repository
.fetch_identity(
&pay_to_identifier,
context.state_transition_execution_context,
)
.await?;

if !is_dry_run && maybe_identifier.is_none() {
if !is_dry_run && maybe_identity.is_none() {
let err = create_error(
context,
dt_create,
Expand Down Expand Up @@ -139,6 +139,7 @@ mod test {
use itertools::Itertools;
use serde_json::json;

use crate::identity::Identity;
use crate::{
data_contract::DataContract,
data_trigger::DataTriggerExecutionContext,
Expand All @@ -160,22 +161,23 @@ mod test {
};

struct TestData {
top_level_identity: Identifier,
top_level_identifier: Identifier,
data_contract: DataContract,
sml_store: SMLStore,
documents: Vec<Document>,
document_transition: DocumentTransition,
identity: Identity,
}

fn setup_test() -> TestData {
let top_level_identity_hex =
let top_level_identifier_hex =
"c286807d463b06c7aba3b9a60acf64c1fc03da8c1422005cd9b4293f08cf0562";
let top_level_identity =
Identifier::from_bytes(&hex::decode(top_level_identity_hex).unwrap()).unwrap();
let top_level_identifier =
Identifier::from_bytes(&hex::decode(top_level_identifier_hex).unwrap()).unwrap();

let sml_entries: Vec<SMLEntry> = vec![
SMLEntry {
pro_reg_tx_hash: top_level_identity_hex.to_string(),
pro_reg_tx_hash: top_level_identifier_hex.to_string(),
confirmed_hash: "4eb56228c535db3b234907113fd41d57bcc7cdcb8e0e00e57590af27ee88c119".to_string(),
service: "192.168.65.2:20101".to_string(),
pub_key_operator: "809519c5f6f3be1c08782ac42ae9a83b6c7205eba43f9a96a4f032ec7a73f1a7c25fa78cce0d6d9c135f7e2c28527179".to_string(),
Expand Down Expand Up @@ -208,9 +210,10 @@ mod test {
TestData {
documents,
data_contract,
top_level_identity,
top_level_identifier,
sml_store,
document_transition: document_transitions[0].clone(),
identity: Identity::default(),
}
}

Expand Down Expand Up @@ -238,7 +241,7 @@ mod test {
documents,
sml_store,
data_contract,
top_level_identity,
top_level_identifier,
..
} = setup_test();

Expand All @@ -247,7 +250,7 @@ mod test {
.expect_fetch_sml_store()
.returning(move || Ok(sml_store.clone()));
state_repository_mock
.expect_fetch_identity::<Vec<u8>>()
.expect_fetch_identity()
.returning(|_, _| Ok(None));
state_repository_mock
.expect_fetch_documents()
Expand All @@ -259,7 +262,7 @@ mod test {
let execution_context = StateTransitionExecutionContext::default();
let context = DataTriggerExecutionContext {
data_contract: &data_contract,
owner_id: &top_level_identity,
owner_id: &top_level_identifier,
state_repository: &state_repository_mock,
state_transition_execution_context: &execution_context,
};
Expand All @@ -281,7 +284,7 @@ mod test {
document_transition,
sml_store,
data_contract,
top_level_identity,
top_level_identifier,
..
} = setup_test();

Expand All @@ -290,7 +293,7 @@ mod test {
.expect_fetch_sml_store()
.returning(move || Ok(sml_store.clone()));
state_repository_mock
.expect_fetch_identity::<Vec<u8>>()
.expect_fetch_identity()
.returning(move |_, _| Ok(None));
state_repository_mock
.expect_fetch_documents::<Document>()
Expand All @@ -299,7 +302,7 @@ mod test {
let execution_context = StateTransitionExecutionContext::default();
let context = DataTriggerExecutionContext {
data_contract: &data_contract,
owner_id: &top_level_identity,
owner_id: &top_level_identifier,
state_repository: &state_repository_mock,
state_transition_execution_context: &execution_context,
};
Expand Down Expand Up @@ -338,7 +341,7 @@ mod test {
.expect_fetch_sml_store()
.returning(move || Ok(sml_store.clone()));
state_repository_mock
.expect_fetch_identity::<Vec<u8>>()
.expect_fetch_identity()
.returning(move |_, _| Ok(None));
state_repository_mock
.expect_fetch_documents::<Document>()
Expand Down Expand Up @@ -368,26 +371,26 @@ mod test {
document_transition,
sml_store,
data_contract,
top_level_identity,
top_level_identifier,
identity,
..
} = setup_test();

let mut state_repository_mock = MockStateRepositoryLike::new();
let identity_to_return = top_level_identity.as_bytes().to_vec();
state_repository_mock
.expect_fetch_sml_store()
.returning(move || Ok(sml_store.clone()));
state_repository_mock
.expect_fetch_identity::<Vec<u8>>()
.returning(move |_, _| Ok(Some(identity_to_return.clone())));
.expect_fetch_identity()
.returning(move |_, _| Ok(Some(identity.clone())));
state_repository_mock
.expect_fetch_documents::<Document>()
.returning(move |_, _, _, _| Ok(vec![]));

let execution_context = StateTransitionExecutionContext::default();
let context = DataTriggerExecutionContext {
data_contract: &data_contract,
owner_id: &top_level_identity,
owner_id: &top_level_identifier,
state_repository: &state_repository_mock,
state_transition_execution_context: &execution_context,
};
Expand All @@ -404,18 +407,18 @@ mod test {
document_transition,
sml_store,
data_contract,
top_level_identity,
top_level_identifier,
identity,
..
} = setup_test();

let mut state_repository_mock = MockStateRepositoryLike::new();
let identity_to_return = top_level_identity.as_bytes().to_vec();
state_repository_mock
.expect_fetch_sml_store()
.returning(move || Ok(sml_store.clone()));
state_repository_mock
.expect_fetch_identity::<Vec<u8>>()
.returning(move |_, _| Ok(Some(identity_to_return.clone())));
.expect_fetch_identity()
.returning(move |_, _| Ok(Some(identity.clone())));
let documents_to_return: Vec<Document> = (0..16).map(|_| Document::default()).collect();
state_repository_mock
.expect_fetch_documents::<Document>()
Expand All @@ -424,7 +427,7 @@ mod test {
let execution_context = StateTransitionExecutionContext::default();
let context = DataTriggerExecutionContext {
data_contract: &data_contract,
owner_id: &top_level_identity,
owner_id: &top_level_identifier,
state_repository: &state_repository_mock,
state_transition_execution_context: &execution_context,
};
Expand All @@ -445,13 +448,13 @@ mod test {
let TestData {
document_transition,
data_contract,
top_level_identity,
top_level_identifier,
..
} = setup_test();

let mut state_repository_mock = MockStateRepositoryLike::new();
state_repository_mock
.expect_fetch_identity::<Vec<u8>>()
.expect_fetch_identity()
.returning(move |_, _| Ok(None));
state_repository_mock
.expect_fetch_documents::<Document>()
Expand All @@ -462,7 +465,7 @@ mod test {

let context = DataTriggerExecutionContext {
data_contract: &data_contract,
owner_id: &top_level_identity,
owner_id: &top_level_identifier,
state_repository: &state_repository_mock,
state_transition_execution_context: &execution_context,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ impl InvalidAssetLockProofTransactionHeightError {
self.proof_core_chain_locked_height
}

pub fn current_core_chain_locked_height(&self) -> Option<u32> {
pub fn transaction_height(&self) -> Option<u32> {
self.transaction_height
}
}
Expand Down
3 changes: 3 additions & 0 deletions packages/rs-dpp/src/errors/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ pub enum ProtocolError {

#[error("Public key is disabled")]
PublicKeyIsDisabledError { public_key: IdentityPublicKey },

#[error("Identity is not present")]
IdentityNotPresentError { id: Identifier },
}

impl From<NonConsensusError> for ProtocolError {
Expand Down
5 changes: 4 additions & 1 deletion packages/rs-dpp/src/errors/non_consensus_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::{
CompatibleProtocolVersionIsNotDefinedError, InvalidVectorSizeError, SerdeParsingError,
};

#[derive(Debug, Error, Clone)]
#[derive(Debug, Error)]
pub enum NonConsensusError {
#[error("Unexpected serde parsing error: {0:#}")]
SerdeParsingError(SerdeParsingError),
Expand Down Expand Up @@ -34,6 +34,9 @@ pub enum NonConsensusError {
object_name: &'static str,
details: String,
},

#[error(transparent)]
Error(#[from] anyhow::Error),
}

pub mod object_names {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ use thiserror::Error;
#[derive(Error, Debug, Clone, PartialEq, Eq)]
#[error("'Unknown Asset lock proof type'")]
pub struct UnknownAssetLockProofTypeError {
asset_lock_type: u32,
asset_lock_type: Option<u8>,
}

impl UnknownAssetLockProofTypeError {
pub fn new(asset_lock_type: u32) -> Self {
pub fn new(asset_lock_type: Option<u8>) -> Self {
Self { asset_lock_type }
}

pub fn asset_lock_type(&self) -> u32 {
pub fn asset_lock_type(&self) -> Option<u8> {
self.asset_lock_type
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::convert::TryInto;
use std::sync::Arc;

use dashcore::hashes::hex::ToHex;
Expand Down Expand Up @@ -50,8 +51,8 @@ pub async fn fetch_asset_lock_transaction_output(
let output_index = out_point.vout as usize;
let transaction_hash = out_point.txid;

let maybe_raw_transaction = state_repository
.fetch_transaction::<Vec<u8>>(&transaction_hash.to_hex(), execution_context)
let transaction_data = state_repository
.fetch_transaction(&transaction_hash.to_hex(), execution_context)
.await
.map_err(|_| DPPError::InvalidAssetLockTransaction)?;

Expand All @@ -62,9 +63,14 @@ pub async fn fetch_asset_lock_transaction_output(
});
}

if let Some(raw_transaction) = maybe_raw_transaction {
let transaction_data = transaction_data
.try_into()
.map_err(|_| DPPError::InvalidAssetLockTransaction)?;

if let Some(raw_transaction) = transaction_data.data {
let transaction = Transaction::deserialize(&raw_transaction)
.map_err(|_| DPPError::InvalidAssetLockTransaction)?;

transaction
.output
.get(output_index)
Expand All @@ -81,6 +87,7 @@ pub async fn fetch_asset_lock_transaction_output(

#[cfg(test)]
mod test {
use crate::state_repository::FetchTransactionResponse;
use crate::{
identity::state_transition::asset_lock_proof::chain::ChainAssetLockProof,
state_repository::MockStateRepositoryLike,
Expand All @@ -95,8 +102,8 @@ mod test {
let execution_context = StateTransitionExecutionContext::default();

state_repository_mock
.expect_fetch_transaction::<Vec<u8>>()
.return_once(|_, _| Ok(None));
.expect_fetch_transaction()
.return_once(|_, _| Ok(FetchTransactionResponse::default()));
execution_context.enable_dry_run();

let result = fetch_asset_lock_transaction_output(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@ where
}

let out_point = OutPoint::new(transaction.txid(), output_index as u32);
let out_point_buf = consensus::serialize(&out_point);
let mut out_point_buf = consensus::serialize(&out_point);
let (tx_id, _) = out_point_buf.split_at_mut(32);
tx_id.reverse();

let is_out_point_used = self
.state_repository
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
use serde::{Deserialize, Serialize};
use serde_big_array::BigArray;

use crate::identifier::Identifier;
use crate::util::hash::hash;
use crate::util::vec::vec_to_array;
use crate::{
errors::NonConsensusError, identifier::Identifier, util::hash::hash, util::vec::vec_to_array,
};

#[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ChainAssetLockProof {
#[serde(rename = "type")]
asset_lock_type: u8,
Expand Down Expand Up @@ -34,16 +35,22 @@ impl ChainAssetLockProof {
self.core_chain_locked_height
}

pub fn set_core_chain_locked_height(&mut self, value: u32) {
self.core_chain_locked_height = value;
}

/// Get out_point
pub fn out_point(&self) -> &[u8; 36] {
&self.out_point
}

pub fn set_out_point(&mut self, out_point: [u8; 36]) {
self.out_point = out_point;
}

/// Create identifier
pub fn create_identifier(&self) -> Identifier {
return Identifier::new(
vec_to_array(hash(self.out_point()).as_ref())
.expect("Expected hash function to give a 32 byte output"),
);
pub fn create_identifier(&self) -> Result<Identifier, NonConsensusError> {
let array = vec_to_array(hash(self.out_point).as_ref())?;
Ok(Identifier::new(array))
}
}
Loading