stellar-base 0.14.0 → 0.15.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 6d155c06a6614979a0ea9eba7e5dcd903066c724
4
- data.tar.gz: 0c64ccb007896ef7ce617b19aff2d542f9fe40cb
2
+ SHA256:
3
+ metadata.gz: fa23fad0329efcda8cb73f539a3adc91b735d573937b0ba392fd9c992dc3e067
4
+ data.tar.gz: 24d04f5f147f3c28cb3bcaed0388b4400746893b1fda8148a1da1eee690bbf80
5
5
  SHA512:
6
- metadata.gz: 00a096af9c978b25848d9a2efd572cc279e52e4860c5db26dee72a7ab954693b09b9e5178b6d63f1c0ff977de8ea0ee83cfd07c58332ce0045b67dbf86eb2706
7
- data.tar.gz: f19a0bad6a1489411bb673ecf060a5232aa3c76ee029f6f24c901769501c709dc3058c693bb19fc4ba2defba259b24faa55b844e66b76c8ef5ce8d536b4d89d4
6
+ metadata.gz: a03b5ee1650f1c98d93f014d6d5e3ceabdd0470913a76704e590a770359b3881e0d841ce7da0fd9136affd7b950a3819a3cc7bb5d4f285c83414f43ce408c532
7
+ data.tar.gz: f81d001d2cb2da33752e039419d0ae151ab55820f41c8a7e06fbb3b4ac631eb9010aee5bd4252dce0cfa552281cdda986a2f35d862fb9098257d27a057ee57ec
data/CHANGELOG.md CHANGED
@@ -6,7 +6,14 @@ file. This project adheres to [Semantic Versioning](http://semver.org/).
6
6
  As this project is pre 1.0, breaking changes may happen for minor version
7
7
  bumps. A breaking change will get clearly notified in this log.
8
8
 
9
- ## [unreleased](https://github.com/stellar/ruby-stellar-base/compare/v0.14.0...master)
9
+ ## [unreleased](https://github.com/stellar/ruby-stellar-base/compare/v0.15.0...master)
10
+
11
+ ## [0.15.0](https://github.com/stellar/ruby-stellar-base/compare/v0.14.0...v0.15.0)
12
+ ### Added
13
+ - `Stellar::Operation.change_trust` can accept `Stellar::Asset` instance for `line`
14
+
15
+ ### Fixed
16
+ - Protect `Stellar::Operation.change_trust` against malicious arguments, in the event that developers pass this argument directly from user input
10
17
 
11
18
  ## [0.14.0](https://github.com/stellar/ruby-stellar-base/compare/v0.13.0...v0.14.0)
12
19
 
data/lib/stellar/asset.rb CHANGED
@@ -1,5 +1,7 @@
1
1
  module Stellar
2
2
  class Asset
3
+ TYPES = %i(native alphanum4 alphanum12)
4
+
3
5
  def self.native
4
6
  new(:asset_type_native)
5
7
  end
@@ -1,5 +1,5 @@
1
1
  module Stellar
2
2
  module Base
3
- VERSION = "0.14.0"
3
+ VERSION = "0.15.0"
4
4
  end
5
5
  end
@@ -115,14 +115,21 @@ module Stellar
115
115
  # transactions `operations` array.
116
116
  #
117
117
  # @param [Hash] attributes the attributes to create the operation with
118
- # @option attributes [Stellar::Currrency] :line the asset to trust
118
+ # @option attributes [Stellar::Asset] :line the asset to trust
119
119
  # @option attributes [Fixnum] :limit the maximum amount to trust, defaults to max int64,
120
120
  # if the limit is set to 0 it deletes the trustline.
121
121
  #
122
122
  # @return [Stellar::Operation] the built operation, containing a
123
123
  # Stellar::ChangeTrustOp body
124
124
  def self.change_trust(attributes={})
125
- line = Asset.send(*attributes[:line])
125
+ line = attributes[:line]
126
+ if !line.is_a?(Asset)
127
+ if !Asset::TYPES.include?(line[0])
128
+ fail ArgumentError, "must be one of #{Asset::TYPES}"
129
+ end
130
+ line = Asset.send(*line)
131
+ end
132
+
126
133
  limit = attributes.key?(:limit) ? interpret_amount(attributes[:limit]) : MAX_INT64
127
134
 
128
135
  raise ArgumentError, "Bad :limit #{limit}" unless limit.is_a?(Integer)
@@ -41,6 +41,20 @@ describe Stellar::Operation, ".change_trust" do
41
41
  expect(op.body.value.limit).to eq(9223372036854775807)
42
42
  end
43
43
 
44
+ it "creates a ChangeTrustOp with an asset" do
45
+ asset = Stellar::Asset.alphanum4("USD", issuer)
46
+ op = Stellar::Operation.change_trust(line: asset, limit: 1234.75)
47
+ expect(op.body.value).to be_an_instance_of(Stellar::ChangeTrustOp)
48
+ expect(op.body.value.line).to eq(Stellar::Asset.alphanum4("USD", issuer))
49
+ expect(op.body.value.limit).to eq(12347500000)
50
+ end
51
+
52
+ it "only allow sound `line` arguments" do
53
+ expect {
54
+ Stellar::Operation.change_trust(line: [:harmful_call, "USD", issuer])
55
+ }.to raise_error(ArgumentError, "must be one of #{Stellar::Asset::TYPES}")
56
+ end
57
+
44
58
  it "creates a ChangeTrustOp with limit" do
45
59
  op = Stellar::Operation.change_trust(line: [:alphanum4, "USD", issuer], limit: 1234.75)
46
60
  expect(op.body.value).to be_an_instance_of(Stellar::ChangeTrustOp)
@@ -54,4 +68,4 @@ describe Stellar::Operation, ".change_trust" do
54
68
  }.to raise_error(ArgumentError)
55
69
  end
56
70
 
57
- end
71
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stellar-base
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.14.0
4
+ version: 0.15.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Scott Fleckenstein
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-04-06 00:00:00.000000000 Z
11
+ date: 2018-06-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: xdr
@@ -451,7 +451,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
451
451
  version: '0'
452
452
  requirements: []
453
453
  rubyforge_project:
454
- rubygems_version: 2.6.8
454
+ rubygems_version: 2.7.6
455
455
  signing_key:
456
456
  specification_version: 4
457
457
  summary: 'Stellar client library: XDR'