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

fix: putVote was using wrong identity for nonce #1907

Merged
merged 3 commits into from
Jun 27, 2024
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
1 change: 1 addition & 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 packages/rs-sdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ dashcore-rpc = { git = "https://github.com/dashpay/rust-dashcore-rpc", tag = "v0
lru = { version = "0.12.3", optional = true }
bip37-bloom-filter = { git = "https://github.com/dashpay/rs-bip37-bloom-filter", branch = "develop" }
pollster = { version = "0.3.0" }
sha2 = "0.10.8"

[dev-dependencies]
tokio = { version = "1.36.0", features = ["macros", "rt-multi-thread"] }
Expand Down
25 changes: 23 additions & 2 deletions packages/rs-sdk/src/platform/transition/vote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::platform::transition::put_settings::PutSettings;
use crate::platform::Fetch;
use crate::{Error, Sdk};
use dapi_grpc::platform::VersionedGrpcResponse;
use dpp::identity::hash::IdentityPublicKeyHashMethodsV0;
use dpp::identity::signer::Signer;
use dpp::identity::IdentityPublicKey;
use dpp::prelude::Identifier;
Expand All @@ -15,6 +16,7 @@ use dpp::voting::votes::resource_vote::accessors::v0::ResourceVoteGettersV0;
use dpp::voting::votes::Vote;
use drive::drive::Drive;
use rs_dapi_client::DapiRequest;
use sha2::{Digest, Sha256};

#[async_trait::async_trait]
/// A trait for putting a vote on platform
Expand Down Expand Up @@ -49,8 +51,10 @@ impl<S: Signer> PutVote<S> for Vote {
signer: &S,
settings: Option<PutSettings>,
) -> Result<(), Error> {
let voting_identity_id = get_voting_identity_id(voter_pro_tx_hash, voting_public_key)?;

let new_masternode_voting_nonce = sdk
.get_identity_nonce(voter_pro_tx_hash, true, settings)
.get_identity_nonce(voting_identity_id, true, settings)
.await?;

let settings = settings.unwrap_or_default();
Expand Down Expand Up @@ -79,8 +83,10 @@ impl<S: Signer> PutVote<S> for Vote {
signer: &S,
settings: Option<PutSettings>,
) -> Result<Vote, Error> {
let voting_identity_id = get_voting_identity_id(voter_pro_tx_hash, voting_public_key)?;

let new_masternode_voting_nonce = sdk
.get_identity_nonce(voter_pro_tx_hash, true, settings)
.get_identity_nonce(voting_identity_id, true, settings)
.await?;

let settings = settings.unwrap_or_default();
Expand Down Expand Up @@ -141,3 +147,18 @@ impl<S: Signer> PutVote<S> for Vote {
}
}
}

fn get_voting_identity_id(
voter_pro_tx_hash: Identifier,
voting_public_key: &IdentityPublicKey,
) -> Result<Identifier, Error> {
let pub_key_hash = voting_public_key.public_key_hash()?;

let mut hasher = Sha256::new();
hasher.update(voter_pro_tx_hash.as_bytes());
hasher.update(pub_key_hash);
let voting_identity_id_hashed = hasher.finalize();

Identifier::from_bytes(&voting_identity_id_hashed)
.map_err(|e| Error::Generic(format!("Couldn't convert id string to Identifier: {}", e)))
}
Loading