MCPcopy Index your code
hub / github.com/ccxt/ccxt / networkCodeToId

Method networkCodeToId

java/lib/src/main/java/io/github/ccxt/Exchange.java:7930–7974  ·  view source on GitHub ↗
(Object networkCode, Object... optionalArgs)

Source from the content-addressed store, hash-verified

7928 }
7929
7930 public Object networkCodeToId(Object networkCode, Object... optionalArgs)
7931 {
7932 /**
7933 * @ignore
7934 * @method
7935 * @name exchange#networkCodeToId
7936 * @description tries to convert the provided networkCode (which is expected to be an unified network code) to a network id. In order to achieve this, derived class needs to have 'options->networks' defined.
7937 * @param {string} networkCode unified network code
7938 * @param {string} currencyCode unified currency code, but this argument is not required by default, unless there is an exchange (like huobi) that needs an override of the method to be able to pass currencyCode argument additionally
7939 * @returns {string|undefined} exchange-specific network id
7940 */
7941 Object currencyCode = Helpers.getArg(optionalArgs, 0, null);
7942 if (Helpers.isTrue(Helpers.isEqual(networkCode, null)))
7943 {
7944 return null;
7945 }
7946 Object networkIdsByCodes = this.safeDict(this.options, "networks", new java.util.HashMap<String, Object>() {{}});
7947 // try the preferred form first, fall back to its alternative (e.g. when only 'ETH' or only 'ERC20' is defined)
7948 var preferredChainalternativeChainVariable = this.prioritizedNetworkAliases(networkCode, currencyCode, false);
7949 var preferredChain = ((java.util.List<Object>) preferredChainalternativeChainVariable).get(0);
7950 var alternativeChain = ((java.util.List<Object>) preferredChainalternativeChainVariable).get(1);
7951 Object networkId = this.safeString2(networkIdsByCodes, preferredChain, alternativeChain);
7952 if (Helpers.isTrue(!Helpers.isEqual(networkId, null)))
7953 {
7954 return networkId;
7955 }
7956 // fall back to scanning loaded currencies
7957 Object currenciesToCheck = new java.util.ArrayList<Object>(java.util.Arrays.asList());
7958 if (Helpers.isTrue(Helpers.isEqual(currencyCode, null)))
7959 {
7960 currenciesToCheck = Helpers.objectKeys(this.currencies);
7961 } else
7962 {
7963 currenciesToCheck = new java.util.ArrayList<Object>(java.util.Arrays.asList(this.safeDict(this.currencies, currencyCode)));
7964 }
7965 for (var i = 0; Helpers.isLessThan(i, Helpers.getArrayLength(currenciesToCheck)); i++)
7966 {
7967 Object networks = this.safeDict(Helpers.GetValue(currenciesToCheck, i), "networks", new java.util.HashMap<String, Object>() {{}});
7968 if (Helpers.isTrue(Helpers.inOp(networks, networkCode)))
7969 {
7970 return this.safeString(Helpers.GetValue(networks, networkCode), "id");
7971 }
7972 }
7973 return networkCode;
7974 }
7975
7976 public Object networkIdToCode(Object... optionalArgs)
7977 {

Callers 3

handleRequestNetworkMethod · 0.95
testOptionsNetworksMethod · 0.45

Calls 13

getArgMethod · 0.95
isTrueMethod · 0.95
isEqualMethod · 0.95
safeDictMethod · 0.95
safeString2Method · 0.95
objectKeysMethod · 0.95
isLessThanMethod · 0.95
getArrayLengthMethod · 0.95
GetValueMethod · 0.95
inOpMethod · 0.95
safeStringMethod · 0.95

Tested by 1

testOptionsNetworksMethod · 0.36