From 0f357963bb0f990812ff9633f7cb1f5244c6b5af Mon Sep 17 00:00:00 2001 From: Marek Fedorovic Date: Tue, 12 Sep 2023 18:02:47 +1000 Subject: [PATCH] feat: Use i64 when converting numbers from JS to Rust. --- cohort_banking_initiator_js/src/banking-app.ts | 6 +++--- cohort_banking_initiator_js/src/main.ts | 2 -- packages/cohort_sdk_js/src/initiator/mod.rs | 18 +++++++++--------- 3 files changed, 12 insertions(+), 14 deletions(-) diff --git a/cohort_banking_initiator_js/src/banking-app.ts b/cohort_banking_initiator_js/src/banking-app.ts index 8bb913e7..ebe810b2 100644 --- a/cohort_banking_initiator_js/src/banking-app.ts +++ b/cohort_banking_initiator_js/src/banking-app.ts @@ -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 { @@ -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() @@ -154,7 +154,7 @@ export class BankingApp { } } - private async installOutOfOrder(tx: TransferRequest, request: OoRequest): Promise { + private async installOutOfOrder(tx: TransferRequest, request: OutOfOrderRequest): Promise { let cnn: PoolClient try { // Params order: diff --git a/cohort_banking_initiator_js/src/main.ts b/cohort_banking_initiator_js/src/main.ts index b4225c61..9b36dd30 100644 --- a/cohort_banking_initiator_js/src/main.ts +++ b/cohort_banking_initiator_js/src/main.ts @@ -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) diff --git a/packages/cohort_sdk_js/src/initiator/mod.rs b/packages/cohort_sdk_js/src/initiator/mod.rs index 544fc4dd..5cc7be08 100644 --- a/packages/cohort_sdk_js/src/initiator/mod.rs +++ b/packages/cohort_sdk_js/src/initiator/mod.rs @@ -69,7 +69,7 @@ impl From for Config { pub struct JsCertificationCandidate { pub readset: Vec, pub writeset: Vec, - pub readvers: Vec, + pub readvers: Vec, pub statemaps: Option>>, } @@ -87,7 +87,7 @@ impl From for CertificationCandidate { #[napi(object)] pub struct JsCertificationRequestPayload { pub candidate: JsCertificationCandidate, - pub snapshot: u32, + pub snapshot: i64, pub timeout_ms: u32, } @@ -124,7 +124,7 @@ impl Initiator { pub async fn certify( &self, #[napi(ts_arg_type = "() => Promise")] make_new_request_callback: ThreadsafeFunction<()>, - ooo_callback: ThreadsafeFunction, + ooo_callback: ThreadsafeFunction, ) -> napi::Result { // println!("Initiator.certify()"); let new_request_provider = NewRequestProvider { make_new_request_callback }; @@ -139,13 +139,13 @@ impl Initiator { } struct OutOfOrderInstallerImpl { - ooo_callback: ThreadsafeFunction, + ooo_callback: ThreadsafeFunction, } #[async_trait] impl OutOfOrderInstaller for OutOfOrderInstallerImpl { async fn install(&self, request: OutOfOrderInstallRequest) -> Result { - let oorequest = OoRequest { + let oorequest = OutOfOrderRequest { xid: request.xid, safepoint: request.safepoint.try_into().unwrap(), new_version: request.version.try_into().unwrap(), @@ -153,7 +153,7 @@ impl OutOfOrderInstaller for OutOfOrderInstallerImpl { let result = self .ooo_callback - .call_async::>(Ok(oorequest)) + .call_async::>(Ok(oorequest)) .await .map_err(map_error_to_napi_error); match result { @@ -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, }