From f3f7889f9d85cef97cda8435da46a20c560de9f6 Mon Sep 17 00:00:00 2001 From: ppe Date: Tue, 20 Sep 2022 13:51:14 +0200 Subject: [PATCH] fix: isomorhpic randomUUID --- src/core/ContractCallRecord.ts | 5 ++++- src/utils/utils.ts | 11 ++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/core/ContractCallRecord.ts b/src/core/ContractCallRecord.ts index a27ae46..a827e0a 100644 --- a/src/core/ContractCallRecord.ts +++ b/src/core/ContractCallRecord.ts @@ -1,11 +1,14 @@ import { InteractionData } from './modules/impl/HandlerExecutorFactory'; import { InnerCallType } from '../contract/Contract'; +import { isomorphicRandomUUID } from '../utils/utils'; export class ContractCallRecord { readonly interactions: { [key: string]: InteractionCall } = {}; readonly id: string; - constructor(readonly contractTxId: string, readonly depth: number, readonly innerCallType: InnerCallType = null) {} + constructor(readonly contractTxId: string, readonly depth: number, readonly innerCallType: InnerCallType = null) { + this.id = isomorphicRandomUUID(); + } addInteractionData(interactionData: InteractionData): InteractionCall { const { interaction, interactionTx } = interactionData; diff --git a/src/utils/utils.ts b/src/utils/utils.ts index d487138..c112c4c 100644 --- a/src/utils/utils.ts +++ b/src/utils/utils.ts @@ -1,7 +1,8 @@ /* eslint-disable */ import cloneDeep from 'lodash/cloneDeep'; import copy from 'fast-copy'; -import { Buffer } from 'redstone-isomorphic'; +import {Buffer} from 'redstone-isomorphic'; +import {randomUUID} from "crypto"; export const sleep = (ms: number): Promise => { return new Promise((resolve) => setTimeout(resolve, ms)); @@ -75,3 +76,11 @@ export function bufToBn(buf: Buffer) { return BigInt('0x' + hex.join('')); } + +export function isomorphicRandomUUID() { + if (self.crypto) { + return self.crypto.randomUUID(); + } else { + return randomUUID(); + } +}