Skip to content

Commit

Permalink
feat(sdk): fix metadata bigint parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
pshenmic committed Feb 4, 2025
1 parent f924e6f commit ee79545
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ function getDataContractHistoryFactory(grpcTransport) {
* Fetch Data Contract by id
* @typedef {getDataContractHistory}
* @param {Buffer} contractId
* @param {number} [startAtMs]
* @param {bigint} [startAtMs]
* @param {number} [limit]
* @param {number} [offset]
* @param {DAPIClientOptions & {prove: boolean}} [options]
* @returns {Promise<GetDataContractHistoryResponse>}
*/
async function getDataContractHistory(
contractId,
startAtMs = 0,
startAtMs = BigInt(0),
limit = 10,
offset = 0,
options = {},
Expand All @@ -45,7 +45,7 @@ function getDataContractHistoryFactory(grpcTransport) {
getDataContractHistoryRequest.setV0(
new GetDataContractHistoryRequestV0()
.setId(contractId)
.setStartAtMs(startAtMs)
.setStartAtMs(startAtMs.toString())
.setLimit(new UInt32Value([limit]))
.setOffset(new UInt32Value([offset]))
.setProve(!!options.prove),
Expand Down
10 changes: 5 additions & 5 deletions packages/js-dash-sdk/src/SDK/Client/Platform/Fetcher/Fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,14 @@ class Fetcher {

/**
* Fetches data contract by it's ID
* @param id
* @param startAMs
* @param limit
* @param offset
* @param id {Identifier}
* @param startAMs {bigint}
* @param limit {number}
* @param offset {number}
*/
public async fetchDataContractHistory(
id: Identifier,
startAMs: number,
startAMs: bigint,
limit: number,
offset: number,
): Promise<GetDataContractHistoryResponse> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ export async function get(this: Platform, identifier: ContractIdentifier): Promi
let metadata;
const responseMetadata = dataContractResponse.getMetadata();
if (responseMetadata) {
metadata = new Metadata({
blockHeight: responseMetadata.getHeight(),
coreChainLockedHeight: responseMetadata.getCoreChainLockedHeight(),
timeMs: responseMetadata.getTimeMs(),
protocolVersion: responseMetadata.getProtocolVersion(),
});
metadata = new Metadata(
responseMetadata.getHeight(),
responseMetadata.getCoreChainLockedHeight(),
responseMetadata.getTimeMs(),
responseMetadata.getProtocolVersion(),
);
}
contract.setMetadata(metadata);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// @ts-ignore
import { DataContract, Identifier } from '@dashevo/wasm-dpp';
import {
GetDataContractHistoryResponse,
Expand All @@ -13,15 +12,15 @@ declare type ContractIdentifier = string | Identifier;
* Get contracts from the platform
*
* @param {ContractIdentifier} identifier - identifier of the contract to fetch
* @param startAtMs
* @param limit
* @param offset
* @param {bigint} startAtMs
* @param {number} limit
* @param {number} offset
* @returns contracts
*/
export async function history(
this: Platform,
identifier: ContractIdentifier,
startAtMs: number,
startAtMs: bigint,
limit: number,
offset: number,
): Promise<any> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,12 @@ export async function get(this: Platform, typeLocator: string, opts: QueryOption
let metadata;
const responseMetadata = documentsResponse.getMetadata();
if (responseMetadata) {
metadata = new Metadata({
blockHeight: responseMetadata.getHeight(),
coreChainLockedHeight: responseMetadata.getCoreChainLockedHeight(),
timeMs: responseMetadata.getTimeMs(),
protocolVersion: responseMetadata.getProtocolVersion(),
});
metadata = new Metadata(
responseMetadata.getHeight(),
responseMetadata.getCoreChainLockedHeight(),
responseMetadata.getTimeMs(),
responseMetadata.getProtocolVersion(),
);
}
document.setMetadata(metadata);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ export async function get(this: Platform, id: Identifier | string): Promise<any>
let metadata;
const responseMetadata = identityResponse.getMetadata();
if (responseMetadata) {
metadata = new Metadata({
blockHeight: responseMetadata.getHeight(),
coreChainLockedHeight: responseMetadata.getCoreChainLockedHeight(),
timeMs: responseMetadata.getTimeMs(),
protocolVersion: responseMetadata.getProtocolVersion(),
});
metadata = new Metadata(
responseMetadata.getHeight(),
responseMetadata.getCoreChainLockedHeight(),
responseMetadata.getTimeMs(),
responseMetadata.getProtocolVersion(),
);
}

identity.setMetadata(metadata);
Expand Down
20 changes: 3 additions & 17 deletions packages/wasm-dpp/src/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,25 +34,11 @@ impl Into<Metadata> for MetadataWasm {
#[wasm_bindgen(js_class=Metadata)]
impl MetadataWasm {
#[wasm_bindgen(constructor)]
pub fn new(options: JsValue) -> Result<MetadataWasm, JsValue> {
let metadata_options = options.with_serde_to_json_value()?;
let block_height = metadata_options
.get_u64("blockHeight")
.map_err(|e| JsError::new(&e.to_string()))?;
let core_chain_locked_height = metadata_options
.get_u32("coreChainLockedHeight")
.map_err(|e| JsError::new(&e.to_string()))?;
let time_ms = metadata_options
.get_u64("timeMs")
.map_err(|e| JsError::new(&e.to_string()))?;
let protocol_version = metadata_options
.get_u32("protocolVersion")
.map_err(|e| JsError::new(&e.to_string()))?;

pub fn new(block_height: u64, core_chain_locked_height: u32, time_ms: u64, protocol_version:u32) -> Result<MetadataWasm, JsValue> {
let inner = Metadata {
block_height: block_height,
block_height,
core_chain_locked_height: core_chain_locked_height as u64,
time_ms: time_ms,
time_ms,
protocol_version: protocol_version as u64 as ProtocolVersion,
};
Ok(inner.into())
Expand Down

0 comments on commit ee79545

Please sign in to comment.