ethereum-tx 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +33 -8
- data/ethereum-tx.gemspec +3 -3
- data/lib/ethereum.rb +0 -1
- data/lib/ethereum/tx.rb +29 -3
- data/lib/ethereum/utils.rb +9 -0
- metadata +2 -3
- data/lib/ethereum/tx/version.rb +0 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fc27033601f87178ca950deac60cf55e4423993a
|
4
|
+
data.tar.gz: cce917c5ee1aba95dc0e0ac70293193c5acda069
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0489c124c62a0fd46dbd6094d0428773e419f38b91402aafe4e40be7b4a8c89e7bf42e14f0da0bdd817e8aa34ae768bc4317b59142148b9ff6a8cfbd7decb122
|
7
|
+
data.tar.gz: bd089946955e17cadd852f8561a0a8bf84cc66c448d67589197b90c0dbe0d563a08be22034edb205e0945a07c64e79a88f0118b26fcd67a17c9093a0fdaf42e6
|
data/README.md
CHANGED
@@ -1,8 +1,6 @@
|
|
1
1
|
# Ethereum::Tx
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
TODO: Delete this and the text above, and describe your gem
|
3
|
+
A simple, light weight, library to build and sign Ethereum transactions.
|
6
4
|
|
7
5
|
## Installation
|
8
6
|
|
@@ -22,20 +20,47 @@ Or install it yourself as:
|
|
22
20
|
|
23
21
|
## Usage
|
24
22
|
|
25
|
-
|
23
|
+
### Keys
|
24
|
+
Create a new key:
|
25
|
+
```
|
26
|
+
key = Ethereum::Key.new
|
27
|
+
```
|
28
|
+
Or import and existing one:
|
29
|
+
```
|
30
|
+
old_key = Ethereum::Key.new private_key
|
31
|
+
```
|
32
|
+
|
33
|
+
### Transactions
|
26
34
|
|
27
|
-
|
35
|
+
Build a transaction from scratch:
|
36
|
+
```
|
37
|
+
tx = Ethereum::Tx.new to: key.address, gas_price: 25_000, gas_limit: 25_000
|
38
|
+
tx.data = 'abcdef' #optional
|
39
|
+
tx.value = 1_000_000_000_000 #optional
|
40
|
+
```
|
41
|
+
Or decode an encoded raw transaction:
|
42
|
+
```
|
43
|
+
tx = Ethereum::Tx.decode hex
|
44
|
+
```
|
28
45
|
|
29
|
-
|
46
|
+
Then sign the transaction:
|
47
|
+
```
|
48
|
+
tx.sign key
|
49
|
+
```
|
50
|
+
Finally you can broadcast the raw transaction, `tx.encoded`, to your Ethereum node.
|
30
51
|
|
31
|
-
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
52
|
|
33
53
|
## Contributing
|
34
54
|
|
35
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
55
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/se3000/ethereum-tx.
|
36
56
|
|
37
57
|
|
38
58
|
## License
|
39
59
|
|
40
60
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
41
61
|
|
62
|
+
## TODO
|
63
|
+
- Better test suite.
|
64
|
+
- Expose API for HD keys.
|
65
|
+
- Separate out code pulled from [bitcoin-ruby](https://github.com/lian/bitcoin-ruby) and [ruby-ethereum](github.com/janx/ruby-ethereum) into their own gems to eliminate duplication.
|
66
|
+
- Support signing with [libsecp256k1](https://github.com/bitcoin-core/secp256k1).
|
data/ethereum-tx.gemspec
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
lib = File.expand_path('../lib', __FILE__)
|
3
3
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require 'ethereum
|
4
|
+
require 'ethereum'
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "ethereum-tx"
|
8
|
-
spec.version =
|
8
|
+
spec.version = '0.2.0'
|
9
9
|
spec.authors = ["Steve Ellis"]
|
10
10
|
spec.email = ["email@steveell.is"]
|
11
11
|
|
@@ -19,7 +19,7 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
20
|
spec.require_paths = ["lib"]
|
21
21
|
|
22
|
-
spec.add_dependency
|
22
|
+
spec.add_dependency "digest-sha3", "~> 1.1"
|
23
23
|
spec.add_dependency "ffi", "~> 1.0"
|
24
24
|
spec.add_dependency "money-tree", "~> 0.9"
|
25
25
|
spec.add_dependency "rlp", "~> 0.7"
|
data/lib/ethereum.rb
CHANGED
data/lib/ethereum/tx.rb
CHANGED
@@ -19,7 +19,12 @@ module Ethereum
|
|
19
19
|
s: big_endian_int
|
20
20
|
})
|
21
21
|
|
22
|
-
|
22
|
+
attr_writer :signature
|
23
|
+
|
24
|
+
def self.decode(data)
|
25
|
+
data = Utils.hex_to_bin(data) if data.match(/\A\h+\Z/)
|
26
|
+
deserialize(RLP.decode data)
|
27
|
+
end
|
23
28
|
|
24
29
|
def initialize(*args)
|
25
30
|
fields = {v: 0, r: 0, s: 0}.merge parse_field_args(args)
|
@@ -45,10 +50,27 @@ module Ethereum
|
|
45
50
|
self
|
46
51
|
end
|
47
52
|
|
53
|
+
def to_h
|
54
|
+
self.class.serializable_fields.keys.inject({}) do |hash, field|
|
55
|
+
hash[field] = send field
|
56
|
+
hash
|
57
|
+
end
|
58
|
+
end
|
48
59
|
|
49
|
-
|
60
|
+
def from
|
61
|
+
return @from if @from
|
62
|
+
@from ||= OpenSsl.recover_compact(signature_hash, signature) if signature
|
63
|
+
end
|
50
64
|
|
51
|
-
|
65
|
+
def signature
|
66
|
+
return @signature if @signature
|
67
|
+
self.signature = [v, r, s].map do |integer|
|
68
|
+
Utils.int_to_base256 integer
|
69
|
+
end.join if [v, r, s].all?
|
70
|
+
end
|
71
|
+
|
72
|
+
|
73
|
+
private
|
52
74
|
|
53
75
|
def check_transaction_validity
|
54
76
|
if [gas_price, gas_limit, value, nonce].max > UINT_MAX
|
@@ -72,5 +94,9 @@ module Ethereum
|
|
72
94
|
GTXDATANONZERO * num_non_zero_bytes
|
73
95
|
end
|
74
96
|
|
97
|
+
def signature_hash
|
98
|
+
Utils.keccak256 unsigned_encoded
|
99
|
+
end
|
100
|
+
|
75
101
|
end
|
76
102
|
end
|
data/lib/ethereum/utils.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ethereum-tx
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Steve Ellis
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-05-
|
11
|
+
date: 2016-05-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: digest-sha3
|
@@ -144,7 +144,6 @@ files:
|
|
144
144
|
- lib/ethereum/open_ssl.rb
|
145
145
|
- lib/ethereum/sedes.rb
|
146
146
|
- lib/ethereum/tx.rb
|
147
|
-
- lib/ethereum/tx/version.rb
|
148
147
|
- lib/ethereum/utils.rb
|
149
148
|
homepage: https://github.com/se3000/ethereum-tx
|
150
149
|
licenses:
|