Skip to content

Commit

Permalink
chore: #50 Customization for initial balance
Browse files Browse the repository at this point in the history
  • Loading branch information
satran004 committed Jun 2, 2024
1 parent 24e80c5 commit 90ad9c2
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 29 deletions.
6 changes: 5 additions & 1 deletion applications/cli/config/node.properties
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
protocolMagic=42
#protocolMagic=42
#
#disableFaucet=true
#initialFunds.008c5bf0f2af6f1ef08bb3f6ec702dd16e1c514b7e1d12f7549b47db9f4d943c7af0aaec774757d4745d1a2c8dd3220e6ec2c9df23f757a2f8=40000
#initialFunds.005154f7a46e7fe9eb003e6a1a5a184685dbec77fa336c9f1abcf5c5e601b135a188a0e114739809762b650a2ca5ea8f20060d867bcca39a18=10000
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
package com.bloxbean.cardano.yacicli.commands.localcluster.config;

import jakarta.annotation.PostConstruct;
import lombok.*;
import org.springframework.boot.context.properties.ConfigurationProperties;

import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;

@ConfigurationProperties(ignoreUnknownFields = true)
@Data
Expand Down Expand Up @@ -90,6 +88,52 @@ public class GenesisConfig {
private BigInteger dRepDeposit = BigInteger.valueOf(2000000);
private int dRepActivity = 20;

private boolean disableFaucet = false;
//Default faucet address
private Map<String, BigInteger> faucets= new LinkedHashMap<>();
private Map<String, BigInteger> initialFunds = new LinkedHashMap<>();
private List<MapItem<String, BigInteger>> initialFundsList = new ArrayList<>();

@PostConstruct
public void postInit() {
if (faucets.size() == 0 && !disableFaucet) {
faucets = Map.of(
"007290ea8fa9433c1045a4c8473959ad608e6c03a58c7de33bdbd3ce6f295b987135610616f3c74e11c94d77b6ced5ccc93a7d719cfb135062", BigInteger.valueOf(300000000000L),
"605276322ac7882434173dcc6441905f6737689bd309b68ad8b3614fd8", BigInteger.valueOf(3000000000000000L),
"60a0f1aa7dca95017c11e7e373aebcf0c4568cf47ec12b94f8eb5bba8b", BigInteger.valueOf(3000000000000000L),
"60ba957a0fff6816021b2afa7900beea68fd10f2d78fb5b64de0d2379c", BigInteger.valueOf(3000000000000000L)
);
}

if (initialFunds.size() == 0) {
initialFunds.put( "00c8c47610a36034aac6fc58848bdae5c278d994ff502c05455e3b3ee8f8ed3a0eea0ef835ffa7bbfcde55f7fe9d2cc5d55ea62cecb42bab3c", BigInteger.valueOf(10000000000L));
initialFunds.put( "004048ff89ca4f88e66598e620aa0c7128c2145d9a181ae9a4a81ca8e3e849af38840c5562dd382be37c9e76545c8191f9d8f6df1d20cfcee0", BigInteger.valueOf(10000000000L));
initialFunds.put( "00ca6e1b1f320d543a24adeabc0aa4627635c7349b639f86f74bdfdd78d31b28c9619a58b3792a7394ab85deb36889c4d7b0632c8167b855d2", BigInteger.valueOf(10000000000L));
initialFunds.put( "0007d781fe8e33883e371f9550c2f1087321fc32e06e80b65e349ccb027702d6880e86e77a0520efa37ede45002a1de43b68692e175b742e67", BigInteger.valueOf(10000000000L));
initialFunds.put( "00627b2598dd71129167825160c564067d1d245e79cc237094815c5cb2b125e30ec2f4ce4059a069e08c3cd82cdfc9451bfb22487f8a25ceef", BigInteger.valueOf(10000000000L));
initialFunds.put( "00c6cf7bd50f37f7e4cc161fc00f07e9b2226ba5552ccaf30d315fa0135bbc8cbd9ab5379f368fc8d3500c37a9d14074cc6ddad89e3686f0e0", BigInteger.valueOf(10000000000L));
initialFunds.put( "005164ab186715c86378020956d892cf72f67636b78967d67cfe7360479130dc89cf7a9bc89109f939956b66f93293ade4c3920b72fd40beea", BigInteger.valueOf(10000000000L));
initialFunds.put( "003dd38742e9848c6f12c13ddb1f9464fc0ce0bb92102768087975317e5a9f869fcd913562c9b0e0f01f77e5359ea780d37f9355f9702eff8b", BigInteger.valueOf(10000000000L));
initialFunds.put( "0088e7e670b45cab2322b518ef7b6f66d30aec0d923dc463e467091a790f67796b9fa71224f2846cebbcf4950c11e040ee124d30f6e164bcd5", BigInteger.valueOf(10000000000L));
initialFunds.put( "00c70b8421617802d3f23956cab1957e1d306cd4808589b41760e97927ebfd6053ba12b38288b2b6d5d4c4618d6a8ce59d50580e9c6f704af5", BigInteger.valueOf(10000000000L));
initialFunds.put( "00c0933b8238f6f3332e48c34cf1a8e0555943b33cd4abc53aefb7d6124b7ce40dd496bdc02b34602f3a773ff7cccee873991e4c8866f3a70b", BigInteger.valueOf(10000000000L));
initialFunds.put( "0069f7d7289de2f01cd1e0265ac5be943b41775abae0ce6b3eac0edee0ce9cadb7cdec2bded3ef8a7bbe3352869bfc1387754c9ee6b1782d9c", BigInteger.valueOf(10000000000L));
initialFunds.put( "00709a7070005c652c27df73dbbde3319a90b127bea96aded1c5fb87a59c51dbcf90fa890174497f3f66a0dad06eb7f131e06567995e9c50a5", BigInteger.valueOf(10000000000L));
initialFunds.put( "00fc576df3a279885a7a4d0fc500372daa1d96f26c6763542ecd2ad8551753024adea37c134edebb68dc0cfaed5a7009e8305fe1fed8d0ccd1", BigInteger.valueOf(10000000000L));
initialFunds.put( "003346a630e6972bf38cce87219db1d63061e7cd324cad88c18e504f2990cac68e973f51256ca938683fa4ea12173d7d047d940fbb883bd0e8", BigInteger.valueOf(10000000000L));
initialFunds.put( "0028b862d001e6a64a02b3560cbc532eab4557593477c39cc523e0b9fc527100898c11e731194171b908aad463770d6cbf7ec8871c4cb1e518", BigInteger.valueOf(10000000000L));
initialFunds.put( "005e0e57040b06e9d71e0f28f126262838a68db0b52b4fd1b3877dda2203d5d7d4f19c5ee3a1ed51bb670779de19d40aaff2e5e9468cc05c5e", BigInteger.valueOf(10000000000L));
initialFunds.put( "00367f65ab69b1e6715c8d5a14964214c9505ed17032266b3209a2c40dcbae9a2a881e603ff39d36e987bacfb87ee98051f222c5fe3efd350c", BigInteger.valueOf(10000000000L));
initialFunds.put( "00c5c4ca287f3b53948b5468e5e23b1c87fe61ce52c0d9afd65d070795038751a619d463e91eaed0a774ebdb2f8e12a01a378a153bc3627323", BigInteger.valueOf(10000000000L));
initialFunds.put( "00ef198fb7c35e1968308a0b75cfee54a46e13e86dd3354283300831d624165c357b5a0413906a0bfea8ba57587331f0836a186d632ed041b8", BigInteger.valueOf(10000000000L));
}

if (faucets.size() > 0 && !disableFaucet)
initialFunds.putAll(faucets);

initialFundsList = createListWithLastFlag(initialFunds);
}

public Map getConfigMap() {
Map map = new HashMap();
map.put("networkId", networkId);
Expand Down Expand Up @@ -156,6 +200,8 @@ public Map getConfigMap() {
map.put("dRepDeposit", dRepDeposit);
map.put("dRepActivity", dRepActivity);

map.put("initialFunds", initialFundsList);

return map;
}

Expand Down Expand Up @@ -224,9 +270,26 @@ public GenesisConfig copy() {
genesisConfig.setDRepDeposit(dRepDeposit);
genesisConfig.setDRepActivity(dRepActivity);

genesisConfig.setFaucets(faucets);
genesisConfig.setInitialFunds(initialFunds);
genesisConfig.setInitialFundsList(initialFundsList);

return genesisConfig;
}

private <K, V> List<MapItem<K, V>> createListWithLastFlag(Map<K, V> faucets) {
List<MapItem<K, V>> faucetList = new ArrayList<>();
int i = 0;
int size = faucets.size();
for (Map.Entry<K, V> entry : faucets.entrySet()) {
var item = new MapItem<K, V>(entry.getKey(), entry.getValue(), i == size - 1);
faucetList.add(item);
i++;
}

return faucetList;
}

}

@Data
Expand All @@ -244,3 +307,4 @@ class Pool {
}

record Delegator(String stakeKeyHash, String poolHash) {}
record MapItem<K, V>(K key, V value, boolean last) {}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public List<DefaultAddress> getDefaultAddresses() {
var defaultAddress = new DefaultAddress();
defaultAddress.setDerivationPath(derivationPath);
defaultAddress.setAddress(account.baseAddress());
defaultAddress.setAddressHex(HexUtil.encodeHexString(new Address(account.baseAddress()).getBytes()));
defaultAddress.setStakeAddress(account.stakeAddress());
defaultAddress.setPaymentKey(Bech32.encode(account.privateKeyBytes(), ED_25519_E_SK));
defaultAddress.setStakingKey(Bech32.encode(account.stakeHdKeyPair().getPrivateKey().getKeyData(), ED_25519_E_SK));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
public class DefaultAddress {
private DerivationPath derivationPath;
private String address;
private String addressHex;
private String stakeAddress;
private String paymentKey;
private String stakingKey;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,11 @@
}
},
"initialFunds": {
"007290ea8fa9433c1045a4c8473959ad608e6c03a58c7de33bdbd3ce6f295b987135610616f3c74e11c94d77b6ced5ccc93a7d719cfb135062": 300000000000,
"605276322ac7882434173dcc6441905f6737689bd309b68ad8b3614fd8": 3000000000000000,
"60a0f1aa7dca95017c11e7e373aebcf0c4568cf47ec12b94f8eb5bba8b": 3000000000000000,
"60ba957a0fff6816021b2afa7900beea68fd10f2d78fb5b64de0d2379c": 3000000000000000,
"00c8c47610a36034aac6fc58848bdae5c278d994ff502c05455e3b3ee8f8ed3a0eea0ef835ffa7bbfcde55f7fe9d2cc5d55ea62cecb42bab3c": 10000000000,
"004048ff89ca4f88e66598e620aa0c7128c2145d9a181ae9a4a81ca8e3e849af38840c5562dd382be37c9e76545c8191f9d8f6df1d20cfcee0": 10000000000,
"00ca6e1b1f320d543a24adeabc0aa4627635c7349b639f86f74bdfdd78d31b28c9619a58b3792a7394ab85deb36889c4d7b0632c8167b855d2": 10000000000,
"0007d781fe8e33883e371f9550c2f1087321fc32e06e80b65e349ccb027702d6880e86e77a0520efa37ede45002a1de43b68692e175b742e67": 10000000000,
"00627b2598dd71129167825160c564067d1d245e79cc237094815c5cb2b125e30ec2f4ce4059a069e08c3cd82cdfc9451bfb22487f8a25ceef": 10000000000,
"00c6cf7bd50f37f7e4cc161fc00f07e9b2226ba5552ccaf30d315fa0135bbc8cbd9ab5379f368fc8d3500c37a9d14074cc6ddad89e3686f0e0": 10000000000,
"005164ab186715c86378020956d892cf72f67636b78967d67cfe7360479130dc89cf7a9bc89109f939956b66f93293ade4c3920b72fd40beea": 10000000000,
"003dd38742e9848c6f12c13ddb1f9464fc0ce0bb92102768087975317e5a9f869fcd913562c9b0e0f01f77e5359ea780d37f9355f9702eff8b": 10000000000,
"0088e7e670b45cab2322b518ef7b6f66d30aec0d923dc463e467091a790f67796b9fa71224f2846cebbcf4950c11e040ee124d30f6e164bcd5": 10000000000,
"00c70b8421617802d3f23956cab1957e1d306cd4808589b41760e97927ebfd6053ba12b38288b2b6d5d4c4618d6a8ce59d50580e9c6f704af5": 10000000000,
"00c0933b8238f6f3332e48c34cf1a8e0555943b33cd4abc53aefb7d6124b7ce40dd496bdc02b34602f3a773ff7cccee873991e4c8866f3a70b": 10000000000,
"0069f7d7289de2f01cd1e0265ac5be943b41775abae0ce6b3eac0edee0ce9cadb7cdec2bded3ef8a7bbe3352869bfc1387754c9ee6b1782d9c": 10000000000,
"00709a7070005c652c27df73dbbde3319a90b127bea96aded1c5fb87a59c51dbcf90fa890174497f3f66a0dad06eb7f131e06567995e9c50a5": 10000000000,
"00fc576df3a279885a7a4d0fc500372daa1d96f26c6763542ecd2ad8551753024adea37c134edebb68dc0cfaed5a7009e8305fe1fed8d0ccd1": 10000000000,
"003346a630e6972bf38cce87219db1d63061e7cd324cad88c18e504f2990cac68e973f51256ca938683fa4ea12173d7d047d940fbb883bd0e8": 10000000000,
"0028b862d001e6a64a02b3560cbc532eab4557593477c39cc523e0b9fc527100898c11e731194171b908aad463770d6cbf7ec8871c4cb1e518": 10000000000,
"005e0e57040b06e9d71e0f28f126262838a68db0b52b4fd1b3877dda2203d5d7d4f19c5ee3a1ed51bb670779de19d40aaff2e5e9468cc05c5e": 10000000000,
"00367f65ab69b1e6715c8d5a14964214c9505ed17032266b3209a2c40dcbae9a2a881e603ff39d36e987bacfb87ee98051f222c5fe3efd350c": 10000000000,
"00c5c4ca287f3b53948b5468e5e23b1c87fe61ce52c0d9afd65d070795038751a619d463e91eaed0a774ebdb2f8e12a01a378a153bc3627323": 10000000000,
"00ef198fb7c35e1968308a0b75cfee54a46e13e86dd3354283300831d624165c357b5a0413906a0bfea8ba57587331f0836a186d632ed041b8": 10000000000
{{#initialFunds}}
"{{key}}": {{value}}{{^last}},
{{/last}}
{{/initialFunds}}

},
"maxKESEvolutions": {{maxKESEvolutions}},
"maxLovelaceSupply": {{maxLovelaceSupply}},
Expand Down

0 comments on commit 90ad9c2

Please sign in to comment.