keoken 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.travis.yml +2 -0
- data/Gemfile.lock +1 -1
- data/README.md +21 -23
- data/Rakefile +5 -0
- data/lib/keoken/backend/bitcoin_ruby/transaction.rb +62 -0
- data/lib/keoken/version.rb +1 -1
- data/lib/keoken.rb +1 -1
- data/spec/keoken_spec.rb +72 -71
- metadata +3 -2
- data/lib/keoken/transaction/token.rb +0 -60
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ba894b4d1eb45706769ec0d108bd4c536e251df656b2fdc3c9e3afa00b579b23
|
4
|
+
data.tar.gz: a7c8394f8b7318b7c5a7c212f62daafcc2e8d315ca9709a3c84a9c43772698d0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: adea9c7e45ea15ca0f534aebd211438b332b46399d76ee43ad14a876707784bdabc763a87df80ef0d9e5f7966db3e627e24413a5d2e676f6e9550499dd051217
|
7
|
+
data.tar.gz: 5e07c420dd1807e7f836e66df385fabf3217632c7f4c0aff3d62b2557045bc69c294c7ef946d3063a6fc44cd03fac8099e8f1d56c4182cd3ba2022cc0d3b0dca
|
data/.travis.yml
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -24,13 +24,13 @@ Or install it yourself as:
|
|
24
24
|
|
25
25
|
### Create token and send it to the blockchain
|
26
26
|
|
27
|
-
```ruby
|
27
|
+
```ruby
|
28
28
|
# It uses bitcoin-ruby, but you can use Trezor or Electrum, the most important command is the script,
|
29
|
-
# which you can obtain with token.hex,
|
29
|
+
# which you can obtain with token.hex,
|
30
30
|
# then you can send it as an output with a scriptPubKey and a value of 0.
|
31
31
|
# In order to crate a token you need two outputs,
|
32
|
-
# the change address with an amount less than original (for fees)
|
33
|
-
# and the other one for the script. To send money you need three outputs,
|
32
|
+
# the change address with an amount less than original (for fees)
|
33
|
+
# and the other one for the script. To send money you need three outputs,
|
34
34
|
# the change address, the address who owns the recipient token and the script.
|
35
35
|
|
36
36
|
Bitcoin.network = :testnet3
|
@@ -43,20 +43,20 @@ script = token.hex
|
|
43
43
|
input_amount = 5_0000_0000
|
44
44
|
output_amount = 4_9991_0000
|
45
45
|
key = Bitcoin::Key.from_base58("cShKfHoHVf6iKKZym18ip1MJFQFxJwbcLxW53MQikxdDsGd2oxBU")
|
46
|
-
@transaction_token = Keoken::Transaction
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
46
|
+
@transaction_token = Keoken::Backend::BitcoinRuby::Transaction.create(tx_id,
|
47
|
+
position,
|
48
|
+
input_script,
|
49
|
+
input_amount,
|
50
|
+
output_amount,
|
51
|
+
key,
|
52
|
+
script)
|
53
53
|
transaction = Keoken::Bitprim::Transaction.new(@transaction_token.raw)
|
54
54
|
transaction.send_tx
|
55
55
|
```
|
56
56
|
|
57
57
|
### Send token money and send transaction to the blockchain
|
58
58
|
|
59
|
-
```ruby
|
59
|
+
```ruby
|
60
60
|
Bitcoin.network = :testnet3
|
61
61
|
transaction = Keoken::Bitprim::Transaction.new
|
62
62
|
data = transaction.get_assets_by_address('mro9aqn4xCzXVS7jRFFuzT2ERKonvPdSDAs')
|
@@ -71,25 +71,23 @@ output_amount = 4_9991_0000
|
|
71
71
|
output_amount_address = 20_000
|
72
72
|
output_address = 'mnTd41YZ1e1YqsaPNJh3wkeSUrFvp1guzi'
|
73
73
|
key = Bitcoin::Key.from_base58("cShKfHoHVf6iKKZym18ip1MJFQFxJwbcLxW53MQikxdDsGd2oxBU")
|
74
|
-
@transaction_token = Keoken::Transaction
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
74
|
+
@transaction_token = Keoken::Backend::BitcoinRuby::Transaction.send_amount(tx_id,
|
75
|
+
position,
|
76
|
+
input_script,
|
77
|
+
input_amount,
|
78
|
+
output_amount,
|
79
|
+
output_amount_address,
|
80
|
+
output_address,
|
81
|
+
key,
|
82
|
+
script)
|
83
83
|
transaction = Keoken::Bitprim::Transaction.new(@transaction_token.raw)
|
84
84
|
transaction.send_tx
|
85
85
|
```
|
86
86
|
|
87
|
-
|
88
87
|
## Contributing
|
89
88
|
|
90
89
|
Bug reports and pull requests are welcome on GitHub at https://github.com/bitex-la/keoken-ruby.
|
91
90
|
|
92
|
-
|
93
91
|
## License
|
94
92
|
|
95
93
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
module Keoken
|
2
|
+
module Backend
|
3
|
+
module BitcoinRuby
|
4
|
+
class Transaction
|
5
|
+
attr_accessor :to_json, :raw
|
6
|
+
extend Bitcoin::Builder
|
7
|
+
|
8
|
+
def self.create(tx_id, position, input_script, input_amount, output_amount, key, script)
|
9
|
+
token = self.new
|
10
|
+
tx = build_tx do |t|
|
11
|
+
t.input do |i|
|
12
|
+
i.prev_out(tx_id, position, input_script.htb, input_amount, 0)
|
13
|
+
i.signature_key(key)
|
14
|
+
end
|
15
|
+
t.output do |o|
|
16
|
+
o.value output_amount
|
17
|
+
o.script do |s|
|
18
|
+
s.recipient(key.addr)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
t.output do |o|
|
22
|
+
o.value 0
|
23
|
+
o.to(script, :custom)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
token.to_json = tx.to_json
|
27
|
+
token.raw = tx.to_payload.bth
|
28
|
+
token
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.send_amount(tx_id, position, input_script, input_amount, output_amount, output_amount_to_addr2, addr2, key, script)
|
32
|
+
token = self.new
|
33
|
+
tx = build_tx do |t|
|
34
|
+
t.input do |i|
|
35
|
+
i.prev_out(tx_id, position, input_script.htb, input_amount, 0)
|
36
|
+
i.signature_key(key)
|
37
|
+
end
|
38
|
+
t.output do |o|
|
39
|
+
o.value output_amount_to_addr2
|
40
|
+
o.script do |s|
|
41
|
+
s.recipient(addr2)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
t.output do |o|
|
45
|
+
o.value output_amount
|
46
|
+
o.script do |s|
|
47
|
+
s.recipient(key.addr)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
t.output do |o|
|
51
|
+
o.value 0
|
52
|
+
o.to(script, :custom)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
token.to_json = tx.to_json
|
56
|
+
token.raw = tx.to_payload.bth
|
57
|
+
token
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
data/lib/keoken/version.rb
CHANGED
data/lib/keoken.rb
CHANGED
@@ -2,7 +2,7 @@ require 'bitcoin'
|
|
2
2
|
|
3
3
|
require 'keoken/extensions/bitcoin/script'
|
4
4
|
require 'keoken/token'
|
5
|
-
require 'keoken/transaction
|
5
|
+
require 'keoken/backend/bitcoin_ruby/transaction'
|
6
6
|
require 'keoken/bitprim/transaction'
|
7
7
|
require 'keoken/errors/id_not_found'
|
8
8
|
require 'keoken/errors/name_not_found'
|
data/spec/keoken_spec.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe Keoken do
|
4
|
-
it
|
4
|
+
it "has a version number" do
|
5
5
|
expect(Keoken::VERSION).not_to be nil
|
6
6
|
end
|
7
7
|
|
8
|
-
it
|
8
|
+
it "defines keoken constants" do
|
9
9
|
expect(Keoken::PREFIX_SIZE).not_to be nil
|
10
10
|
expect(Keoken::PREFIX).not_to be nil
|
11
11
|
expect(Keoken::VERSION_NODE).not_to be nil
|
@@ -17,170 +17,171 @@ describe Keoken do
|
|
17
17
|
expect(Keoken::ASSET_ID_SIZE).not_to be nil
|
18
18
|
end
|
19
19
|
|
20
|
-
it
|
21
|
-
token = Keoken::Token.new(name:
|
20
|
+
it "creates the test-keoken token" do
|
21
|
+
token = Keoken::Token.new(name: "test-keoken")
|
22
22
|
token.create(1_000_000)
|
23
23
|
expect(token.hex).to(
|
24
|
-
eq(
|
24
|
+
eq("6a0400004b501800000000746573742d6b656f6b656e000000000001000000")
|
25
25
|
)
|
26
26
|
end
|
27
27
|
|
28
|
-
it
|
28
|
+
it "raise an error when name is not provided" do
|
29
29
|
token = Keoken::Token.new
|
30
30
|
expect { token.create(1_000_000) }.to raise_error(Keoken::NameNotFound)
|
31
31
|
end
|
32
32
|
|
33
|
-
it
|
33
|
+
it "raise an error when id is not provided" do
|
34
34
|
token = Keoken::Token.new
|
35
35
|
expect { token.send_amount(1_000_000) }.to raise_error(Keoken::IdNotFound)
|
36
36
|
end
|
37
37
|
|
38
|
-
it
|
38
|
+
it "send 1_000_000 to token with 34 id" do
|
39
39
|
token = Keoken::Token.new(id: 34)
|
40
40
|
token.send_amount(1_000_000)
|
41
41
|
expect(token.hex).to(
|
42
|
-
eq(
|
42
|
+
eq("6a0400004b501000000001000000340000000001000000")
|
43
43
|
)
|
44
44
|
end
|
45
45
|
|
46
|
-
describe
|
46
|
+
describe "creates token" do
|
47
47
|
before(:each) do
|
48
48
|
Bitcoin.network = :testnet3
|
49
|
-
token = Keoken::Token.new(name:
|
49
|
+
token = Keoken::Token.new(name: "test-keoken")
|
50
50
|
token.create(1_000_000)
|
51
|
-
tx_id =
|
52
|
-
input_script =
|
51
|
+
tx_id = "aa699dc5ddf598a50dc2cb2cb2729629cb9d2d865df38e4367d13f81ef55f96e"
|
52
|
+
input_script = "76a9147bb97684cc43e2f8ea0ed1d50dddce3ebf80063888ac"
|
53
53
|
position = 0
|
54
54
|
script = token.hex
|
55
55
|
input_amount = 5_0000_0000
|
56
56
|
output_amount = 4_9991_0000
|
57
57
|
key = Bitcoin::Key.from_base58("cShKfHoHVf6iKKZym18ip1MJFQFxJwbcLxW53MQikxdDsGd2oxBU")
|
58
|
-
|
58
|
+
|
59
|
+
@transaction_token = Keoken::Backend::BitcoinRuby::Transaction.create(tx_id, position, input_script, input_amount, output_amount, key, script)
|
59
60
|
end
|
60
61
|
|
61
|
-
it
|
62
|
+
it "format to_json" do
|
62
63
|
json = JSON.parse(@transaction_token.to_json)
|
63
|
-
expect(json[
|
64
|
+
expect(json["out"]).to(
|
64
65
|
eq(
|
65
66
|
[
|
66
67
|
{
|
67
68
|
"value" => "4.99910000",
|
68
|
-
"scriptPubKey" => "OP_DUP OP_HASH160 7bb97684cc43e2f8ea0ed1d50dddce3ebf800638 OP_EQUALVERIFY OP_CHECKSIG"
|
69
|
+
"scriptPubKey" => "OP_DUP OP_HASH160 7bb97684cc43e2f8ea0ed1d50dddce3ebf800638 OP_EQUALVERIFY OP_CHECKSIG",
|
69
70
|
},
|
70
71
|
{
|
71
72
|
"value" => "0.00000000",
|
72
|
-
"scriptPubKey" => "OP_RETURN 00004b50 00000000746573742d6b656f6b656e000000000001000000"
|
73
|
-
}
|
73
|
+
"scriptPubKey" => "OP_RETURN 00004b50 00000000746573742d6b656f6b656e000000000001000000",
|
74
|
+
},
|
74
75
|
]
|
75
76
|
)
|
76
77
|
)
|
77
78
|
end
|
78
79
|
|
79
|
-
it
|
80
|
+
it "raw transaction" do
|
80
81
|
raw = @transaction_token.raw
|
81
|
-
expect(raw).to start_with(
|
82
|
-
expect(raw).to end_with(
|
82
|
+
expect(raw).to start_with("01000000016ef955ef813fd167438ef35d862d9dcb299672b22ccbc20da598f5ddc59d69aa00000000")
|
83
|
+
expect(raw).to end_with("6a0400004b501800000000746573742d6b656f6b656e00000000000100000000000000")
|
83
84
|
end
|
84
85
|
|
85
|
-
it
|
86
|
-
stub_request(:post,
|
87
|
-
.with(:body => {"rawtx"=> /01000000016ef955ef813fd167438ef35d862d9dcb/},
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
.to_return(status: 200, body:
|
86
|
+
it "broadcast transaction" do
|
87
|
+
stub_request(:post, "http://tbch.blockdozer.com:443/insight-api/tx/send")
|
88
|
+
.with(:body => {"rawtx" => /01000000016ef955ef813fd167438ef35d862d9dcb/},
|
89
|
+
headers: {
|
90
|
+
"Accept" => "*/*",
|
91
|
+
"Accept-Encoding" => "gzip;q=1.0,deflate;q=0.6,identity;q=0.3",
|
92
|
+
"Content-Type" => "application/x-www-form-urlencoded",
|
93
|
+
"Host" => "tbch.blockdozer.com",
|
94
|
+
"User-Agent" => "Ruby",
|
95
|
+
})
|
96
|
+
.to_return(status: 200, body: "", headers: {})
|
96
97
|
transaction = Keoken::Bitprim::Transaction.new
|
97
98
|
expect(transaction.send_tx(@transaction_token.raw)).to be_nil
|
98
99
|
end
|
99
100
|
end
|
100
101
|
|
101
|
-
describe
|
102
|
+
describe "send money token" do
|
102
103
|
before(:each) do
|
103
104
|
Bitcoin.network = :testnet3
|
104
105
|
token = Keoken::Token.new(id: 21)
|
105
106
|
token.send_amount(500_000)
|
106
|
-
tx_id =
|
107
|
-
input_script =
|
107
|
+
tx_id = "aa699dc5ddf598a50dc2cb2cb2729629cb9d2d865df38e4367d13f81ef55f96e"
|
108
|
+
input_script = "76a9147bb97684cc43e2f8ea0ed1d50dddce3ebf80063888ac"
|
108
109
|
position = 0
|
109
110
|
script = token.hex
|
110
111
|
input_amount = 5_0000_0000
|
111
112
|
output_amount = 4_9991_0000
|
112
113
|
output_amount_address = 20_000
|
113
|
-
output_address =
|
114
|
+
output_address = "mnTd41YZ1e1YqsaPNJh3wkeSUrFvp1guzi"
|
114
115
|
key = Bitcoin::Key.from_base58("cShKfHoHVf6iKKZym18ip1MJFQFxJwbcLxW53MQikxdDsGd2oxBU")
|
115
|
-
@transaction_token = Keoken::Transaction
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
116
|
+
@transaction_token = Keoken::Backend::BitcoinRuby::Transaction.send_amount(tx_id,
|
117
|
+
position,
|
118
|
+
input_script,
|
119
|
+
input_amount,
|
120
|
+
output_amount,
|
121
|
+
output_amount_address,
|
122
|
+
output_address,
|
123
|
+
key,
|
124
|
+
script)
|
124
125
|
end
|
125
126
|
|
126
|
-
it
|
127
|
+
it "format to_json" do
|
127
128
|
json = JSON.parse(@transaction_token.to_json)
|
128
|
-
expect(json[
|
129
|
+
expect(json["out"]).to(
|
129
130
|
eq(
|
130
131
|
[
|
131
132
|
{
|
132
133
|
"value" => "0.00020000",
|
133
|
-
"scriptPubKey" => "OP_DUP OP_HASH160 4c2791f07c046ef21d688f12296f91ad7b44d2bb OP_EQUALVERIFY OP_CHECKSIG"
|
134
|
+
"scriptPubKey" => "OP_DUP OP_HASH160 4c2791f07c046ef21d688f12296f91ad7b44d2bb OP_EQUALVERIFY OP_CHECKSIG",
|
134
135
|
},
|
135
136
|
{
|
136
|
-
"value"=>"4.99910000",
|
137
|
-
"scriptPubKey"=> "OP_DUP OP_HASH160 7bb97684cc43e2f8ea0ed1d50dddce3ebf800638 OP_EQUALVERIFY OP_CHECKSIG"
|
137
|
+
"value" => "4.99910000",
|
138
|
+
"scriptPubKey" => "OP_DUP OP_HASH160 7bb97684cc43e2f8ea0ed1d50dddce3ebf800638 OP_EQUALVERIFY OP_CHECKSIG",
|
138
139
|
},
|
139
140
|
{
|
140
141
|
"value" => "0.00000000",
|
141
|
-
"scriptPubKey" => "OP_RETURN 00004b50 00000001000000210000000000500000"
|
142
|
-
}
|
142
|
+
"scriptPubKey" => "OP_RETURN 00004b50 00000001000000210000000000500000",
|
143
|
+
},
|
143
144
|
]
|
144
145
|
)
|
145
146
|
)
|
146
147
|
end
|
147
148
|
|
148
|
-
it
|
149
|
+
it "raw transaction" do
|
149
150
|
raw = @transaction_token.raw
|
150
|
-
expect(raw).to start_with(
|
151
|
-
expect(raw).to end_with(
|
151
|
+
expect(raw).to start_with("01000000016ef955ef813fd167438ef35d862d9dcb299672b22ccbc20da598f5ddc59d69aa00000000")
|
152
|
+
expect(raw).to end_with("6a0400004b50100000000100000021000000000050000000000000")
|
152
153
|
end
|
153
154
|
end
|
154
155
|
|
155
|
-
describe
|
156
|
+
describe "get assets" do
|
156
157
|
before(:each) do
|
157
158
|
Bitcoin.network = :testnet3
|
158
159
|
end
|
159
160
|
|
160
|
-
it
|
161
|
+
it "get assets by address mnTd41YZ1e1YqsaPNJh3wkeSUrFvp1guzi" do
|
161
162
|
body_response = "[{'amount': 100000, 'asset_creator': 'mnTd41YZ1e1YqsaPNJh3wkeSUrFvp1guzi', 'asset_id': 123, 'asset_name': 'keoken-token'}]"
|
162
|
-
stub_request(:get,
|
163
|
+
stub_request(:get, "https://explorer.testnet.keoken.io/api/get_assets_by_address?address=mnTd41YZ1e1YqsaPNJh3wkeSUrFvp1guzi")
|
163
164
|
.with(
|
164
165
|
headers: {
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
}
|
166
|
+
"Accept" => "*/*",
|
167
|
+
"Accept-Encoding" => "gzip;q=1.0,deflate;q=0.6,identity;q=0.3",
|
168
|
+
"Host" => "explorer.testnet.keoken.io",
|
169
|
+
"User-Agent" => "Ruby",
|
170
|
+
},
|
170
171
|
)
|
171
172
|
.to_return(status: 200, body: body_response, headers: {})
|
172
173
|
|
173
174
|
transaction = Keoken::Bitprim::Transaction.new
|
174
|
-
assets = transaction.get_assets_by_address(
|
175
|
+
assets = transaction.get_assets_by_address("mnTd41YZ1e1YqsaPNJh3wkeSUrFvp1guzi")
|
175
176
|
|
176
177
|
expect(assets).to eq(
|
177
178
|
[
|
178
179
|
{
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
}
|
180
|
+
"amount" => 100_000,
|
181
|
+
"asset_creator" => "mnTd41YZ1e1YqsaPNJh3wkeSUrFvp1guzi",
|
182
|
+
"asset_id" => 123,
|
183
|
+
"asset_name" => "keoken-token",
|
184
|
+
},
|
184
185
|
]
|
185
186
|
)
|
186
187
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: keoken
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bitex
|
@@ -120,15 +120,16 @@ files:
|
|
120
120
|
- Gemfile
|
121
121
|
- Gemfile.lock
|
122
122
|
- README.md
|
123
|
+
- Rakefile
|
123
124
|
- keoken.gemspec
|
124
125
|
- lib/keoken.rb
|
126
|
+
- lib/keoken/backend/bitcoin_ruby/transaction.rb
|
125
127
|
- lib/keoken/bitprim/config.yaml
|
126
128
|
- lib/keoken/bitprim/transaction.rb
|
127
129
|
- lib/keoken/errors/id_not_found.rb
|
128
130
|
- lib/keoken/errors/name_not_found.rb
|
129
131
|
- lib/keoken/extensions/bitcoin/script.rb
|
130
132
|
- lib/keoken/token.rb
|
131
|
-
- lib/keoken/transaction/token.rb
|
132
133
|
- lib/keoken/version.rb
|
133
134
|
- spec/keoken_spec.rb
|
134
135
|
- spec/spec_helper.rb
|
@@ -1,60 +0,0 @@
|
|
1
|
-
module Keoken
|
2
|
-
module Transaction
|
3
|
-
class Token
|
4
|
-
attr_accessor :to_json, :raw
|
5
|
-
extend Bitcoin::Builder
|
6
|
-
|
7
|
-
def self.create(tx_id, position, input_script, input_amount, output_amount, key, script)
|
8
|
-
token = self.new
|
9
|
-
tx = build_tx do |t|
|
10
|
-
t.input do |i|
|
11
|
-
i.prev_out(tx_id, position, input_script.htb, input_amount, 0)
|
12
|
-
i.signature_key(key)
|
13
|
-
end
|
14
|
-
t.output do |o|
|
15
|
-
o.value output_amount
|
16
|
-
o.script do |s|
|
17
|
-
s.recipient(key.addr)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
t.output do |o|
|
21
|
-
o.value 0
|
22
|
-
o.to(script, :custom)
|
23
|
-
end
|
24
|
-
end
|
25
|
-
token.to_json = tx.to_json
|
26
|
-
token.raw = tx.to_payload.bth
|
27
|
-
token
|
28
|
-
end
|
29
|
-
|
30
|
-
def self.send_amount(tx_id, position, input_script, input_amount, output_amount, output_amount_to_addr2, addr2, key, script)
|
31
|
-
token = self.new
|
32
|
-
tx = build_tx do |t|
|
33
|
-
t.input do |i|
|
34
|
-
i.prev_out(tx_id, position, input_script.htb, input_amount, 0)
|
35
|
-
i.signature_key(key)
|
36
|
-
end
|
37
|
-
t.output do |o|
|
38
|
-
o.value output_amount_to_addr2
|
39
|
-
o.script do |s|
|
40
|
-
s.recipient(addr2)
|
41
|
-
end
|
42
|
-
end
|
43
|
-
t.output do |o|
|
44
|
-
o.value output_amount
|
45
|
-
o.script do |s|
|
46
|
-
s.recipient(key.addr)
|
47
|
-
end
|
48
|
-
end
|
49
|
-
t.output do |o|
|
50
|
-
o.value 0
|
51
|
-
o.to(script, :custom)
|
52
|
-
end
|
53
|
-
end
|
54
|
-
token.to_json = tx.to_json
|
55
|
-
token.raw = tx.to_payload.bth
|
56
|
-
token
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|