33import com .bloxbean .cardano .client .address .Address ;
44import com .bloxbean .cardano .client .address .Credential ;
55import com .bloxbean .cardano .client .api .model .Amount ;
6+ import com .bloxbean .cardano .client .api .model .ProtocolParams ;
67import com .bloxbean .cardano .client .function .TxBuilder ;
78import com .bloxbean .cardano .client .function .exception .TxBuildException ;
89import com .bloxbean .cardano .client .transaction .spec .TransactionOutput ;
2627
2728@ Slf4j
2829public class GovTx {
29- //TODO -- Read from protocol
30- public static final BigInteger DREP_REG_DEPOSIT = adaToLovelace (500.0 );
31- public static final Amount DUMMY_MIN_OUTPUT_VAL = Amount .ada (1.0 );
30+ private static final BigInteger DEFAULT_DREP_REG_DEPOSIT = adaToLovelace (500.0 );
31+ private static final BigInteger DEFAULT_GOV_ACTION_DEPOSIT = adaToLovelace (50000 );
32+
33+ private static final Amount DUMMY_MIN_OUTPUT_VAL = Amount .ada (1.0 );
34+
35+ protected BigInteger drepRegDeposit ;
36+ protected BigInteger govActionDeposit ;
3237
3338 protected List <RegDRepCert > dRepRegistrations ;
3439 protected List <DRepDeregestrationContext > dRepDeregestrationContexts ;
@@ -37,6 +42,21 @@ public class GovTx {
3742 protected List <VotingProcedureContext > votingProcedureContexts ;
3843 protected List <VoteDelegCert > voteDelegCerts ;
3944
45+ public GovTx () {
46+ drepRegDeposit = DEFAULT_DREP_REG_DEPOSIT ;
47+ govActionDeposit = DEFAULT_GOV_ACTION_DEPOSIT ;
48+ }
49+
50+ public GovTx (ProtocolParams protocolParams ) {
51+ if (protocolParams != null ) {
52+ drepRegDeposit = protocolParams .getDrepDeposit ();
53+ govActionDeposit = protocolParams .getGovActionDeposit ();
54+ } else {
55+ drepRegDeposit = DEFAULT_DREP_REG_DEPOSIT ;
56+ govActionDeposit = DEFAULT_GOV_ACTION_DEPOSIT ;
57+ }
58+ }
59+
4060 /**
4161 * Register DRep
4262 * @param drepCredential DRep credential
@@ -47,7 +67,7 @@ public GovTx registerDRep(@NonNull Credential drepCredential, Anchor anchor) {
4767 var regDRepCert = RegDRepCert .builder ()
4868 .drepCredential (drepCredential )
4969 .anchor (anchor )
50- .coin (DREP_REG_DEPOSIT )
70+ .coin (drepRegDeposit )
5171 .build ();
5272
5373 if (dRepRegistrations == null )
@@ -87,7 +107,7 @@ public GovTx registerDRep(@NonNull Credential drepCredential, @NonNull BigIntege
87107 */
88108 public GovTx unregisterDRep (@ NonNull Credential drepCredential , String refundAddress , BigInteger refundAmount ) {
89109 if (refundAmount == null )
90- refundAmount = DREP_REG_DEPOSIT ;
110+ refundAmount = drepRegDeposit ;
91111
92112 var unregDRepCert = UnregDRepCert .builder ()
93113 .drepCredential (drepCredential )
@@ -213,7 +233,7 @@ private List<GovTx.PaymentContext> buildGovernancePayments(String fromAddress, S
213233
214234 if (dRepRegistrations != null && dRepRegistrations .size () > 0 ) {
215235 //Dummy pay to fromAddress to add deposit
216- Amount totalDRepRegistrationDepositAmount = Amount .lovelace (DREP_REG_DEPOSIT .multiply (BigInteger .valueOf (dRepRegistrations .size ())));
236+ Amount totalDRepRegistrationDepositAmount = Amount .lovelace (drepRegDeposit .multiply (BigInteger .valueOf (dRepRegistrations .size ())));
217237 paymentContexts .add (new GovTx .PaymentContext (fromAddress , totalDRepRegistrationDepositAmount ));
218238 }
219239
@@ -252,8 +272,6 @@ private TxBuilder buildDRepRegistration(TxBuilder txBuilder, String fromAddress)
252272
253273 certificates .addAll (dRepRegistrations );
254274
255- String drepRegDepositParam = DREP_REG_DEPOSIT .toString ();//context.getProtocolParams().getKeyDeposit(); //TODO -- Get protocol param
256- BigInteger drepRegDeposit = new BigInteger (drepRegDepositParam );
257275 BigInteger totalDRepRegDeposit = drepRegDeposit .multiply (BigInteger .valueOf (dRepRegistrations .size ()));
258276 log .debug ("Total stakekey registration deposit: " + totalDRepRegDeposit );
259277
0 commit comments