doulangbizhan5160
2018-05-31 12:22
采纳率: 100%
浏览 69
已采纳

访问内存位置数组中的数据

I am trying to parse the following type array in geth to "look inside" and get the info but can not figure out how to do it. txs []*types.Transaction

This type is declared elsewhere in geth as

type Transaction struct {
    data    txdata
    hash    atomic.Value
    size    atomic.Value
    from    atomic.Value
}

and I am trying to access the data using the following loop but I can't seem to access any of these values.

    for _, tx := range *txs {
        fmt.Println(fmt.Sprintf("transactions in this block - hash: %s and data: ", tx.hash))
    }

Can anyone point me in the right direction as to how I can access the data in memory locations that is an array

图片转代码服务由CSDN问答提供 功能建议

我正在尝试解析geth中的以下类型数组以“向内看”并获取信息,但无法确定 txs [] * types.Transaction

此类型在geth中的其他地方声明为

  type事务结构{
 data txdata 
 hash atomic.Value 
大小atomic.Value 
来自atomic.Value 
} 
   
 \  n 

,并且我尝试使用以下循环访问数据,但似乎无法访问任何这些值。

  for _,tx:= range  * txs {
 fmt.Println(fmt.Sprintf(“此区块中的交易-哈希:%s和数据:”,tx.hash))
} 
   
 
  

任何人都可以针对我如何访问数组中的内存位置中的数据指出正确的方向

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • donglun1020 2018-05-31 14:47
    已采纳

    *types.Transaction has accessor methods:

    func (tx *Transaction) Hash() common.Hash
    func (tx *Transaction) Data() []byte
    func (tx *Transaction) Nonce() uint64
    func (tx *Transaction) To() *common.Address
    

    (and many more)

    Read the package documentation and learn Go. Lowercase field names are unexported (private).

    已采纳该答案
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题