aboutsummaryrefslogtreecommitdiffstats
path: root/light/odr_util.go
diff options
context:
space:
mode:
authorFelföldi Zsolt <zsfelfoldi@gmail.com>2019-05-13 19:41:10 +0800
committerPéter Szilágyi <peterke@gmail.com>2019-05-13 19:41:10 +0800
commit40cdcf8c47ff094775aca08fd5d94051f9cf1dbb (patch)
tree3a9fc715ec501ab0fec8c81004e17477bd136f9f /light/odr_util.go
parentf4fb1a18015d88aa7b424709aac346da59edf410 (diff)
downloadgo-tangerine-40cdcf8c47ff094775aca08fd5d94051f9cf1dbb.tar
go-tangerine-40cdcf8c47ff094775aca08fd5d94051f9cf1dbb.tar.gz
go-tangerine-40cdcf8c47ff094775aca08fd5d94051f9cf1dbb.tar.bz2
go-tangerine-40cdcf8c47ff094775aca08fd5d94051f9cf1dbb.tar.lz
go-tangerine-40cdcf8c47ff094775aca08fd5d94051f9cf1dbb.tar.xz
go-tangerine-40cdcf8c47ff094775aca08fd5d94051f9cf1dbb.tar.zst
go-tangerine-40cdcf8c47ff094775aca08fd5d94051f9cf1dbb.zip
les, light: implement ODR transaction lookup by hash (#19069)
* les, light: implement ODR transaction lookup by hash * les: delete useless file * internal/ethapi: always use backend to find transaction * les, eth, internal/ethapi: renamed GetCanonicalTransaction to GetTransaction * light: add canonical header verification to GetTransaction
Diffstat (limited to 'light/odr_util.go')
-rw-r--r--light/odr_util.go21
1 files changed, 21 insertions, 0 deletions
diff --git a/light/odr_util.go b/light/odr_util.go
index cce532f8e..100bd5842 100644
--- a/light/odr_util.go
+++ b/light/odr_util.go
@@ -21,6 +21,7 @@ import (
"context"
"github.com/ethereum/go-ethereum/common"
+ "github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/rawdb"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
@@ -227,3 +228,23 @@ func GetBloomBits(ctx context.Context, odr OdrBackend, bitIdx uint, sectionIdxLi
return result, nil
}
}
+
+// GetTransaction retrieves a canonical transaction by hash and also returns its position in the chain
+func GetTransaction(ctx context.Context, odr OdrBackend, txHash common.Hash) (*types.Transaction, common.Hash, uint64, uint64, error) {
+ r := &TxStatusRequest{Hashes: []common.Hash{txHash}}
+ if err := odr.Retrieve(ctx, r); err != nil || r.Status[0].Status != core.TxStatusIncluded {
+ return nil, common.Hash{}, 0, 0, err
+ } else {
+ pos := r.Status[0].Lookup
+ // first ensure that we have the header, otherwise block body retrieval will fail
+ // also verify if this is a canonical block by getting the header by number and checking its hash
+ if header, err := GetHeaderByNumber(ctx, odr, pos.BlockIndex); err != nil || header.Hash() != pos.BlockHash {
+ return nil, common.Hash{}, 0, 0, err
+ }
+ if body, err := GetBody(ctx, odr, pos.BlockHash, pos.BlockIndex); err != nil || uint64(len(body.Transactions)) <= pos.Index || body.Transactions[pos.Index].Hash() != txHash {
+ return nil, common.Hash{}, 0, 0, err
+ } else {
+ return body.Transactions[pos.Index], pos.BlockHash, pos.BlockIndex, pos.Index, nil
+ }
+ }
+}