@@ -18,6 +18,7 @@ module Cardano.Rpc.Server.Internal.UtxoRpc.Type
1818 , utxoRpcTxOutputToTxOut
1919 , protocolParamsToUtxoRpcPParams
2020 , simpleScriptToUtxoRpcNativeScript
21+ , utxoRpcBigIntToInteger
2122 , mkChainPointMsg
2223 )
2324where
@@ -70,20 +71,20 @@ protocolParamsToUtxoRpcPParams era pparams = obtainCommonConstraints era $ do
7071 drepVotingThresholds :: L. DRepVotingThresholds =
7172 pparams ^. L. ppDRepVotingThresholdsL
7273 def
73- & # coinsPerUtxoByte .~ pparams ^. L. ppCoinsPerUTxOByteL . to L. unCoinPerByte . to fromIntegral
74+ & # coinsPerUtxoByte .~ pparams ^. L. ppCoinsPerUTxOByteL . to L. unCoinPerByte . to inject
7475 & # maxTxSize .~ pparams ^. L. ppMaxTxSizeL . to fromIntegral
75- & # minFeeCoefficient .~ pparams ^. L. ppMinFeeBL . to fromIntegral
76- & # minFeeConstant .~ pparams ^. L. ppMinFeeAL . to fromIntegral
76+ & # minFeeCoefficient .~ pparams ^. L. ppMinFeeBL . to inject
77+ & # minFeeConstant .~ pparams ^. L. ppMinFeeAL . to inject
7778 & # maxBlockBodySize .~ pparams ^. L. ppMaxBBSizeL . to fromIntegral
7879 & # maxBlockHeaderSize .~ pparams ^. L. ppMaxBHSizeL . to fromIntegral
79- & # stakeKeyDeposit .~ pparams ^. L. ppKeyDepositL . to fromIntegral
80- & # poolDeposit .~ pparams ^. L. ppPoolDepositL . to fromIntegral
80+ & # stakeKeyDeposit .~ pparams ^. L. ppKeyDepositL . to inject
81+ & # poolDeposit .~ pparams ^. L. ppPoolDepositL . to inject
8182 & # poolRetirementEpochBound .~ pparams ^. L. ppEMaxL . to L. unEpochInterval . to fromIntegral
8283 & # desiredNumberOfPools .~ pparams ^. L. ppNOptL . to fromIntegral
8384 & # poolInfluence .~ pparams ^. L. ppA0L . to L. unboundRational . to inject
8485 & # monetaryExpansion .~ pparams ^. L. ppRhoL . to L. unboundRational . to inject
8586 & # treasuryExpansion .~ pparams ^. L. ppTauL . to L. unboundRational . to inject
86- & # minPoolCost .~ pparams ^. L. ppMinPoolCostL . to fromIntegral
87+ & # minPoolCost .~ pparams ^. L. ppMinPoolCostL . to inject
8788 & # protocolVersion . # major .~ pparams ^. L. ppProtocolVersionL . to L. pvMajor . to L. getVersion
8889 & # protocolVersion . # minor .~ pparams ^. L. ppProtocolVersionL . to L. pvMinor . to fromIntegral
8990 & # maxValueSize .~ pparams ^. L. ppMaxValSizeL . to fromIntegral
@@ -129,8 +130,8 @@ protocolParamsToUtxoRpcPParams era pparams = obtainCommonConstraints era $ do
129130 .~ pparams ^. L. ppCommitteeMaxTermLengthL . to L. unEpochInterval . to fromIntegral
130131 & # governanceActionValidityPeriod
131132 .~ pparams ^. L. ppGovActionLifetimeL . to L. unEpochInterval . to fromIntegral
132- & # governanceActionDeposit .~ pparams ^. L. ppGovActionDepositL . to fromIntegral
133- & # drepDeposit .~ pparams ^. L. ppDRepDepositL . to fromIntegral
133+ & # governanceActionDeposit .~ pparams ^. L. ppGovActionDepositL . to inject
134+ & # drepDeposit .~ pparams ^. L. ppDRepDepositL . to inject
134135 & # drepInactivityPeriod .~ pparams ^. L. ppDRepActivityL . to L. unEpochInterval . to fromIntegral
135136
136137utxoRpcPParamsToProtocolParams
@@ -140,8 +141,10 @@ utxoRpcPParamsToProtocolParams
140141utxoRpcPParamsToProtocolParams era pp = conwayEraOnwardsConstraints (convert era) $ do
141142 def
142143 & appFuns
143- [ pure
144- . (L. ppCoinsPerUTxOByteL .~ pp ^. # coinsPerUtxoByte . to fromIntegral . to L. Coin . to L. CoinPerByte )
144+ [ \ r -> do
145+ coinsPerUtxoByte <-
146+ pp ^. # coinsPerUtxoByte . to utxoRpcBigIntToInteger ?! " Invalid coinsPerUtxoByte"
147+ pure $ set L. ppCoinsPerUTxOByteL (L. CoinPerByte $ L. Coin coinsPerUtxoByte) r
145148 , pure . (L. ppMaxTxSizeL .~ pp ^. # maxTxSize . to fromIntegral )
146149 , pure . (L. ppMinFeeBL .~ pp ^. # minFeeCoefficient . to fromIntegral )
147150 , pure . (L. ppMinFeeAL .~ pp ^. # minFeeConstant . to fromIntegral )
@@ -399,15 +402,7 @@ scriptDataToUtxoRpcPlutusData :: ScriptData -> Proto UtxoRpc.PlutusData
399402scriptDataToUtxoRpcPlutusData = \ case
400403 ScriptDataBytes bs ->
401404 defMessage & # boundedBytes .~ bs
402- ScriptDataNumber int
403- | int <= fromIntegral (maxBound @ Int64 )
404- && int >= fromIntegral (minBound @ Int64 ) ->
405- defMessage & # bigInt . # int .~ fromIntegral int
406- | int < 0 ->
407- -- https://www.rfc-editor.org/rfc/rfc8949.html#name-bignums see 3.4.3 for negative integers
408- defMessage & # bigInt . # bigNInt .~ serialiseToRawBytes (fromIntegral @ _ @ Natural (- 1 - int))
409- | otherwise ->
410- defMessage & # bigInt . # bigUInt .~ serialiseToRawBytes (fromIntegral @ _ @ Natural int)
405+ ScriptDataNumber int -> defMessage & # bigInt .~ inject int
411406 ScriptDataList sds ->
412407 defMessage & # array . # items .~ map scriptDataToUtxoRpcPlutusData sds
413408 ScriptDataMap elements -> do
@@ -563,3 +558,18 @@ utxoRpcTxOutputToTxOut txOutput = do
563558 )
564559 datum
565560 referenceScript
561+
562+ utxoRpcBigIntToInteger
563+ :: forall m
564+ . HasCallStack
565+ => MonadThrow m
566+ => Proto UtxoRpc. BigInt
567+ -> m Integer
568+ utxoRpcBigIntToInteger bigInt
569+ | Just int <- bigInt ^. # maybe'int = fromIntegral int
570+ | Just bytes <- bigInt ^. # maybe'bigNInt = do
571+ n <- fmap fromIntegral . liftEitherError $ deserialiseFromRawBytes AsNatural bytes
572+ pure $ - n - 1
573+ | Just bytes <- bigInt ^. # maybe'bigUInt =
574+ map fromIntegral . liftEitherError $ deserialiseFromRawBytes AsNatural bytes
575+ | otherwise = pure 0 -- assume default value
0 commit comments