Skip to content

Commit

Permalink
refactor: rename getTotalCreditsOnPlatform (dashpay#2056)
Browse files Browse the repository at this point in the history
  • Loading branch information
pauldelucia authored Aug 14, 2024
1 parent c554062 commit e8fc49e
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 73 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
const AbstractResponse = require('../response/AbstractResponse');
const InvalidResponseError = require('../response/errors/InvalidResponseError');

class GetTotalCreditsInPlatformResponse extends AbstractResponse {
/**
* @param {number} totalCreditsInPlatform
* @param {Metadata} metadata
* @param {Proof} [proof]
*/
constructor(totalCreditsInPlatform, metadata, proof = undefined) {
super(metadata, proof);

this.totalCreditsInPlatform = totalCreditsInPlatform;
}

/**
* @returns {number}
*/
getTotalCreditsInPlatform() {
return this.totalCreditsInPlatform;
}

/**
* @param proto
* @returns {GetTotalCreditsInPlatformResponse}
*/
static createFromProto(proto) {
// eslint-disable-next-line
const totalCreditsInPlatform = proto.getV0().getTotalCreditsInPlatform();
const { metadata, proof } = AbstractResponse.createMetadataAndProofFromProto(
proto,
);

if ((typeof totalCreditsInPlatform === 'undefined' || totalCreditsInPlatform === null) && !proof) {
throw new InvalidResponseError('Total Credits on Platform data is not defined');
}

return new GetTotalCreditsInPlatformResponse(
totalCreditsInPlatform,
metadata,
proof,
);
}
}

module.exports = GetTotalCreditsInPlatformResponse;

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
const {
v0: {
PlatformPromiseClient,
GetTotalCreditsOnPlatformRequest,
GetTotalCreditsInPlatformRequest,
},
} = require('@dashevo/dapi-grpc');

const GetTotalCreditsOnPlatformResponse = require('./GetTotalCreditsOnPlatformResponse');
const GetTotalCreditsInPlatformResponse = require('./GetTotalCreditsInPlatformResponse');
const InvalidResponseError = require('../response/errors/InvalidResponseError');

/**
* @param {GrpcTransport} grpcTransport
* @returns {getTotalCreditsOnPlatform}
* @returns {getTotalCreditsInPlatform}
*/
function getTotalCreditsOnPlatformFactory(grpcTransport) {
function getTotalCreditsInPlatformFactory(grpcTransport) {
/**
* Fetch the version upgrade votes status
* @typedef {getTotalCreditsOnPlatform}
* @typedef {getTotalCreditsInPlatform}
* @param {DAPIClientOptions & {prove: boolean}} [options]
* @returns {Promise<GetTotalCreditsOnPlatformResponse>}
* @returns {Promise<GetTotalCreditsInPlatformResponse>}
*/
async function getTotalCreditsOnPlatform(options = {}) {
async function getTotalCreditsInPlatform(options = {}) {
const {
GetTotalCreditsOnPlatformRequestV0,
} = GetTotalCreditsOnPlatformRequest;
GetTotalCreditsInPlatformRequestV0,
} = GetTotalCreditsInPlatformRequest;

// eslint-disable-next-line max-len
const getTotalCreditsOnPlatformRequest = new GetTotalCreditsOnPlatformRequest();
const getTotalCreditsInPlatformRequest = new GetTotalCreditsInPlatformRequest();

getTotalCreditsOnPlatformRequest.setV0(
new GetTotalCreditsOnPlatformRequestV0()
getTotalCreditsInPlatformRequest.setV0(
new GetTotalCreditsInPlatformRequestV0()
.setProve(!!options.prove),
);

Expand All @@ -38,15 +38,15 @@ function getTotalCreditsOnPlatformFactory(grpcTransport) {
for (let i = 0; i < 3; i += 1) {
try {
// eslint-disable-next-line no-await-in-loop
const getTotalCreditsOnPlatformResponse = await grpcTransport.request(
const getTotalCreditsInPlatformResponse = await grpcTransport.request(
PlatformPromiseClient,
'getTotalCreditsOnPlatform',
getTotalCreditsOnPlatformRequest,
'getTotalCreditsInPlatform',
getTotalCreditsInPlatformRequest,
options,
);

return GetTotalCreditsOnPlatformResponse
.createFromProto(getTotalCreditsOnPlatformResponse);
return GetTotalCreditsInPlatformResponse
.createFromProto(getTotalCreditsInPlatformResponse);
} catch (e) {
if (e instanceof InvalidResponseError) {
lastError = e;
Expand All @@ -61,7 +61,7 @@ function getTotalCreditsOnPlatformFactory(grpcTransport) {
throw lastError;
}

return getTotalCreditsOnPlatform;
return getTotalCreditsInPlatform;
}

module.exports = getTotalCreditsOnPlatformFactory;
module.exports = getTotalCreditsInPlatformFactory;
4 changes: 2 additions & 2 deletions packages/rs-drive-proof-verifier/src/proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1646,7 +1646,7 @@ impl FromProof<platform::GetContestedResourceIdentityVotesRequest> for Vote {
}
}

impl FromProof<platform::GetTotalCreditsInPlatformRequest> for TotalCreditsOnPlatform {
impl FromProof<platform::GetTotalCreditsInPlatformRequest> for TotalCreditsInPlatform {
type Request = platform::GetTotalCreditsInPlatformRequest;
type Response = platform::GetTotalCreditsInPlatformResponse;

Expand Down Expand Up @@ -1685,7 +1685,7 @@ impl FromProof<platform::GetTotalCreditsInPlatformRequest> for TotalCreditsOnPla
verify_tenderdash_proof(proof, mtd, &root_hash, provider)?;

Ok((
Some(TotalCreditsOnPlatform(credits)),
Some(TotalCreditsInPlatform(credits)),
mtd.clone(),
proof.clone(),
))
Expand Down
2 changes: 1 addition & 1 deletion packages/rs-drive-proof-verifier/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ pub struct KeysInPath {
derive(Encode, Decode, PlatformSerialize, PlatformDeserialize),
platform_serialize(unversioned)
)]
pub struct TotalCreditsOnPlatform(pub Credits);
pub struct TotalCreditsInPlatform(pub Credits);

/// A query with no parameters
#[derive(Debug, Clone, Copy)]
Expand Down
4 changes: 2 additions & 2 deletions packages/rs-sdk/src/mock/requests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use dpp::{
};
use drive_proof_verifier::types::{
Contenders, ContestedResources, ElementFetchRequestItem, IdentityBalanceAndRevision,
MasternodeProtocolVote, PrefundedSpecializedBalance, TotalCreditsOnPlatform,
MasternodeProtocolVote, PrefundedSpecializedBalance, TotalCreditsInPlatform,
VotePollsGroupedByTimestamp, Voters,
};
use std::collections::BTreeMap;
Expand Down Expand Up @@ -227,5 +227,5 @@ impl_mock_response!(Contenders);
impl_mock_response!(Voters);
impl_mock_response!(VotePollsGroupedByTimestamp);
impl_mock_response!(PrefundedSpecializedBalance);
impl_mock_response!(TotalCreditsOnPlatform);
impl_mock_response!(TotalCreditsInPlatform);
impl_mock_response!(ElementFetchRequestItem);
2 changes: 1 addition & 1 deletion packages/rs-sdk/src/platform/fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ impl Fetch for drive_proof_verifier::types::IdentityBalance {
type Request = platform_proto::GetIdentityBalanceRequest;
}

impl Fetch for drive_proof_verifier::types::TotalCreditsOnPlatform {
impl Fetch for drive_proof_verifier::types::TotalCreditsInPlatform {
type Request = platform_proto::GetTotalCreditsInPlatformRequest;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ use crate::platform::fetch_current_no_parameters::FetchCurrent;
use crate::{platform::Fetch, Error, Sdk};
use async_trait::async_trait;
use dapi_grpc::platform::v0::{Proof, ResponseMetadata};
use drive_proof_verifier::types::{NoParamQuery, TotalCreditsOnPlatform};
use drive_proof_verifier::types::{NoParamQuery, TotalCreditsInPlatform};

#[async_trait]
impl FetchCurrent for TotalCreditsOnPlatform {
impl FetchCurrent for TotalCreditsInPlatform {
async fn fetch_current(sdk: &Sdk) -> Result<Self, Error> {
let (total_credits_on_platform, _) = Self::fetch_current_with_metadata(sdk).await?;
Ok(total_credits_on_platform)
Expand Down

0 comments on commit e8fc49e

Please sign in to comment.