@@ -8,7 +8,12 @@ import {
88import { StateQueueTx } from "@/transactions/index.js" ;
99import * as SDK from "@al-ft/midgard-sdk" ;
1010import { NodeSdk } from "@effect/opentelemetry" ;
11- import { fromHex , getAddressDetails , toHex , CML } from "@lucid-evolution/lucid" ;
11+ import {
12+ fromHex ,
13+ getAddressDetails ,
14+ toHex ,
15+ CML ,
16+ } from "@lucid-evolution/lucid" ;
1217import { PrometheusExporter } from "@opentelemetry/exporter-prometheus" ;
1318import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-http" ;
1419import { BatchSpanProcessor } from "@opentelemetry/sdk-trace-base" ;
@@ -23,7 +28,7 @@ import {
2328 Queue ,
2429 Ref ,
2530 Schedule ,
26- Schema as S
31+ Schema as S ,
2732} from "effect" ;
2833import {
2934 AddressHistoryDB ,
@@ -66,7 +71,6 @@ import {
6671 txQueueProcessorFiber ,
6772} from "@/fibers/index.js" ;
6873import { RequestError } from "@effect/platform/HttpServerError" ;
69- import { isNotNull } from "effect/Predicate" ;
7074
7175const TX_ENDPOINT : string = "tx" ;
7276const ADDRESS_HISTORY_ENDPOINT : string = "txs" ;
@@ -104,10 +108,12 @@ const parseRequestBody = <A, I>(
104108 const result = S . decodeUnknownEither ( schema ) ( body ) ;
105109 if ( result . _tag === "Left" ) {
106110 yield * Effect . logInfo ( `Invalid request body: ${ result . left } ` ) ;
107- return yield * Effect . fail ( new RequestBodyParseError ( {
108- message : "Invalid request body" ,
109- cause : result . left ,
110- } ) ) ;
111+ return yield * Effect . fail (
112+ new RequestBodyParseError ( {
113+ message : "Invalid request body" ,
114+ cause : result . left ,
115+ } ) ,
116+ ) ;
111117 }
112118 return result . right ;
113119 } ) ;
@@ -120,10 +126,7 @@ const handleRequestBodyParseFailure = (
120126 Effect . gen ( function * ( ) {
121127 const msg = `${ method } /${ endpoint } - ${ error . message } : ${ error . cause } ` ;
122128 yield * Effect . logInfo ( msg ) ;
123- return yield * HttpServerResponse . json (
124- { error : msg } ,
125- { status : 400 } ,
126- ) ;
129+ return yield * HttpServerResponse . json ( { error : msg } , { status : 400 } ) ;
127130 } ) ;
128131
129132const failWith500Helper = (
@@ -635,7 +638,7 @@ const postTxOrderHandler = Effect.gen(function* () {
635638 { status : 400 } ,
636639 ) ;
637640 }
638- const refundAddressData = yield * SDK . addressDataFromBech32 ( refund_address ) ;
641+ const refundAddress = yield * SDK . midgardAddressFromBech32 ( refund_address ) ;
639642
640643 yield * lucid . switchToOperatorsMainWallet ;
641644
@@ -645,7 +648,7 @@ const postTxOrderHandler = Effect.gen(function* () {
645648 txOrderScriptAddress : txOrderAuthValidator . spendScriptAddress ,
646649 mintingPolicy : txOrderAuthValidator . mintScript ,
647650 policyId : txOrderAuthValidator . policyId ,
648- refundAddress : refundAddressData ,
651+ refundAddress : refundAddress ,
649652 refundDatum : refund_datum ,
650653 midgardTxBody : "" ,
651654 midgardTxWits : "" ,
@@ -664,7 +667,7 @@ const postTxOrderHandler = Effect.gen(function* () {
664667 } ) ;
665668} ) . pipe (
666669 Effect . catchTag ( "RequestBodyParseError" , ( e ) =>
667- handleRequestBodyParseFailure ( "POST" , TX_ORDER_ENDPOINT , e )
670+ handleRequestBodyParseFailure ( "POST" , TX_ORDER_ENDPOINT , e ) ,
668671 ) ,
669672 Effect . catchTag ( "HttpBodyError" , ( e ) =>
670673 failWith500 ( "POST" , TX_ORDER_ENDPOINT , e ) ,
@@ -711,7 +714,7 @@ const postDepositHandler = Effect.gen(function* () {
711714 { status : 400 } ,
712715 ) ;
713716 }
714- const l2DatumValue = datum ?? null
717+ const l2DatumValue = datum ?? null ;
715718
716719 yield * lucid . switchToOperatorsMainWallet ;
717720
@@ -741,7 +744,7 @@ const postDepositHandler = Effect.gen(function* () {
741744 } ) ;
742745} ) . pipe (
743746 Effect . catchTag ( "RequestBodyParseError" , ( e ) =>
744- handleRequestBodyParseFailure ( "POST" , DEPOSIT_ENDPOINT , e )
747+ handleRequestBodyParseFailure ( "POST" , DEPOSIT_ENDPOINT , e ) ,
745748 ) ,
746749 Effect . catchTag ( "HttpBodyError" , ( e ) =>
747750 failWith500 ( "POST" , DEPOSIT_ENDPOINT , e ) ,
@@ -798,7 +801,9 @@ const postWithdrawalHandler = Effect.gen(function* () {
798801 [ "" , new Map ( [ [ "" , BigInt ( withdrawal_body . l2_value ) ] ] ) ] ,
799802 ] ) ;
800803
801- const l1AddressData = yield * SDK . addressDataFromBech32 ( withdrawal_body . l1_address ) ;
804+ const l1Address = yield * SDK . midgardAddressFromBech32 (
805+ withdrawal_body . l1_address ,
806+ ) ;
802807
803808 const l1Datum : SDK . CardanoDatum =
804809 withdrawal_body . l1_datum === "NoDatum"
@@ -812,31 +817,28 @@ const postWithdrawalHandler = Effect.gen(function* () {
812817 } ) ,
813818 } ) ;
814819
815- const refundAddressData = yield * SDK . addressDataFromBech32 ( refund_address ) ;
820+ const refundAddress = yield * SDK . midgardAddressFromBech32 ( refund_address ) ;
816821
817822 yield * lucid . switchToOperatorsMainWallet ;
818823
819- const signedTx = yield * SDK . unsignedWithdrawalTxProgram (
820- lucid . api ,
821- {
822- withdrawalScriptAddress : withdrawalAuthValidator . spendScriptAddress ,
823- mintingPolicy : withdrawalAuthValidator . mintScript ,
824- policyId : withdrawalAuthValidator . policyId ,
825- withdrawalBody : {
826- l2_outref : {
827- txHash : { hash : withdrawal_body . l2_outref . txHash . hash } ,
828- outputIndex : BigInt ( withdrawal_body . l2_outref . outputIndex ) ,
829- } ,
830- l2_owner : withdrawal_body . l2_owner ,
831- l2_value : { inner : l2ValueInner } ,
832- l1_address : l1AddressData ,
833- l1_datum : l1Datum ,
824+ const signedTx = yield * SDK . unsignedWithdrawalTxProgram ( lucid . api , {
825+ withdrawalScriptAddress : withdrawalAuthValidator . spendScriptAddress ,
826+ mintingPolicy : withdrawalAuthValidator . mintScript ,
827+ policyId : withdrawalAuthValidator . policyId ,
828+ withdrawalBody : {
829+ l2_outref : {
830+ txHash : { hash : withdrawal_body . l2_outref . txHash . hash } ,
831+ outputIndex : BigInt ( withdrawal_body . l2_outref . outputIndex ) ,
834832 } ,
835- withdrawalSignature : withdrawalSignatureMap ,
836- refundAddress : refundAddressData ,
837- refundDatum : refund_datum ,
833+ l2_owner : withdrawal_body . l2_owner ,
834+ l2_value : { inner : l2ValueInner } ,
835+ l1_address : l1Address ,
836+ l1_datum : l1Datum ,
838837 } ,
839- ) ;
838+ withdrawalSignature : withdrawalSignatureMap ,
839+ refundAddress : refundAddress ,
840+ refundDatum : refund_datum ,
841+ } ) ;
840842
841843 yield * Effect . logInfo ( `Submitting withdrawal order tx...` ) ;
842844 const txHash = yield * handleSignSubmit ( lucid . api , signedTx ) ;
@@ -846,7 +848,7 @@ const postWithdrawalHandler = Effect.gen(function* () {
846848 } ) ;
847849} ) . pipe (
848850 Effect . catchTag ( "RequestBodyParseError" , ( e ) =>
849- handleRequestBodyParseFailure ( "POST" , WITHDRAWAL_ENDPOINT , e )
851+ handleRequestBodyParseFailure ( "POST" , WITHDRAWAL_ENDPOINT , e ) ,
850852 ) ,
851853 Effect . catchTag ( "HttpBodyError" , ( e ) =>
852854 failWith500 ( "POST" , WITHDRAWAL_ENDPOINT , e ) ,
0 commit comments