-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
eth_tx.go
69 lines (60 loc) · 2.04 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
package presenters
import (
"strconv"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/smartcontractkit/chainlink/core/chains/evm/txmgr"
"github.com/smartcontractkit/chainlink/core/utils"
)
// 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 utils.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.EthTx) EthTxResource {
return EthTxResource{
Data: hexutil.Bytes(tx.EncodedPayload),
From: &tx.FromAddress,
GasLimit: strconv.FormatUint(uint64(tx.GasLimit), 10),
State: string(tx.State),
To: &tx.ToAddress,
Value: tx.Value.String(),
EVMChainID: tx.EVMChainID,
}
}
func NewEthTxResourceFromAttempt(txa txmgr.EthTxAttempt) EthTxResource {
tx := txa.EthTx
r := NewEthTxResource(tx)
r.JAID = NewJAID(txa.Hash.Hex())
r.GasPrice = txa.GasPrice.ToInt().String()
r.Hash = txa.Hash
r.Hex = hexutil.Encode(txa.SignedRawTx)
r.EVMChainID = txa.EthTx.EVMChainID
if tx.Nonce != nil {
r.Nonce = strconv.FormatUint(uint64(*tx.Nonce), 10)
}
if txa.BroadcastBeforeBlockNum != nil {
r.SentAt = strconv.FormatUint(uint64(*txa.BroadcastBeforeBlockNum), 10)
}
return r
}