Class: Moac::Tx
- Inherits:
-
Object
show all
- Extended by:
- Sedes
- Includes:
- RLP::Sedes::Serializable
- Defined in:
- lib/moac/tx.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Sedes
address, big_endian_int, binary, hash32, int20, int256, int32, trie_root
Constructor Details
#initialize(params) ⇒ Tx
Returns a new instance of Tx.
29
30
31
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/moac/tx.rb', line 29
def initialize(params)
fields = params.merge({v: Moac.chain_id, r: 0, s: 0})
fields[:to] = Utils.normalize_address(fields[:to])
if params[:data]
self.data = params.delete(:data)
fields[:data_bin] = data_bin
end
serializable_initialize fields
check_transaction_validity
end
|
Instance Attribute Details
Class Method Details
.decode(data) ⇒ Object
24
25
26
27
|
# File 'lib/moac/tx.rb', line 24
def self.decode(data)
data = Utils.hex_to_bin(data) if data.match(/\A(?:0x)?\h+\Z/)
deserialize(RLP.decode data)
end
|
Instance Method Details
#data ⇒ Object
105
106
107
|
# File 'lib/moac/tx.rb', line 105
def data
Moac.tx_data_hex? ? data_hex : data_bin
end
|
#data=(string) ⇒ Object
109
110
111
|
# File 'lib/moac/tx.rb', line 109
def data=(string)
Moac.tx_data_hex? ? self.data_hex=(string) : self.data_bin=(string)
end
|
#data_hex=(hex) ⇒ Object
101
102
103
|
# File 'lib/moac/tx.rb', line 101
def data_hex=(hex)
self.data_bin = Utils.hex_to_bin(hex)
end
|
#encoded ⇒ Object
51
52
53
|
# File 'lib/moac/tx.rb', line 51
def encoded
RLP.encode self
end
|
#hash ⇒ Object
Also known as:
id
#sign(key) ⇒ Object
59
60
61
62
63
64
65
66
67
|
# File 'lib/moac/tx.rb', line 59
def sign(key)
self.signature = key.sign(unsigned_encoded)
vrs = Utils.v_r_s_for signature
self.v = vrs[0]
self.r = vrs[1]
self.s = vrs[2]
self
end
|
#to_h ⇒ Object
69
70
71
72
73
74
|
# File 'lib/moac/tx.rb', line 69
def to_h
hash_keys.inject({}) do |hash, field|
hash[field] = send field
hash
end
end
|
#unsigned_encoded ⇒ Object
43
44
45
|
# File 'lib/moac/tx.rb', line 43
def unsigned_encoded
RLP.encode(unsigned, sedes: sedes)
end
|