github.com/Finschia/ostracon@v1.1.5/mempool/v1/tx.go (about) 1 //go:build deprecated 2 3 package v1 4 5 import ( 6 "sync" 7 "time" 8 9 "github.com/tendermint/tendermint/types" 10 ) 11 12 // WrappedTx defines a wrapper around a raw transaction with additional metadata 13 // that is used for indexing. 14 type WrappedTx struct { 15 tx types.Tx // the original transaction data 16 hash types.TxKey // the transaction hash 17 height int64 // height when this transaction was initially checked (for expiry) 18 timestamp time.Time // time when transaction was entered (for TTL) 19 20 mtx sync.Mutex 21 gasWanted int64 // app: gas required to execute this transaction 22 priority int64 // app: priority value for this transaction 23 sender string // app: assigned sender label 24 peers map[uint16]bool // peer IDs who have sent us this transaction 25 } 26 27 // Size reports the size of the raw transaction in bytes. 28 func (w *WrappedTx) Size() int64 { return int64(len(w.tx)) } 29 30 // SetPeer adds the specified peer ID as a sender of w. 31 func (w *WrappedTx) SetPeer(id uint16) { 32 w.mtx.Lock() 33 defer w.mtx.Unlock() 34 if w.peers == nil { 35 w.peers = map[uint16]bool{id: true} 36 } else { 37 w.peers[id] = true 38 } 39 } 40 41 // HasPeer reports whether the specified peer ID is a sender of w. 42 func (w *WrappedTx) HasPeer(id uint16) bool { 43 w.mtx.Lock() 44 defer w.mtx.Unlock() 45 _, ok := w.peers[id] 46 return ok 47 } 48 49 // SetGasWanted sets the application-assigned gas requirement of w. 50 func (w *WrappedTx) SetGasWanted(gas int64) { 51 w.mtx.Lock() 52 defer w.mtx.Unlock() 53 w.gasWanted = gas 54 } 55 56 // GasWanted reports the application-assigned gas requirement of w. 57 func (w *WrappedTx) GasWanted() int64 { 58 w.mtx.Lock() 59 defer w.mtx.Unlock() 60 return w.gasWanted 61 } 62 63 // SetSender sets the application-assigned sender of w. 64 func (w *WrappedTx) SetSender(sender string) { 65 w.mtx.Lock() 66 defer w.mtx.Unlock() 67 w.sender = sender 68 } 69 70 // Sender reports the application-assigned sender of w. 71 func (w *WrappedTx) Sender() string { 72 w.mtx.Lock() 73 defer w.mtx.Unlock() 74 return w.sender 75 } 76 77 // SetPriority sets the application-assigned priority of w. 78 func (w *WrappedTx) SetPriority(p int64) { 79 w.mtx.Lock() 80 defer w.mtx.Unlock() 81 w.priority = p 82 } 83 84 // Priority reports the application-assigned priority of w. 85 func (w *WrappedTx) Priority() int64 { 86 w.mtx.Lock() 87 defer w.mtx.Unlock() 88 return w.priority 89 }