【问题标题】:Access data inside memory location array访问内存位置数组中的数据
【发布时间】:2018-11-10 11:06:46
【问题描述】:

我正在尝试解析 geth 中的以下类型数组以“查看内部”并获取信息,但无法弄清楚如何去做。 txs []*types.Transaction

这个类型在geth的其他地方被声明为

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

我正在尝试使用以下循环访问数据,但我似乎无法访问这些值中的任何一个。

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

谁能指出我如何访问数组内存位置中的数据的正确方向

【问题讨论】:

  • 查看带有示例的文档:atomic.Value 只有 2 种方法。
  • 参加围棋之旅。给定的 txs 声明与您的范围不匹配。
  • 我是新手,已经参观了 go,但仍然不明白如何解析这个
  • 您为什么要访问未导出的值?你不应该这样做。它们未出口是有原因的。
  • 一点帮助都没有......答案在下面

标签: go ethereum go-ethereum


【解决方案1】:

*types.Transaction 具有访问器方法:

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

(还有更多)

阅读包文档并学习 Go。小写字段名称未导出(私有)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-27
    • 1970-01-01
    • 2015-02-17
    相关资源
    最近更新 更多