Skip to content

Commit 6f3ba0f

Browse files
committed
Address API changes
1 parent 8c9106a commit 6f3ba0f

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

src/BotPlutusInterface/Balance.hs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ import Ledger.Tx (
5656
TxOutRef (..),
5757
)
5858
import Ledger.Tx qualified as Tx
59+
import Ledger.Tx.CardanoAPI (CardanoBuildTx)
5960
import Ledger.Value (Value)
6061
import Ledger.Value qualified as Value
6162
import Plutus.V1.Ledger.Api (
@@ -394,9 +395,10 @@ addValidRange ::
394395
forall (w :: Type) (effs :: [Type -> Type]).
395396
Member (PABEffect w) effs =>
396397
POSIXTimeRange ->
397-
Tx ->
398+
Either CardanoBuildTx Tx ->
398399
Eff effs (Either Text Tx)
399-
addValidRange timeRange tx =
400+
addValidRange _ (Left _) = pure $ Left "BPI is not using CardanoBuildTx"
401+
addValidRange timeRange (Right tx) =
400402
if validateRange timeRange
401403
then
402404
bimap (Text.pack . show) (setRange tx)

src/BotPlutusInterface/CardanoCLI.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ import Ledger.Scripts qualified as Scripts
7575
import Ledger.Tx (ChainIndexTxOut, RedeemerPtr (..), Redeemers, ScriptTag (..), Tx (..), TxId (..), TxIn (..), TxInType (..), TxOut (..), TxOutRef (..), txId)
7676
import Ledger.Value (Value)
7777
import Ledger.Value qualified as Value
78-
import Plutus.Contract.CardanoAPI (toCardanoAddress)
78+
import Ledger.Tx.CardanoAPI (toCardanoAddressInEra)
7979
import Plutus.V1.Ledger.Api (
8080
CurrencySymbol (..),
8181
ExBudget (..),
@@ -399,7 +399,7 @@ valueToCliArg val =
399399

400400
unsafeSerialiseAddress :: NetworkId -> Address -> Text
401401
unsafeSerialiseAddress network address =
402-
case serialiseAddress <$> toCardanoAddress network address of
402+
case serialiseAddress <$> toCardanoAddressInEra network address of
403403
Right a -> a
404404
Left _ -> error "Couldn't create address"
405405

src/BotPlutusInterface/Contract.hs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ import Data.Aeson.Extras (encodeByteString)
4848
import Data.Aeson.KeyMap qualified as KeyMap
4949
import Data.Function (fix)
5050
import Data.Kind (Type)
51+
import Data.List.NonEmpty (NonEmpty ((:|)))
5152
import Data.Map qualified as Map
5253
import Data.Row (Row)
5354
import Data.Text (Text)
@@ -171,8 +172,13 @@ handlePABReq contractEnv req = do
171172
----------------------
172173
-- Handled requests --
173174
----------------------
174-
OwnPaymentPublicKeyHashReq ->
175-
pure $ OwnPaymentPublicKeyHashResp $ PaymentPubKeyHash contractEnv.cePABConfig.pcOwnPubKeyHash
175+
OwnAddressesReq ->
176+
pure
177+
. OwnAddressesResp
178+
. nonEmptySingleton
179+
$ Ledger.pubKeyHashAddress
180+
(PaymentPubKeyHash contractEnv.cePABConfig.pcOwnPubKeyHash)
181+
contractEnv.cePABConfig.pcOwnStakePubKeyHash
176182
OwnContractInstanceIdReq ->
177183
pure $ OwnContractInstanceIdResp (ceContractInstanceId contractEnv)
178184
ChainIndexQueryReq query ->
@@ -451,3 +457,9 @@ currentTime contractEnv =
451457
currentSlot @w contractEnv
452458
>>= slotToPOSIXTime @w
453459
>>= either (error . show) return
460+
461+
{- | Construct a 'NonEmpty' list from a single element.
462+
Should be replaced by NonEmpty.singleton after updating to base 4.15
463+
-}
464+
nonEmptySingleton :: a -> NonEmpty a
465+
nonEmptySingleton = (:| [])

0 commit comments

Comments
 (0)