open-core 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +15 -0
- data/.travis.yml +15 -0
- data/.yardopts +8 -0
- data/CONTRIBUTING.md +48 -0
- data/Gemfile +15 -0
- data/Guardfile +5 -0
- data/LICENSE.txt +202 -0
- data/README.md +83 -0
- data/Rakefile +4 -0
- data/examples/create_account.rb +26 -0
- data/examples/low_level_transaction_post.rb +46 -0
- data/examples/mid_level_transaction_post.rb +33 -0
- data/examples/non_native_payment.rb +60 -0
- data/examples/offer.rb +75 -0
- data/examples/transaction_merge.rb +23 -0
- data/generated/stellar-base-generated.rb +134 -0
- data/generated/stellar/account_entry.rb +53 -0
- data/generated/stellar/account_entry/ext.rb +24 -0
- data/generated/stellar/account_flags.rb +27 -0
- data/generated/stellar/account_merge_result.rb +26 -0
- data/generated/stellar/account_merge_result_code.rb +30 -0
- data/generated/stellar/allow_trust_op.rb +38 -0
- data/generated/stellar/allow_trust_op/asset.rb +33 -0
- data/generated/stellar/allow_trust_result.rb +25 -0
- data/generated/stellar/allow_trust_result_code.rb +31 -0
- data/generated/stellar/asset.rb +47 -0
- data/generated/stellar/asset/alpha_num12.rb +22 -0
- data/generated/stellar/asset/alpha_num4.rb +22 -0
- data/generated/stellar/asset_type.rb +24 -0
- data/generated/stellar/bucket_entry.rb +28 -0
- data/generated/stellar/bucket_entry_type.rb +22 -0
- data/generated/stellar/change_trust_op.rb +22 -0
- data/generated/stellar/change_trust_result.rb +25 -0
- data/generated/stellar/change_trust_result_code.rb +30 -0
- data/generated/stellar/claim_offer_atom.rb +33 -0
- data/generated/stellar/create_account_op.rb +20 -0
- data/generated/stellar/create_account_result.rb +25 -0
- data/generated/stellar/create_account_result_code.rb +32 -0
- data/generated/stellar/create_passive_offer_op.rb +24 -0
- data/generated/stellar/crypto_key_type.rb +20 -0
- data/generated/stellar/decorated_signature.rb +20 -0
- data/generated/stellar/dont_have.rb +20 -0
- data/generated/stellar/envelope_type.rb +22 -0
- data/generated/stellar/error.rb +20 -0
- data/generated/stellar/hello.rb +26 -0
- data/generated/stellar/inflation_payout.rb +20 -0
- data/generated/stellar/inflation_result.rb +26 -0
- data/generated/stellar/inflation_result_code.rb +24 -0
- data/generated/stellar/ledger_entry.rb +44 -0
- data/generated/stellar/ledger_entry/data.rb +33 -0
- data/generated/stellar/ledger_entry/ext.rb +24 -0
- data/generated/stellar/ledger_entry_change.rb +31 -0
- data/generated/stellar/ledger_entry_change_type.rb +24 -0
- data/generated/stellar/ledger_entry_type.rb +24 -0
- data/generated/stellar/ledger_header.rb +65 -0
- data/generated/stellar/ledger_header/ext.rb +24 -0
- data/generated/stellar/ledger_header_history_entry.rb +33 -0
- data/generated/stellar/ledger_header_history_entry/ext.rb +24 -0
- data/generated/stellar/ledger_key.rb +50 -0
- data/generated/stellar/ledger_key/account.rb +20 -0
- data/generated/stellar/ledger_key/offer.rb +22 -0
- data/generated/stellar/ledger_key/trust_line.rb +22 -0
- data/generated/stellar/ledger_upgrade.rb +27 -0
- data/generated/stellar/ledger_upgrade_type.rb +22 -0
- data/generated/stellar/manage_offer_effect.rb +24 -0
- data/generated/stellar/manage_offer_op.rb +28 -0
- data/generated/stellar/manage_offer_result.rb +26 -0
- data/generated/stellar/manage_offer_result_code.rb +48 -0
- data/generated/stellar/manage_offer_success_result.rb +34 -0
- data/generated/stellar/manage_offer_success_result/offer.rb +30 -0
- data/generated/stellar/memo.rb +38 -0
- data/generated/stellar/memo_type.rb +28 -0
- data/generated/stellar/message_type.rb +45 -0
- data/generated/stellar/offer_entry.rb +49 -0
- data/generated/stellar/offer_entry/ext.rb +24 -0
- data/generated/stellar/offer_entry_flags.rb +21 -0
- data/generated/stellar/operation.rb +51 -0
- data/generated/stellar/operation/body.rb +60 -0
- data/generated/stellar/operation_meta.rb +18 -0
- data/generated/stellar/operation_result.rb +53 -0
- data/generated/stellar/operation_result/tr.rb +61 -0
- data/generated/stellar/operation_result_code.rb +25 -0
- data/generated/stellar/operation_type.rb +38 -0
- data/generated/stellar/path_payment_op.rb +32 -0
- data/generated/stellar/path_payment_result.rb +34 -0
- data/generated/stellar/path_payment_result/success.rb +22 -0
- data/generated/stellar/path_payment_result_code.rb +45 -0
- data/generated/stellar/payment_op.rb +22 -0
- data/generated/stellar/payment_result.rb +25 -0
- data/generated/stellar/payment_result_code.rb +39 -0
- data/generated/stellar/peer_address.rb +22 -0
- data/generated/stellar/price.rb +20 -0
- data/generated/stellar/public_key.rb +23 -0
- data/generated/stellar/scp_ballot.rb +20 -0
- data/generated/stellar/scp_envelope.rb +20 -0
- data/generated/stellar/scp_nomination.rb +22 -0
- data/generated/stellar/scp_quorum_set.rb +22 -0
- data/generated/stellar/scp_statement.rb +59 -0
- data/generated/stellar/scp_statement/pledges.rb +64 -0
- data/generated/stellar/scp_statement/pledges/confirm.rb +28 -0
- data/generated/stellar/scp_statement/pledges/externalize.rb +28 -0
- data/generated/stellar/scp_statement/pledges/prepare.rb +32 -0
- data/generated/stellar/scp_statement_type.rb +26 -0
- data/generated/stellar/set_options_op.rb +41 -0
- data/generated/stellar/set_options_result.rb +25 -0
- data/generated/stellar/set_options_result_code.rb +38 -0
- data/generated/stellar/signer.rb +20 -0
- data/generated/stellar/simple_payment_result.rb +22 -0
- data/generated/stellar/stellar_message.rb +66 -0
- data/generated/stellar/stellar_value.rb +40 -0
- data/generated/stellar/stellar_value/ext.rb +24 -0
- data/generated/stellar/threshold_indexes.rb +26 -0
- data/generated/stellar/time_bounds.rb +20 -0
- data/generated/stellar/transaction.rb +50 -0
- data/generated/stellar/transaction/ext.rb +24 -0
- data/generated/stellar/transaction_envelope.rb +20 -0
- data/generated/stellar/transaction_history_entry.rb +33 -0
- data/generated/stellar/transaction_history_entry/ext.rb +24 -0
- data/generated/stellar/transaction_history_result_entry.rb +33 -0
- data/generated/stellar/transaction_history_result_entry/ext.rb +24 -0
- data/generated/stellar/transaction_meta.rb +31 -0
- data/generated/stellar/transaction_meta/v0.rb +22 -0
- data/generated/stellar/transaction_result.rb +43 -0
- data/generated/stellar/transaction_result/ext.rb +24 -0
- data/generated/stellar/transaction_result/result.rb +30 -0
- data/generated/stellar/transaction_result_code.rb +45 -0
- data/generated/stellar/transaction_result_pair.rb +20 -0
- data/generated/stellar/transaction_result_set.rb +18 -0
- data/generated/stellar/transaction_set.rb +20 -0
- data/generated/stellar/trust_line_entry.rb +41 -0
- data/generated/stellar/trust_line_entry/ext.rb +24 -0
- data/generated/stellar/trust_line_flags.rb +21 -0
- data/lib/stellar-base.rb +32 -0
- data/lib/stellar/account_flags.rb +28 -0
- data/lib/stellar/asset.rb +69 -0
- data/lib/stellar/base.rb +1 -0
- data/lib/stellar/base/version.rb +5 -0
- data/lib/stellar/convert.rb +32 -0
- data/lib/stellar/key_pair.rb +112 -0
- data/lib/stellar/networks.rb +45 -0
- data/lib/stellar/operation.rb +304 -0
- data/lib/stellar/path_payment_result.rb +17 -0
- data/lib/stellar/price.rb +32 -0
- data/lib/stellar/thresholds.rb +39 -0
- data/lib/stellar/transaction.rb +170 -0
- data/lib/stellar/transaction_envelope.rb +32 -0
- data/lib/stellar/util/continued_fraction.rb +96 -0
- data/lib/stellar/util/strkey.rb +43 -0
- data/open-core.gemspec +37 -0
- data/spec/lib/stellar/account_flags_spec.rb +19 -0
- data/spec/lib/stellar/asset_spec.rb +45 -0
- data/spec/lib/stellar/convert_spec.rb +61 -0
- data/spec/lib/stellar/key_pair_spec.rb +238 -0
- data/spec/lib/stellar/networks_spec.rb +77 -0
- data/spec/lib/stellar/path_payment_result_spec.rb +95 -0
- data/spec/lib/stellar/price_spec.rb +34 -0
- data/spec/lib/stellar/thresholds_spec.rb +62 -0
- data/spec/lib/stellar/transaction_envelope_spec.rb +93 -0
- data/spec/lib/stellar/transaction_spec.rb +54 -0
- data/spec/lib/stellar/util/strkey_spec.rb +46 -0
- data/spec/spec_helper.rb +16 -0
- data/spec/support/matchers/be_strkey.rb +9 -0
- data/spec/support/matchers/eq_bytes.rb +5 -0
- data/spec/support/matchers/have_length.rb +5 -0
- data/tasks/rspec.rake +6 -0
- data/tasks/travis.rake +1 -0
- data/tasks/xdr.rake +50 -0
- data/xdr/Stellar-SCP.x +87 -0
- data/xdr/Stellar-ledger-entries.x +222 -0
- data/xdr/Stellar-ledger.x +231 -0
- data/xdr/Stellar-overlay.x +87 -0
- data/xdr/Stellar-transaction.x +670 -0
- data/xdr/Stellar-types.x +34 -0
- metadata +444 -0
@@ -0,0 +1,31 @@
|
|
1
|
+
# This code was automatically generated using xdrgen
|
2
|
+
# DO NOT EDIT or your changes may be overwritten
|
3
|
+
|
4
|
+
require 'xdr'
|
5
|
+
|
6
|
+
# === xdr source ============================================================
|
7
|
+
#
|
8
|
+
# union TransactionMeta switch (int v)
|
9
|
+
# {
|
10
|
+
# case 0:
|
11
|
+
# struct
|
12
|
+
# {
|
13
|
+
# LedgerEntryChanges changes;
|
14
|
+
# OperationMeta operations<>;
|
15
|
+
# } v0;
|
16
|
+
# };
|
17
|
+
#
|
18
|
+
# ===========================================================================
|
19
|
+
module Stellar
|
20
|
+
class TransactionMeta < XDR::Union
|
21
|
+
include XDR::Namespace
|
22
|
+
|
23
|
+
autoload :V0
|
24
|
+
|
25
|
+
switch_on XDR::Int, :v
|
26
|
+
|
27
|
+
switch 0, :v0
|
28
|
+
|
29
|
+
attribute :v0, V0
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# This code was automatically generated using xdrgen
|
2
|
+
# DO NOT EDIT or your changes may be overwritten
|
3
|
+
|
4
|
+
require 'xdr'
|
5
|
+
|
6
|
+
# === xdr source ============================================================
|
7
|
+
#
|
8
|
+
# struct
|
9
|
+
# {
|
10
|
+
# LedgerEntryChanges changes;
|
11
|
+
# OperationMeta operations<>;
|
12
|
+
# }
|
13
|
+
#
|
14
|
+
# ===========================================================================
|
15
|
+
module Stellar
|
16
|
+
class TransactionMeta
|
17
|
+
class V0 < XDR::Struct
|
18
|
+
attribute :changes, LedgerEntryChanges
|
19
|
+
attribute :operations, XDR::VarArray[OperationMeta]
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# This code was automatically generated using xdrgen
|
2
|
+
# DO NOT EDIT or your changes may be overwritten
|
3
|
+
|
4
|
+
require 'xdr'
|
5
|
+
|
6
|
+
# === xdr source ============================================================
|
7
|
+
#
|
8
|
+
# struct TransactionResult
|
9
|
+
# {
|
10
|
+
# int64 feeCharged; // actual fee charged for the transaction
|
11
|
+
#
|
12
|
+
# union switch (TransactionResultCode code)
|
13
|
+
# {
|
14
|
+
# case txSUCCESS:
|
15
|
+
# case txFAILED:
|
16
|
+
# OperationResult results<>;
|
17
|
+
# default:
|
18
|
+
# void;
|
19
|
+
# }
|
20
|
+
# result;
|
21
|
+
#
|
22
|
+
# // reserved for future use
|
23
|
+
# union switch (int v)
|
24
|
+
# {
|
25
|
+
# case 0:
|
26
|
+
# void;
|
27
|
+
# }
|
28
|
+
# ext;
|
29
|
+
# };
|
30
|
+
#
|
31
|
+
# ===========================================================================
|
32
|
+
module Stellar
|
33
|
+
class TransactionResult < XDR::Struct
|
34
|
+
include XDR::Namespace
|
35
|
+
|
36
|
+
autoload :Result
|
37
|
+
autoload :Ext
|
38
|
+
|
39
|
+
attribute :fee_charged, Int64
|
40
|
+
attribute :result, Result
|
41
|
+
attribute :ext, Ext
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# This code was automatically generated using xdrgen
|
2
|
+
# DO NOT EDIT or your changes may be overwritten
|
3
|
+
|
4
|
+
require 'xdr'
|
5
|
+
|
6
|
+
# === xdr source ============================================================
|
7
|
+
#
|
8
|
+
# union switch (int v)
|
9
|
+
# {
|
10
|
+
# case 0:
|
11
|
+
# void;
|
12
|
+
# }
|
13
|
+
#
|
14
|
+
# ===========================================================================
|
15
|
+
module Stellar
|
16
|
+
class TransactionResult
|
17
|
+
class Ext < XDR::Union
|
18
|
+
switch_on XDR::Int, :v
|
19
|
+
|
20
|
+
switch 0
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# This code was automatically generated using xdrgen
|
2
|
+
# DO NOT EDIT or your changes may be overwritten
|
3
|
+
|
4
|
+
require 'xdr'
|
5
|
+
|
6
|
+
# === xdr source ============================================================
|
7
|
+
#
|
8
|
+
# union switch (TransactionResultCode code)
|
9
|
+
# {
|
10
|
+
# case txSUCCESS:
|
11
|
+
# case txFAILED:
|
12
|
+
# OperationResult results<>;
|
13
|
+
# default:
|
14
|
+
# void;
|
15
|
+
# }
|
16
|
+
#
|
17
|
+
# ===========================================================================
|
18
|
+
module Stellar
|
19
|
+
class TransactionResult
|
20
|
+
class Result < XDR::Union
|
21
|
+
switch_on TransactionResultCode, :code
|
22
|
+
|
23
|
+
switch :tx_success, :results
|
24
|
+
switch :tx_failed, :results
|
25
|
+
switch :default
|
26
|
+
|
27
|
+
attribute :results, XDR::VarArray[OperationResult]
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# This code was automatically generated using xdrgen
|
2
|
+
# DO NOT EDIT or your changes may be overwritten
|
3
|
+
|
4
|
+
require 'xdr'
|
5
|
+
|
6
|
+
# === xdr source ============================================================
|
7
|
+
#
|
8
|
+
# enum TransactionResultCode
|
9
|
+
# {
|
10
|
+
# txSUCCESS = 0, // all operations succeeded
|
11
|
+
#
|
12
|
+
# txFAILED = -1, // one of the operations failed (none were applied)
|
13
|
+
#
|
14
|
+
# txTOO_EARLY = -2, // ledger closeTime before minTime
|
15
|
+
# txTOO_LATE = -3, // ledger closeTime after maxTime
|
16
|
+
# txMISSING_OPERATION = -4, // no operation was specified
|
17
|
+
# txBAD_SEQ = -5, // sequence number does not match source account
|
18
|
+
#
|
19
|
+
# txBAD_AUTH = -6, // not enough signatures to perform transaction
|
20
|
+
# txINSUFFICIENT_BALANCE = -7, // fee would bring account below reserve
|
21
|
+
# txNO_ACCOUNT = -8, // source account not found
|
22
|
+
# txINSUFFICIENT_FEE = -9, // fee is too small
|
23
|
+
# txBAD_AUTH_EXTRA = -10, // too many signatures on transaction
|
24
|
+
# txINTERNAL_ERROR = -11 // an unknown error occured
|
25
|
+
# };
|
26
|
+
#
|
27
|
+
# ===========================================================================
|
28
|
+
module Stellar
|
29
|
+
class TransactionResultCode < XDR::Enum
|
30
|
+
member :tx_success, 0
|
31
|
+
member :tx_failed, -1
|
32
|
+
member :tx_too_early, -2
|
33
|
+
member :tx_too_late, -3
|
34
|
+
member :tx_missing_operation, -4
|
35
|
+
member :tx_bad_seq, -5
|
36
|
+
member :tx_bad_auth, -6
|
37
|
+
member :tx_insufficient_balance, -7
|
38
|
+
member :tx_no_account, -8
|
39
|
+
member :tx_insufficient_fee, -9
|
40
|
+
member :tx_bad_auth_extra, -10
|
41
|
+
member :tx_internal_error, -11
|
42
|
+
|
43
|
+
seal
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# This code was automatically generated using xdrgen
|
2
|
+
# DO NOT EDIT or your changes may be overwritten
|
3
|
+
|
4
|
+
require 'xdr'
|
5
|
+
|
6
|
+
# === xdr source ============================================================
|
7
|
+
#
|
8
|
+
# struct TransactionResultPair
|
9
|
+
# {
|
10
|
+
# Hash transactionHash;
|
11
|
+
# TransactionResult result; // result for the transaction
|
12
|
+
# };
|
13
|
+
#
|
14
|
+
# ===========================================================================
|
15
|
+
module Stellar
|
16
|
+
class TransactionResultPair < XDR::Struct
|
17
|
+
attribute :transaction_hash, Hash
|
18
|
+
attribute :result, TransactionResult
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# This code was automatically generated using xdrgen
|
2
|
+
# DO NOT EDIT or your changes may be overwritten
|
3
|
+
|
4
|
+
require 'xdr'
|
5
|
+
|
6
|
+
# === xdr source ============================================================
|
7
|
+
#
|
8
|
+
# struct TransactionResultSet
|
9
|
+
# {
|
10
|
+
# TransactionResultPair results<MAX_TX_PER_LEDGER>;
|
11
|
+
# };
|
12
|
+
#
|
13
|
+
# ===========================================================================
|
14
|
+
module Stellar
|
15
|
+
class TransactionResultSet < XDR::Struct
|
16
|
+
attribute :results, XDR::VarArray[TransactionResultPair, MAX_TX_PER_LEDGER]
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# This code was automatically generated using xdrgen
|
2
|
+
# DO NOT EDIT or your changes may be overwritten
|
3
|
+
|
4
|
+
require 'xdr'
|
5
|
+
|
6
|
+
# === xdr source ============================================================
|
7
|
+
#
|
8
|
+
# struct TransactionSet
|
9
|
+
# {
|
10
|
+
# Hash previousLedgerHash;
|
11
|
+
# TransactionEnvelope txs<MAX_TX_PER_LEDGER>;
|
12
|
+
# };
|
13
|
+
#
|
14
|
+
# ===========================================================================
|
15
|
+
module Stellar
|
16
|
+
class TransactionSet < XDR::Struct
|
17
|
+
attribute :previous_ledger_hash, Hash
|
18
|
+
attribute :txs, XDR::VarArray[TransactionEnvelope, MAX_TX_PER_LEDGER]
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# This code was automatically generated using xdrgen
|
2
|
+
# DO NOT EDIT or your changes may be overwritten
|
3
|
+
|
4
|
+
require 'xdr'
|
5
|
+
|
6
|
+
# === xdr source ============================================================
|
7
|
+
#
|
8
|
+
# struct TrustLineEntry
|
9
|
+
# {
|
10
|
+
# AccountID accountID; // account this trustline belongs to
|
11
|
+
# Asset asset; // type of asset (with issuer)
|
12
|
+
# int64 balance; // how much of this asset the user has.
|
13
|
+
# // Asset defines the unit for this;
|
14
|
+
#
|
15
|
+
# int64 limit; // balance cannot be above this
|
16
|
+
# uint32 flags; // see TrustLineFlags
|
17
|
+
#
|
18
|
+
# // reserved for future use
|
19
|
+
# union switch (int v)
|
20
|
+
# {
|
21
|
+
# case 0:
|
22
|
+
# void;
|
23
|
+
# }
|
24
|
+
# ext;
|
25
|
+
# };
|
26
|
+
#
|
27
|
+
# ===========================================================================
|
28
|
+
module Stellar
|
29
|
+
class TrustLineEntry < XDR::Struct
|
30
|
+
include XDR::Namespace
|
31
|
+
|
32
|
+
autoload :Ext
|
33
|
+
|
34
|
+
attribute :account_id, AccountID
|
35
|
+
attribute :asset, Asset
|
36
|
+
attribute :balance, Int64
|
37
|
+
attribute :limit, Int64
|
38
|
+
attribute :flags, Uint32
|
39
|
+
attribute :ext, Ext
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# This code was automatically generated using xdrgen
|
2
|
+
# DO NOT EDIT or your changes may be overwritten
|
3
|
+
|
4
|
+
require 'xdr'
|
5
|
+
|
6
|
+
# === xdr source ============================================================
|
7
|
+
#
|
8
|
+
# union switch (int v)
|
9
|
+
# {
|
10
|
+
# case 0:
|
11
|
+
# void;
|
12
|
+
# }
|
13
|
+
#
|
14
|
+
# ===========================================================================
|
15
|
+
module Stellar
|
16
|
+
class TrustLineEntry
|
17
|
+
class Ext < XDR::Union
|
18
|
+
switch_on XDR::Int, :v
|
19
|
+
|
20
|
+
switch 0
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# This code was automatically generated using xdrgen
|
2
|
+
# DO NOT EDIT or your changes may be overwritten
|
3
|
+
|
4
|
+
require 'xdr'
|
5
|
+
|
6
|
+
# === xdr source ============================================================
|
7
|
+
#
|
8
|
+
# enum TrustLineFlags
|
9
|
+
# {
|
10
|
+
# // issuer has authorized account to perform transactions with its credit
|
11
|
+
# AUTHORIZED_FLAG = 1
|
12
|
+
# };
|
13
|
+
#
|
14
|
+
# ===========================================================================
|
15
|
+
module Stellar
|
16
|
+
class TrustLineFlags < XDR::Enum
|
17
|
+
member :authorized_flag, 1
|
18
|
+
|
19
|
+
seal
|
20
|
+
end
|
21
|
+
end
|
data/lib/stellar-base.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'xdr'
|
2
|
+
require 'rbnacl/libsodium'
|
3
|
+
require 'digest/sha2'
|
4
|
+
require 'active_support/core_ext/object/blank'
|
5
|
+
require 'active_support/core_ext/enumerable'
|
6
|
+
require 'active_support/core_ext/kernel/reporting'
|
7
|
+
|
8
|
+
# See ../generated for code-gen'ed files
|
9
|
+
|
10
|
+
silence_warnings do
|
11
|
+
require 'stellar-base-generated'
|
12
|
+
end
|
13
|
+
Stellar.load_all!
|
14
|
+
|
15
|
+
Stellar::ONE = 1_0000000
|
16
|
+
|
17
|
+
|
18
|
+
# extensions onto the generated files must be loaded manually, below
|
19
|
+
|
20
|
+
require_relative './stellar/account_flags'
|
21
|
+
require_relative './stellar/asset'
|
22
|
+
require_relative './stellar/key_pair'
|
23
|
+
require_relative './stellar/operation'
|
24
|
+
require_relative './stellar/path_payment_result'
|
25
|
+
require_relative './stellar/price'
|
26
|
+
require_relative './stellar/thresholds'
|
27
|
+
require_relative './stellar/transaction'
|
28
|
+
require_relative './stellar/transaction_envelope'
|
29
|
+
require_relative './stellar/util/strkey'
|
30
|
+
require_relative './stellar/util/continued_fraction'
|
31
|
+
require_relative './stellar/convert'
|
32
|
+
require_relative './stellar/networks'
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Stellar
|
2
|
+
class AccountFlags
|
3
|
+
|
4
|
+
|
5
|
+
#
|
6
|
+
# Converts an array of Stellar::AccountFlags members into
|
7
|
+
# an Integer suitable for use in a SetOptionsOp.
|
8
|
+
#
|
9
|
+
# @param flags=nil [Array<Stellar::AccountFlags>] the flags to combine
|
10
|
+
#
|
11
|
+
# @return [Fixnum] the combined result
|
12
|
+
def self.make_mask(flags=nil)
|
13
|
+
flags ||= []
|
14
|
+
|
15
|
+
flags.map(&:value).inject(&:|) || 0
|
16
|
+
end
|
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.values.select{|m| (m.value & combined) != 0}
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
module Stellar
|
2
|
+
class Asset
|
3
|
+
def self.native
|
4
|
+
new(:asset_type_native)
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.alphanum4(code, issuer)
|
8
|
+
raise ArgumentError, "Bad :issuer" unless issuer.is_a?(KeyPair)
|
9
|
+
code = normalize_code(code, 4)
|
10
|
+
an = AlphaNum4.new({asset_code:code, issuer:issuer.account_id})
|
11
|
+
new(:asset_type_credit_alphanum4, an)
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.alphanum12(code, issuer)
|
15
|
+
raise ArgumentError, "Bad :issuer" unless issuer.is_a?(KeyPair)
|
16
|
+
code = normalize_code(code, 12)
|
17
|
+
an = AlphaNum12.new({asset_code:code, issuer:issuer.account_id})
|
18
|
+
new(:asset_type_credit_alphanum12, an)
|
19
|
+
end
|
20
|
+
|
21
|
+
def to_s
|
22
|
+
case switch
|
23
|
+
when AssetType.asset_type_native
|
24
|
+
"native"
|
25
|
+
when AssetType.asset_type_credit_alphanum4
|
26
|
+
anum = alpha_num4!
|
27
|
+
issuer_address = Stellar::Convert.pk_to_address(anum.issuer)
|
28
|
+
"#{anum.asset_code}/#{issuer_address}"
|
29
|
+
when AssetType.asset_type_credit_alphanum12
|
30
|
+
anum = alpha_num12!
|
31
|
+
issuer_address = Stellar::Convert.pk_to_address(anum.issuer)
|
32
|
+
"#{anum.asset_code}/#{issuer_address}"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def inspect
|
37
|
+
label = switch.to_s
|
38
|
+
"#<Stellar::Asset #{to_s}>"
|
39
|
+
end
|
40
|
+
|
41
|
+
def code
|
42
|
+
case switch
|
43
|
+
when AssetType.asset_type_credit_alphanum4
|
44
|
+
alpha_num4!.asset_code
|
45
|
+
when AssetType.asset_type_credit_alphanum12
|
46
|
+
alpha_num12!.asset_code
|
47
|
+
else
|
48
|
+
raise "#{switch} assets do not have a code"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def issuer
|
53
|
+
case switch
|
54
|
+
when AssetType.asset_type_credit_alphanum4
|
55
|
+
alpha_num4!.issuer
|
56
|
+
when AssetType.asset_type_credit_alphanum12
|
57
|
+
alpha_num12!.issuer
|
58
|
+
else
|
59
|
+
raise "#{switch} assets do not have a isuuer"
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def self.normalize_code(code, length)
|
64
|
+
raise ArgumentError, "Invalid asset code: #{code}, must be <= #{length} bytes" if code.length > length
|
65
|
+
|
66
|
+
code.ljust(length, "\x00")
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|