-
Notifications
You must be signed in to change notification settings - Fork 6
/
txWithFee.go
87 lines (71 loc) · 2.58 KB
/
txWithFee.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
79
80
81
82
83
84
85
86
87
package outport
import (
"math/big"
"github.com/ElrondNetwork/elrond-go-core/data"
)
// FeeInfo holds information about the fee and gas used
type FeeInfo struct {
GasUsed uint64
Fee *big.Int
InitialPaidFee *big.Int
}
// TransactionHandlerWithGasAndFee holds a data.TransactionHandler and information about fee and gas used
type TransactionHandlerWithGasAndFee struct {
data.TransactionHandler
FeeInfo
ExecutionOrder int
}
// NewTransactionHandlerWithGasAndFee returns a new instance of transactionHandlerWithGasAndFee which matches the interface
func NewTransactionHandlerWithGasAndFee(txHandler data.TransactionHandler, gasUsed uint64, fee *big.Int) data.TransactionHandlerWithGasUsedAndFee {
return &TransactionHandlerWithGasAndFee{
TransactionHandler: txHandler,
FeeInfo: FeeInfo{
GasUsed: gasUsed,
Fee: fee,
},
}
}
// SetInitialPaidFee will set the initial paid fee
func (t *TransactionHandlerWithGasAndFee) SetInitialPaidFee(fee *big.Int) {
t.InitialPaidFee = fee
}
// GetInitialPaidFee returns the initial paid fee of the transactions
func (t *TransactionHandlerWithGasAndFee) GetInitialPaidFee() *big.Int {
return t.InitialPaidFee
}
// SetGasUsed sets the used gas internally
func (t *TransactionHandlerWithGasAndFee) SetGasUsed(gasUsed uint64) {
t.GasUsed = gasUsed
}
// GetGasUsed returns the used gas of the transaction
func (t *TransactionHandlerWithGasAndFee) GetGasUsed() uint64 {
return t.GasUsed
}
// SetFee sets the fee internally
func (t *TransactionHandlerWithGasAndFee) SetFee(fee *big.Int) {
t.Fee = fee
}
// GetFee returns the fee of the transaction
func (t *TransactionHandlerWithGasAndFee) GetFee() *big.Int {
return t.Fee
}
// GetTxHandler will return the TransactionHandler
func (t *TransactionHandlerWithGasAndFee) GetTxHandler() data.TransactionHandler {
return t.TransactionHandler
}
// SetExecutionOrder will set the execution order of the TransactionHandler
func (t *TransactionHandlerWithGasAndFee) SetExecutionOrder(order int) {
t.ExecutionOrder = order
}
// GetExecutionOrder will return the execution order of the TransactionHandler
func (t *TransactionHandlerWithGasAndFee) GetExecutionOrder() int {
return t.ExecutionOrder
}
// WrapTxsMap will wrap the provided transactions map in a map fo transactions with fee and gas used
func WrapTxsMap(txs map[string]data.TransactionHandler) map[string]data.TransactionHandlerWithGasUsedAndFee {
newMap := make(map[string]data.TransactionHandlerWithGasUsedAndFee, len(txs))
for txHash, tx := range txs {
newMap[txHash] = NewTransactionHandlerWithGasAndFee(tx, 0, big.NewInt(0))
}
return newMap
}