stellar-base 0.24.0 → 0.25.0
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/CHANGELOG.md +42 -32
- data/README.md +4 -4
- data/lib/stellar-base.rb +3 -0
- data/lib/stellar/asset.rb +10 -0
- data/lib/stellar/base/version.rb +1 -1
- data/lib/stellar/compat.rb +0 -4
- data/lib/stellar/concerns/transaction.rb +2 -3
- data/lib/stellar/dsl.rb +9 -5
- data/lib/stellar/ext/xdr.rb +8 -7
- data/lib/stellar/key_pair.rb +22 -23
- data/lib/stellar/ledger_key.rb +4 -2
- data/lib/stellar/muxed_account.rb +16 -0
- data/lib/stellar/operation.rb +4 -3
- data/lib/stellar/transaction.rb +1 -1
- data/lib/stellar/transaction_envelope.rb +6 -16
- data/lib/stellar/transaction_v0.rb +2 -10
- metadata +7 -5
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 06de7ab1f501228afa8b011a494da83f9a75c9723f2612868bb7e324ee309794
|
|
4
|
+
data.tar.gz: 9a0f29f6b55bf4e508dc54a3fb131b411799022c2bf87fd5246119e681efaf99
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: fb09428b1c5c96b291a114132c989b9cd5aa602a2e67989748c014de1bc6179fad881449e5dcaeb956b3ae5dc2c259f740d9223d822e35da29831c6a62465c73
|
|
7
|
+
data.tar.gz: 5a31dee71d5d6dd1140eebc06f8ae353d6a63e7678e4be220e8f572b6d77268b77948303d62ec4d2b06dc2e3896e0eda0a41995436a82525fb481ace9ca16241
|
data/CHANGELOG.md
CHANGED
|
@@ -1,87 +1,97 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this
|
|
4
|
-
file.
|
|
4
|
+
file. The format is based on [Keep a Changelog](http://keepachangelog.com/)
|
|
5
|
+
and this project adheres to [Semantic Versioning](http://semver.org/).
|
|
5
6
|
|
|
6
7
|
As this project is pre 1.0, breaking changes may happen for minor version
|
|
7
8
|
bumps. A breaking change will get clearly notified in this log.
|
|
8
9
|
|
|
9
|
-
## [Unreleased]
|
|
10
|
+
## [Unreleased](https://github.com/stellar/ruby-stellar-sdk/compare/v0.25.0...master)
|
|
11
|
+
|
|
12
|
+
## [0.25.0](https://github.com/stellar/ruby-stellar-sdk/compare/v0.24.0...v0.25.0) - 2020-10-30
|
|
13
|
+
### Added
|
|
14
|
+
- `MuxedAccount` implements `#to_keypair` conversion protocol
|
|
15
|
+
- `MuxedAccount` correctly responds to `#address` with strkey encoded public key
|
|
16
|
+
### Fixed
|
|
17
|
+
- `Transaction::V0#source_account` now properly returns `MuxedAccount` instead of raw bytes
|
|
18
|
+
|
|
19
|
+
## [0.24.0](https://github.com/stellar/ruby-stellar-sdk/compare/v0.23.1...v0.24.0) - 2020-10-20
|
|
10
20
|
### Added
|
|
11
21
|
- Add conversion methods for KeyPair and Asset
|
|
12
22
|
- Stellar Protocol 14 support
|
|
13
23
|
- Regenerate XDR wrappers from definitions in stellar-core 14.1.1
|
|
14
24
|
- Add [CAP-23 Two-Part Payments](https://github.com/stellar/stellar-protocol/blob/master/core/cap-0023.md) support
|
|
15
25
|
- Add ClaimPredicate DSL methods which help with creation of claim predicates.
|
|
16
|
-
```
|
|
17
|
-
# use class-level helpers to create simple predicates
|
|
26
|
+
```ruby
|
|
27
|
+
# use class-level helpers to create simple predicates
|
|
18
28
|
unconditional = Stellar::ClaimPredicate.unconditional
|
|
19
29
|
before_rel_time = Stellar::ClaimPredicate.before_relative_time(1.hour)
|
|
20
30
|
before_abs_time = Stellar::ClaimPredicate.before_absolute_time(Date.tomorrow.beginning_of_day)
|
|
21
|
-
|
|
31
|
+
|
|
22
32
|
# negate predicates using `~` unary operator
|
|
23
33
|
~predicate # same as predicate.not
|
|
24
|
-
|
|
34
|
+
|
|
25
35
|
# build complex predicates using `&` and `|` infix operators
|
|
26
36
|
predicate & other_predicate # same as `predicate.and(other_predicate)`
|
|
27
37
|
predicate | other_predicate # same as `predicate.or(other_predicate)`
|
|
28
|
-
|
|
29
|
-
# quickly define complex predicates using `.compose` class method with the block
|
|
38
|
+
|
|
39
|
+
# quickly define complex predicates using `.compose` class method with the block
|
|
30
40
|
unconditional = Stellar::ClaimPredicate.compose { }
|
|
31
|
-
complex = Stellar::ClaimPredicate.compose do
|
|
32
|
-
before_relative_time(1.week) & ~before_relative_time(10.seconds) |
|
|
41
|
+
complex = Stellar::ClaimPredicate.compose do
|
|
42
|
+
before_relative_time(1.week) & ~before_relative_time(10.seconds) |
|
|
33
43
|
end
|
|
34
|
-
|
|
35
|
-
# here's what building this predicate would look like without DSL
|
|
44
|
+
|
|
45
|
+
# here's what building this predicate would look like without DSL
|
|
36
46
|
complex = Stellar::ClaimPredicate.new(
|
|
37
|
-
Stellar::ClaimPredicateType::AND,
|
|
47
|
+
Stellar::ClaimPredicateType::AND,
|
|
38
48
|
Stellar::ClaimPredicate.new(
|
|
39
49
|
Stellar::ClaimPredicateType::BEFORE_RELATIVE_TIME, 7 * 24 * 60 * 60
|
|
40
|
-
),
|
|
50
|
+
),
|
|
41
51
|
Stellar::ClaimPredicate.new(
|
|
42
52
|
Stellar::ClaimPredicateType::NOT, Stellar::ClaimPredicate.new(
|
|
43
53
|
Stellar::ClaimPredicateType::BEFORE_RELATIVE_TIME, 10
|
|
44
54
|
)
|
|
45
55
|
)
|
|
46
56
|
)
|
|
47
|
-
|
|
57
|
+
|
|
48
58
|
```
|
|
49
59
|
- Extend Operation with `create_claimable_balance` and `claim_claimable_balance` helpers
|
|
50
60
|
- Add Claimant and ClaimPredicate DSL methods to reduce the noise.
|
|
51
|
-
```
|
|
61
|
+
```ruby
|
|
52
62
|
include Stellar::DSL
|
|
53
|
-
|
|
63
|
+
|
|
54
64
|
sender = KeyPair('S....')
|
|
55
65
|
recipient = 'G....'
|
|
56
|
-
|
|
66
|
+
|
|
57
67
|
op = Operation.create_claimable_balance(
|
|
58
68
|
asset: Stellar::Asset.native,
|
|
59
69
|
amount: 100,
|
|
60
70
|
claimants: [
|
|
61
71
|
Claimant(recipient) { after(10.seconds) & before(1.week) },
|
|
62
|
-
Claimant(sender), # allow unconditional claim-back
|
|
72
|
+
Claimant(sender), # allow unconditional claim-back
|
|
63
73
|
]
|
|
64
74
|
)
|
|
65
75
|
])
|
|
66
76
|
```
|
|
67
77
|
- Add simple predicate evaluation feature so that developers can sanity-check their predicates
|
|
68
|
-
```
|
|
78
|
+
```ruby
|
|
69
79
|
include Stellar::DSL
|
|
70
|
-
|
|
80
|
+
|
|
71
81
|
predicate = ClaimPredicate { before_relative_time(1.week) & ~before_relative_time(10.seconds) }
|
|
72
|
-
|
|
82
|
+
|
|
73
83
|
# predicate.evaluate(balance_creation_time, claim_evaluation_time)
|
|
74
84
|
predicate.evaluate("2020-10-20 09:00:00", "2020-10-20 09:00:05") # => false
|
|
75
85
|
predicate.evaluate("2020-10-20 09:00:00", "2020-10-20 09:01:00") # => true
|
|
76
86
|
predicate.evaluate("2020-10-20 09:00:00", "2020-10-27 08:50:00") # => true
|
|
77
|
-
|
|
87
|
+
|
|
78
88
|
# you can also pass an instance of ActiveSupport::Duration as a second parameter, in this case
|
|
79
|
-
# it works as a relative offset from `balance_creation_time`
|
|
89
|
+
# it works as a relative offset from `balance_creation_time`
|
|
80
90
|
predicate.evaluate("2020-10-20 09:00:00", 1.week + 1.second) # => false
|
|
81
|
-
|
|
91
|
+
|
|
82
92
|
# it is effectively the same as
|
|
83
|
-
predicate.evaluate("2020-10-20 09:00:00", "2020-10-27 09:00:01") # => false
|
|
84
|
-
```
|
|
93
|
+
predicate.evaluate("2020-10-20 09:00:00", "2020-10-27 09:00:01") # => false
|
|
94
|
+
```
|
|
85
95
|
- Add [CAP-33 Sponsored Reserves](https://github.com/stellar/stellar-protocol/blob/master/core/cap-0033.md) support
|
|
86
96
|
- Extend the operation class with helpers that allow sponsoring reserves and also revoke sponsorships.
|
|
87
97
|
- `Operation.begin_sponsoring_future_reserves`
|
|
@@ -92,20 +102,20 @@ bumps. A breaking change will get clearly notified in this log.
|
|
|
92
102
|
- `Operation.revoke_sponsorship(account_id:, data_name:)`
|
|
93
103
|
- `Operation.revoke_sponsorship(account_id:, balance_id:)`
|
|
94
104
|
- `Operation.revoke_sponsorship(account_id:, signer:)`
|
|
95
|
-
|
|
96
105
|
|
|
97
|
-
|
|
106
|
+
|
|
107
|
+
## [0.23.1](https://github.com/stellar/ruby-stellar-sdk/compare/v0.23.0...v0.23.1) - 2020-06-18
|
|
98
108
|
### Added
|
|
99
109
|
- Transaction builder now builds V1 transactions
|
|
100
110
|
- FeeBumpTransaction can wrap V0 transaction
|
|
101
|
-
|
|
102
|
-
## [0.23.0](https://github.com/stellar/ruby-stellar-sdk/compare/v0.
|
|
111
|
+
|
|
112
|
+
## [0.23.0](https://github.com/stellar/ruby-stellar-sdk/compare/v0.22.0...v0.23.0) - 2020-06-11
|
|
103
113
|
### Added
|
|
104
114
|
- Stellar Protocol 13 support
|
|
105
115
|
- Fee-Bump transactions ([CAP-0015](https://github.com/stellar/stellar-protocol/blob/master/core/cap-0015.md))
|
|
106
116
|
- Multiplexed accounts ([CAP-0027](https://github.com/stellar/stellar-protocol/blob/master/core/cap-0027.md))
|
|
107
117
|
- Fine-Grained control on trustline authorization ([CAP-0018](https://github.com/stellar/stellar-protocol/blob/master/core/cap-0018.md))
|
|
108
|
-
|
|
118
|
+
|
|
109
119
|
## [0.22.0](https://github.com/stellar/ruby-stellar-base/compare/v0.21.0...v0.22.0) - 2020-03-26
|
|
110
120
|
### Added
|
|
111
121
|
- Add TransactionBuilder ([#54](https://github.com/stellar/ruby-stellar-base/issues/54))
|
data/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
# Stellar
|
|
2
|
-
|
|
3
|
-
[](https://badge.fury.io/rb/stellar-base)
|
|
3
|
+
[](https://github.com/astroband/ruby-stellar-sdk/actions?query=branch%3Amaster)
|
|
4
|
+
[](https://codeclimate.com/github/astroband/ruby-stellar-sdk/maintainability)
|
|
5
5
|
|
|
6
6
|
The stellar-base library is the lowest-level stellar helper library. It consists of classes
|
|
7
7
|
to read, write, hash, and sign the xdr structures that are used in stellard.
|
data/lib/stellar-base.rb
CHANGED
|
@@ -5,6 +5,8 @@ require "active_support/core_ext/object/blank"
|
|
|
5
5
|
require "active_support/core_ext/enumerable"
|
|
6
6
|
require "active_support/core_ext/kernel/reporting"
|
|
7
7
|
require "active_support/core_ext/module/attribute_accessors_per_thread"
|
|
8
|
+
require "active_support/core_ext/module/delegation"
|
|
9
|
+
require "active_support/deprecation"
|
|
8
10
|
|
|
9
11
|
require_relative "stellar/ext/xdr"
|
|
10
12
|
|
|
@@ -18,6 +20,7 @@ require_relative "stellar/base/version"
|
|
|
18
20
|
Stellar::VERSION = Stellar::Base::VERSION
|
|
19
21
|
|
|
20
22
|
Stellar::ONE = 1_0000000
|
|
23
|
+
Stellar::Deprecation = ActiveSupport::Deprecation.new("next release", "stellar-base")
|
|
21
24
|
|
|
22
25
|
# extensions onto the generated files must be loaded manually, below
|
|
23
26
|
|
data/lib/stellar/asset.rb
CHANGED
|
@@ -6,14 +6,24 @@ module Stellar
|
|
|
6
6
|
new(:asset_type_native)
|
|
7
7
|
end
|
|
8
8
|
|
|
9
|
+
# @param code [String] asset code
|
|
10
|
+
# @param issuer [#to_keypair] asset issuer
|
|
11
|
+
#
|
|
12
|
+
# @return [Stellar::Asset::AlphaNum4] asset4 representation
|
|
9
13
|
def self.alphanum4(code, issuer)
|
|
14
|
+
issuer = issuer.to_keypair if issuer.respond_to?(:to_keypair)
|
|
10
15
|
raise ArgumentError, "Bad :issuer" unless issuer.is_a?(KeyPair)
|
|
11
16
|
code = normalize_code(code, 4)
|
|
12
17
|
an = AlphaNum4.new({asset_code: code, issuer: issuer.account_id})
|
|
13
18
|
new(:asset_type_credit_alphanum4, an)
|
|
14
19
|
end
|
|
15
20
|
|
|
21
|
+
# @param code [String] asset code
|
|
22
|
+
# @param issuer [#to_keypair] asset issuer
|
|
23
|
+
#
|
|
24
|
+
# @return [Stellar::Asset::AlphaNum4] asset4 representation
|
|
16
25
|
def self.alphanum12(code, issuer)
|
|
26
|
+
issuer = issuer.to_keypair if issuer.respond_to?(:to_keypair)
|
|
17
27
|
raise ArgumentError, "Bad :issuer" unless issuer.is_a?(KeyPair)
|
|
18
28
|
code = normalize_code(code, 12)
|
|
19
29
|
an = AlphaNum12.new({asset_code: code, issuer: issuer.account_id})
|
data/lib/stellar/base/version.rb
CHANGED
data/lib/stellar/compat.rb
CHANGED
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
require "active_support/deprecation"
|
|
2
|
-
|
|
3
|
-
Stellar::Deprecation ||= ActiveSupport::Deprecation.new("next release", "stellar-base")
|
|
4
|
-
|
|
5
1
|
class << Stellar::Operation
|
|
6
2
|
alias_method :manage_offer, :manage_sell_offer
|
|
7
3
|
alias_method :create_passive_offer, :create_passive_sell_offer
|
|
@@ -32,9 +32,8 @@ module Stellar::Concerns
|
|
|
32
32
|
#
|
|
33
33
|
# @return [Array<Operation>] the operations
|
|
34
34
|
def to_operations
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
operations.each do |op|
|
|
35
|
+
cloned = Marshal.load Marshal.dump(operations)
|
|
36
|
+
cloned.each do |op|
|
|
38
37
|
op.source_account ||= source_account
|
|
39
38
|
end
|
|
40
39
|
end
|
data/lib/stellar/dsl.rb
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
module Stellar
|
|
2
2
|
module DSL
|
|
3
|
+
module_function
|
|
4
|
+
|
|
3
5
|
# Constructs a new ClaimPredicate using DSL
|
|
4
6
|
#
|
|
5
7
|
# @example fulfilled during [T+5min, T+60min] period, where T refers to claimable balance entry creation time
|
|
@@ -47,14 +49,16 @@ module Stellar
|
|
|
47
49
|
case subject
|
|
48
50
|
when ->(subj) { subj.respond_to?(:to_keypair) }
|
|
49
51
|
subject.to_keypair
|
|
50
|
-
when /G[A-Z0-9]{55}/
|
|
51
|
-
KeyPair.from_address(subject)
|
|
52
|
-
when /S[A-Z0-9]{55}/
|
|
53
|
-
KeyPair.from_seed(subject)
|
|
54
52
|
when PublicKey
|
|
55
53
|
KeyPair.from_public_key(subject.value)
|
|
56
54
|
when SignerKey
|
|
57
55
|
KeyPair.from_raw_seed(subject.value)
|
|
56
|
+
when /^G[A-Z0-9]{55}$/
|
|
57
|
+
KeyPair.from_address(subject.to_str)
|
|
58
|
+
when /^S[A-Z0-9]{55}$/
|
|
59
|
+
KeyPair.from_seed(subject.to_str)
|
|
60
|
+
when /^.{32}$/
|
|
61
|
+
KeyPair.from_raw_seed(subject.to_str)
|
|
58
62
|
when nil
|
|
59
63
|
KeyPair.random
|
|
60
64
|
else
|
|
@@ -81,5 +85,5 @@ module Stellar
|
|
|
81
85
|
end
|
|
82
86
|
end
|
|
83
87
|
|
|
84
|
-
|
|
88
|
+
include DSL
|
|
85
89
|
end
|
data/lib/stellar/ext/xdr.rb
CHANGED
|
@@ -39,11 +39,12 @@ XDR::DSL::Union.redefine_method(:switch) do |switch, arm = nil|
|
|
|
39
39
|
end
|
|
40
40
|
end
|
|
41
41
|
|
|
42
|
-
# XDR::Union
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
42
|
+
# XDR::Union delegates missing methods to the underlying value
|
|
43
|
+
XDR::Union.define_method(:method_missing) do |name, *args|
|
|
44
|
+
return super(name, *args) unless value&.respond_to?(name)
|
|
45
|
+
value&.public_send(name, *args)
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
XDR::Union.define_method(:respond_to_missing?) do |*args|
|
|
49
|
+
value&.respond_to?(*args)
|
|
49
50
|
end
|
data/lib/stellar/key_pair.rb
CHANGED
|
@@ -6,6 +6,11 @@ module Stellar
|
|
|
6
6
|
from_raw_seed seed_bytes
|
|
7
7
|
end
|
|
8
8
|
|
|
9
|
+
def from_address(address)
|
|
10
|
+
pk_bytes = Util::StrKey.check_decode(:account_id, address)
|
|
11
|
+
from_public_key(pk_bytes)
|
|
12
|
+
end
|
|
13
|
+
|
|
9
14
|
def from_raw_seed(seed_bytes)
|
|
10
15
|
secret_key = RbNaCl::SigningKey.new(seed_bytes)
|
|
11
16
|
public_key = secret_key.verify_key
|
|
@@ -17,11 +22,6 @@ module Stellar
|
|
|
17
22
|
new(public_key)
|
|
18
23
|
end
|
|
19
24
|
|
|
20
|
-
def from_address(address)
|
|
21
|
-
pk_bytes = Util::StrKey.check_decode(:account_id, address)
|
|
22
|
-
from_public_key(pk_bytes)
|
|
23
|
-
end
|
|
24
|
-
|
|
25
25
|
def random
|
|
26
26
|
secret_key = RbNaCl::SigningKey.generate
|
|
27
27
|
public_key = secret_key.verify_key
|
|
@@ -40,11 +40,21 @@ module Stellar
|
|
|
40
40
|
|
|
41
41
|
extend FactoryMethods
|
|
42
42
|
|
|
43
|
+
# @param [RbNaCl::VerifyKey] public_key
|
|
44
|
+
# @param [RbNaCl::SigningKey, nil] secret_key
|
|
43
45
|
def initialize(public_key, secret_key = nil)
|
|
44
46
|
@public_key = public_key
|
|
45
47
|
@secret_key = secret_key
|
|
46
48
|
end
|
|
47
49
|
|
|
50
|
+
def address
|
|
51
|
+
Util::StrKey.check_encode(:account_id, raw_public_key)
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def seed
|
|
55
|
+
Util::StrKey.check_encode(:seed, raw_seed)
|
|
56
|
+
end
|
|
57
|
+
|
|
48
58
|
def account_id
|
|
49
59
|
Stellar::AccountID.new :public_key_type_ed25519, raw_public_key
|
|
50
60
|
end
|
|
@@ -61,16 +71,17 @@ module Stellar
|
|
|
61
71
|
Stellar::SignerKey.new :signer_key_type_ed25519, raw_public_key
|
|
62
72
|
end
|
|
63
73
|
|
|
64
|
-
def raw_public_key
|
|
65
|
-
@public_key.to_bytes
|
|
66
|
-
end
|
|
67
|
-
|
|
68
74
|
def signature_hint
|
|
69
75
|
# take last 4 bytes
|
|
70
76
|
account_id.to_xdr.slice(-4, 4)
|
|
71
77
|
end
|
|
72
78
|
|
|
79
|
+
def raw_public_key
|
|
80
|
+
@public_key.to_bytes
|
|
81
|
+
end
|
|
82
|
+
|
|
73
83
|
def raw_seed
|
|
84
|
+
raise "no private key" if @secret_key.nil?
|
|
74
85
|
@secret_key.to_bytes
|
|
75
86
|
end
|
|
76
87
|
|
|
@@ -82,25 +93,13 @@ module Stellar
|
|
|
82
93
|
@public_key
|
|
83
94
|
end
|
|
84
95
|
|
|
85
|
-
def address
|
|
86
|
-
pk_bytes = raw_public_key
|
|
87
|
-
Util::StrKey.check_encode(:account_id, pk_bytes)
|
|
88
|
-
end
|
|
89
|
-
|
|
90
|
-
def seed
|
|
91
|
-
raise "no private key" if @secret_key.nil?
|
|
92
|
-
# TODO: improve the error class above
|
|
93
|
-
seed_bytes = raw_seed
|
|
94
|
-
Util::StrKey.check_encode(:seed, seed_bytes)
|
|
95
|
-
end
|
|
96
|
-
|
|
97
96
|
def sign?
|
|
98
97
|
!@secret_key.nil?
|
|
99
98
|
end
|
|
100
99
|
|
|
101
100
|
def sign(message)
|
|
102
|
-
raise "no private key"
|
|
103
|
-
|
|
101
|
+
raise NotImplementedError, "no private key, signing is not available" unless sign?
|
|
102
|
+
|
|
104
103
|
@secret_key.sign(message)
|
|
105
104
|
end
|
|
106
105
|
|
data/lib/stellar/ledger_key.rb
CHANGED
|
@@ -4,6 +4,8 @@ require "stellar/dsl"
|
|
|
4
4
|
module Stellar
|
|
5
5
|
class LedgerKey
|
|
6
6
|
class << self
|
|
7
|
+
include Stellar::DSL
|
|
8
|
+
|
|
7
9
|
def switch_for_arm(name)
|
|
8
10
|
(@switch_by_arm ||= switches.invert).fetch(name)
|
|
9
11
|
end
|
|
@@ -12,7 +14,7 @@ module Stellar
|
|
|
12
14
|
field, value = options.first
|
|
13
15
|
case field
|
|
14
16
|
when nil
|
|
15
|
-
account(account_id:
|
|
17
|
+
account(account_id: KeyPair(account_id).account_id)
|
|
16
18
|
when :balance_id
|
|
17
19
|
claimable_balance(balance_id: ClaimableBalanceID.v0(Stellar::Convert.from_hex(value.to_s)))
|
|
18
20
|
when :offer_id
|
|
@@ -20,7 +22,7 @@ module Stellar
|
|
|
20
22
|
when :data_name
|
|
21
23
|
data(account_id: account_id, data_name: value.to_s)
|
|
22
24
|
when :asset
|
|
23
|
-
trust_line(account_id: account_id, asset:
|
|
25
|
+
trust_line(account_id: account_id, asset: Asset(value))
|
|
24
26
|
else
|
|
25
27
|
raise ArgumentError, "unknown option #{field} (not in :asset, :offer_id, :data_name, :balance_id)"
|
|
26
28
|
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
module Stellar
|
|
2
|
+
class MuxedAccount
|
|
3
|
+
def to_keypair
|
|
4
|
+
case arm
|
|
5
|
+
when :ed25519 then KeyPair.from_public_key(value)
|
|
6
|
+
when :med25519 then KeyPair.from_public_key(value.ed25519)
|
|
7
|
+
else
|
|
8
|
+
raise "impossible"
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def address
|
|
13
|
+
to_keypair.address
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
data/lib/stellar/operation.rb
CHANGED
|
@@ -5,6 +5,7 @@ module Stellar
|
|
|
5
5
|
MAX_INT64 = 2**63 - 1
|
|
6
6
|
|
|
7
7
|
class << self
|
|
8
|
+
include Stellar::DSL
|
|
8
9
|
#
|
|
9
10
|
# Construct a new Stellar::Operation from the provided
|
|
10
11
|
# source account and body
|
|
@@ -233,7 +234,7 @@ module Stellar
|
|
|
233
234
|
|
|
234
235
|
def begin_sponsoring_future_reserves(sponsored:, **attributes)
|
|
235
236
|
op = BeginSponsoringFutureReservesOp.new(
|
|
236
|
-
sponsored_id:
|
|
237
|
+
sponsored_id: KeyPair(sponsored).account_id
|
|
237
238
|
)
|
|
238
239
|
|
|
239
240
|
make(attributes.merge(body: [:begin_sponsoring_future_reserves, op]))
|
|
@@ -247,10 +248,10 @@ module Stellar
|
|
|
247
248
|
def revoke_sponsorship(sponsored:, **attributes)
|
|
248
249
|
key_fields = attributes.slice(:offer_id, :data_name, :balance_id, :asset, :signer)
|
|
249
250
|
raise ArgumentError, "conflicting attributes: #{key_fields.keys.join(", ")}" if key_fields.size > 1
|
|
250
|
-
account_id =
|
|
251
|
+
account_id = KeyPair(sponsored).account_id
|
|
251
252
|
key, value = key_fields.first
|
|
252
253
|
op = if key == :signer
|
|
253
|
-
RevokeSponsorshipOp.signer(account_id: account_id, signer_key:
|
|
254
|
+
RevokeSponsorshipOp.signer(account_id: account_id, signer_key: SignerKey(value))
|
|
254
255
|
else
|
|
255
256
|
RevokeSponsorshipOp.ledger_key(LedgerKey.from(account_id: account_id, **key_fields))
|
|
256
257
|
end
|
data/lib/stellar/transaction.rb
CHANGED
|
@@ -1,13 +1,7 @@
|
|
|
1
1
|
module Stellar
|
|
2
2
|
class TransactionEnvelope
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
value&.public_send(method, *args) || super
|
|
6
|
-
end
|
|
7
|
-
|
|
8
|
-
def respond_to_missing?(method, include_private = false)
|
|
9
|
-
%w[tx signatures].include?(method) || super
|
|
10
|
-
end
|
|
3
|
+
delegate :tx, :signatures, to: :value
|
|
4
|
+
delegate :hash, to: :tx
|
|
11
5
|
|
|
12
6
|
# Checks to ensure that every signature for the envelope is
|
|
13
7
|
# a valid signature of one of the provided `key_pairs`
|
|
@@ -19,23 +13,19 @@ module Stellar
|
|
|
19
13
|
#
|
|
20
14
|
# @return [Boolean] true if all signatures are from the provided key_pairs and validly sign the tx's hash
|
|
21
15
|
def signed_correctly?(*key_pairs)
|
|
22
|
-
hash = tx.hash
|
|
23
16
|
return false if signatures.empty?
|
|
24
17
|
|
|
25
|
-
|
|
18
|
+
tx_hash = tx.hash
|
|
19
|
+
keys_by_hint = key_pairs.index_by(&:signature_hint)
|
|
26
20
|
|
|
27
21
|
signatures.all? do |sig|
|
|
28
|
-
key_pair =
|
|
22
|
+
key_pair = keys_by_hint[sig.hint]
|
|
29
23
|
break false if key_pair.nil?
|
|
30
24
|
|
|
31
|
-
key_pair.verify(sig.signature,
|
|
25
|
+
key_pair.verify(sig.signature, tx_hash)
|
|
32
26
|
end
|
|
33
27
|
end
|
|
34
28
|
|
|
35
|
-
def hash
|
|
36
|
-
Digest::SHA256.digest(to_xdr)
|
|
37
|
-
end
|
|
38
|
-
|
|
39
29
|
def merge(other)
|
|
40
30
|
merged_tx = tx.merge(other.tx)
|
|
41
31
|
merged_tx.signatures = [signatures, other.signatures]
|
|
@@ -3,15 +3,7 @@ module Stellar
|
|
|
3
3
|
include Stellar::Concerns::Transaction
|
|
4
4
|
|
|
5
5
|
def to_v1
|
|
6
|
-
Transaction.new(
|
|
7
|
-
source_account: Stellar::MuxedAccount.new(:key_type_ed25519, source_account),
|
|
8
|
-
seq_num: seq_num,
|
|
9
|
-
operations: operations,
|
|
10
|
-
fee: fee,
|
|
11
|
-
memo: memo,
|
|
12
|
-
time_bounds: time_bounds,
|
|
13
|
-
ext: ext
|
|
14
|
-
)
|
|
6
|
+
Transaction.new(**attributes.except(:source_account_ed25519), source_account: source_account)
|
|
15
7
|
end
|
|
16
8
|
|
|
17
9
|
def to_envelope(*key_pairs)
|
|
@@ -45,7 +37,7 @@ module Stellar
|
|
|
45
37
|
end
|
|
46
38
|
|
|
47
39
|
def source_account
|
|
48
|
-
source_account_ed25519
|
|
40
|
+
Stellar::MuxedAccount.ed25519(source_account_ed25519)
|
|
49
41
|
end
|
|
50
42
|
end
|
|
51
43
|
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.
|
|
4
|
+
version: 0.25.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Scott Fleckenstein
|
|
@@ -10,7 +10,7 @@ authors:
|
|
|
10
10
|
autorequire:
|
|
11
11
|
bindir: exe
|
|
12
12
|
cert_chain: []
|
|
13
|
-
date: 2020-10-
|
|
13
|
+
date: 2020-10-30 00:00:00.000000000 Z
|
|
14
14
|
dependencies:
|
|
15
15
|
- !ruby/object:Gem::Dependency
|
|
16
16
|
name: activesupport
|
|
@@ -417,6 +417,7 @@ files:
|
|
|
417
417
|
- lib/stellar/fee_bump_transaction.rb
|
|
418
418
|
- lib/stellar/key_pair.rb
|
|
419
419
|
- lib/stellar/ledger_key.rb
|
|
420
|
+
- lib/stellar/muxed_account.rb
|
|
420
421
|
- lib/stellar/networks.rb
|
|
421
422
|
- lib/stellar/operation.rb
|
|
422
423
|
- lib/stellar/path_payment_strict_receive_result.rb
|
|
@@ -432,9 +433,10 @@ homepage: https://github.com/astroband/ruby-stellar-sdk/tree/master/base
|
|
|
432
433
|
licenses:
|
|
433
434
|
- Apache-2.0
|
|
434
435
|
metadata:
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
436
|
+
github_repo: ssh://github.com/astroband/ruby-stellar-sdk
|
|
437
|
+
documentation_uri: https://rubydoc.info/gems/stellar-base/0.25.0/
|
|
438
|
+
changelog_uri: https://github.com/astroband/ruby-stellar-sdk/blob/v0.25.0/base/CHANGELOG.md
|
|
439
|
+
source_code_uri: https://github.com/astroband/ruby-stellar-sdk/tree/v0.25.0/base
|
|
438
440
|
post_install_message:
|
|
439
441
|
rdoc_options: []
|
|
440
442
|
require_paths:
|