3
3
import com .bloxbean .cardano .client .address .Address ;
4
4
import com .bloxbean .cardano .client .address .Credential ;
5
5
import com .bloxbean .cardano .client .api .model .Amount ;
6
+ import com .bloxbean .cardano .client .api .model .ProtocolParams ;
6
7
import com .bloxbean .cardano .client .function .TxBuilder ;
7
8
import com .bloxbean .cardano .client .function .exception .TxBuildException ;
8
9
import com .bloxbean .cardano .client .transaction .spec .TransactionOutput ;
26
27
27
28
@ Slf4j
28
29
public 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 ;
32
37
33
38
protected List <RegDRepCert > dRepRegistrations ;
34
39
protected List <DRepDeregestrationContext > dRepDeregestrationContexts ;
@@ -37,6 +42,21 @@ public class GovTx {
37
42
protected List <VotingProcedureContext > votingProcedureContexts ;
38
43
protected List <VoteDelegCert > voteDelegCerts ;
39
44
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
+
40
60
/**
41
61
* Register DRep
42
62
* @param drepCredential DRep credential
@@ -47,7 +67,7 @@ public GovTx registerDRep(@NonNull Credential drepCredential, Anchor anchor) {
47
67
var regDRepCert = RegDRepCert .builder ()
48
68
.drepCredential (drepCredential )
49
69
.anchor (anchor )
50
- .coin (DREP_REG_DEPOSIT )
70
+ .coin (drepRegDeposit )
51
71
.build ();
52
72
53
73
if (dRepRegistrations == null )
@@ -87,7 +107,7 @@ public GovTx registerDRep(@NonNull Credential drepCredential, @NonNull BigIntege
87
107
*/
88
108
public GovTx unregisterDRep (@ NonNull Credential drepCredential , String refundAddress , BigInteger refundAmount ) {
89
109
if (refundAmount == null )
90
- refundAmount = DREP_REG_DEPOSIT ;
110
+ refundAmount = drepRegDeposit ;
91
111
92
112
var unregDRepCert = UnregDRepCert .builder ()
93
113
.drepCredential (drepCredential )
@@ -213,7 +233,7 @@ private List<GovTx.PaymentContext> buildGovernancePayments(String fromAddress, S
213
233
214
234
if (dRepRegistrations != null && dRepRegistrations .size () > 0 ) {
215
235
//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 ())));
217
237
paymentContexts .add (new GovTx .PaymentContext (fromAddress , totalDRepRegistrationDepositAmount ));
218
238
}
219
239
@@ -252,8 +272,6 @@ private TxBuilder buildDRepRegistration(TxBuilder txBuilder, String fromAddress)
252
272
253
273
certificates .addAll (dRepRegistrations );
254
274
255
- String drepRegDepositParam = DREP_REG_DEPOSIT .toString ();//context.getProtocolParams().getKeyDeposit(); //TODO -- Get protocol param
256
- BigInteger drepRegDeposit = new BigInteger (drepRegDepositParam );
257
275
BigInteger totalDRepRegDeposit = drepRegDeposit .multiply (BigInteger .valueOf (dRepRegistrations .size ()));
258
276
log .debug ("Total stakekey registration deposit: " + totalDRepRegDeposit );
259
277
0 commit comments