Skip to content

Commit

Permalink
feat: Use i64 when converting numbers from JS to Rust.
Browse files Browse the repository at this point in the history
  • Loading branch information
fmarek-kindred committed Sep 12, 2023
1 parent a56c879 commit 0f35796
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 14 deletions.
6 changes: 3 additions & 3 deletions cohort_banking_initiator_js/src/banking-app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Pond } from "./pond"
import { logger } from "./logger"

import { CapturedItemState, CapturedState, CertificationCandidate, CertificationRequest, TransferRequest, TransferRequestMessage } from "./model"
import { Initiator, JsCertificationRequestPayload, OoRequest } from "cohort_sdk_js"
import { Initiator, JsCertificationRequestPayload, OutOfOrderRequest } from "cohort_sdk_js"
import { SDK_CONFIG as sdkConfig } from "./cfg/config-cohort-sdk"

export class BankingApp {
Expand Down Expand Up @@ -93,7 +93,7 @@ export class BankingApp {
stateDuration = n - s
return { newRequest }
},
async (_e, request: OoRequest) => {
async (_e, request: OutOfOrderRequest) => {
const s = Date.now()
const r = await this.installOutOfOrder(tx, request) as any
const n = Date.now()
Expand Down Expand Up @@ -154,7 +154,7 @@ export class BankingApp {
}
}

private async installOutOfOrder(tx: TransferRequest, request: OoRequest): Promise<number> {
private async installOutOfOrder(tx: TransferRequest, request: OutOfOrderRequest): Promise<number> {
let cnn: PoolClient
try {
// Params order:
Expand Down
2 changes: 0 additions & 2 deletions cohort_banking_initiator_js/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ class LaunchParams {
}

new Promise(async (resolve) => {
logger.info("args: %s", JSON.stringify(process.argv, null, 2))

const params = LaunchParams.parse(process.argv)

const database = new Pool(DB_CONFIG)
Expand Down
18 changes: 9 additions & 9 deletions packages/cohort_sdk_js/src/initiator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ impl From<JsInitiatorConfig> for Config {
pub struct JsCertificationCandidate {
pub readset: Vec<String>,
pub writeset: Vec<String>,
pub readvers: Vec<u32>,
pub readvers: Vec<i64>,
pub statemaps: Option<Vec<HashMap<String, Value>>>,
}

Expand All @@ -87,7 +87,7 @@ impl From<JsCertificationCandidate> for CertificationCandidate {
#[napi(object)]
pub struct JsCertificationRequestPayload {
pub candidate: JsCertificationCandidate,
pub snapshot: u32,
pub snapshot: i64,
pub timeout_ms: u32,
}

Expand Down Expand Up @@ -124,7 +124,7 @@ impl Initiator {
pub async fn certify(
&self,
#[napi(ts_arg_type = "() => Promise<any>")] make_new_request_callback: ThreadsafeFunction<()>,
ooo_callback: ThreadsafeFunction<OoRequest>,
ooo_callback: ThreadsafeFunction<OutOfOrderRequest>,
) -> napi::Result<String> {
// println!("Initiator.certify()");
let new_request_provider = NewRequestProvider { make_new_request_callback };
Expand All @@ -139,21 +139,21 @@ impl Initiator {
}

struct OutOfOrderInstallerImpl {
ooo_callback: ThreadsafeFunction<OoRequest>,
ooo_callback: ThreadsafeFunction<OutOfOrderRequest>,
}

#[async_trait]
impl OutOfOrderInstaller for OutOfOrderInstallerImpl {
async fn install(&self, request: OutOfOrderInstallRequest) -> Result<OutOfOrderInstallOutcome, String> {
let oorequest = OoRequest {
let oorequest = OutOfOrderRequest {
xid: request.xid,
safepoint: request.safepoint.try_into().unwrap(),
new_version: request.version.try_into().unwrap(),
};

let result = self
.ooo_callback
.call_async::<Promise<u32>>(Ok(oorequest))
.call_async::<Promise<i64>>(Ok(oorequest))
.await
.map_err(map_error_to_napi_error);
match result {
Expand Down Expand Up @@ -204,8 +204,8 @@ impl NewRequestProvider {
}

#[napi(object)]
pub struct OoRequest {
pub struct OutOfOrderRequest {
pub xid: String,
pub safepoint: u32,
pub new_version: u32,
pub safepoint: i64,
pub new_version: i64,
}

0 comments on commit 0f35796

Please sign in to comment.