Module: Stellar::DSL
- Included in:
- Stellar, LedgerKey, Operation, TransactionBuilder
- Defined in:
- lib/stellar/dsl.rb
Class Method Summary collapse
- .Account(subject = nil) ⇒ Object
-
.Asset(subject = nil) ⇒ Stellar::Asset
Instance of the Stellar::Asset.
- .Claimant(destination, &block) ⇒ Object
-
.ClaimPredicate(&block) ⇒ Object
Constructs a new ClaimPredicate using DSL.
-
.KeyPair(subject = nil) ⇒ Stellar::Keypair
Generates Stellar::Keypair from subject, use Stellar::Client.to_keypair as shortcut.
-
.SignerKey(input = nil) ⇒ Stellar::SignerKey
Provides conversion from different input types into the SignerKey to use in ManageData operation.
Class Method Details
.Account(subject = nil) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/stellar/dsl.rb', line 30 def Account(subject = nil) case subject when Account subject when /^M[A-Z0-9]{68}$/ Account.from_address(subject.to_str) when nil Account.random else begin keypair = KeyPair(subject) Account.new(keypair) rescue TypeError raise TypeError, "Cannot convert #{subject.inspect} to Stellar::Account" end end end |
.Asset(subject = nil) ⇒ Stellar::Asset
Returns instance of the Stellar::Asset.
52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/stellar/dsl.rb', line 52 def Asset(subject = nil) case subject when Asset subject when nil, /^(XLM[-:])?native$/ Asset.native when /^([0-9A-Z]{1,4})[-:](G[A-Z0-9]{55})$/ Asset.alphanum4($1, KeyPair($2)) when /^([0-9A-Z]{5,12})[-:](G[A-Z0-9]{55})$/ Asset.alphanum12($1, KeyPair($2)) else raise TypeError, "Cannot convert #{subject.inspect} to Stellar::Asset" end end |
.Claimant(destination, &block) ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'lib/stellar/dsl.rb', line 20 def Claimant(destination, &block) Claimant.new( ClaimantType.claimant_type_v0, Claimant::V0.new( destination: KeyPair(destination).account_id, predicate: ClaimPredicate(&block) ) ) end |
.ClaimPredicate(&block) ⇒ Object
Constructs a new ClaimPredicate using DSL
15 16 17 18 |
# File 'lib/stellar/dsl.rb', line 15 def ClaimPredicate(&block) return ClaimPredicate.unconditional unless block ClaimPredicate.compose(&block) end |
.KeyPair(subject = nil) ⇒ Stellar::Keypair
Generates Stellar::Keypair from subject, use Stellar::Client.to_keypair as shortcut.
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/stellar/dsl.rb', line 71 def KeyPair(subject = nil) case subject when ->(subj) { subj.respond_to?(:to_keypair) } subject.to_keypair when PublicKey KeyPair.from_public_key(subject.value) when SignerKey KeyPair.from_raw_seed(subject.value) when /^G[A-Z0-9]{55}$/ KeyPair.from_address(subject.to_str) when /^S[A-Z0-9]{55}$/ KeyPair.from_seed(subject.to_str) when /^.{32}$/ KeyPair.from_raw_seed(subject.to_str) when nil KeyPair.random else raise TypeError, "cannot convert #{subject.inspect} to Stellar::KeyPair" end end |
.SignerKey(input = nil) ⇒ Stellar::SignerKey
Provides conversion from different input types into the SignerKey to use in ManageData operation.
95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/stellar/dsl.rb', line 95 def SignerKey(input = nil) case input when Transaction SignerKey.pre_auth_tx(input.hash) when /^[0-9A-Za-z+\/=]{44}$/ SignerKey.hash_x(Stellar::Convert.from_base64(input)) when /^[0-9a-f]{64}$/ SignerKey.hash_x(Stellar::Convert.from_hex(input)) when /^.{32}$/ SignerKey.hash_x(input) else SignerKey.ed25519(KeyPair(input)) end end |