forked from Argus-Labs/world-engine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathworld_receipt.go
61 lines (54 loc) · 1.79 KB
/
world_receipt.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
57
58
59
60
61
package cardinal
import (
"github.com/rotisserie/eris"
"pkg.world.dev/world-engine/cardinal/receipt"
"pkg.world.dev/world-engine/cardinal/txpool"
)
type EVMTxReceipt struct {
ABIResult []byte
Errs []error
EVMTxHash string
}
func (w *World) GetTransactionReceiptsForTick(tick uint64) ([]receipt.Receipt, error) {
return w.receiptHistory.GetReceiptsForTick(tick)
}
// ConsumeEVMMsgResult consumes a tx result from an EVM originated Cardinal message.
// It will fetch the receipt from the map, and then delete ('consume') it from the map.
func (w *World) ConsumeEVMMsgResult(evmTxHash string) ([]byte, []error, string, bool) {
rcpt, exists := w.evmTxReceipts[evmTxHash]
delete(w.evmTxReceipts, evmTxHash)
return rcpt.ABIResult, rcpt.Errs, rcpt.EVMTxHash, exists
}
func (w *World) GetEVMMsgReceipt(evmTxHash string) (EVMTxReceipt, bool) {
rcpt, exists := w.evmTxReceipts[evmTxHash]
// TODO(scott): this is an anti pattern, getters shouldnt be state mutating
delete(w.evmTxReceipts, evmTxHash)
return rcpt, exists
}
func (w *World) setEvmResults(txs []txpool.TxData) {
// iterate over all EVM originated transactions
for _, tx := range txs {
// see if tx has a receipt. sometimes it won't because:
// The system isn't using TxIterators && never explicitly called SetResult.
rec, ok := w.receiptHistory.GetReceipt(tx.TxHash)
if !ok {
continue
}
evmRec := EVMTxReceipt{EVMTxHash: tx.EVMSourceTxHash}
msg, ok := w.GetMessageByID(tx.MsgID)
if !ok {
rec.Errs = append(rec.Errs, eris.New("failed to get message by id?"))
}
if rec.Result != nil {
abiBz, err := msg.ABIEncode(rec.Result)
if err != nil {
rec.Errs = append(rec.Errs, err)
}
evmRec.ABIResult = abiBz
}
if len(rec.Errs) > 0 {
evmRec.Errs = rec.Errs
}
w.evmTxReceipts[evmRec.EVMTxHash] = evmRec
}
}