forked from cerc-io/ipld-eth-server
605b0a96ae
* Add graphql server * Update Makefile * Update log_filters constraint * Add GetLogFilter to repo * Update travis (use Makefile, go fmt, go vet) * Add logFilter schema and resolvers * Add GetWatchedEvent to watched_events_repo * Add watchedEventLog schema and resolvers
50 lines
1.2 KiB
Go
50 lines
1.2 KiB
Go
package postgres
|
|
|
|
import (
|
|
"database/sql"
|
|
|
|
"github.com/vulcanize/vulcanizedb/pkg/core"
|
|
"github.com/vulcanize/vulcanizedb/pkg/repositories"
|
|
)
|
|
|
|
func (db DB) GetReceipt(txHash string) (core.Receipt, error) {
|
|
row := db.DB.QueryRow(
|
|
`SELECT contract_address,
|
|
tx_hash,
|
|
cumulative_gas_used,
|
|
gas_used,
|
|
state_root,
|
|
status
|
|
FROM receipts
|
|
WHERE tx_hash = $1`, txHash)
|
|
receipt, err := loadReceipt(row)
|
|
if err != nil {
|
|
switch err {
|
|
case sql.ErrNoRows:
|
|
return core.Receipt{}, repositories.ErrReceiptDoesNotExist(txHash)
|
|
default:
|
|
return core.Receipt{}, err
|
|
}
|
|
}
|
|
return receipt, nil
|
|
}
|
|
|
|
func loadReceipt(receiptsRow *sql.Row) (core.Receipt, error) {
|
|
var contractAddress string
|
|
var txHash string
|
|
var cumulativeGasUsed int64
|
|
var gasUsed int64
|
|
var stateRoot string
|
|
var status int
|
|
|
|
err := receiptsRow.Scan(&contractAddress, &txHash, &cumulativeGasUsed, &gasUsed, &stateRoot, &status)
|
|
return core.Receipt{
|
|
TxHash: txHash,
|
|
ContractAddress: contractAddress,
|
|
CumulativeGasUsed: cumulativeGasUsed,
|
|
GasUsed: gasUsed,
|
|
StateRoot: stateRoot,
|
|
Status: status,
|
|
}, err
|
|
}
|