Skip to content

Commit 4a77130

Browse files
add DRep retirement command
1 parent 466a587 commit 4a77130

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Tutorial : [Quick Start with Gov-Cli](https://cardanoapi.github.io/gov-cli/docs/
1717
|------------------------------|----------------------------------------|----------------------------------------------------|
1818
| `CARDANO_NODE_SOCKET_PATH` | Node's socket path | (e.g., path to the socket file) |
1919
| `NETWORK` | Cardano network | `1`, `2`, `3`, `4`, `mainnet`, `preprod`, `sancho`, `preview` |
20-
| `KEYS_DIR` | Where keys are generated and stored | `$HOME/.cardano/key` |
20+
| `KEYS_DIR` | Where keys are generated and stored | `$HOME/.cardano/key` |
2121
| `LOG_CLI` | Show commands executed in CLI | `yes`, `no`, `false` |
2222

2323

clean-keys.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
rm -rf $HOME/.cardano/keys/

gov_cli/gov_cli.py

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,27 @@ def register_drep(self, wallet: Wallet, drep: Key):
408408
else:
409409
print(f"DRep registration transaction submitted successfully!\nTx ID: {submit_result.txid}")
410410

411-
411+
def deregister_drep(self, wallet:Wallet, drep: Key):
412+
drep_cert = os.path.join(TEMP_DIR, "drep_retire.cert")
413+
# Generate DRep retirement certificate
414+
self.load_gov_state()
415+
self.cardano_cli_conway("governance", "drep",
416+
[ "retirement-certificate","--drep-verification-key-file", drep.public, "--deposit-amt",
417+
str(self.gov_state["currentPParams"]["dRepDeposit"])
418+
,"--out-file", drep_cert])
419+
submit_result:SubmitResult=self.build_and_submit(wallet,'drep_reg',
420+
["--witness-override","2",
421+
"--certificate-file", drep_cert]
422+
423+
,raise_error=False,extra_keys=[drep.private])
424+
if submit_result.process.returncode != 0 :
425+
if "ConwayDRepNotRegistered" in submit_result.process.stderr:
426+
print("DRep key is not registered ...")
427+
print("Nothing was done on-chain.")
428+
else:
429+
raise Exception (f"Process failed \n {submit_result.process.stdout} \n {submit_result.process.stderr}")
430+
else:
431+
print(f"DRep retirement transaction submitted successfully!\nTx ID: {submit_result.txid}")
412432

413433
def sign_and_submit(self,wallet:Wallet,tx_raw_file,signed_tx_file,raise_error=True,extra_keys=[])->Optional[SubmitResult]:
414434
# Sign the transaction
@@ -640,6 +660,15 @@ def vote(store:WalletStore,role):
640660
print("Registering stake key")
641661
# Register stake key
642662
cli.register_stake(wallet)
663+
elif command == "deregister":
664+
store=WalletStore(KEYS_DIR)
665+
wallet = store.load_wallet()
666+
667+
if len(sys.argv)>2:
668+
if sys.argv[2] == "drep":
669+
drep=store.load_drep_key()
670+
cli.deregister_drep(wallet,drep)
671+
643672
elif command == 'delegate':
644673
store=WalletStore(KEYS_DIR)
645674
wallet = store.load_wallet()

0 commit comments

Comments
 (0)