dongre6404 2018-10-09 12:48
浏览 1335
已采纳

如何将等效的GO代码转换为Java代码?

I'm making an RPC call using a Java library, I'm taking refrence from a GO code which I need to convert to java. I fairly know nothing about the go syntax. Can anyone help me describe the following code :

Params: []interface{}{
            from, // first parameter is address to send from (where the ZEC comes from)
            []interface{}{
                map[string]interface{}{
                    "amount":  msgval,
                    "address": to,
                    "memo":    hex.EncodeToString([]byte(msg)),
                },
            },

Below is how, I'm trying the equivalent Java code :

Map<String,Object> params = new HashMap<>();
      params.put( "from", fromAddress );
      params.put( "amount", 1.0000 );
      params.put( "address", toAddress );
      params.put( "memo", hexMessage );

Below is the argument description :

This is an Asynchronous RPC call. Send funds from an address to multiple outputs. The address can be a taddr or a zaddr. Amounts is a list containing key/value pairs corresponding to the addresses and amount to pay. Each output address can be in taddr or zaddr format. When sending to a zaddr, you also have the option of of attaching a memo in hexadecimal format.

Is this correct?

  • 写回答

2条回答 默认 最新

  • dongnanbi4942 2018-10-09 15:27
    关注
    Params: []interface{}{
                from, // first parameter is address to send from (where the ZEC comes from)
                []interface{}{
                    map[string]interface{}{
                        "amount":  msgval,
                        "address": to,
                        "memo":    hex.EncodeToString([]byte(msg)),
                    },
                },
    

    Reads roughly like this pseudocode:

    Params => Array<Object>(
        $from,
        Array<Object>(
           Hash<String, Object>(
               "amount" => msgval,
               "address" => to,
               "memo" => hex.EncodeToString(msg),
           )
        )
    )
    

    So, whatever to put in Params is

    1. An array of objects (i.e. of any type), in which
    2. The 1st element is the "from" addres,
    3. The 2nd element is another array,
    4. In which the 1st element is a hash map of string to objects (of any type), which you've already created.
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog