首页 > 解决方案 > 访问内存位置数组中的数据

问题描述

我正在尝试解析 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))
    }

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

标签: goethereumgo-ethereum

解决方案


*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。小写字段名称未导出(私有)。


推荐阅读