WavesCS
WavesCS copied to clipboard
Converted tx from JSON for chains besides 'S', 'T', 'W' throws errors
Describe the bug Try to convert TX from Json specifying an alternative chainId throws a "invalid chainId error"
This is due to the constructor for TXs requiring a instance of Node which will only allow the three chainIds as it uses chain-only constructor
public static string NodeHostByChainID(char chainId)
{
switch (chainId)
{
case StageNetChainId : return StageNetHost;
case TestNetChainId : return TestNetHost;
case MainNetChainId : return MainNetHost;
default: throw new ArgumentException("Unknown chainId: " + chainId);
}
}
public Node(char nodeChainId = TestNetChainId) : this(NodeHostByChainID(nodeChainId), nodeChainId) { }
To Reproduce Steps to reproduce the behavior:
- Try to convert a json using any other chain id
var jsonConverted = WavesCS.Transaction.FromJson('l',transaction);
Expected behavior tx should be correctly parsed allowing for any chainId
Suggested Solutions My suggested solution is to either always pass empty host to allow for any chain
public TransferTransaction(DictionaryObject tx): base(tx)
{
var node = new Node("",tx.GetChar("chainId"));
OR just passing an empty node host if the chainId is not found
public static string NodeHostByChainID(char chainId)
{
switch (chainId)
{
case StageNetChainId : return StageNetHost;
case TestNetChainId : return TestNetHost;
case MainNetChainId : return MainNetHost;
default: return "";
}
}
PR #56 also fixes this issue