Skip to content

Commit

Permalink
Merge branch 'v1.1-dev' into fix/create-some-id-transitions
Browse files Browse the repository at this point in the history
  • Loading branch information
pauldelucia authored Aug 19, 2024
2 parents 7e262d8 + 7accd40 commit 7ff3198
Show file tree
Hide file tree
Showing 10 changed files with 111 additions and 73 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ const {
GetIdentityNonceResponse: PBJSGetIdentityNonceResponse,
GetIdentityKeysRequest: PBJSGetIdentityKeysRequest,
GetIdentityKeysResponse: PBJSGetIdentityKeysResponse,
GetTotalCreditsInPlatformRequest: PBJSGetTotalCreditsInPlatformRequest,
GetTotalCreditsInPlatformResponse: PBJSGetTotalCreditsInPlatformResponse,
},
},
},
Expand All @@ -82,6 +84,7 @@ const {
GetIdentityContractNonceResponse: ProtocGetIdentityContractNonceResponse,
GetIdentityNonceResponse: ProtocGetIdentityNonceResponse,
GetIdentityKeysResponse: ProtocGetIdentityKeysResponse,
GetTotalCreditsInPlatformResponse: ProtocGetTotalCreditsInPlatformResponse,
} = require('./platform_protoc');

const getPlatformDefinition = require('../../../../lib/getPlatformDefinition');
Expand Down Expand Up @@ -172,6 +175,10 @@ class PlatformPromiseClient {
this.client.getIdentityKeys.bind(this.client),
);

this.client.getTotalCreditsInPlatform = promisify(
this.client.getTotalCreditsInPlatform.bind(this.client),
);

this.protocolVersion = undefined;
}

Expand Down Expand Up @@ -690,6 +697,35 @@ class PlatformPromiseClient {
);
}

getTotalCreditsInPlatform(
getTotalCreditsInPlatformRequest,
metadata = {},
options = {},
) {
if (!isObject(metadata)) {
throw new Error('metadata must be an object');
}

return this.client.getTotalCreditsInPlatform(
getTotalCreditsInPlatformRequest,
convertObjectToMetadata(metadata),
{
interceptors: [
jsonToProtobufInterceptorFactory(
jsonToProtobufFactory(
ProtocGetTotalCreditsInPlatformResponse,
PBJSGetTotalCreditsInPlatformResponse,
),
protobufToJsonFactory(
PBJSGetTotalCreditsInPlatformRequest,
),
),
],
...options,
},
);
}

/**
* @param {string} protocolVersion
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const getProtocolVersionUpgradeStateFactory = require('./getProtocolVersionUpgra
const getIdentityContractNonceFactory = require('./getIdentityContractNonce/getIdentityContractNonceFactory');
const getIdentityNonceFactory = require('./getIdentityNonce/getIdentityNonceFactory');
const getIdentityKeysFactory = require('./getIdentityKeys/getIdentityKeysFactory');
const getTotalCreditsInPlatformFactory = require('./getTotalCreditsInPlatform/getTotalCreditsInPlatformFactory');

class PlatformMethodsFacade {
/**
Expand All @@ -36,6 +37,7 @@ class PlatformMethodsFacade {
this.getIdentityContractNonce = getIdentityContractNonceFactory(grpcTransport);
this.getIdentityNonce = getIdentityNonceFactory(grpcTransport);
this.getIdentityKeys = getIdentityKeysFactory(grpcTransport);
this.getTotalCreditsInPlatform = getTotalCreditsInPlatformFactory(grpcTransport);
}
}

Expand Down
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().getCredits();
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;
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;

This file was deleted.

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 7ff3198

Please sign in to comment.