Class: Eth::Tx
- Inherits:
-
Object
show all
- Extended by:
- Sedes
- Includes:
- RLP::Sedes::Serializable
- Defined in:
- lib/eth/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(*args) ⇒ Tx
Returns a new instance of Tx.
26
27
28
29
30
31
32
33
|
# File 'lib/eth/tx.rb', line 26
def initialize(*args)
fields = {v: 0, r: 0, s: 0}.merge parse_field_args(args)
fields[:to] = Utils.normalize_address(fields[:to])
serializable_initialize fields
check_transaction_validity
end
|
Instance Attribute Details
#signature ⇒ Object
66
67
68
69
70
71
|
# File 'lib/eth/tx.rb', line 66
def signature
return @signature if @signature
self.signature = [v, r, s].map do |integer|
Utils.int_to_base256 integer
end.join if [v, r, s].all?
end
|
Class Method Details
.decode(data) ⇒ Object
21
22
23
24
|
# File 'lib/eth/tx.rb', line 21
def self.decode(data)
data = Utils.hex_to_bin(data) if data.match(/\A\h+\Z/)
deserialize(RLP.decode data)
end
|
Instance Method Details
#encoded ⇒ Object
39
40
41
|
# File 'lib/eth/tx.rb', line 39
def encoded
RLP.encode self
end
|
#from ⇒ Object
61
62
63
64
|
# File 'lib/eth/tx.rb', line 61
def from
return @from if @from
@from ||= OpenSsl.recover_compact(signature_hash, signature) if signature
end
|
#hex ⇒ Object
43
44
45
|
# File 'lib/eth/tx.rb', line 43
def hex
bin_to_hex encoded
end
|
#sign(key) ⇒ Object
47
48
49
50
51
52
|
# File 'lib/eth/tx.rb', line 47
def sign(key)
self.signature = key.sign(unsigned_encoded)
self.vrs = Utils.v_r_s_for signature
self
end
|
#to_h ⇒ Object
54
55
56
57
58
59
|
# File 'lib/eth/tx.rb', line 54
def to_h
self.class.serializable_fields.keys.inject({}) do |hash, field|
hash[field] = send field
hash
end
end
|
#unsigned_encoded ⇒ Object
35
36
37
|
# File 'lib/eth/tx.rb', line 35
def unsigned_encoded
RLP.encode self, sedes: Tx.exclude([:v, :r, :s])
end
|