File tree Expand file tree Collapse file tree 2 files changed +10
-11
lines changed Expand file tree Collapse file tree 2 files changed +10
-11
lines changed Original file line number Diff line number Diff line change 11import axios from 'axios' ;
22import { gzip } from 'pako' ;
3- import { btoa , randomAddress } from './utils' ;
3+ import { randomAddress , btoaUniversal } from './utils' ;
44import type {
55 GetBlockResponse ,
66 GetCode ,
@@ -184,15 +184,11 @@ export function addTransaction(tx: Transaction): Promise<AddTransactionResponse>
184184}
185185
186186export function compressProgram ( program : string ) : CompressedProgram {
187- try {
188- const json = JSON . parse ( program ) ;
189- const stringified = JSON . stringify ( json ) ;
190- const compressedProgram = gzip ( stringified ) ;
191- const base64 = btoa ( compressedProgram ) ;
192- return base64 ;
193- } catch {
194- throw new Error ( 'couldnt compress program' ) ;
195- }
187+ const json = JSON . parse ( program ) ;
188+ const stringified = JSON . stringify ( json ) ;
189+ const compressedProgram = gzip ( stringified ) ;
190+ const base64 = btoaUniversal ( compressedProgram ) ;
191+ return base64 ;
196192}
197193
198194export function deployContract (
Original file line number Diff line number Diff line change 11import { CONTRACT_ADDRESS_LOWER_BOUND , CONTRACT_ADDRESS_UPPER_BOUND } from './constants' ;
22
3- export const btoa = ( b : ArrayBuffer ) : string => Buffer . from ( b ) . toString ( 'base64' ) ;
3+ const isBrowser = typeof window !== 'undefined' ;
4+
5+ export const btoaUniversal = ( b : ArrayBuffer ) : string =>
6+ isBrowser ? btoa ( String . fromCharCode . apply ( null , b as any ) ) : Buffer . from ( b ) . toString ( 'base64' ) ;
47
58export function randomIntFromInterval ( min : number , max : number ) {
69 return Math . floor ( Math . random ( ) * ( max - min + 1 ) + min ) ;
You can’t perform that action at this time.
0 commit comments