1

I would like to have the functionality in my Solidity contract that when a user sends a transaction with a transaction hash, the contract parses it to get information of the timestamp etc. The best way I can think of doing this is using a method similar to eth_getTransactionReceipt. But I can't seem to find the code for that on Github. Could someone please point me to where this is implemented? (Any other solution to achieve the functionality I want it welcome too :) )

1 Answer 1

0

The code for getTransactionReceipt(...) can be found at go-ethereum - eth/api.go, lines 1090-1140 and is as follows:

// GetTransactionReceipt returns the transaction receipt for the given transaction hash.
func (s *PublicTransactionPoolAPI) GetTransactionReceipt(txHash common.Hash) (map[string]interface{}, error) {
    receipt := core.GetReceipt(s.chainDb, txHash)
    if receipt == nil {
        glog.V(logger.Debug).Infof("receipt not found for transaction %s", txHash.Hex())
        return nil, nil
    }

    tx, _, err := getTransaction(s.chainDb, s.txPool, txHash)
    if err != nil {
        glog.V(logger.Debug).Infof("%v\n", err)
        return nil, nil
    }

    txBlock, blockIndex, index, err := getTransactionBlockData(s.chainDb, txHash)
    if err != nil {
        glog.V(logger.Debug).Infof("%v\n", err)
        return nil, nil
    }

    from, err := tx.FromFrontier()
    if err != nil {
        glog.V(logger.Debug).Infof("%v\n", err)
        return nil, nil
    }

    fields := map[string]interface{}{
        "root":              common.Bytes2Hex(receipt.PostState),
        "blockHash":         txBlock,
        "blockNumber":       rpc.NewHexNumber(blockIndex),
        "transactionHash":   txHash,
        "transactionIndex":  rpc.NewHexNumber(index),
        "from":              from,
        "to":                tx.To(),
        "gasUsed":           rpc.NewHexNumber(receipt.GasUsed),
        "cumulativeGasUsed": rpc.NewHexNumber(receipt.CumulativeGasUsed),
        "contractAddress":   nil,
        "logs":              receipt.Logs,
    }

    if receipt.Logs == nil {
        fields["logs"] = []vm.Logs{}
    }

    // If the ContractAddress is 20 0x0 bytes, assume it is not a contract creation
    if bytes.Compare(receipt.ContractAddress.Bytes(), bytes.Repeat([]byte{0}, 20)) != 0 {
        fields["contractAddress"] = receipt.ContractAddress
    }

    return fields, nil
}

This site is temporarily in read-only mode and not accepting new answers.

Not the answer you're looking for? Browse other questions tagged .