-
Notifications
You must be signed in to change notification settings - Fork 0
/
eth_tx.go
78 lines (67 loc) · 2.21 KB
/
eth_tx.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package presenters
import (
"strconv"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/O1MaGnUmO1/erinaceus-vrf/core/chains/evm/assets"
"github.com/O1MaGnUmO1/erinaceus-vrf/core/chains/evm/txmgr"
"github.com/O1MaGnUmO1/erinaceus-vrf/core/chains/evm/utils/big"
)
// EthTxResource represents a Ethereum Transaction JSONAPI resource.
type EthTxResource struct {
JAID
State string `json:"state"`
Data hexutil.Bytes `json:"data"`
From *common.Address `json:"from"`
GasLimit string `json:"gasLimit"`
GasPrice string `json:"gasPrice"`
Hash common.Hash `json:"hash"`
Hex string `json:"rawHex"`
Nonce string `json:"nonce"`
SentAt string `json:"sentAt"`
To *common.Address `json:"to"`
Value string `json:"value"`
EVMChainID big.Big `json:"evmChainID"`
}
// GetName implements the api2go EntityNamer interface
func (EthTxResource) GetName() string {
return "evm_transactions"
}
// NewEthTxResource generates a EthTxResource from an Eth.Tx.
//
// For backwards compatibility, there is no id set when initializing from an
// EthTx as the id being used was the EthTxAttempt Hash.
// This should really use it's proper id
func NewEthTxResource(tx txmgr.Tx) EthTxResource {
v := assets.Eth(tx.Value)
r := EthTxResource{
Data: hexutil.Bytes(tx.EncodedPayload),
From: &tx.FromAddress,
GasLimit: strconv.FormatUint(uint64(tx.FeeLimit), 10),
State: string(tx.State),
To: &tx.ToAddress,
Value: v.String(),
}
if tx.ChainID != nil {
r.EVMChainID = *big.New(tx.ChainID)
}
return r
}
func NewEthTxResourceFromAttempt(txa txmgr.TxAttempt) EthTxResource {
tx := txa.Tx
r := NewEthTxResource(tx)
r.JAID = NewJAID(txa.Hash.String())
r.GasPrice = txa.TxFee.Legacy.ToInt().String()
r.Hash = txa.Hash
r.Hex = hexutil.Encode(txa.SignedRawTx)
if txa.Tx.ChainID != nil {
r.EVMChainID = *big.New(txa.Tx.ChainID)
}
if tx.Sequence != nil {
r.Nonce = strconv.FormatUint(uint64(*tx.Sequence), 10)
}
if txa.BroadcastBeforeBlockNum != nil {
r.SentAt = strconv.FormatUint(uint64(*txa.BroadcastBeforeBlockNum), 10)
}
return r
}