Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Added new networks #157 #158

Merged
merged 2 commits into from
Oct 5, 2022

Conversation

nejcr
Copy link
Contributor

@nejcr nejcr commented Sep 30, 2022

I added new networks, however, I am not deeply familiar with this lib, and if someone (@satran004) could provide me the correct integer values I will update it accordingly.
#157

@sonatype-lift
Copy link
Contributor

sonatype-lift bot commented Sep 30, 2022

⚠️ 8 God Classes were detected by Lift in this project. Visit the Lift web console for more details.

@nejcr nejcr changed the title [WIP] Added new networks [WIP] Added new networks https://github.com/bloxbean/cardano-client-lib/issues/157 Sep 30, 2022
@nejcr nejcr changed the title [WIP] Added new networks https://github.com/bloxbean/cardano-client-lib/issues/157 [WIP] Added new networks #157 Sep 30, 2022
@satran004
Copy link
Member

@nejcr Thanks for working on this PR.

For new networks like prepod and preview, networkId (also known as Network Tag) is still 0 as these are test networks.
AFAIK there are only two possible values for network id 1 (for mainnet) and 0 (for all testnets including custom private testnets).

You can refer to this CIP for more details https://cips.cardano.org/cips/cip19/#networktag

But, the Network class in cardano-client has an another field protocolMagic which is network specific. Prepod = 1 and Preview = 2. But protocol magic is not used directly inside cardano client lib.

Network Id is used in Address generation and during transaction serialization (optional).

Please refer to my other comments inline.

Copy link
Member

@satran004 satran004 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nejcr Can you please also add few tests to include PREVIEW, PREPOD network ?

Basically we need to check if a developer pass the network as PREVIEW or PREPOD, the generated address should be similar to regular testnet (starts with addr_test). I think we can add few tests in AddressTest class or AccountTest class.

@@ -34,6 +34,8 @@ public static String getPrefixTail(NetworkId network) {
String prefixTail;
switch (network) {
case TESTNET:
case PREVIEW:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need PREVIEW and PREPOD here. Only TESTNET networkId is enough. So NetworkId enum will have two values TESTNET, MAINNET where TESTNET is for all testnets

@@ -52,6 +54,10 @@ public static NetworkId getNetworkId(Network networkInfo) {
network = NetworkId.MAINNET;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need to change this logic. In existing code, Network object is being compared but instead we should compare NetworkId of the network and return NetworkId.MAINNET or NetworkId.TESTNET

Some thing like

if (NetworkId.MAINNET.equals(networkInfo.getNetworkId()) return NetworkId.MAINNET;
else  if //check for network TESTNET network id

else throw AddressRuntimeException

@@ -10,4 +10,14 @@ public static Network testnet() {
Network testnet = new Network(0b0000, 1097911063);
return testnet;
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me. You may want to change the local variable name in prepod & preview methods to prepod/preview instead of testnet.

@@ -2,5 +2,7 @@

public enum NetworkId {
TESTNET,
MAINNET
MAINNET,
PREVIEW,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PREVIEW and PREPOD are not required as only two possible values for NetworkId.

@@ -155,6 +155,14 @@ public Map serialize() throws CborSerializationException, AddressExcepion {
case TESTNET:
bodyMap.put(new UnsignedInteger(15), new UnsignedInteger(0));
break;
case PREVIEW:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are network Ids. So only 1, 0. This change is not required.

@@ -298,7 +306,15 @@ public static TransactionBody deserialize(Map bodyMap) throws CborDeserializatio
int networkIdInt = networkIdUI.getValue().intValue();
if (networkIdInt == 0) {
transactionBody.setNetworkId(NetworkId.TESTNET);
}else if (networkIdInt == 1) {
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above. This change is not required.

@satran004
Copy link
Member

@nejcr Let me know if you need any additional info for this PR

@satran004 satran004 added this to the 0.3.0 milestone Oct 4, 2022
@satran004 satran004 changed the base branch from master to network_fix_merge October 5, 2022 13:39
@satran004
Copy link
Member

Thanks @nejcr for the changes. Looks good to me. Merging it to a temp branch for now.

I will do a minor change to compare networkid instead of network obj in AddressEncoderDecoderUtil and merge back to master.

@satran004 satran004 merged commit a1242ab into bloxbean:network_fix_merge Oct 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants