@@ -18,6 +18,7 @@ import {
18
18
IListener ,
19
19
ISubmitter ,
20
20
Protocol ,
21
+ RedeemerTagType ,
21
22
toBytes ,
22
23
TransactionInfo ,
23
24
UTxO ,
@@ -115,8 +116,7 @@ import { utxosToAssets } from "./common/utxos-to-assets";
115
116
* ```
116
117
*/
117
118
export class U5CProvider
118
- implements IFetcher , ISubmitter , IEvaluator , IListener
119
- {
119
+ implements IFetcher , ISubmitter , IEvaluator , IListener {
120
120
// Clients for querying and submitting transactions on the Cardano blockchain.
121
121
private queryClient : CardanoQueryClient ;
122
122
private submitClient : CardanoSubmitClient ;
@@ -176,8 +176,33 @@ export class U5CProvider
176
176
* Evaluates the resources required to execute the transaction
177
177
* @param tx - The transaction to evaluate
178
178
*/
179
- evaluateTx ( tx : string ) : Promise < Omit < Action , "data" > [ ] > {
180
- throw new Error ( "Method not implemented." ) ;
179
+ async evaluateTx ( tx : string ) : Promise < Omit < Action , "data" > [ ] > {
180
+
181
+ const report = await this . submitClient . evalTx ( hexToBytes ( tx ) ) ;
182
+ const evalResult = report . report [ 0 ] ! . chain . value ?. redeemers ! ;
183
+
184
+ const tagMap : { [ key : number ] : RedeemerTagType } = {
185
+ // 0: "UNSPECIFIED", // REDEEMER_PURPOSE_UNSPECIFIED
186
+ 1 : "SPEND" , // REDEEMER_PURPOSE_SPEND
187
+ 2 : "MINT" , // REDEEMER_PURPOSE_MINT
188
+ 3 : "CERT" , // REDEEMER_PURPOSE_CERT
189
+ 4 : "REWARD" , // REDEEMER_PURPOSE_REWARD
190
+ 5 : "VOTE" , // REDEEMER_PURPOSE_VOTE
191
+ 6 : "PROPOSE" , // REDEEMER_PURPOSE_PROPOSE
192
+ } ;
193
+
194
+ const result : Omit < Action , "data" > [ ] = [ ] ;
195
+
196
+ evalResult . map ( ( action : any ) => {
197
+ result . push ( {
198
+ tag : tagMap [ action . purpose ! ] ! ,
199
+ index : action . index ,
200
+ budget : { mem : Number ( action . exUnits ! . memory ) , steps : Number ( action . exUnits ! . steps ) } ,
201
+ } ) ;
202
+ } )
203
+
204
+ return result ;
205
+
181
206
}
182
207
183
208
/**
@@ -213,7 +238,7 @@ export class U5CProvider
213
238
* @returns UTxOs for the given address
214
239
*/
215
240
async fetchAddressUTxOs ( address : string , asset ?: string ) : Promise < UTxO [ ] > {
216
- const addressBytes = Buffer . from ( Address . fromBech32 ( address ) . toBytes ( ) ) ;
241
+ const addressBytes = hexToBytes ( Address . fromBech32 ( address ) . toBytes ( ) ) ;
217
242
218
243
const utxoSearchResult =
219
244
await this . queryClient . searchUtxosByAddress ( addressBytes ) ;
@@ -344,13 +369,21 @@ export class U5CProvider
344
369
}
345
370
346
371
/**
347
- * Unimplemented - open for contribution
372
+ * Not complete - open for contribution
348
373
*
349
374
* Fetches output UTxOs of a given transaction hash.
350
375
* @param hash - The transaction hash
351
376
*/
352
- fetchUTxOs ( hash : string ) : Promise < UTxO [ ] > {
353
- throw new Error ( "Method not implemented." ) ;
377
+ async fetchUTxOs ( hash : string , index ?: number ) : Promise < UTxO [ ] > {
378
+ const utxoSearchResult = await this . queryClient . readUtxosByOutputRef (
379
+ [ {
380
+ txHash : hexToBytes ( hash ) ,
381
+ outputIndex : index || 0 , // TODO: handle case when index is not provided. Note: readUtxos might not support this, try when readTx is implemented
382
+ } ]
383
+ ) ;
384
+ return utxoSearchResult . map ( ( item ) => {
385
+ return this . _rpcUtxoToMeshUtxo ( item . txoRef , item . parsedValued ! ) ;
386
+ } ) ;
354
387
}
355
388
356
389
/**
0 commit comments