WavesCS icon indicating copy to clipboard operation
WavesCS copied to clipboard

Converted tx from JSON for chains besides 'S', 'T', 'W' throws errors

Open xucito opened this issue 5 years ago • 1 comments

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:

  1. 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 "";
            }
        }

xucito avatar Jul 20 '20 21:07 xucito

PR #56 also fixes this issue

xucito avatar Jul 21 '20 06:07 xucito