digitalbits-base 0.27.1 → 0.27.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +9 -9
- data/lib/digitalbits-base.rb +3 -3
- data/lib/digitalbits/account_flags.rb +5 -5
- data/lib/digitalbits/asset.rb +6 -6
- data/lib/digitalbits/claim_predicate.rb +3 -3
- data/lib/digitalbits/compat.rb +2 -2
- data/lib/digitalbits/concerns/transaction.rb +4 -4
- data/lib/digitalbits/convert.rb +4 -4
- data/lib/digitalbits/dsl.rb +16 -16
- data/lib/digitalbits/fee_bump_transaction.rb +4 -4
- data/lib/digitalbits/key_pair.rb +7 -7
- data/lib/digitalbits/ledger_key.rb +3 -3
- data/lib/digitalbits/muxed_account.rb +1 -1
- data/lib/digitalbits/networks.rb +5 -5
- data/lib/digitalbits/operation.rb +71 -71
- data/lib/digitalbits/path_payment_strict_receive_result.rb +1 -1
- data/lib/digitalbits/price.rb +2 -2
- data/lib/digitalbits/signer_key.rb +5 -5
- data/lib/digitalbits/thresholds.rb +1 -1
- data/lib/digitalbits/transaction.rb +6 -6
- data/lib/digitalbits/transaction_builder.rb +18 -18
- data/lib/digitalbits/transaction_envelope.rb +2 -2
- data/lib/digitalbits/transaction_v0.rb +10 -10
- data/lib/digitalbits/trust_line_flags.rb +9 -9
- data/lib/digitalbits/util/strkey.rb +7 -7
- data/lib/digitalbits/version.rb +2 -2
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f31c7fa834751bbf8148e8e3a8f2aa90deba9f0c4bbeecac1d4d1cee634466d4
|
4
|
+
data.tar.gz: d14e6159b2c5d6368872f7a832aac9eb3d47746a0cd838f7bd39a9ee646f4d2f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8f4637ab1f4192110e981cf74f3dbc22b20ad8f0a925a17b2b6a619ae0ac47debad7ef642b09af1957bfc4661441c63159c86a74ef17436be72792f2ed6602f7
|
7
|
+
data.tar.gz: 53a232621f4300038f8c84f09e308028ff234b7adfb4acf22b6270ff7074200177e4044818da9c4fcea2ea22c00a3f0e24135488534ffe7013ded67222d128dd
|
data/README.md
CHANGED
@@ -31,19 +31,19 @@ It seems as though jruby is particularly slow when it comes to BigDecimal math;
|
|
31
31
|
|
32
32
|
In addition to the code generated from the XDR definition files, this library also provides some digitalbits specific features. Let's look at some of them.
|
33
33
|
|
34
|
-
We wrap rbnacl with `
|
34
|
+
We wrap rbnacl with `Digitalbits::KeyPair`, providing some digitalbits specific functionality as seen below:
|
35
35
|
|
36
36
|
```ruby
|
37
37
|
|
38
38
|
# Create a keypair from a digitalbits secret seed
|
39
|
-
signer =
|
39
|
+
signer = Digitalbits::KeyPair.from_seed("SCBASSEX34FJNIPLUYQPSMZHHYXXQNWOOV42XYZFXM6EGYX2DPIZVIA3")
|
40
40
|
|
41
41
|
# Create a keypair from a digitalbits address
|
42
|
-
verifier =
|
42
|
+
verifier = Digitalbits::KeyPair.from_address("GBQWWBFLRP3BXD2RI2FH7XNNU2MKIYVUI7QXUAIVG34JY6MQGXVUO3RX")
|
43
43
|
|
44
44
|
# Produce a digitalbits compliant "decorated signature" that is compliant with digitalbits transactions
|
45
45
|
|
46
|
-
signer.sign_decorated("Hello world!") # => #<
|
46
|
+
signer.sign_decorated("Hello world!") # => #<Digitalbits::DecoratedSignature ...>
|
47
47
|
|
48
48
|
```
|
49
49
|
|
@@ -51,15 +51,15 @@ This library also provides an impementation of DigitalBits's "StrKey" encoding (
|
|
51
51
|
|
52
52
|
```ruby
|
53
53
|
|
54
|
-
|
55
|
-
|
54
|
+
Digitalbits::Util::StrKey.check_encode(:account_id, "\xFF\xFF\xFF\xFF\xFF\xFF\xFF") # => "GD777777777764TU"
|
55
|
+
Digitalbits::Util::StrKey.check_encode(:seed, "\x00\x00\x00\x00\x00\x00\x39") # => "SAAAAAAAAAADST3H"
|
56
56
|
|
57
57
|
# To prevent interpretation mistakes, you must pass the expected version byte
|
58
58
|
# when decoding a check_encoded value
|
59
59
|
|
60
|
-
encoded =
|
61
|
-
|
62
|
-
|
60
|
+
encoded = Digitalbits::Util::StrCheck.check_encode(:account_id, "\x61\x6b\x04\xab\x8b\xf6\x1b")
|
61
|
+
Digitalbits::Util::StrKey.check_decode(:account_id, encoded) # => "\x61\x6b\x04\xab\x8b\xf6\x1b"
|
62
|
+
Digitalbits::Util::StrKey.check_decode(:seed, encoded) # => throws ArgumentError: Unexpected version: :account_id
|
63
63
|
|
64
64
|
```
|
65
65
|
|
data/lib/digitalbits-base.rb
CHANGED
@@ -14,12 +14,12 @@ require_relative "digitalbits/ext/xdr"
|
|
14
14
|
silence_warnings do
|
15
15
|
require "digitalbits-base-generated"
|
16
16
|
end
|
17
|
-
|
17
|
+
Digitalbits.load_all!
|
18
18
|
|
19
19
|
require_relative "digitalbits/version"
|
20
20
|
|
21
|
-
|
22
|
-
|
21
|
+
Digitalbits::ONE = 1_0000000
|
22
|
+
Digitalbits::Deprecation = ActiveSupport::Deprecation.new("next release", "digitalbits-base")
|
23
23
|
|
24
24
|
# extensions onto the generated files must be loaded manually, below
|
25
25
|
|
@@ -1,10 +1,10 @@
|
|
1
|
-
module
|
1
|
+
module Digitalbits
|
2
2
|
class AccountFlags
|
3
3
|
#
|
4
|
-
# Converts an array of
|
4
|
+
# Converts an array of Digitalbits::AccountFlags members into
|
5
5
|
# an Integer suitable for use in a SetOptionsOp.
|
6
6
|
#
|
7
|
-
# @param flags [Array<
|
7
|
+
# @param flags [Array<Digitalbits::AccountFlags>] the flags to combine
|
8
8
|
#
|
9
9
|
# @return [Fixnum] the combined result
|
10
10
|
def self.make_mask(flags = nil)
|
@@ -15,10 +15,10 @@ module DigitalBits
|
|
15
15
|
|
16
16
|
#
|
17
17
|
# Converts an integer used in SetOptionsOp on the set/clear flag options
|
18
|
-
# into an array of
|
18
|
+
# into an array of Digitalbits::AccountFlags members
|
19
19
|
#
|
20
20
|
# @param combined [Fixnum]
|
21
|
-
# @return [Array<
|
21
|
+
# @return [Array<Digitalbits::AccountFlags>]
|
22
22
|
def self.parse_mask(combined)
|
23
23
|
members.values.select { |m| (m.value & combined) != 0 }
|
24
24
|
end
|
data/lib/digitalbits/asset.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
module
|
1
|
+
module Digitalbits
|
2
2
|
class Asset
|
3
3
|
TYPES = %i[native alphanum4 alphanum12]
|
4
4
|
|
@@ -9,7 +9,7 @@ module DigitalBits
|
|
9
9
|
# @param code [String] asset code
|
10
10
|
# @param issuer [#to_keypair] asset issuer
|
11
11
|
#
|
12
|
-
# @return [
|
12
|
+
# @return [Digitalbits::Asset::AlphaNum4] asset4 representation
|
13
13
|
def self.alphanum4(code, issuer)
|
14
14
|
issuer = issuer.to_keypair if issuer.respond_to?(:to_keypair)
|
15
15
|
raise ArgumentError, "Bad :issuer" unless issuer.is_a?(KeyPair)
|
@@ -21,7 +21,7 @@ module DigitalBits
|
|
21
21
|
# @param code [String] asset code
|
22
22
|
# @param issuer [#to_keypair] asset issuer
|
23
23
|
#
|
24
|
-
# @return [
|
24
|
+
# @return [Digitalbits::Asset::AlphaNum4] asset4 representation
|
25
25
|
def self.alphanum12(code, issuer)
|
26
26
|
issuer = issuer.to_keypair if issuer.respond_to?(:to_keypair)
|
27
27
|
raise ArgumentError, "Bad :issuer" unless issuer.is_a?(KeyPair)
|
@@ -36,18 +36,18 @@ module DigitalBits
|
|
36
36
|
"native"
|
37
37
|
when AssetType.asset_type_credit_alphanum4
|
38
38
|
anum = alpha_num4!
|
39
|
-
issuer_address =
|
39
|
+
issuer_address = Digitalbits::Convert.pk_to_address(anum.issuer)
|
40
40
|
"#{anum.asset_code}/#{issuer_address}"
|
41
41
|
when AssetType.asset_type_credit_alphanum12
|
42
42
|
anum = alpha_num12!
|
43
|
-
issuer_address =
|
43
|
+
issuer_address = Digitalbits::Convert.pk_to_address(anum.issuer)
|
44
44
|
"#{anum.asset_code}/#{issuer_address}"
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
48
48
|
def inspect
|
49
49
|
# label = switch.to_s
|
50
|
-
"#<
|
50
|
+
"#<Digitalbits::Asset #{self}>"
|
51
51
|
end
|
52
52
|
|
53
53
|
def code
|
@@ -2,7 +2,7 @@
|
|
2
2
|
require "active_support/core_ext/integer/time"
|
3
3
|
require "active_support/core_ext/string/conversions"
|
4
4
|
|
5
|
-
module
|
5
|
+
module Digitalbits
|
6
6
|
# Represents claim predicate on DigitalBits network.
|
7
7
|
#
|
8
8
|
class ClaimPredicate
|
@@ -19,7 +19,7 @@ module DigitalBits
|
|
19
19
|
# Constructs a `before_relative_time` claim predicate.
|
20
20
|
#
|
21
21
|
# This predicate will be fulfilled if the closing time of the ledger that includes
|
22
|
-
# the
|
22
|
+
# the Digitalbits::CreateClaimableBalance operation plus this relative time delta (in seconds)
|
23
23
|
# is less than the current time.
|
24
24
|
#
|
25
25
|
# @param seconds [#to_int|#to_i] seconds since `closeTime` of the ledger in which
|
@@ -32,7 +32,7 @@ module DigitalBits
|
|
32
32
|
# Constructs an `before_absolute_time` claim predicate.
|
33
33
|
#
|
34
34
|
# This predicate will be fulfilled if the closing time of the ledger that includes
|
35
|
-
# the
|
35
|
+
# the Digitalbits::CreateClaimableBalance operation is less than provided timestamp.
|
36
36
|
#
|
37
37
|
# @param timestamp [#to_time|#to_int|#to_i] time value or timestamp
|
38
38
|
#
|
data/lib/digitalbits/compat.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
class <<
|
1
|
+
class << Digitalbits::Operation
|
2
2
|
alias_method :manage_offer, :manage_sell_offer
|
3
3
|
alias_method :create_passive_offer, :create_passive_sell_offer
|
4
4
|
|
5
|
-
deprecate deprecator:
|
5
|
+
deprecate deprecator: Digitalbits::Deprecation,
|
6
6
|
manage_offer: :manage_sell_offer,
|
7
7
|
create_passive_offer: :create_passive_sell_offer,
|
8
8
|
allow_trust: :set_trust_line_flags
|
@@ -1,4 +1,4 @@
|
|
1
|
-
module
|
1
|
+
module Digitalbits::Concerns
|
2
2
|
module Transaction
|
3
3
|
# Returns the string of bytes that, when hashed, provide the value which
|
4
4
|
# should be signed to create a valid digitalbits transaction signature
|
@@ -32,7 +32,7 @@ module DigitalBits::Concerns
|
|
32
32
|
#
|
33
33
|
# @return [Array<Operation>] the operations
|
34
34
|
def to_operations
|
35
|
-
codec = XDR::VarArray[
|
35
|
+
codec = XDR::VarArray[Digitalbits::Operation]
|
36
36
|
ops = respond_to?(:operations) ? operations : inner_tx.value.tx.operations
|
37
37
|
cloned = codec.from_xdr(codec.to_xdr(ops))
|
38
38
|
cloned.each do |op|
|
@@ -43,8 +43,8 @@ module DigitalBits::Concerns
|
|
43
43
|
def apply_defaults
|
44
44
|
self.operations ||= []
|
45
45
|
self.fee ||= 100
|
46
|
-
self.memo ||=
|
47
|
-
self.ext ||=
|
46
|
+
self.memo ||= Digitalbits::Memo.new(:memo_none)
|
47
|
+
self.ext ||= Digitalbits::Transaction::Ext.new 0
|
48
48
|
end
|
49
49
|
end
|
50
50
|
end
|
data/lib/digitalbits/convert.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
module
|
1
|
+
module Digitalbits
|
2
2
|
#
|
3
3
|
# Generic format conversion module
|
4
4
|
#
|
@@ -21,10 +21,10 @@ module DigitalBits
|
|
21
21
|
Base64.strict_decode64(base64_string)
|
22
22
|
end
|
23
23
|
|
24
|
-
## Converts a
|
25
|
-
#
|
24
|
+
## Converts a Digitalbits::PublicKey instance (or any typedef of it such as
|
25
|
+
# Digitalbits::AccountID) to an address
|
26
26
|
def pk_to_address(pk)
|
27
|
-
|
27
|
+
Digitalbits::Util::StrKey.check_encode(:account_id, pk.ed25519!)
|
28
28
|
end
|
29
29
|
|
30
30
|
extend self
|
data/lib/digitalbits/dsl.rb
CHANGED
@@ -1,17 +1,17 @@
|
|
1
|
-
module
|
1
|
+
module Digitalbits
|
2
2
|
module DSL
|
3
3
|
module_function
|
4
4
|
|
5
5
|
# Constructs a new ClaimPredicate using DSL
|
6
6
|
#
|
7
7
|
# @example fulfilled during [T+5min, T+60min] period, where T refers to claimable balance entry creation time
|
8
|
-
#
|
8
|
+
# Digitalbits::ClaimPredicate { before_relative_time(1.hour) & ~before_relative_time(5.minutes) }
|
9
9
|
#
|
10
10
|
# @example not fulfilled starting from today midnight until tomorrow midnight,
|
11
|
-
#
|
11
|
+
# Digitalbits::ClaimPredicate { before_absolute_time(Date.today.end_of_day) | ~before_absolute_time(Date.tomorrow.end_of_day) }
|
12
12
|
#
|
13
13
|
# @example always fulfilled
|
14
|
-
#
|
14
|
+
# Digitalbits::ClaimPredicate { }
|
15
15
|
def ClaimPredicate(&block)
|
16
16
|
return ClaimPredicate.unconditional unless block
|
17
17
|
ClaimPredicate.compose(&block)
|
@@ -28,8 +28,8 @@ module DigitalBits
|
|
28
28
|
end
|
29
29
|
|
30
30
|
# @param [Asset, String, nil] subject
|
31
|
-
# @return [
|
32
|
-
# @raise [TypeError] if subject cannot be converted to
|
31
|
+
# @return [Digitalbits::Asset] instance of the Digitalbits::Asset
|
32
|
+
# @raise [TypeError] if subject cannot be converted to Digitalbits::Asset
|
33
33
|
def Asset(subject = nil)
|
34
34
|
case subject
|
35
35
|
when Asset
|
@@ -41,14 +41,14 @@ module DigitalBits
|
|
41
41
|
when /^([0-9A-Z]{5,12})[-:](G[A-Z0-9]{55})$/
|
42
42
|
Asset.alphanum12($1, KeyPair($2))
|
43
43
|
else
|
44
|
-
raise TypeError, "Cannot convert #{subject.inspect} to
|
44
|
+
raise TypeError, "Cannot convert #{subject.inspect} to Digitalbits::Asset"
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
48
|
-
# Generates
|
49
|
-
# @param subject [String|
|
50
|
-
# @return [
|
51
|
-
# @raise [TypeError] if subject cannot be converted to
|
48
|
+
# Generates Digitalbits::Keypair from subject, use Digitalbits::Client.to_keypair as shortcut.
|
49
|
+
# @param subject [String|Digitalbits::Account|Digitalbits::PublicKey|Digitalbits::SignerKey|Digitalbits::Keypair] subject.
|
50
|
+
# @return [Digitalbits::Keypair] Digitalbits::Keypair instance.
|
51
|
+
# @raise [TypeError] if subject cannot be converted to Digitalbits::KeyPair
|
52
52
|
def KeyPair(subject = nil)
|
53
53
|
case subject
|
54
54
|
when ->(subj) { subj.respond_to?(:to_keypair) }
|
@@ -66,21 +66,21 @@ module DigitalBits
|
|
66
66
|
when nil
|
67
67
|
KeyPair.random
|
68
68
|
else
|
69
|
-
raise TypeError, "cannot convert #{subject.inspect} to
|
69
|
+
raise TypeError, "cannot convert #{subject.inspect} to Digitalbits::KeyPair"
|
70
70
|
end
|
71
71
|
end
|
72
72
|
|
73
73
|
# Provides conversion from different input types into the SignerKey to use in ManageData operation.
|
74
|
-
# @param input [String|
|
75
|
-
# @return [
|
74
|
+
# @param input [String|zDigitalbits::Account|Digitalbits::PublicKey|Digitalbits::SignerKey|Digitalbits::Keypair] subject.
|
75
|
+
# @return [Digitalbits::SignerKey] Digitalbits::Keypair instance.
|
76
76
|
def SignerKey(input = nil)
|
77
77
|
case input
|
78
78
|
when Transaction
|
79
79
|
SignerKey.pre_auth_tx(input.hash)
|
80
80
|
when /^[0-9A-Za-z+\/=]{44}$/
|
81
|
-
SignerKey.hash_x(
|
81
|
+
SignerKey.hash_x(Digitalbits::Convert.from_base64(input))
|
82
82
|
when /^[0-9a-f]{64}$/
|
83
|
-
SignerKey.hash_x(
|
83
|
+
SignerKey.hash_x(Digitalbits::Convert.from_hex(input))
|
84
84
|
when /^.{32}$/
|
85
85
|
SignerKey.hash_x(input)
|
86
86
|
else
|
@@ -1,6 +1,6 @@
|
|
1
|
-
module
|
1
|
+
module Digitalbits
|
2
2
|
class FeeBumpTransaction
|
3
|
-
include
|
3
|
+
include Digitalbits::Concerns::Transaction
|
4
4
|
|
5
5
|
def to_envelope(*key_pairs)
|
6
6
|
signatures = (key_pairs || []).map(&method(:sign_decorated))
|
@@ -9,9 +9,9 @@ module DigitalBits
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def signature_base_prefix
|
12
|
-
val =
|
12
|
+
val = Digitalbits::EnvelopeType.envelope_type_tx_fee_bump
|
13
13
|
|
14
|
-
|
14
|
+
Digitalbits.current_network_id + Digitalbits::EnvelopeType.to_xdr(val)
|
15
15
|
end
|
16
16
|
|
17
17
|
def source_account
|
data/lib/digitalbits/key_pair.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
module
|
1
|
+
module Digitalbits
|
2
2
|
class KeyPair
|
3
3
|
module FactoryMethods
|
4
4
|
def from_seed(seed)
|
@@ -34,7 +34,7 @@ module DigitalBits
|
|
34
34
|
end
|
35
35
|
|
36
36
|
def master
|
37
|
-
from_raw_seed(
|
37
|
+
from_raw_seed(Digitalbits.current_network_id)
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
@@ -56,19 +56,19 @@ module DigitalBits
|
|
56
56
|
end
|
57
57
|
|
58
58
|
def account_id
|
59
|
-
|
59
|
+
Digitalbits::AccountID.new :public_key_type_ed25519, raw_public_key
|
60
60
|
end
|
61
61
|
|
62
62
|
def muxed_account
|
63
|
-
|
63
|
+
Digitalbits::MuxedAccount.new :key_type_ed25519, raw_public_key
|
64
64
|
end
|
65
65
|
|
66
66
|
def public_key
|
67
|
-
|
67
|
+
Digitalbits::PublicKey.new :public_key_type_ed25519, raw_public_key
|
68
68
|
end
|
69
69
|
|
70
70
|
def signer_key
|
71
|
-
|
71
|
+
Digitalbits::SignerKey.new :signer_key_type_ed25519, raw_public_key
|
72
72
|
end
|
73
73
|
|
74
74
|
def signature_hint
|
@@ -105,7 +105,7 @@ module DigitalBits
|
|
105
105
|
|
106
106
|
def sign_decorated(message)
|
107
107
|
raw_signature = sign(message)
|
108
|
-
|
108
|
+
Digitalbits::DecoratedSignature.new({
|
109
109
|
hint: signature_hint,
|
110
110
|
signature: raw_signature
|
111
111
|
})
|
@@ -1,10 +1,10 @@
|
|
1
1
|
require "digitalbits/convert"
|
2
2
|
require "digitalbits/dsl"
|
3
3
|
|
4
|
-
module
|
4
|
+
module Digitalbits
|
5
5
|
class LedgerKey
|
6
6
|
class << self
|
7
|
-
include
|
7
|
+
include Digitalbits::DSL
|
8
8
|
|
9
9
|
def switch_for_arm(name)
|
10
10
|
(@switch_by_arm ||= switches.invert).fetch(name)
|
@@ -16,7 +16,7 @@ module DigitalBits
|
|
16
16
|
when nil
|
17
17
|
account(account_id: KeyPair(account_id).account_id)
|
18
18
|
when :balance_id
|
19
|
-
claimable_balance(balance_id: ClaimableBalanceID.v0(
|
19
|
+
claimable_balance(balance_id: ClaimableBalanceID.v0(Digitalbits::Convert.from_hex(value.to_s)))
|
20
20
|
when :offer_id
|
21
21
|
offer(seller_id: account_id, offer_id: Integer(value))
|
22
22
|
when :data_name
|
data/lib/digitalbits/networks.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
module
|
1
|
+
module Digitalbits
|
2
2
|
# Provides a container for well-known network passphrases, such as the main network and SDF test network
|
3
3
|
module Networks
|
4
4
|
PUBLIC = "LiveNet Global DigitalBits Network ; February 2021"
|
@@ -12,16 +12,16 @@ module DigitalBits
|
|
12
12
|
# methods of specifying a network if you need two threads in the same process to communicate with
|
13
13
|
# different networks
|
14
14
|
#
|
15
|
-
# @see
|
15
|
+
# @see Digitalbits.on_network
|
16
16
|
mattr_accessor :default_network, default: Networks::TESTNET
|
17
17
|
|
18
18
|
# DigitalBits network passphrase selected for current thread
|
19
19
|
#
|
20
|
-
# @see
|
21
|
-
# @see
|
20
|
+
# @see Digitalbits.current_network
|
21
|
+
# @see Digitalbits.on_network
|
22
22
|
thread_mattr_accessor :network
|
23
23
|
|
24
|
-
# Returns the passphrase for the network currently active per-thread with a fallback to `
|
24
|
+
# Returns the passphrase for the network currently active per-thread with a fallback to `Digitalbits.default_network`
|
25
25
|
def self.current_network
|
26
26
|
network.presence || default_network
|
27
27
|
end
|
@@ -1,35 +1,35 @@
|
|
1
1
|
require "bigdecimal"
|
2
2
|
|
3
|
-
module
|
3
|
+
module Digitalbits
|
4
4
|
class Operation
|
5
5
|
MAX_INT64 = 2**63 - 1
|
6
6
|
TRUST_LINE_FLAGS_MAPPING = {
|
7
|
-
full:
|
8
|
-
maintain_liabilities:
|
9
|
-
clawback_enabled:
|
7
|
+
full: Digitalbits::TrustLineFlags.authorized_flag,
|
8
|
+
maintain_liabilities: Digitalbits::TrustLineFlags.authorized_to_maintain_liabilities_flag,
|
9
|
+
clawback_enabled: false
|
10
10
|
}.freeze
|
11
11
|
|
12
12
|
class << self
|
13
|
-
include
|
13
|
+
include Digitalbits::DSL
|
14
14
|
#
|
15
|
-
# Construct a new
|
15
|
+
# Construct a new Digitalbits::Operation from the provided
|
16
16
|
# source account and body
|
17
17
|
#
|
18
18
|
# @param [Hash] attributes the attributes to create the operation with
|
19
|
-
# @option attributes [
|
20
|
-
# @option attributes [
|
19
|
+
# @option attributes [Digitalbits::KeyPair] :source_account
|
20
|
+
# @option attributes [Digitalbits::Operation::Body] :body
|
21
21
|
#
|
22
|
-
# @return [
|
22
|
+
# @return [Digitalbits::Operation] the built operation
|
23
23
|
def make(attributes = {})
|
24
24
|
source_account = attributes[:source_account]
|
25
25
|
|
26
|
-
if source_account && !source_account.is_a?(
|
26
|
+
if source_account && !source_account.is_a?(Digitalbits::KeyPair)
|
27
27
|
raise ArgumentError, "Bad :source_account"
|
28
28
|
end
|
29
29
|
|
30
|
-
body =
|
30
|
+
body = Digitalbits::Operation::Body.new(*attributes[:body])
|
31
31
|
|
32
|
-
|
32
|
+
Digitalbits::Operation.new(
|
33
33
|
body: body,
|
34
34
|
source_account: source_account&.muxed_account
|
35
35
|
)
|
@@ -40,13 +40,13 @@ module DigitalBits
|
|
40
40
|
# in the necessary XDR structs to be included within a
|
41
41
|
# transactions `operations` array.
|
42
42
|
#
|
43
|
-
# @see
|
43
|
+
# @see Digitalbits::Asset
|
44
44
|
#
|
45
45
|
# @param [Hash] attributes the attributes to create the operation with
|
46
|
-
# @option attributes [
|
46
|
+
# @option attributes [Digitalbits::KeyPair] :destination the receiver of the payment
|
47
47
|
# @option attributes [Array] :amount the amount to pay
|
48
|
-
# @return [
|
49
|
-
#
|
48
|
+
# @return [Digitalbits::Operation] the built operation, containing a
|
49
|
+
# Digitalbits::PaymentOp body
|
50
50
|
def payment(attributes = {})
|
51
51
|
destination = attributes[:destination]
|
52
52
|
asset, amount = get_asset_amount(attributes[:amount])
|
@@ -70,15 +70,15 @@ module DigitalBits
|
|
70
70
|
#
|
71
71
|
# @deprecated Please use Operation.path_payment_strict_receive
|
72
72
|
#
|
73
|
-
# @see
|
73
|
+
# @see Digitalbits::Asset
|
74
74
|
#
|
75
75
|
# @param [Hash] attributes the attributes to create the operation with
|
76
|
-
# @option attributes [
|
76
|
+
# @option attributes [Digitalbits::KeyPair] :destination the receiver of the payment
|
77
77
|
# @option attributes [Array] :amount the destination asset and the amount to pay
|
78
78
|
# @option attributes [Array] :with the source asset and maximum allowed source amount to pay with
|
79
|
-
# @option attributes [Array<
|
79
|
+
# @option attributes [Array<Digitalbits::Asset>] :path the payment path to use
|
80
80
|
#
|
81
|
-
# @return [
|
81
|
+
# @return [Digitalbits::Operation] the built operation, containing a Digitalbits::PaymentOp body
|
82
82
|
#
|
83
83
|
def path_payment(attributes = {})
|
84
84
|
path_payment_strict_receive(attributes)
|
@@ -89,22 +89,22 @@ module DigitalBits
|
|
89
89
|
# in the necessary XDR structs to be included within a
|
90
90
|
# transactions `operations` array.
|
91
91
|
#
|
92
|
-
# @see
|
92
|
+
# @see Digitalbits::Asset
|
93
93
|
#
|
94
94
|
# @param [Hash] attributes the attributes to create the operation with
|
95
|
-
# @option attributes [
|
95
|
+
# @option attributes [Digitalbits::KeyPair] :destination the receiver of the payment
|
96
96
|
# @option attributes [Array] :amount the destination asset and the amount to pay
|
97
97
|
# @option attributes [Array] :with the source asset and maximum allowed source amount to pay with
|
98
|
-
# @option attributes [Array<
|
98
|
+
# @option attributes [Array<Digitalbits::Asset>] :path the payment path to use
|
99
99
|
#
|
100
|
-
# @return [
|
100
|
+
# @return [Digitalbits::Operation] the built operation, containing a Digitalbits::PaymentOp body
|
101
101
|
#
|
102
102
|
def path_payment_strict_receive(attributes = {})
|
103
103
|
destination = attributes[:destination]
|
104
104
|
asset, amount = get_asset_amount(attributes[:amount])
|
105
105
|
send_asset, send_max = get_asset_amount(attributes[:with])
|
106
106
|
path = (attributes[:path] || []).map { |p|
|
107
|
-
p.is_a?(Array) ?
|
107
|
+
p.is_a?(Array) ? Digitalbits::Asset.send(*p) : p
|
108
108
|
}
|
109
109
|
|
110
110
|
raise ArgumentError unless destination.is_a?(KeyPair)
|
@@ -127,22 +127,22 @@ module DigitalBits
|
|
127
127
|
# in the necessary XDR structs to be included within a
|
128
128
|
# transactions `operations` array.
|
129
129
|
#
|
130
|
-
# @see
|
130
|
+
# @see Digitalbits::Asset
|
131
131
|
#
|
132
132
|
# @param [Hash] attributes the attributes to create the operation with
|
133
|
-
# @option attributes [
|
133
|
+
# @option attributes [Digitalbits::KeyPair] :destination the receiver of the payment
|
134
134
|
# @option attributes [Array] :amount the destination asset and the minimum amount of destination asset to be received
|
135
135
|
# @option attributes [Array] :with the source asset and amount to pay with
|
136
|
-
# @option attributes [Array<
|
136
|
+
# @option attributes [Array<Digitalbits::Asset>] :path the payment path to use
|
137
137
|
#
|
138
|
-
# @return [
|
138
|
+
# @return [Digitalbits::Operation] the built operation, containing a Digitalbits::PaymentOp body
|
139
139
|
#
|
140
140
|
def path_payment_strict_send(attributes = {})
|
141
141
|
destination = attributes[:destination]
|
142
142
|
asset, dest_min = get_asset_amount(attributes[:amount])
|
143
143
|
send_asset, send_amount = get_asset_amount(attributes[:with])
|
144
144
|
path = (attributes[:path] || []).map { |p|
|
145
|
-
p.is_a?(Array) ?
|
145
|
+
p.is_a?(Array) ? Digitalbits::Asset.send(*p) : p
|
146
146
|
}
|
147
147
|
|
148
148
|
raise ArgumentError unless destination.is_a?(KeyPair)
|
@@ -180,12 +180,12 @@ module DigitalBits
|
|
180
180
|
# transactions `operations` array.
|
181
181
|
#
|
182
182
|
# @param [Hash] attributes the attributes to create the operation with
|
183
|
-
# @option attributes [
|
183
|
+
# @option attributes [Digitalbits::Asset] :line the asset to trust
|
184
184
|
# @option attributes [Fixnum] :limit the maximum amount to trust, defaults to max int64,
|
185
185
|
# if the limit is set to 0 it deletes the trustline.
|
186
186
|
#
|
187
|
-
# @return [
|
188
|
-
#
|
187
|
+
# @return [Digitalbits::Operation] the built operation, containing a
|
188
|
+
# Digitalbits::ChangeTrustOp body
|
189
189
|
def change_trust(attributes = {})
|
190
190
|
line = attributes[:line]
|
191
191
|
unless line.is_a?(Asset)
|
@@ -209,7 +209,7 @@ module DigitalBits
|
|
209
209
|
# Helper method to create a valid CreateClaimableBalanceOp, ready to be used
|
210
210
|
# within a transactions `operations` array.
|
211
211
|
#
|
212
|
-
# @see
|
212
|
+
# @see Digitalbits::DSL::Claimant
|
213
213
|
#
|
214
214
|
# @param asset [Asset] the asset to transfer to a claimable balance
|
215
215
|
# @param amount [Fixnum] the amount of `asset` to put into a claimable balance
|
@@ -225,11 +225,11 @@ module DigitalBits
|
|
225
225
|
# Helper method to create a valid CreateClaimableBalanceOp, ready to be used
|
226
226
|
# within a transactions `operations` array.
|
227
227
|
#
|
228
|
-
# @see
|
228
|
+
# @see Digitalbits::DSL::Claimant
|
229
229
|
#
|
230
230
|
# @param balance_id [ClaimableBalanceID] unique ID of claimable balance
|
231
231
|
#
|
232
|
-
# @return [Operation] the built operation, containing a
|
232
|
+
# @return [Operation] the built operation, containing a Digitalbits::ChangeTrustOp body
|
233
233
|
def claim_claimable_balance(balance_id:, **attributes)
|
234
234
|
op = ClaimClaimableBalanceOp.new(balance_id: balance_id)
|
235
235
|
|
@@ -344,18 +344,18 @@ module DigitalBits
|
|
344
344
|
# transactions `operations` array.
|
345
345
|
#
|
346
346
|
# @param [Hash] attributes the attributes to create the operation with
|
347
|
-
# @option attributes [
|
348
|
-
# @option attributes [Array<
|
349
|
-
# @option attributes [Array<
|
347
|
+
# @option attributes [Digitalbits::KeyPair] :inflation_dest
|
348
|
+
# @option attributes [Array<Digitalbits::AccountFlags>] :set flags to set
|
349
|
+
# @option attributes [Array<Digitalbits::AccountFlags>] :clear flags to clear
|
350
350
|
# @option attributes [String] :thresholds
|
351
|
-
# @option attributes [
|
351
|
+
# @option attributes [Digitalbits::Signer] :signer
|
352
352
|
#
|
353
|
-
# @return [
|
354
|
-
#
|
353
|
+
# @return [Digitalbits::Operation] the built operation, containing a
|
354
|
+
# Digitalbits::SetOptionsOp body
|
355
355
|
def set_options(attributes = {})
|
356
356
|
op = SetOptionsOp.new
|
357
|
-
op.set_flags =
|
358
|
-
op.clear_flags =
|
357
|
+
op.set_flags = Digitalbits::AccountFlags.make_mask attributes[:set]
|
358
|
+
op.clear_flags = Digitalbits::AccountFlags.make_mask attributes[:clear]
|
359
359
|
op.master_weight = attributes[:master_weight]
|
360
360
|
op.low_threshold = attributes[:low_threshold]
|
361
361
|
op.med_threshold = attributes[:med_threshold]
|
@@ -366,7 +366,7 @@ module DigitalBits
|
|
366
366
|
|
367
367
|
inflation_dest = attributes[:inflation_dest]
|
368
368
|
if inflation_dest
|
369
|
-
raise ArgumentError, "Bad :inflation_dest" unless inflation_dest.is_a?(
|
369
|
+
raise ArgumentError, "Bad :inflation_dest" unless inflation_dest.is_a?(Digitalbits::KeyPair)
|
370
370
|
op.inflation_dest = inflation_dest.account_id
|
371
371
|
end
|
372
372
|
|
@@ -375,15 +375,15 @@ module DigitalBits
|
|
375
375
|
}))
|
376
376
|
end
|
377
377
|
|
378
|
-
# @param asset [
|
379
|
-
# @param trustor [
|
380
|
-
# @param flags [{String, Symbol,
|
381
|
-
# @param source_account [
|
378
|
+
# @param asset [Digitalbits::Asset]
|
379
|
+
# @param trustor [Digitalbits::KeyPair]
|
380
|
+
# @param flags [{String, Symbol, Digitalbits::TrustLineFlags => true, false}] flags to to set or clear
|
381
|
+
# @param source_account [Digitalbits::KeyPair] source account (default is `nil`, which will use the source account of transaction)
|
382
382
|
def set_trust_line_flags(asset:, trustor:, flags: {}, source_account: nil)
|
383
|
-
op =
|
383
|
+
op = Digitalbits::SetTrustLineFlagsOp.new
|
384
384
|
op.trustor = KeyPair(trustor).account_id
|
385
385
|
op.asset = Asset(asset)
|
386
|
-
op.attributes =
|
386
|
+
op.attributes = Digitalbits::TrustLineFlags.set_clear_masks(flags)
|
387
387
|
|
388
388
|
make(
|
389
389
|
source_account: source_account,
|
@@ -400,12 +400,12 @@ module DigitalBits
|
|
400
400
|
# @deprecated Use `set_trustline_flags` operation
|
401
401
|
#
|
402
402
|
# @param [Hash] attributes the attributes to create the operation with
|
403
|
-
# @option attributes [
|
404
|
-
# @option attributes [
|
403
|
+
# @option attributes [Digitalbits::KeyPair] :trustor
|
404
|
+
# @option attributes [Digitalbits::Asset] :asset
|
405
405
|
# @option attributes [Symbol, Boolean] :authorize :full, maintain_liabilities or :none
|
406
406
|
#
|
407
|
-
# @return [
|
408
|
-
#
|
407
|
+
# @return [Digitalbits::Operation] the built operation, containing a
|
408
|
+
# Digitalbits::AllowTrustOp body
|
409
409
|
def allow_trust(attributes = {})
|
410
410
|
op = AllowTrustOp.new
|
411
411
|
|
@@ -417,7 +417,7 @@ module DigitalBits
|
|
417
417
|
asset = Asset.send(*asset)
|
418
418
|
end
|
419
419
|
|
420
|
-
raise ArgumentError, "Bad :trustor" unless trustor.is_a?(
|
420
|
+
raise ArgumentError, "Bad :trustor" unless trustor.is_a?(Digitalbits::KeyPair)
|
421
421
|
|
422
422
|
allowed_flags = TRUST_LINE_FLAGS_MAPPING.slice(:full, :maintain_liabilities)
|
423
423
|
|
@@ -430,7 +430,7 @@ module DigitalBits
|
|
430
430
|
raise ArgumentError, "Bad :authorize, supported values: :full, :maintain_liabilities, :none"
|
431
431
|
end
|
432
432
|
|
433
|
-
raise ArgumentError, "Bad :asset" unless asset.type ==
|
433
|
+
raise ArgumentError, "Bad :asset" unless asset.type == Digitalbits::AssetType.asset_type_credit_alphanum4
|
434
434
|
|
435
435
|
op.trustor = trustor.account_id
|
436
436
|
op.asset = AssetCode.new(:asset_type_credit_alphanum4, asset.code)
|
@@ -444,9 +444,9 @@ module DigitalBits
|
|
444
444
|
# Helper method to create an account merge operation
|
445
445
|
#
|
446
446
|
# @param [Hash] attributes the attributes to create the operation with
|
447
|
-
# @option attributes [
|
447
|
+
# @option attributes [Digitalbits::KeyPair] :destination
|
448
448
|
#
|
449
|
-
# @return [
|
449
|
+
# @return [Digitalbits::Operation] the built operation
|
450
450
|
def account_merge(attributes = {})
|
451
451
|
destination = attributes[:destination]
|
452
452
|
|
@@ -464,7 +464,7 @@ module DigitalBits
|
|
464
464
|
# @param [Hash] attributes the attributes to create the operation with
|
465
465
|
# @option attributes [Integer] :sequence
|
466
466
|
#
|
467
|
-
# @return [
|
467
|
+
# @return [Digitalbits::Operation] the built operation
|
468
468
|
def inflation(attributes = {})
|
469
469
|
sequence = attributes[:sequence]
|
470
470
|
|
@@ -482,7 +482,7 @@ module DigitalBits
|
|
482
482
|
# @param [Hash] attributes the attributes to create the operation with
|
483
483
|
# @option attributes [Integer] :sequence
|
484
484
|
#
|
485
|
-
# @return [
|
485
|
+
# @return [Digitalbits::Operation] the built operation
|
486
486
|
def manage_data(attributes = {})
|
487
487
|
op = ManageDataOp.new
|
488
488
|
|
@@ -543,12 +543,12 @@ module DigitalBits
|
|
543
543
|
|
544
544
|
# Helper method to create clawback claimable balance operation
|
545
545
|
#
|
546
|
-
# @param [
|
546
|
+
# @param [Digitalbits::KeyPair] source_account the attributes to create the operation with
|
547
547
|
# @param [String] balance_id `ClaimableBalanceID`, serialized in hex
|
548
548
|
#
|
549
|
-
# @return [
|
549
|
+
# @return [Digitalbits::Operation] the built operation
|
550
550
|
def clawback_claimable_balance(source_account:, balance_id:)
|
551
|
-
balance_id =
|
551
|
+
balance_id = Digitalbits::ClaimableBalanceID.from_xdr(balance_id, :hex)
|
552
552
|
op = ClawbackClaimableBalanceOp.new(balance_id: balance_id)
|
553
553
|
|
554
554
|
make(
|
@@ -563,10 +563,10 @@ module DigitalBits
|
|
563
563
|
|
564
564
|
def get_asset_amount(values)
|
565
565
|
amount = interpret_amount(values.last)
|
566
|
-
asset = if values[0].is_a?(
|
566
|
+
asset = if values[0].is_a?(Digitalbits::Asset)
|
567
567
|
values.first
|
568
568
|
else
|
569
|
-
|
569
|
+
Digitalbits::Asset.send(*values[0...-1])
|
570
570
|
end
|
571
571
|
|
572
572
|
[asset, amount]
|
@@ -575,11 +575,11 @@ module DigitalBits
|
|
575
575
|
def interpret_amount(amount)
|
576
576
|
case amount
|
577
577
|
when String
|
578
|
-
(BigDecimal(amount) *
|
578
|
+
(BigDecimal(amount) * Digitalbits::ONE).floor
|
579
579
|
when Integer
|
580
|
-
amount *
|
580
|
+
amount * Digitalbits::ONE
|
581
581
|
when Numeric
|
582
|
-
(amount *
|
582
|
+
(amount * Digitalbits::ONE).floor
|
583
583
|
else
|
584
584
|
raise ArgumentError, "Invalid amount type: #{amount.class}. Must be String or Numeric"
|
585
585
|
end
|
@@ -592,10 +592,10 @@ module DigitalBits
|
|
592
592
|
Price.from_f(bd)
|
593
593
|
when Numeric
|
594
594
|
Price.from_f(price)
|
595
|
-
when
|
595
|
+
when Digitalbits::Price
|
596
596
|
price
|
597
597
|
else
|
598
|
-
raise ArgumentError, "Invalid price type: #{price.class}. Must be String, Numeric, or
|
598
|
+
raise ArgumentError, "Invalid price type: #{price.class}. Must be String, Numeric, or Digitalbits::Price"
|
599
599
|
end
|
600
600
|
end
|
601
601
|
end
|
data/lib/digitalbits/price.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
module
|
1
|
+
module Digitalbits
|
2
2
|
# reopen class
|
3
3
|
class Price
|
4
4
|
MAX_PRECISION = (2**31) - 1
|
@@ -33,7 +33,7 @@ module DigitalBits
|
|
33
33
|
end
|
34
34
|
|
35
35
|
def inspect
|
36
|
-
"#<
|
36
|
+
"#<Digitalbits::Price #{self}>"
|
37
37
|
end
|
38
38
|
end
|
39
39
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
module
|
1
|
+
module Digitalbits
|
2
2
|
class SignerKey
|
3
3
|
PREIMAGE_LENGTH = 32
|
4
4
|
|
@@ -22,20 +22,20 @@ module DigitalBits
|
|
22
22
|
def to_s
|
23
23
|
case switch
|
24
24
|
when SignerKeyType.signer_key_type_ed25519
|
25
|
-
address =
|
25
|
+
address = Digitalbits::Convert.pk_to_address(self)
|
26
26
|
"ed25519: #{address}"
|
27
27
|
when SignerKeyType.signer_key_type_pre_auth_tx
|
28
|
-
tx =
|
28
|
+
tx = Digitalbits::Convert.to_hex(pre_auth_tx!)
|
29
29
|
"pre_auth_tx: #{tx}"
|
30
30
|
when SignerKeyType.signer_key_type_hash_x
|
31
|
-
hx =
|
31
|
+
hx = Digitalbits::Convert.to_hex(hash_x!)
|
32
32
|
"hash_x: #{hx}"
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
36
|
def inspect
|
37
37
|
# label = switch.to_s
|
38
|
-
"#<
|
38
|
+
"#<Digitalbits::SignerKey #{self}>"
|
39
39
|
end
|
40
40
|
|
41
41
|
def signature_hint
|
@@ -1,9 +1,9 @@
|
|
1
|
-
module
|
1
|
+
module Digitalbits
|
2
2
|
class Transaction
|
3
|
-
include
|
3
|
+
include Digitalbits::Concerns::Transaction
|
4
4
|
|
5
5
|
def to_v0
|
6
|
-
ed25519 = if source_account.switch ==
|
6
|
+
ed25519 = if source_account.switch == Digitalbits::CryptoKeyType.key_type_ed25519
|
7
7
|
source_account.ed25519!
|
8
8
|
else
|
9
9
|
source_account.med25519!.ed25519
|
@@ -21,9 +21,9 @@ module DigitalBits
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def signature_base
|
24
|
-
tagged_tx =
|
25
|
-
|
26
|
-
network_id:
|
24
|
+
tagged_tx = Digitalbits::TransactionSignaturePayload::TaggedTransaction.new(:envelope_type_tx, self)
|
25
|
+
Digitalbits::TransactionSignaturePayload.new(
|
26
|
+
network_id: Digitalbits.current_network_id,
|
27
27
|
tagged_transaction: tagged_tx
|
28
28
|
).to_xdr
|
29
29
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
module
|
1
|
+
module Digitalbits
|
2
2
|
class TransactionBuilder
|
3
3
|
attr_reader :source_account, :sequence_number, :base_fee, :time_bounds, :memo, :operations
|
4
4
|
|
@@ -9,17 +9,17 @@ module DigitalBits
|
|
9
9
|
# It reduces the boilerplate, when you just need to
|
10
10
|
# shoot a single operation in transaction
|
11
11
|
def method_missing(method_name, *args, **kwargs)
|
12
|
-
unless
|
12
|
+
unless Digitalbits::Operation.respond_to?(method_name)
|
13
13
|
return super
|
14
14
|
end
|
15
15
|
|
16
|
-
op =
|
16
|
+
op = Digitalbits::Operation.send(method_name, **kwargs)
|
17
17
|
|
18
18
|
new(**kwargs).add_operation(op).build
|
19
19
|
end
|
20
20
|
|
21
21
|
def respond_to_missing?(method_name, include_private = false)
|
22
|
-
|
22
|
+
Digitalbits::Operation.respond_to?(method_name) || super
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
@@ -31,9 +31,9 @@ module DigitalBits
|
|
31
31
|
memo: nil,
|
32
32
|
**_ # ignore any additional parameters without errors
|
33
33
|
)
|
34
|
-
raise ArgumentError, "Bad :source_account" unless source_account.is_a?(
|
34
|
+
raise ArgumentError, "Bad :source_account" unless source_account.is_a?(Digitalbits::KeyPair)
|
35
35
|
raise ArgumentError, "Bad :sequence_number" unless sequence_number.is_a?(Integer) && sequence_number >= 0
|
36
|
-
raise ArgumentError, "Bad :time_bounds" unless time_bounds.is_a?(
|
36
|
+
raise ArgumentError, "Bad :time_bounds" unless time_bounds.is_a?(Digitalbits::TimeBounds) || time_bounds.nil?
|
37
37
|
raise ArgumentError, "Bad :base_fee" unless base_fee.is_a?(Integer) && base_fee >= 100
|
38
38
|
|
39
39
|
@source_account = source_account
|
@@ -65,18 +65,18 @@ module DigitalBits
|
|
65
65
|
time_bounds: @time_bounds,
|
66
66
|
memo: @memo,
|
67
67
|
operations: @operations,
|
68
|
-
ext:
|
68
|
+
ext: Digitalbits::Transaction::Ext.new(0)
|
69
69
|
}
|
70
70
|
|
71
71
|
@sequence_number += 1
|
72
72
|
|
73
|
-
|
73
|
+
Digitalbits::Transaction.new(attrs)
|
74
74
|
end
|
75
75
|
|
76
76
|
def build_fee_bump(inner_txe:)
|
77
|
-
if inner_txe.switch ==
|
78
|
-
inner_txe =
|
79
|
-
elsif inner_txe.switch !=
|
77
|
+
if inner_txe.switch == Digitalbits::EnvelopeType.envelope_type_tx_v0
|
78
|
+
inner_txe = Digitalbits::TransactionEnvelope.v1(tx: inner_txe.tx.to_v1, signatures: inner_txe.signatures)
|
79
|
+
elsif inner_txe.switch != Digitalbits::EnvelopeType.envelope_type_tx
|
80
80
|
raise ArgumentError, "Invalid inner transaction type #{inner_txe.switch}"
|
81
81
|
end
|
82
82
|
|
@@ -89,16 +89,16 @@ module DigitalBits
|
|
89
89
|
raise "Insufficient base_fee, it should be at least #{inner_base_fee_rate} stroops."
|
90
90
|
end
|
91
91
|
|
92
|
-
|
92
|
+
Digitalbits::FeeBumpTransaction.new(
|
93
93
|
fee_source: @source_account.muxed_account,
|
94
94
|
fee: @base_fee * (inner_ops.length + 1),
|
95
|
-
inner_tx:
|
96
|
-
ext:
|
95
|
+
inner_tx: Digitalbits::FeeBumpTransaction::InnerTx.new(:envelope_type_tx, inner_txe.v1!),
|
96
|
+
ext: Digitalbits::FeeBumpTransaction::Ext.new(0)
|
97
97
|
)
|
98
98
|
end
|
99
99
|
|
100
100
|
def add_operation(operation)
|
101
|
-
raise ArgumentError, "Bad operation" unless operation.is_a?
|
101
|
+
raise ArgumentError, "Bad operation" unless operation.is_a? Digitalbits::Operation
|
102
102
|
@operations.push(operation)
|
103
103
|
self
|
104
104
|
end
|
@@ -109,7 +109,7 @@ module DigitalBits
|
|
109
109
|
end
|
110
110
|
|
111
111
|
def set_source_account(account_kp)
|
112
|
-
raise ArgumentError, "Bad source account" unless account_kp.is_a?(
|
112
|
+
raise ArgumentError, "Bad source account" unless account_kp.is_a?(Digitalbits::KeyPair)
|
113
113
|
@source_account = account_kp
|
114
114
|
self
|
115
115
|
end
|
@@ -126,7 +126,7 @@ module DigitalBits
|
|
126
126
|
end
|
127
127
|
|
128
128
|
if @time_bounds.nil?
|
129
|
-
@time_bounds =
|
129
|
+
@time_bounds = Digitalbits::TimeBounds.new(min_time: 0, max_time: nil)
|
130
130
|
end
|
131
131
|
|
132
132
|
@time_bounds.max_time = timeout == 0 ? timeout : Time.now.to_i + timeout
|
@@ -147,7 +147,7 @@ module DigitalBits
|
|
147
147
|
|
148
148
|
def make_memo(memo)
|
149
149
|
case memo
|
150
|
-
when
|
150
|
+
when Digitalbits::Memo
|
151
151
|
memo
|
152
152
|
when nil
|
153
153
|
Memo.new(:memo_none)
|
@@ -1,4 +1,4 @@
|
|
1
|
-
module
|
1
|
+
module Digitalbits
|
2
2
|
class TransactionEnvelope
|
3
3
|
delegate :tx, :signatures, to: :value
|
4
4
|
delegate :hash, to: :tx
|
@@ -9,7 +9,7 @@ module DigitalBits
|
|
9
9
|
# NOTE: this does not do any authorization checks, which requires access to
|
10
10
|
# the current ledger state.
|
11
11
|
#
|
12
|
-
# @param key_pairs [Array<
|
12
|
+
# @param key_pairs [Array<Digitalbits::KeyPair>] The key pairs to check the envelopes signatures against
|
13
13
|
#
|
14
14
|
# @return [Boolean] true if all signatures are from the provided key_pairs and validly sign the tx's hash
|
15
15
|
def signed_correctly?(*key_pairs)
|
@@ -1,6 +1,6 @@
|
|
1
|
-
module
|
1
|
+
module Digitalbits
|
2
2
|
class TransactionV0
|
3
|
-
include
|
3
|
+
include Digitalbits::Concerns::Transaction
|
4
4
|
|
5
5
|
def to_v1
|
6
6
|
Transaction.new(**attributes.except(:source_account_ed25519), source_account: source_account)
|
@@ -13,31 +13,31 @@ module DigitalBits
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def signature_base_prefix
|
16
|
-
val =
|
16
|
+
val = Digitalbits::EnvelopeType.envelope_type_tx_v0
|
17
17
|
|
18
|
-
|
18
|
+
Digitalbits.current_network_id + Digitalbits::EnvelopeType.to_xdr(val)
|
19
19
|
end
|
20
20
|
|
21
21
|
# Backwards Compatibility: Use ENVELOPE_TYPE_TX to sign ENVELOPE_TYPE_TX_V0
|
22
22
|
# we need a Transaction to generate the signature base
|
23
23
|
def signature_base
|
24
|
-
tx =
|
24
|
+
tx = Digitalbits::Transaction.from_xdr(
|
25
25
|
# TransactionV0 is a transaction with the AccountID discriminant
|
26
26
|
# stripped off, we need to put it back to build a valid transaction
|
27
27
|
# which we can use to build a TransactionSignaturePayloadTaggedTransaction
|
28
|
-
|
28
|
+
Digitalbits::PublicKeyType.to_xdr(Digitalbits::PublicKeyType.public_key_type_ed25519) + to_xdr
|
29
29
|
)
|
30
30
|
|
31
|
-
tagged_tx =
|
31
|
+
tagged_tx = Digitalbits::TransactionSignaturePayload::TaggedTransaction.new(:envelope_type_tx, tx)
|
32
32
|
|
33
|
-
|
34
|
-
network_id:
|
33
|
+
Digitalbits::TransactionSignaturePayload.new(
|
34
|
+
network_id: Digitalbits.current_network_id,
|
35
35
|
tagged_transaction: tagged_tx
|
36
36
|
).to_xdr
|
37
37
|
end
|
38
38
|
|
39
39
|
def source_account
|
40
|
-
|
40
|
+
Digitalbits::MuxedAccount.ed25519(source_account_ed25519)
|
41
41
|
end
|
42
42
|
end
|
43
43
|
end
|
@@ -1,9 +1,9 @@
|
|
1
|
-
module
|
1
|
+
module Digitalbits
|
2
2
|
class TrustLineFlags
|
3
|
-
# Converts an array of
|
3
|
+
# Converts an array of Digitalbits::TrustLineFlags members into
|
4
4
|
# an integers suitable for use in in a SetTrustLineFlagsOp.
|
5
5
|
#
|
6
|
-
# @param flags [Array<
|
6
|
+
# @param flags [Array<Digitalbits::TrustLineFlags>] the flags to combine
|
7
7
|
#
|
8
8
|
# @return [Fixnum] the combined result
|
9
9
|
def self.make_mask(flags)
|
@@ -11,23 +11,23 @@ module DigitalBits
|
|
11
11
|
end
|
12
12
|
|
13
13
|
# Converts an integer used in SetTrustLineFlagsOp on the set/clear flag options
|
14
|
-
# into an array of
|
14
|
+
# into an array of Digitalbits::TrustLineFlags members
|
15
15
|
#
|
16
16
|
# @param combined [Fixnum]
|
17
|
-
# @return [Array<
|
17
|
+
# @return [Array<Digitalbits::AccountFlags>]
|
18
18
|
def self.parse_mask(combined)
|
19
19
|
members.values.select { |m| (m.value & combined) != 0 }
|
20
20
|
end
|
21
21
|
|
22
|
-
# Converts each element of the input array to
|
22
|
+
# Converts each element of the input array to Digitalbits::TrustLineFlags instance.
|
23
23
|
#
|
24
|
-
# @param [Array<
|
25
|
-
# @return [Array<
|
24
|
+
# @param [Array<Digitalbits::TrustLineFlags,Symbol,#to_s>] input
|
25
|
+
# @return [Array<Digitalbits::TrustLineFlags>]
|
26
26
|
# @raise [TypeError] if any element of the input cannot be converted
|
27
27
|
def self.normalize(input)
|
28
28
|
input.map do |val|
|
29
29
|
case val
|
30
|
-
when
|
30
|
+
when Digitalbits::TrustLineFlags
|
31
31
|
val
|
32
32
|
when ->(_) { members.key?(val.to_s) }
|
33
33
|
from_name(val.to_s)
|
@@ -1,4 +1,4 @@
|
|
1
|
-
module
|
1
|
+
module Digitalbits
|
2
2
|
module Util
|
3
3
|
require "base32"
|
4
4
|
require "digest/crc16_xmodem"
|
@@ -21,11 +21,11 @@ module DigitalBits
|
|
21
21
|
Base32.encode(payload + check).tr("=", "")
|
22
22
|
end
|
23
23
|
|
24
|
-
# Converts an
|
25
|
-
# @param muxed_account [
|
24
|
+
# Converts an Digitalbits::MuxedAccount to its string representation, forcing the ed25519 representation.
|
25
|
+
# @param muxed_account [Digitalbits::MuxedAccount] account
|
26
26
|
# @return [String] "G.."-like address
|
27
27
|
def self.encode_muxed_account(muxed_account)
|
28
|
-
ed25519 = if muxed_account.switch ==
|
28
|
+
ed25519 = if muxed_account.switch == Digitalbits::CryptoKeyType.key_type_ed25519
|
29
29
|
muxed_account.ed25519!
|
30
30
|
else
|
31
31
|
muxed_account.med25519!.ed25519
|
@@ -34,12 +34,12 @@ module DigitalBits
|
|
34
34
|
check_encode(:account_id, ed25519)
|
35
35
|
end
|
36
36
|
|
37
|
-
# Returns a
|
37
|
+
# Returns a Digitalbits::MuxedAccount, forcing the ed25519 discriminant
|
38
38
|
#
|
39
39
|
# @param strkey [String] address string to decode
|
40
|
-
# @return [
|
40
|
+
# @return [Digitalbits::MuxedAccount] MuxedAccount with ed25519 discriminant
|
41
41
|
def self.decode_muxed_account(strkey)
|
42
|
-
|
42
|
+
Digitalbits::MuxedAccount.new(:key_type_ed25519, check_decode(:account_id, strkey))
|
43
43
|
end
|
44
44
|
|
45
45
|
def self.check_decode(expected_version, str)
|
data/lib/digitalbits/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
module
|
2
|
-
VERSION = "0.27.
|
1
|
+
module Digitalbits
|
2
|
+
VERSION = "0.27.2"
|
3
3
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: digitalbits-base
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.27.
|
4
|
+
version: 0.27.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- XDB Foundation
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-08-
|
11
|
+
date: 2021-08-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -431,11 +431,11 @@ licenses:
|
|
431
431
|
- Apache-2.0
|
432
432
|
metadata:
|
433
433
|
bug_tracker_uri: https://github.com/xdbfoundation/ruby-digitalbits-sdk/issues
|
434
|
-
changelog_uri: https://github.com/xdbfoundation/ruby-digitalbits-sdk/blob/v0.27.
|
435
|
-
documentation_uri: https://rubydoc.info/gems/digitalbits-base/0.27.
|
434
|
+
changelog_uri: https://github.com/xdbfoundation/ruby-digitalbits-sdk/blob/v0.27.2/base/CHANGELOG.md
|
435
|
+
documentation_uri: https://rubydoc.info/gems/digitalbits-base/0.27.2/
|
436
436
|
github_repo: ssh://github.com/xdbfoundation/ruby-digitalbits-sdk
|
437
437
|
homepage_uri: https://github.com/xdbfoundation/ruby-digitalbits-sdk/tree/main/base
|
438
|
-
source_code_uri: https://github.com/xdbfoundation/ruby-digitalbits-sdk/tree/v0.27.
|
438
|
+
source_code_uri: https://github.com/xdbfoundation/ruby-digitalbits-sdk/tree/v0.27.2/base
|
439
439
|
post_install_message:
|
440
440
|
rdoc_options: []
|
441
441
|
require_paths:
|
@@ -452,7 +452,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
452
452
|
- !ruby/object:Gem::Version
|
453
453
|
version: '0'
|
454
454
|
requirements: []
|
455
|
-
rubygems_version: 3.
|
455
|
+
rubygems_version: 3.2.22
|
456
456
|
signing_key:
|
457
457
|
specification_version: 4
|
458
458
|
summary: 'DigitalBits client library: XDR'
|