@@ -85,11 +85,6 @@ export const formatTimestamp = (timestampInMilliseconds: number): string => {
8585 return formattedDate ;
8686} ;
8787
88- export type Signer = {
89- sk : string ;
90- address : string ;
91- } ;
92-
9388export const generateTokenName = async (
9489 baseToken : AuthToken ,
9590 prefix : string ,
@@ -175,152 +170,11 @@ export const querySystemStart = async (ogmiosUrl: string) => {
175170 return parsedSystemTime ;
176171} ;
177172
178- export const delay = ( duration : number ) => {
179- let elapsedSeconds = 1 ;
180-
181- const logElapsedTime = ( ) => {
182- Deno . stdout . writeSync (
183- new TextEncoder ( ) . encode ( `\rElapsed time: ${ elapsedSeconds } s` )
184- ) ;
185- elapsedSeconds ++ ;
186- } ;
187-
188- const intervalId = setInterval ( logElapsedTime , 1000 ) ;
189-
190- console . log ( `Delay ${ duration } s` ) ;
191-
192- return new Promise < void > ( ( resolve ) => {
193- setTimeout ( ( ) => {
194- clearInterval ( intervalId ) ;
195- Deno . stdout . writeSync (
196- new TextEncoder ( ) . encode ( `\rElapsed time: ${ elapsedSeconds } s` )
197- ) ;
198- Deno . stdout . writeSync ( new TextEncoder ( ) . encode ( `\r` ) ) ;
199- resolve ( ) ;
200- } , duration * 1000 ) ;
201- } ) ;
202- } ;
203-
204- export const parseClientSequence = ( clientId : string ) : bigint => {
205- const fragments = clientId . split ( "-" ) ;
206-
207- if ( fragments . length < 2 ) throw new Error ( "Invalid client id format" ) ;
208-
209- if ( ! ( fragments . slice ( 0 , - 1 ) . join ( "" ) === "ibc_client" ) ) {
210- throw new Error ( "Invalid client id format" ) ;
211- }
212-
213- return BigInt ( fragments . pop ( ) ! ) ;
214- } ;
215-
216- export const parseConnectionSequence = ( connectionId : string ) : bigint => {
217- const fragments = connectionId . split ( "-" ) ;
218-
219- if ( fragments . length != 2 ) throw new Error ( "Invalid connection id format" ) ;
220-
221- if ( ! ( fragments . slice ( 0 , - 1 ) . join ( "" ) === "connection" ) ) {
222- throw new Error ( "Invalid connection id format" ) ;
223- }
224-
225- return BigInt ( fragments . pop ( ) ! ) ;
226- } ;
227- export const parseChannelSequence = ( channelId : string ) : bigint => {
228- const fragments = channelId . split ( "-" ) ;
229-
230- if ( fragments . length != 2 ) throw new Error ( "Invalid channel id format" ) ;
231-
232- if ( ! ( fragments . slice ( 0 , - 1 ) . join ( "" ) === "channel" ) ) {
233- throw new Error ( "Invalid channel id format" ) ;
234- }
235-
236- return BigInt ( fragments . pop ( ) ! ) ;
237- } ;
238-
239- export const createReferenceScriptUtxo = async (
240- lucid : LucidEvolution ,
241- referredScript : Script
242- ) => {
243- const [ , , referenceAddress ] = readValidator (
244- "reference_validator.refer_only.else" ,
245- lucid
246- ) ;
247-
248- const tx = lucid . newTx ( ) . pay . ToContract (
249- referenceAddress ,
250- {
251- kind : 'inline' ,
252- value : Data . void ( ) ,
253- } ,
254- { } ,
255- referredScript ,
256- ) ;
257- const completedTx = await tx . complete ( ) ;
258- const signedTx = await completedTx . sign . withWallet ( ) . complete ( ) ;
259- const txHash = await signedTx . submit ( ) ;
260-
261- await lucid . awaitTx ( txHash , 2000 ) ;
262-
263- const referenceUtxo = (
264- await lucid . utxosByOutRef ( [ { txHash, outputIndex : 0 } ] )
265- ) [ 0 ] ;
266-
267- return referenceUtxo ;
268- } ;
269-
270173export const generateIdentifierTokenName = ( outRef : OutputReference ) => {
271174 const serializedData = Data . to ( outRef , OutputReference ) ;
272175 return hashSha3_256 ( serializedData ) ;
273176} ;
274177
275- export const insertSortMap = < K , V > (
276- inputMap : Map < K , V > ,
277- newKey : K ,
278- newValue : V ,
279- keyComparator ?: ( a : K , b : K ) => number
280- ) : Map < K , V > => {
281- // Convert the Map to an array of key-value pairs
282- const entriesArray : [ K , V ] [ ] = Array . from ( inputMap . entries ( ) ) ;
283-
284- // Add the new key-value pair to the array
285- entriesArray . push ( [ newKey , newValue ] ) ;
286-
287- // Sort the array based on the keys using the provided comparator function
288- entriesArray . sort ( ( entry1 , entry2 ) =>
289- keyComparator
290- ? keyComparator ( entry1 [ 0 ] , entry2 [ 0 ] )
291- : Number ( entry1 [ 0 ] ) - Number ( entry2 [ 0 ] )
292- ) ;
293-
294- // Create a new Map from the sorted array
295- const sortedMap = new Map < K , V > ( entriesArray ) ;
296-
297- return sortedMap ;
298- } ;
299-
300- export const deleteSortMap = < K , V > (
301- sortedMap : Map < K , V > ,
302- keyToDelete : K ,
303- keyComparator ?: ( a : K , b : K ) => number
304- ) : Map < K , V > => {
305- // Convert the sorted map to an array of key-value pairs
306- const entriesArray : [ K , V ] [ ] = Array . from ( sortedMap . entries ( ) ) ;
307-
308- // Find the index of the key to delete
309- const indexToDelete = entriesArray . findIndex ( ( [ key ] ) =>
310- keyComparator ? keyComparator ( key , keyToDelete ) === 0 : key === keyToDelete
311- ) ;
312-
313- // If the key is found, remove it from the array
314- if ( indexToDelete !== - 1 ) {
315- entriesArray . splice ( indexToDelete , 1 ) ;
316- }
317-
318- // Create a new Map from the modified array
319- const updatedMap = new Map < K , V > ( entriesArray ) ;
320-
321- return updatedMap ;
322- } ;
323-
324178export const getNonceOutRef = async (
325179 lucid : LucidEvolution
326180) : Promise < [ UTxO , OutputReference ] > => {
0 commit comments