/
transactions.go
56 lines (52 loc) · 1.21 KB
/
transactions.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package databaseOverlay
import (
"fmt"
"github.com/FactomProject/factomd/common/interfaces"
)
func (db *Overlay) FetchFactoidTransaction(hash interfaces.IHash) (interfaces.ITransaction, error) {
in, err := db.FetchIncludedIn(hash)
if err != nil {
return nil, err
}
if in == nil {
return nil, nil
}
block, err := db.FetchFBlock(in)
if err != nil {
return nil, err
}
if block == nil {
return nil, fmt.Errorf("Block not found, should not happen")
}
txs := block.GetTransactions()
for _, tx := range txs {
if tx.GetHash().IsSameAs(hash) {
return tx, nil
}
if tx.GetSigHash().IsSameAs(hash) {
return tx, nil
}
}
return nil, fmt.Errorf("Transaction not found in block, should not happen")
}
func (db *Overlay) FetchECTransaction(hash interfaces.IHash) (interfaces.IECBlockEntry, error) {
in, err := db.FetchIncludedIn(hash)
if err != nil {
return nil, err
}
if in == nil {
return nil, nil
}
block, err := db.FetchECBlock(in)
if err != nil {
return nil, err
}
if block == nil {
return nil, fmt.Errorf("Block not found, should not happen")
}
tx := block.GetEntryByHash(hash)
if tx != nil {
return tx, nil
}
return nil, fmt.Errorf("Transaction not found in block, should not happen")
}