-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add functions for retrieving own (un)registered pub stake keys
Add DelegateVoteAbstain example
- Loading branch information
Showing
10 changed files
with
164 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
module Ctl.Examples.Gov.DelegateVoteAbstain | ||
( contract | ||
, example | ||
, main | ||
) where | ||
|
||
import Contract.Prelude | ||
|
||
import Cardano.Transaction.Builder (TransactionBuilderStep(IssueCertificate)) | ||
import Cardano.Types.Certificate (Certificate(VoteRegDelegCert)) | ||
import Cardano.Types.Credential (Credential(PubKeyHashCredential)) | ||
import Cardano.Types.DRep (DRep(AlwaysAbstain)) | ||
import Cardano.Types.PublicKey (hash) as PublicKey | ||
import Cardano.Types.Transaction (hash) as Transaction | ||
import Contract.Config | ||
( ContractParams | ||
, WalletSpec(ConnectToGenericCip30) | ||
, testnetConfig | ||
) | ||
import Contract.Log (logDebug', logInfo') | ||
import Contract.Monad (Contract, launchAff_, runContract) | ||
import Contract.ProtocolParameters (getProtocolParameters) | ||
import Contract.Transaction (awaitTxConfirmed, submitTxFromBuildPlan) | ||
import Contract.Wallet (ownUnregisteredPubStakeKeys) | ||
import Data.Array (head) as Array | ||
import Data.Map (empty) as Map | ||
import Effect.Exception (error) | ||
|
||
main :: Effect Unit | ||
main = example $ testnetConfig | ||
{ walletSpec = Just $ ConnectToGenericCip30 "eternl" { cip95: true } | ||
} | ||
|
||
example :: ContractParams -> Effect Unit | ||
example = launchAff_ <<< flip runContract contract | ||
|
||
contract :: Contract Unit | ||
contract = do | ||
logInfo' "Running Examples.Gov.DelegateVoteAbstain" | ||
|
||
unregPubStakeKeys <- ownUnregisteredPubStakeKeys | ||
logDebug' $ "Unregistered public stake keys: " <> show unregPubStakeKeys | ||
|
||
pubStakeKey <- liftM (error "Failed to get unregistered pub stake key") $ | ||
Array.head unregPubStakeKeys | ||
let stakeCred = wrap $ PubKeyHashCredential $ PublicKey.hash pubStakeKey | ||
|
||
stakeCredDeposit <- _.stakeAddressDeposit <<< unwrap <$> | ||
getProtocolParameters | ||
|
||
tx <- submitTxFromBuildPlan Map.empty mempty | ||
[ IssueCertificate | ||
(VoteRegDelegCert stakeCred AlwaysAbstain stakeCredDeposit) | ||
Nothing | ||
] | ||
|
||
awaitTxConfirmed $ Transaction.hash tx | ||
logInfo' "Tx submitted successfully!" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters