stellar-base 0.0.13 → 0.0.14
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/stellar/account_flags.rb +13 -4
- data/lib/stellar/base/version.rb +1 -1
- data/lib/stellar/operation.rb +1 -0
- data/lib/stellar/thresholds.rb +39 -0
- data/lib/stellar-base.rb +1 -0
- data/spec/lib/stellar/convert_spec.rb +1 -1
- data/spec/lib/stellar/thresholds_spec.rb +62 -0
- metadata +4 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 062552ef5cccd186214542007e7c896a77c8d27d
|
4
|
+
data.tar.gz: 6612c84a962b96295677d3d1c8902a9649f7a461
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 234682c2b9fbdb75608640587e1c6c219372a15ea9688b262a4efdb3899550c1f8ea5c1563af8a7c24039c28ef77fb4ecbd3b7a1a0ac1defd9335cc28eeea5fb
|
7
|
+
data.tar.gz: e3a5db925b179732ee9c61177c0f156989dabc75bb1ef4825b7320921429ac0b5132776b35ba7fa10b7a04fa2c4518caea7f1ce9a9d154b42be388fbac0e33fa
|
@@ -2,12 +2,12 @@ module Stellar
|
|
2
2
|
class AccountFlags
|
3
3
|
|
4
4
|
|
5
|
-
#
|
5
|
+
#
|
6
6
|
# Converts an array of Stellar::AccountFlags members into
|
7
7
|
# an Integer suitable for use in a SetOptionsOp.
|
8
|
-
#
|
8
|
+
#
|
9
9
|
# @param flags=nil [Array<Stellar::AccountFlags>] the flags to combine
|
10
|
-
#
|
10
|
+
#
|
11
11
|
# @return [Fixnum] the combined result
|
12
12
|
def self.make_mask(flags=nil)
|
13
13
|
flags ||= []
|
@@ -15,5 +15,14 @@ module Stellar
|
|
15
15
|
flags.map(&:value).inject(&:|) || 0
|
16
16
|
end
|
17
17
|
|
18
|
+
#
|
19
|
+
# Converts an integer used in SetOptionsOp on the set/clear flag options
|
20
|
+
# into an array of Stellar::AccountFlags members
|
21
|
+
#
|
22
|
+
# @param combined [Fixnum]
|
23
|
+
# @return [Array<Stellar::AccountFlags>]
|
24
|
+
def self.parse_mask(combined)
|
25
|
+
members.select{|m| (m.value & combined) != 0}
|
26
|
+
end
|
18
27
|
end
|
19
|
-
end
|
28
|
+
end
|
data/lib/stellar/base/version.rb
CHANGED
data/lib/stellar/operation.rb
CHANGED
@@ -188,6 +188,7 @@ module Stellar
|
|
188
188
|
op.clear_flags = Stellar::AccountFlags.make_mask attributes[:clear]
|
189
189
|
op.thresholds = attributes[:thresholds]
|
190
190
|
op.signer = attributes[:signer]
|
191
|
+
op.home_domain = attributes[:home_domain]
|
191
192
|
|
192
193
|
|
193
194
|
inflation_dest = attributes[:inflation_dest]
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module Stellar
|
2
|
+
class << Thresholds
|
3
|
+
COMPONENTS = [:master_weight, :low, :medium, :high]
|
4
|
+
VALID_RANGE = 0..255
|
5
|
+
|
6
|
+
def make(thresholds={})
|
7
|
+
|
8
|
+
# error if any of the needed components are not provided
|
9
|
+
if COMPONENTS.any?{|c| thresholds[c].blank? }
|
10
|
+
raise ArgumentError, "invalid thresholds hash, must have #{COMPONENTS.inspect} keys, had: #{thresholds.keys.inspect}"
|
11
|
+
end
|
12
|
+
|
13
|
+
# error if any of the needed components are not numbers 0 <= N <= 255
|
14
|
+
COMPONENTS.each do |c|
|
15
|
+
good = true
|
16
|
+
|
17
|
+
good &&= thresholds[c].is_a?(Fixnum)
|
18
|
+
good &&= VALID_RANGE.include? thresholds[c]
|
19
|
+
|
20
|
+
unless good
|
21
|
+
raise ArgumentError, "invalid #{c.inspect}, must be number in (0..255), got #{thresholds[c].inspect}"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
|
26
|
+
thresholds.values_at(*COMPONENTS).pack("C*")
|
27
|
+
end
|
28
|
+
|
29
|
+
def parse(combined)
|
30
|
+
master_weight, low, medium, high = combined.unpack("C*")
|
31
|
+
{
|
32
|
+
master_weight: master_weight,
|
33
|
+
low: low,
|
34
|
+
medium: medium,
|
35
|
+
high: high,
|
36
|
+
}
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
data/lib/stellar-base.rb
CHANGED
@@ -22,6 +22,7 @@ require_relative './stellar/currency'
|
|
22
22
|
require_relative './stellar/key_pair'
|
23
23
|
require_relative './stellar/operation'
|
24
24
|
require_relative './stellar/price'
|
25
|
+
require_relative './stellar/thresholds'
|
25
26
|
require_relative './stellar/transaction'
|
26
27
|
require_relative './stellar/transaction_envelope'
|
27
28
|
require_relative './stellar/util/base58'
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Stellar::Thresholds, ".parse" do
|
4
|
+
subject{ Stellar::Thresholds }
|
5
|
+
let(:raw) { "\x01\x02\x03\x04" }
|
6
|
+
let(:result) { subject.parse raw }
|
7
|
+
|
8
|
+
it "sets master_weight as the 1st byte" do
|
9
|
+
expect(result[:master_weight]).to eq(1)
|
10
|
+
end
|
11
|
+
|
12
|
+
it "sets low as the 2nd byte" do
|
13
|
+
expect(result[:low]).to eq(2)
|
14
|
+
end
|
15
|
+
|
16
|
+
it "sets medium as the 3rd byte" do
|
17
|
+
expect(result[:medium]).to eq(3)
|
18
|
+
end
|
19
|
+
|
20
|
+
it "sets high as the 4th byte" do
|
21
|
+
expect(result[:high]).to eq(4)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe Stellar::Thresholds, ".make" do
|
26
|
+
subject{ Stellar::Thresholds }
|
27
|
+
let(:good){{master_weight: 1, low: 2, medium: 3, high: 4}}
|
28
|
+
|
29
|
+
it "works" do
|
30
|
+
expect(subject.make(good)).to eq("\x01\x02\x03\x04")
|
31
|
+
end
|
32
|
+
|
33
|
+
it "errors unless all components are provided" do
|
34
|
+
expect{ subject.make(good.except(:master_weight)) }.to raise_error
|
35
|
+
expect{ subject.make(good.except(:low)) }.to raise_error
|
36
|
+
expect{ subject.make(good.except(:medium)) }.to raise_error
|
37
|
+
expect{ subject.make(good.except(:high)) }.to raise_error
|
38
|
+
end
|
39
|
+
|
40
|
+
it "errors unless all components are numbers" do
|
41
|
+
expect{ subject.make(good.merge(master_weight: "hello")) }.to raise_error
|
42
|
+
expect{ subject.make(good.merge(low: "hello")) }.to raise_error
|
43
|
+
expect{ subject.make(good.merge(medium: "hello")) }.to raise_error
|
44
|
+
expect{ subject.make(good.merge(high: "hello")) }.to raise_error
|
45
|
+
end
|
46
|
+
|
47
|
+
it "errors unless all components are in (0..255)" do
|
48
|
+
expect{ subject.make(good.merge(master_weight: -1)) }.to raise_error
|
49
|
+
expect{ subject.make(good.merge(master_weight: 256)) }.to raise_error
|
50
|
+
expect{ subject.make(good.merge(low: -1)) }.to raise_error
|
51
|
+
expect{ subject.make(good.merge(low: 256)) }.to raise_error
|
52
|
+
expect{ subject.make(good.merge(medium: -1)) }.to raise_error
|
53
|
+
expect{ subject.make(good.merge(medium: 256)) }.to raise_error
|
54
|
+
expect{ subject.make(good.merge(high: -1)) }.to raise_error
|
55
|
+
expect{ subject.make(good.merge(high: 256)) }.to raise_error
|
56
|
+
end
|
57
|
+
|
58
|
+
it "ignores additional keys" do
|
59
|
+
expect{ subject.make(good.merge(foo: "a string")) }.not_to raise_error
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stellar-base
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.14
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Scott Fleckenstein
|
@@ -317,6 +317,7 @@ files:
|
|
317
317
|
- lib/stellar/key_pair.rb
|
318
318
|
- lib/stellar/operation.rb
|
319
319
|
- lib/stellar/price.rb
|
320
|
+
- lib/stellar/thresholds.rb
|
320
321
|
- lib/stellar/transaction.rb
|
321
322
|
- lib/stellar/transaction_envelope.rb
|
322
323
|
- lib/stellar/util/base58.rb
|
@@ -325,6 +326,7 @@ files:
|
|
325
326
|
- spec/lib/stellar/convert_spec.rb
|
326
327
|
- spec/lib/stellar/key_pair_spec.rb
|
327
328
|
- spec/lib/stellar/price_spec.rb
|
329
|
+
- spec/lib/stellar/thresholds_spec.rb
|
328
330
|
- spec/lib/stellar/transaction_envelope_spec.rb
|
329
331
|
- spec/lib/stellar/transaction_spec.rb
|
330
332
|
- spec/lib/stellar/util/base58_spec.rb
|
@@ -371,6 +373,7 @@ test_files:
|
|
371
373
|
- spec/lib/stellar/convert_spec.rb
|
372
374
|
- spec/lib/stellar/key_pair_spec.rb
|
373
375
|
- spec/lib/stellar/price_spec.rb
|
376
|
+
- spec/lib/stellar/thresholds_spec.rb
|
374
377
|
- spec/lib/stellar/transaction_envelope_spec.rb
|
375
378
|
- spec/lib/stellar/transaction_spec.rb
|
376
379
|
- spec/lib/stellar/util/base58_spec.rb
|